Search in sources :

Example 1 with ResolvedPeak

use of net.sf.mzmine.modules.peaklistmethods.peakpicking.deconvolution.ResolvedPeak in project mzmine2 by mzmine.

the class MinimumSearchPeakDetector method resolvePeaks.

@Override
public ResolvedPeak[] resolvePeaks(final Feature chromatogram, ParameterSet parameters, RSessionWrapper rSession, CenterFunction mzCenterFunction, double msmsRange, double rTRangeMSMS) {
    int[] scanNumbers = chromatogram.getScanNumbers();
    final int scanCount = scanNumbers.length;
    double[] retentionTimes = new double[scanCount];
    double[] intensities = new double[scanCount];
    RawDataFile dataFile = chromatogram.getDataFile();
    for (int i = 0; i < scanCount; i++) {
        final int scanNum = scanNumbers[i];
        retentionTimes[i] = dataFile.getScan(scanNum).getRetentionTime();
        DataPoint dp = chromatogram.getDataPoint(scanNum);
        if (dp != null)
            intensities[i] = dp.getIntensity();
        else
            intensities[i] = 0.0;
    }
    final int lastScan = scanCount - 1;
    assert scanCount > 0;
    final Range<Double> peakDuration = parameters.getParameter(PEAK_DURATION).getValue();
    final double searchRTRange = parameters.getParameter(SEARCH_RT_RANGE).getValue();
    final double minRatio = parameters.getParameter(MIN_RATIO).getValue();
    final double minHeight = Math.max(parameters.getParameter(MIN_ABSOLUTE_HEIGHT).getValue(), parameters.getParameter(MIN_RELATIVE_HEIGHT).getValue() * chromatogram.getHeight());
    final List<ResolvedPeak> resolvedPeaks = new ArrayList<ResolvedPeak>();
    // First, remove all data points below chromatographic threshold.
    final double chromatographicThresholdLevel = MathUtils.calcQuantile(intensities, parameters.getParameter(CHROMATOGRAPHIC_THRESHOLD_LEVEL).getValue());
    for (int i = 0; i < intensities.length; i++) {
        if (intensities[i] < chromatographicThresholdLevel) {
            intensities[i] = 0.0;
        }
    }
    // candidate for a resolved peak.
    startSearch: for (int currentRegionStart = 0; currentRegionStart < lastScan - 2; currentRegionStart++) {
        // Find at least two consecutive non-zero data points
        if (intensities[currentRegionStart] == 0.0 || intensities[currentRegionStart + 1] == 0.0)
            continue;
        double currentRegionHeight = intensities[currentRegionStart];
        endSearch: for (int currentRegionEnd = currentRegionStart + 1; currentRegionEnd < scanCount; currentRegionEnd++) {
            // Update height of current region.
            currentRegionHeight = Math.max(currentRegionHeight, intensities[currentRegionEnd]);
            // have to stop here.
            if (currentRegionEnd == lastScan || intensities[currentRegionEnd + 1] == 0.0) {
                // Find the intensity at the sides (lowest data points).
                final double peakMinLeft = intensities[currentRegionStart];
                final double peakMinRight = intensities[currentRegionEnd];
                // Check the shape of the peak.
                if (currentRegionHeight >= minHeight && currentRegionHeight >= peakMinLeft * minRatio && currentRegionHeight >= peakMinRight * minRatio && peakDuration.contains(retentionTimes[currentRegionEnd] - retentionTimes[currentRegionStart])) {
                    resolvedPeaks.add(new ResolvedPeak(chromatogram, currentRegionStart, currentRegionEnd, mzCenterFunction, msmsRange, rTRangeMSMS));
                }
                // Set the next region start to current region end - 1
                // because it will be immediately
                // increased +1 as we continue the for-cycle.
                currentRegionStart = currentRegionEnd - 1;
                continue startSearch;
            }
            // Minimum duration of peak must be at least searchRTRange.
            if (retentionTimes[currentRegionEnd] - retentionTimes[currentRegionStart] >= searchRTRange) {
                // Set the RT range to check
                final Range<Double> checkRange = Range.closed(retentionTimes[currentRegionEnd] - searchRTRange, retentionTimes[currentRegionEnd] + searchRTRange);
                // current peak i.
                for (int i = currentRegionEnd - 1; i > 0; i--) {
                    if (!checkRange.contains(retentionTimes[i]))
                        break;
                    if (intensities[i] < intensities[currentRegionEnd]) {
                        continue endSearch;
                    }
                }
                // Search on the right from current peak i.
                for (int i = currentRegionEnd + 1; i < scanCount; i++) {
                    if (!checkRange.contains(retentionTimes[i]))
                        break;
                    if (intensities[i] < intensities[currentRegionEnd]) {
                        continue endSearch;
                    }
                }
                // Find the intensity at the sides (lowest data points).
                final double peakMinLeft = intensities[currentRegionStart];
                final double peakMinRight = intensities[currentRegionEnd];
                // ratio condition, continue searching for next minimum.
                if (currentRegionHeight >= peakMinRight * minRatio) {
                    // Check the shape of the peak.
                    if (currentRegionHeight >= minHeight && currentRegionHeight >= peakMinLeft * minRatio && currentRegionHeight >= peakMinRight * minRatio && peakDuration.contains(retentionTimes[currentRegionEnd] - retentionTimes[currentRegionStart])) {
                        resolvedPeaks.add(new ResolvedPeak(chromatogram, currentRegionStart, currentRegionEnd, mzCenterFunction, msmsRange, rTRangeMSMS));
                    }
                    // Set the next region start to current region end-1
                    // because it will be immediately
                    // increased +1 as we continue the for-cycle.
                    currentRegionStart = currentRegionEnd - 1;
                    continue startSearch;
                }
            }
        }
    }
    return resolvedPeaks.toArray(new ResolvedPeak[resolvedPeaks.size()]);
}
Also used : RawDataFile(net.sf.mzmine.datamodel.RawDataFile) DataPoint(net.sf.mzmine.datamodel.DataPoint) ArrayList(java.util.ArrayList) ResolvedPeak(net.sf.mzmine.modules.peaklistmethods.peakpicking.deconvolution.ResolvedPeak) DataPoint(net.sf.mzmine.datamodel.DataPoint)

