Search in sources :

Example 1 with PeakInfo

use of dulab.adap.datamodel.PeakInfo in project mzmine2 by mzmine.

the class ADAP3DecompositionV1_5Task method getPeaks.

/**
 * Convert MZmine PeakList to a list of ADAP Peaks
 *
 * @param peakList MZmine PeakList object
 * @param edgeToHeightThreshold edge-to-height threshold to determine peaks that can be merged
 * @param deltaToHeightThreshold delta-to-height threshold to determine peaks that can be merged
 * @return list of ADAP Peaks
 */
@Nonnull
public static List<Peak> getPeaks(final PeakList peakList, final double edgeToHeightThreshold, final double deltaToHeightThreshold) {
    RawDataFile dataFile = peakList.getRawDataFile(0);
    List<Peak> peaks = new ArrayList<>();
    for (PeakListRow row : peakList.getRows()) {
        Feature peak = row.getBestPeak();
        int[] scanNumbers = peak.getScanNumbers();
        // Build chromatogram
        NavigableMap<Double, Double> chromatogram = new TreeMap<>();
        for (int scanNumber : scanNumbers) {
            DataPoint dataPoint = peak.getDataPoint(scanNumber);
            if (dataPoint != null)
                chromatogram.put(dataFile.getScan(scanNumber).getRetentionTime(), dataPoint.getIntensity());
        }
        if (chromatogram.size() <= 1)
            continue;
        // Fill out PeakInfo
        PeakInfo info = new PeakInfo();
        try {
            // Note: info.peakID is the index of PeakListRow in PeakList.peakListRows (starts from 0)
            // row.getID is row.myID (starts from 1)
            info.peakID = row.getID() - 1;
            double height = -Double.MIN_VALUE;
            for (int scan : scanNumbers) {
                double intensity = peak.getDataPoint(scan).getIntensity();
                if (intensity > height) {
                    height = intensity;
                    info.peakIndex = scan;
                }
            }
            info.leftApexIndex = scanNumbers[0];
            info.rightApexIndex = scanNumbers[scanNumbers.length - 1];
            info.retTime = peak.getRT();
            info.mzValue = peak.getMZ();
            info.intensity = peak.getHeight();
            info.leftPeakIndex = info.leftApexIndex;
            info.rightPeakIndex = info.rightApexIndex;
        } catch (Exception e) {
            LOG.info("Skipping " + row + ": " + e.getMessage());
            continue;
        }
        peaks.add(new Peak(chromatogram, info));
    }
    FeatureTools.correctPeakBoundaries(peaks, edgeToHeightThreshold, deltaToHeightThreshold);
    return peaks;
}
Also used : ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) Feature(net.sf.mzmine.datamodel.Feature) SimpleFeature(net.sf.mzmine.datamodel.impl.SimpleFeature) PeakInfo(dulab.adap.datamodel.PeakInfo) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) IOException(java.io.IOException) SimplePeakListRow(net.sf.mzmine.datamodel.impl.SimplePeakListRow) PeakListRow(net.sf.mzmine.datamodel.PeakListRow) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) Peak(dulab.adap.datamodel.Peak) Nonnull(javax.annotation.Nonnull)

Example 2 with PeakInfo

use of dulab.adap.datamodel.PeakInfo in project mzmine2 by mzmine.

the class ADAP3AlignerTask method getComponent.

/**
 * Convert a {@link PeakListRow} with one {@link Feature} into {@link Component}.
 *
 * @param row an instance of {@link PeakListRow}. This parameter cannot be null.
 * @return an instance of {@link Component} or null if the row doesn't contain any peaks or isotope patterns.
 */
@Nullable
private Component getComponent(final PeakListRow row) {
    if (row.getNumberOfPeaks() == 0)
        return null;
    // Read Spectrum information
    NavigableMap<Double, Double> spectrum = new TreeMap<>();
    IsotopePattern pattern = row.getBestIsotopePattern();
    if (pattern == null)
        throw new IllegalArgumentException("ADAP Alignment requires mass " + "spectra (or isotopic patterns) of peaks. No spectra found.");
    for (DataPoint dataPoint : pattern.getDataPoints()) spectrum.put(dataPoint.getMZ(), dataPoint.getIntensity());
    // Read Chromatogram
    final Feature peak = row.getBestPeak();
    final RawDataFile dataFile = peak.getDataFile();
    NavigableMap<Double, Double> chromatogram = new TreeMap<>();
    for (final int scan : peak.getScanNumbers()) {
        final DataPoint dataPoint = peak.getDataPoint(scan);
        if (dataPoint != null)
            chromatogram.put(dataFile.getScan(scan).getRetentionTime(), dataPoint.getIntensity());
    }
    return new Component(null, new Peak(chromatogram, new PeakInfo().mzValue(peak.getMZ()).peakID(row.getID())), spectrum, null);
}
Also used : DataPoint(net.sf.mzmine.datamodel.DataPoint) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) IsotopePattern(net.sf.mzmine.datamodel.IsotopePattern) Peak(dulab.adap.datamodel.Peak) TreeMap(java.util.TreeMap) Component(dulab.adap.datamodel.Component) ReferenceComponent(dulab.adap.datamodel.ReferenceComponent) Feature(net.sf.mzmine.datamodel.Feature) PeakInfo(dulab.adap.datamodel.PeakInfo) DataPoint(net.sf.mzmine.datamodel.DataPoint) Nullable(javax.annotation.Nullable)

Example 3 with PeakInfo

use of dulab.adap.datamodel.PeakInfo in project mzmine2 by mzmine.

the class ADAP3DecompositionV2Utils method getPeaks.

/**
 * Convert MZmine PeakList to a list of ADAP Peaks
 *
 * @param peakList MZmine PeakList object
 * @return list of ADAP Peaks
 */
