use of net.sf.mzmine.datamodel.DataPoint in project mzmine2 by mzmine.
the class BaselineCorrector method correctBasePeakBaselines.
/**
* Correct the baselines (using base peak chromatograms).
*
* @param origDataFile dataFile of concern.
* @param writer data file writer.
* @param level the MS level.
* @param numBins number of m/z bins.
* @param parameters parameters specific to the actual method for baseline computing.
* @throws IOException if there are i/o problems.
* @throws RSessionWrapperException
* @throws BaselineCorrectionException
* @throws InterruptedException
*/
private void correctBasePeakBaselines(final RSessionWrapper rSession, final RawDataFile origDataFile, final RawDataFileWriter writer, final int level, final int numBins, final ParameterSet parameters) throws IOException, RSessionWrapperException {
// Get scan numbers from original file.
final int[] scanNumbers = origDataFile.getScanNumbers(level);
final int numScans = scanNumbers.length;
// Build chromatograms.
LOG.finest("Building base peak chromatograms.");
final double[][] baseChrom = buildBasePeakChromatograms(origDataFile, level, numBins);
// Calculate baselines: done in-place, i.e. overwrite chromatograms to
// save memory.
LOG.finest("Calculating baselines.");
for (int binIndex = 0; !isAborted(origDataFile) && binIndex < numBins; binIndex++) {
baseChrom[binIndex] = computeBaseline(rSession, origDataFile, baseChrom[binIndex], parameters);
progressMap.get(origDataFile)[0]++;
}
// Subtract baselines.
LOG.finest("Subtracting baselines.");
for (int scanIndex = 0; !isAborted(origDataFile) && scanIndex < numScans; scanIndex++) {
// Get original scan.
final Scan origScan = origDataFile.getScan(scanNumbers[scanIndex]);
// Get data points (m/z and intensity pairs) of the original scan
final DataPoint[] origDataPoints = origScan.getDataPoints();
// Create and write new corrected scan.
final SimpleScan newScan = new SimpleScan(origScan);
newScan.setDataPoints(subtractBasePeakBaselines(origDataFile, origDataPoints, baseChrom, numBins, scanIndex));
writer.addScan(newScan);
progressMap.get(origDataFile)[0]++;
}
}
use of net.sf.mzmine.datamodel.DataPoint in project mzmine2 by mzmine.
the class BaselineCorrector method subtractBasePeakBaselines.
/**
* Perform baseline correction in bins (base peak).
*
* @param origDataFile dataFile of concern.
* @param dataPoints input data points to correct.
* @param baselines the baselines - one per m/z bin.
* @param numBins the number of m/z bins.
* @param scanIndex the current scan index that these data points come from.
* @return the corrected data points.
*/
private DataPoint[] subtractBasePeakBaselines(final RawDataFile origDataFile, final DataPoint[] dataPoints, final double[][] baselines, final int numBins, final int scanIndex) {
// Create an ArrayList for new data points.
final DataPoint[] newDataPoints = new DataPoint[dataPoints.length];
// Determine MZ range.
final Range<Double> mzRange = origDataFile.getDataMZRange();
// Loop through all original data points.
int i = 0;
for (final DataPoint dp : dataPoints) {
// Subtract baseline.
final double mz = dp.getMZ();
final int bin = RangeUtils.binNumber(mzRange, numBins, mz);
final double baselineIntenstity = baselines[bin][scanIndex];
newDataPoints[i++] = baselineIntenstity <= 0.0 ? new SimpleDataPoint(dp) : new SimpleDataPoint(mz, Math.max(0.0, dp.getIntensity() - baselineIntenstity));
}
// Return the new data points.
return newDataPoints;
}
use of net.sf.mzmine.datamodel.DataPoint in project mzmine2 by mzmine.
the class BaselineCorrector method correctTICBaselines.
/**
* Correct the baselines (using TIC chromatograms).
*
* @param origDataFile dataFile of concern.
* @param writer data file writer.
* @param level the MS level.
* @param numBins number of m/z bins.
* @param parameters parameters specific to the actual method for baseline computing.
* @throws IOException if there are i/o problems.
* @throws RSessionWrapperException
* @throws BaselineCorrectionException
*/
private void correctTICBaselines(final RSessionWrapper rSession, final RawDataFile origDataFile, final RawDataFileWriter writer, final int level, final int numBins, final ParameterSet parameters) throws IOException, RSessionWrapperException {
// Get scan numbers from original file.
final int[] scanNumbers = origDataFile.getScanNumbers(level);
final int numScans = scanNumbers.length;
// Build chromatograms.
LOG.finest("Building TIC chromatograms.");
final double[][] baseChrom = buildTICChromatograms(origDataFile, level, numBins);
// Calculate baselines: done in-place, i.e. overwrite chromatograms to
// save memory.
LOG.finest("Calculating baselines.");
for (int binIndex = 0; !isAborted(origDataFile) && binIndex < numBins; binIndex++) {
// Calculate baseline.
// final double[] baseline = asymBaseline(baseChrom[binIndex]);
final double[] baseline = computeBaseline(rSession, origDataFile, baseChrom[binIndex], parameters);
// Normalize the baseline w.r.t. chromatogram (TIC).
for (int scanIndex = 0; !isAborted(origDataFile) && scanIndex < numScans; scanIndex++) {
final double bc = baseChrom[binIndex][scanIndex];
if (bc != 0.0) {
baseChrom[binIndex][scanIndex] = baseline[scanIndex] / bc;
}
}
progressMap.get(origDataFile)[0]++;
}
// Subtract baselines.
LOG.finest("Subtracting baselines.");
for (int scanIndex = 0; !isAborted(origDataFile) && scanIndex < numScans; scanIndex++) {
// Get original scan.
final Scan origScan = origDataFile.getScan(scanNumbers[scanIndex]);
// Get data points (m/z and intensity pairs) of the original scan
final DataPoint[] origDataPoints = origScan.getDataPoints();
// Create and write new corrected scan.
final SimpleScan newScan = new SimpleScan(origScan);
newScan.setDataPoints(subtractTICBaselines(origDataFile, origDataPoints, baseChrom, numBins, scanIndex));
writer.addScan(newScan);
progressMap.get(origDataFile)[0]++;
}
}
use of net.sf.mzmine.datamodel.DataPoint in project mzmine2 by mzmine.
the class BaselineCorrector method copyScansToWriter.
/**
* Copy scans to RawDataFileWriter.
*
* @param origDataFile dataFile of concern.
* @param writer writer to copy scans to.
* @param level MS-level of scans to copy.
* @throws IOException if there are i/o problems.
*/
private void copyScansToWriter(final RawDataFile origDataFile, final RawDataFileWriter writer, final int level) throws IOException {
LOG.finest("Copy scans");
// Get scan numbers for MS-level.
final int[] scanNumbers = origDataFile.getScanNumbers(level);
final int numScans = scanNumbers.length;
// Create copy of scans.
for (int scanIndex = 0; !isAborted(origDataFile) && scanIndex < numScans; scanIndex++) {
// Get original scan.
final Scan origScan = origDataFile.getScan(scanNumbers[scanIndex]);
// Get data points (m/z and intensity pairs) of the original scan
final DataPoint[] origDataPoints = origScan.getDataPoints();
final DataPoint[] newDataPoints = new DataPoint[origDataPoints.length];
// Copy original data points.
int i = 0;
for (final DataPoint dp : origDataPoints) {
newDataPoints[i++] = new SimpleDataPoint(dp);
}
// Create new copied scan.
final SimpleScan newScan = new SimpleScan(origScan);
newScan.setDataPoints(newDataPoints);
writer.addScan(newScan);
progressMap.get(origDataFile)[0]++;
}
}
use of net.sf.mzmine.datamodel.DataPoint in project mzmine2 by mzmine.
the class BaselineCorrector method buildBasePeakChromatograms.
/**
* Constructs base peak (max) chromatograms - one for each m/z bin.
*
* @param origDataFile dataFile of concern.
* @param level the MS level.
* @param numBins number of m/z bins.
* @return the chromatograms as double[number of bins][number of scans].
*/
private double[][] buildBasePeakChromatograms(final RawDataFile origDataFile, final int level, final int numBins) {
// Get scan numbers from original file.
final int[] scanNumbers = origDataFile.getScanNumbers(level);
final int numScans = scanNumbers.length;
// Determine MZ range.
final Range<Double> mzRange = origDataFile.getDataMZRange();
// Create chromatograms.
final double[][] chromatograms = new double[numBins][numScans];
for (int scanIndex = 0; !isAborted(origDataFile) && scanIndex < numScans; scanIndex++) {
// Get original scan.
final Scan scan = origDataFile.getScan(scanNumbers[scanIndex]);
// Process data points.
for (final DataPoint dataPoint : scan.getDataPoints()) {
final int bin = RangeUtils.binNumber(mzRange, numBins, dataPoint.getMZ());
final double value = chromatograms[bin][scanIndex];
chromatograms[bin][scanIndex] = Math.max(value, dataPoint.getIntensity());
}
progressMap.get(origDataFile)[0]++;
}
return chromatograms;
}
Aggregations