Example 2 with ResolvedPeak

use of net.sf.mzmine.modules.peaklistmethods.peakpicking.deconvolution.ResolvedPeak in project mzmine2 by mzmine.

the class ADAPDetector method resolvePeaks.

@Override
public ResolvedPeak[] resolvePeaks(final Feature chromatogram, final ParameterSet parameters, RSessionWrapper rSession, CenterFunction mzCenterFunction, double msmsRange, double rTRangeMSMS) throws RSessionWrapperException {
    int[] scanNumbers = chromatogram.getScanNumbers();
    final int scanCount = scanNumbers.length;
    double[] retentionTimes = new double[scanCount];
    double[] intensities = new double[scanCount];
    RawDataFile dataFile = chromatogram.getDataFile();
    for (int i = 0; i < scanCount; i++) {
        final int scanNum = scanNumbers[i];
        retentionTimes[i] = dataFile.getScan(scanNum).getRetentionTime();
        DataPoint dp = chromatogram.getDataPoint(scanNum);
        if (dp != null)
            intensities[i] = dp.getIntensity();
        else
            intensities[i] = 0.0;
    }
    // List<PeakInfo> ADAPPeaks = new ArrayList<PeakInfo>();
    List<PeakInfo> ADAPPeaks = null;
    Range<Double> peakDuration = parameters.getParameter(PEAK_DURATION).getValue();
    final MZmineProcessingStep<SNEstimatorChoice> signalNoiseEstimator = parameters.getParameter(SN_ESTIMATORS).getValue();
    String SNCode = signalNoiseEstimator.getModule().getSNCode();
    double signalNoiseWindowMult = -1.0;
    boolean absWavCoeffs = false;
    Map<String, Object> informationSN = new HashMap<String, Object>();
    if (SNCode == "Wavelet Coefficient Estimator") {
        informationSN.put("code", "Wavelet Coefficient Estimator");
        signalNoiseWindowMult = signalNoiseEstimator.getParameterSet().getParameter(HALF_WAVELET_WINDOW).getValue();
        absWavCoeffs = signalNoiseEstimator.getParameterSet().getParameter(ABS_WAV_COEFFS).getValue();
        informationSN.put("multiplier", signalNoiseWindowMult);
        informationSN.put("absolutewavecoeffs", absWavCoeffs);
    }
    if (SNCode == "Intensity Window Estimator") {
        informationSN.put("code", "Intensity Window Estimator");
    }
    // get the average rt spacing
    double rtSum = 0.0;
    for (int i = 0; i < retentionTimes.length - 1; i++) {
        rtSum += retentionTimes[i + 1] - retentionTimes[i];
    }
    double avgRTInterval = rtSum / (retentionTimes.length - 1);
    // Change the lower and uper bounds for the wavelet scales from retention times to number of
    // scans.
    Range<Double> rtRangeForCWTScales = parameters.getParameter(RT_FOR_CWT_SCALES_DURATION).getValue();
    double rtLow = rtRangeForCWTScales.lowerEndpoint();
    double rtHigh = rtRangeForCWTScales.upperEndpoint();
    int numScansRTLow = (int) Math.round(rtLow / avgRTInterval);
    int numScansRTHigh = (int) Math.round(rtHigh / avgRTInterval);
    if (numScansRTLow < 1) {
        numScansRTLow = 1;
    }
    if (numScansRTHigh >= retentionTimes.length) {
        numScansRTHigh = retentionTimes.length;
    }
    ADAPPeaks = DeconvoluteSignal(retentionTimes, intensities, chromatogram.getMZ(), parameters.getParameter(SN_THRESHOLD).getValue(), parameters.getParameter(MIN_FEAT_HEIGHT).getValue(), peakDuration, parameters.getParameter(COEF_AREA_THRESHOLD).getValue(), numScansRTLow, numScansRTHigh, informationSN);
    final List<ResolvedPeak> resolvedPeaks;
    if (ADAPPeaks == null) {
        resolvedPeaks = new ArrayList<ResolvedPeak>(0);
    } else {
        // Process peak matrix.
        resolvedPeaks = new ArrayList<ResolvedPeak>(ADAPPeaks.size());
        // for (final double[] peakRow : peakMatrix) {
        for (int i = 0; i < ADAPPeaks.size(); i++) {
            PeakInfo curPeak = ADAPPeaks.get(i);
            SimplePeakInformation information = new SimplePeakInformation();
            information.addProperty("Signal-to-Noise", Double.toString(curPeak.signalToNoiseRatio));
            information.addProperty("Coefficient-over-area", Double.toString(curPeak.coeffOverArea));
            // information.addProperty("index",
            // //Integer.toString(scans[(int) peakIndex[j] - 1])); // Substract one because r-indices
            // start from 1
            // Integer.toString((int) curPeak.peakIndex));
            // information.addProperty("sharpness",
            // Double.toString(curPeak.sharpness));
            // information.addProperty("signalToNoiseRatio",
            // Double.toString(curPeak.signalToNoiseRatio));
            // information.addProperty("isShared",
            // Boolean.toString(curPeak.isShared));
            // //Boolean.toString(1.0 == curPeak.isShared));
            // information.addProperty("offset",
            // Integer.toString((int) curPeak.offset));
            ResolvedPeak peak = new ResolvedPeak(chromatogram, curPeak.leftApexIndex, curPeak.rightApexIndex, mzCenterFunction, msmsRange, rTRangeMSMS);
            peak.setPeakInformation(information);
            resolvedPeaks.add(peak);
        // resolvedPeaks.add(new ResolvedPeak(chromatogram,curPeak.leftApexIndex,
        // curPeak.rightApexIndex));
        }
    }
    return resolvedPeaks.toArray(new ResolvedPeak[resolvedPeaks.size()]);
}
Also used : HashMap(java.util.HashMap) PeakInfo(dulab.adap.datamodel.PeakInfo) DataPoint(net.sf.mzmine.datamodel.DataPoint) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) DataPoint(net.sf.mzmine.datamodel.DataPoint) ResolvedPeak(net.sf.mzmine.modules.peaklistmethods.peakpicking.deconvolution.ResolvedPeak) SimplePeakInformation(net.sf.mzmine.datamodel.impl.SimplePeakInformation)