@Nonnull
public List<BetterPeak> getPeaks(@Nonnull final PeakList peakList) {
    RawDataFile dataFile = peakList.getRawDataFile(0);
    List<BetterPeak> peaks = new ArrayList<>();
    for (PeakListRow row : peakList.getRows()) {
        Feature peak = row.getBestPeak();
        int[] scanNumbers = peak.getScanNumbers();
        // Build chromatogram
        double[] retTimes = new double[scanNumbers.length];
        double[] intensities = new double[scanNumbers.length];
        for (int i = 0; i < scanNumbers.length; ++i) {
            int scan = scanNumbers[i];
            retTimes[i] = getRetTime(dataFile, scan);
            DataPoint dataPoint = peak.getDataPoint(scan);
            if (dataPoint != null)
                intensities[i] = dataPoint.getIntensity();
        }
        Chromatogram chromatogram = new Chromatogram(retTimes, intensities);
        if (chromatogram.length <= 1)
            continue;
        // Fill out PeakInfo
        PeakInfo info = new PeakInfo();
        try {
            // Note: info.peakID is the index of PeakListRow in PeakList.peakListRows (starts from 0)
            // row.getID is row.myID (starts from 1)
            info.peakID = row.getID() - 1;
            double height = -Double.MIN_VALUE;
            for (int scan : scanNumbers) {
                DataPoint dataPoint = peak.getDataPoint(scan);
                if (dataPoint == null)
                    continue;
                double intensity = dataPoint.getIntensity();
                if (intensity > height) {
                    height = intensity;
                    info.peakIndex = scan;
                }
            }
            info.leftApexIndex = scanNumbers[0];
            info.rightApexIndex = scanNumbers[scanNumbers.length - 1];
            info.retTime = peak.getRT();
            info.mzValue = peak.getMZ();
            info.intensity = peak.getHeight();
            info.leftPeakIndex = info.leftApexIndex;
            info.rightPeakIndex = info.rightApexIndex;
        } catch (Exception e) {
            log.info("Skipping " + row + ": " + e.getMessage());
            continue;
        }
        BetterPeak betterPeak = new BetterPeak(row.getID(), chromatogram, info);
        betterPeak.setParentId(peak.getParentChromatogramRowID());
        peaks.add(betterPeak);
    }
    return peaks;
}
Also used : BetterPeak(dulab.adap.datamodel.BetterPeak) ArrayList(java.util.ArrayList) Chromatogram(dulab.adap.datamodel.Chromatogram) PeakInfo(dulab.adap.datamodel.PeakInfo) Nonnull(javax.annotation.Nonnull)

Example 4 with PeakInfo

use of dulab.adap.datamodel.PeakInfo 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 5 with PeakInfo

use of dulab.adap.datamodel.PeakInfo in project mzmine2 by mzmine.

the class ADAPInterface method getComponent.

public static Component getComponent(final PeakListRow row) {
    if (row.getNumberOfPeaks() == 0)
        throw new IllegalArgumentException("No peaks found");
    NavigableMap<Double, Double> spectrum = new TreeMap<>();
    // Read Spectrum information
    IsotopePattern ip = row.getBestIsotopePattern();
    if (ip != null) {
        for (DataPoint dataPoint : ip.getDataPoints()) spectrum.put(dataPoint.getMZ(), dataPoint.getIntensity());
    }
    // Read Chromatogram
    final Feature peak = row.getBestPeak();
    final RawDataFile dataFile = peak.getDataFile();
    NavigableMap<Double, Double> chromatogram = new TreeMap<>();
    for (final int scan : peak.getScanNumbers()) {
        final DataPoint dataPoint = peak.getDataPoint(scan);
        if (dataPoint != null)
            chromatogram.put(dataFile.getScan(scan).getRetentionTime(), dataPoint.getIntensity());
    }
    return new Component(null, new Peak(chromatogram, new PeakInfo().mzValue(peak.getMZ()).peakID(row.getID())), spectrum, null);
}
Also used : DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) IsotopePattern(net.sf.mzmine.datamodel.IsotopePattern) Peak(dulab.adap.datamodel.Peak) BetterPeak(dulab.adap.datamodel.BetterPeak) TreeMap(java.util.TreeMap) Component(dulab.adap.datamodel.Component) Feature(net.sf.mzmine.datamodel.Feature) SimpleFeature(net.sf.mzmine.datamodel.impl.SimpleFeature) PeakInfo(dulab.adap.datamodel.PeakInfo) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint)

Aggregations

PeakInfo (dulab.adap.datamodel.PeakInfo)5 DataPoint (net.sf.mzmine.datamodel.DataPoint)4 RawDataFile (net.sf.mzmine.datamodel.RawDataFile)4 Peak (dulab.adap.datamodel.Peak)3 TreeMap (java.util.TreeMap)3 Feature (net.sf.mzmine.datamodel.Feature)3 BetterPeak (dulab.adap.datamodel.BetterPeak)2 Component (dulab.adap.datamodel.Component)2 ArrayList (java.util.ArrayList)2 Nonnull (javax.annotation.Nonnull)2 IsotopePattern (net.sf.mzmine.datamodel.IsotopePattern)2 SimpleDataPoint (net.sf.mzmine.datamodel.impl.SimpleDataPoint)2 SimpleFeature (net.sf.mzmine.datamodel.impl.SimpleFeature)2 Chromatogram (dulab.adap.datamodel.Chromatogram)1 ReferenceComponent (dulab.adap.datamodel.ReferenceComponent)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Nullable (javax.annotation.Nullable)1 PeakListRow (net.sf.mzmine.datamodel.PeakListRow)1 SimplePeakInformation (net.sf.mzmine.datamodel.impl.SimplePeakInformation)1