Example 3 with ResolvedPeak

use of net.sf.mzmine.modules.peaklistmethods.peakpicking.deconvolution.ResolvedPeak in project mzmine2 by mzmine.

the class BaselinePeakDetector method resolvePeaks.

@Override
public ResolvedPeak[] resolvePeaks(final Feature chromatogram, ParameterSet parameters, RSessionWrapper rSession, CenterFunction mzCenterFunction, double msmsRange, double rTRangeMSMS) {
    int[] scanNumbers = chromatogram.getScanNumbers();
    final int scanCount = scanNumbers.length;
    double[] retentionTimes = new double[scanCount];
    double[] intensities = new double[scanCount];
    RawDataFile dataFile = chromatogram.getDataFile();
    for (int i = 0; i < scanCount; i++) {
        final int scanNum = scanNumbers[i];
        retentionTimes[i] = dataFile.getScan(scanNum).getRetentionTime();
        DataPoint dp = chromatogram.getDataPoint(scanNum);
        if (dp != null)
            intensities[i] = dp.getIntensity();
        else
            intensities[i] = 0.0;
    }
    // Get parameters.
    final double minimumPeakHeight = parameters.getParameter(MIN_PEAK_HEIGHT).getValue();
    final double baselineLevel = parameters.getParameter(BASELINE_LEVEL).getValue();
    final Range<Double> durationRange = parameters.getParameter(PEAK_DURATION).getValue();
    final List<ResolvedPeak> resolvedPeaks = new ArrayList<ResolvedPeak>(2);
    // intensity above baseline level.
    for (int currentRegionStart = 0; currentRegionStart < scanCount; currentRegionStart++) {
        // Find a start of the region.
        final DataPoint startPeak = chromatogram.getDataPoint(scanNumbers[currentRegionStart]);
        if (startPeak != null && startPeak.getIntensity() >= baselineLevel) {
            double currentRegionHeight = startPeak.getIntensity();
            // Search for end of the region
            int currentRegionEnd;
            for (currentRegionEnd = currentRegionStart + 1; currentRegionEnd < scanCount; currentRegionEnd++) {
                final DataPoint endPeak = chromatogram.getDataPoint(scanNumbers[currentRegionEnd]);
                if (endPeak == null || endPeak.getIntensity() < baselineLevel) {
                    break;
                }
                currentRegionHeight = Math.max(currentRegionHeight, endPeak.getIntensity());
            }
            // Subtract one index, so the end index points at the last data
            // point of current region.
            currentRegionEnd--;
            // Check current region, if it makes a good peak.
            if (durationRange.contains(retentionTimes[currentRegionEnd] - retentionTimes[currentRegionStart]) && currentRegionHeight >= minimumPeakHeight) {
                // Create a new ResolvedPeak and add it.
                resolvedPeaks.add(new ResolvedPeak(chromatogram, currentRegionStart, currentRegionEnd, mzCenterFunction, msmsRange, rTRangeMSMS));
            }
            // Find next peak region, starting from next data point.
            currentRegionStart = currentRegionEnd;
        }
    }
    return resolvedPeaks.toArray(new ResolvedPeak[resolvedPeaks.size()]);
}
Also used : RawDataFile(net.sf.mzmine.datamodel.RawDataFile) DataPoint(net.sf.mzmine.datamodel.DataPoint) ArrayList(java.util.ArrayList) ResolvedPeak(net.sf.mzmine.modules.peaklistmethods.peakpicking.deconvolution.ResolvedPeak) DataPoint(net.sf.mzmine.datamodel.DataPoint)

Example 4 with ResolvedPeak

use of net.sf.mzmine.modules.peaklistmethods.peakpicking.deconvolution.ResolvedPeak in project mzmine2 by mzmine.

the class CentWaveDetector method resolvePeaks.

@Override
public ResolvedPeak[] resolvePeaks(final Feature chromatogram, final ParameterSet parameters, RSessionWrapper rSession, CenterFunction mzCenterFunction, double msmsRange, double rTRangeMSMS) throws RSessionWrapperException {
    int[] scanNumbers = chromatogram.getScanNumbers();
    final int scanCount = scanNumbers.length;
    double[] retentionTimes = new double[scanCount];
    double[] intensities = new double[scanCount];
    RawDataFile dataFile = chromatogram.getDataFile();
    for (int i = 0; i < scanCount; i++) {
        final int scanNum = scanNumbers[i];
        retentionTimes[i] = dataFile.getScan(scanNum).getRetentionTime();
        DataPoint dp = chromatogram.getDataPoint(scanNum);
        if (dp != null)
            intensities[i] = dp.getIntensity();
        else
            intensities[i] = 0.0;
    }
    // Call findPeaks.centWave.
    double[][] peakMatrix = null;
    peakMatrix = centWave(rSession, retentionTimes, intensities, chromatogram.getMZ(), parameters.getParameter(SN_THRESHOLD).getValue(), parameters.getParameter(PEAK_SCALES).getValue(), parameters.getParameter(INTEGRATION_METHOD).getValue());
    final List<ResolvedPeak> resolvedPeaks;
    if (peakMatrix == null) {
        resolvedPeaks = new ArrayList<ResolvedPeak>(0);
    } else {
        LOG.finest("Processing peak matrix...");
        final Range<Double> peakDuration = parameters.getParameter(PEAK_DURATION).getValue();
        // Process peak matrix.
        resolvedPeaks = new ArrayList<ResolvedPeak>(peakMatrix.length);
        for (final double[] peakRow : peakMatrix) {
            // Get peak start and end.
            final int peakLeft = findRTIndex(retentionTimes, peakRow[4]);
            final int peakRight = findRTIndex(retentionTimes, peakRow[5]);
            // a peak for each.
            for (int start = peakLeft; start < peakRight; start++) {
                if (chromatogram.getDataPoint(scanNumbers[start]) != null) {
                    int end = start;
                    while (end < peakRight && chromatogram.getDataPoint(scanNumbers[end + 1]) != null) {
                        end++;
                    }
                    if ((end > start) && (peakDuration.contains(retentionTimes[end] - retentionTimes[start]))) {
                        resolvedPeaks.add(new ResolvedPeak(chromatogram, start, end, mzCenterFunction, msmsRange, rTRangeMSMS));
                    }
                    start = end;
                }
            }
        }
    }
    return resolvedPeaks.toArray(new ResolvedPeak[resolvedPeaks.size()]);
}
Also used : RawDataFile(net.sf.mzmine.datamodel.RawDataFile) DataPoint(net.sf.mzmine.datamodel.DataPoint) ResolvedPeak(net.sf.mzmine.modules.peaklistmethods.peakpicking.deconvolution.ResolvedPeak) DataPoint(net.sf.mzmine.datamodel.DataPoint)

Example 5 with ResolvedPeak

use of net.sf.mzmine.modules.peaklistmethods.peakpicking.deconvolution.ResolvedPeak in project mzmine2 by mzmine.

the class NoiseAmplitudePeakDetector method resolvePeaks.

@Override
public ResolvedPeak[] resolvePeaks(final Feature chromatogram, ParameterSet parameters, RSessionWrapper rSession, CenterFunction mzCenterFunction, double msmsRange, double rTRangeMSMS) {
    int[] scanNumbers = chromatogram.getScanNumbers();
    final int scanCount = scanNumbers.length;
    double[] retentionTimes = new double[scanCount];
    double[] intensities = new double[scanCount];
    RawDataFile dataFile = chromatogram.getDataFile();
    for (int i = 0; i < scanCount; i++) {
        final int scanNum = scanNumbers[i];
        retentionTimes[i] = dataFile.getScan(scanNum).getRetentionTime();
        DataPoint dp = chromatogram.getDataPoint(scanNum);
        if (dp != null)
            intensities[i] = dp.getIntensity();
        else
            intensities[i] = 0.0;
    }
    final double amplitudeOfNoise = parameters.getParameter(NOISE_AMPLITUDE).getValue();
    // This treeMap stores the score of frequency of intensity ranges
    final TreeMap<Integer, Integer> binsFrequency = new TreeMap<Integer, Integer>();
    double maxIntensity = 0.0;
    double avgIntensity = 0.0;
    for (final double intensity : intensities) {
        addNewIntensity(intensity, binsFrequency, amplitudeOfNoise);
        maxIntensity = Math.max(maxIntensity, intensity);
        avgIntensity += intensity;
    }
    avgIntensity /= scanCount;
    final List<ResolvedPeak> resolvedPeaks = new ArrayList<ResolvedPeak>(2);
    // noise.
    if (avgIntensity <= maxIntensity / 2.0) {
        final double noiseThreshold = getNoiseThreshold(binsFrequency, maxIntensity, amplitudeOfNoise);
        boolean activePeak = false;
        final Range<Double> peakDuration = parameters.getParameter(PEAK_DURATION).getValue();
        final double minimumPeakHeight = parameters.getParameter(MIN_PEAK_HEIGHT).getValue();
        // Index of starting region of the current peak.
        int currentPeakStart = 0;
        for (int i = 0; i < scanCount; i++) {
            if (intensities[i] > noiseThreshold && !activePeak) {
                currentPeakStart = i;
                activePeak = true;
            }
            if (intensities[i] <= noiseThreshold && activePeak) {
                int currentPeakEnd = i;
                // If the last data point is zero, ignore it.
                if (intensities[currentPeakEnd] == 0.0) {
                    currentPeakEnd--;
                }
                if (currentPeakEnd - currentPeakStart > 0) {
                    final ResolvedPeak peak = new ResolvedPeak(chromatogram, currentPeakStart, currentPeakEnd, mzCenterFunction, msmsRange, rTRangeMSMS);
                    if (peakDuration.contains(RangeUtils.rangeLength(peak.getRawDataPointsRTRange())) && peak.getHeight() >= minimumPeakHeight) {
                        resolvedPeaks.add(peak);
                    }
                }
                activePeak = false;
            }
        }
    }
    return resolvedPeaks.toArray(new ResolvedPeak[resolvedPeaks.size()]);
}
Also used : ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) DataPoint(net.sf.mzmine.datamodel.DataPoint) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) DataPoint(net.sf.mzmine.datamodel.DataPoint) ResolvedPeak(net.sf.mzmine.modules.peaklistmethods.peakpicking.deconvolution.ResolvedPeak)

Aggregations

DataPoint (net.sf.mzmine.datamodel.DataPoint)6 ResolvedPeak (net.sf.mzmine.modules.peaklistmethods.peakpicking.deconvolution.ResolvedPeak)6 RawDataFile (net.sf.mzmine.datamodel.RawDataFile)5 ArrayList (java.util.ArrayList)4 PeakInfo (dulab.adap.datamodel.PeakInfo)1 HashMap (java.util.HashMap)1 TreeMap (java.util.TreeMap)1 Feature (net.sf.mzmine.datamodel.Feature)1 SimplePeakInformation (net.sf.mzmine.datamodel.impl.SimplePeakInformation)1