Search in sources :

Example 1 with Chromatogram

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

the class ADAPInterface method peakToFeature.

@Nonnull
public static Feature peakToFeature(@Nonnull RawDataFile file, @Nonnull Peak peak) {
    NavigableMap<Double, Double> chromatogram = peak.getChromatogram();
    double[] retTimes = new double[chromatogram.size()];
    double[] intensities = new double[chromatogram.size()];
    int index = 0;
    for (Entry<Double, Double> e : chromatogram.entrySet()) {
        retTimes[index] = e.getKey();
        intensities[index] = e.getValue();
        ++index;
    }
    BetterPeak betterPeak = new BetterPeak(peak.getInfo().peakID, new Chromatogram(retTimes, intensities), peak.getInfo());
    return peakToFeature(file, betterPeak);
}
Also used : BetterPeak(dulab.adap.datamodel.BetterPeak) Chromatogram(dulab.adap.datamodel.Chromatogram) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) Nonnull(javax.annotation.Nonnull)

Example 2 with Chromatogram

use of dulab.adap.datamodel.Chromatogram 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 3 with Chromatogram

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

the class ADAPInterface method peakToFeature.

@Nonnull
public static Feature peakToFeature(@Nonnull RawDataFile file, @Nonnull BetterPeak peak) {
    Chromatogram chromatogram = peak.chromatogram;
    // Retrieve scan numbers
    int representativeScan = 0;
    int[] scanNumbers = new int[chromatogram.length];
    int count = 0;
    for (int num : file.getScanNumbers()) {
        double retTime = file.getScan(num).getRetentionTime();
        Double intensity = chromatogram.getIntensity(retTime, false);
        if (intensity != null)
            scanNumbers[count++] = num;
        if (retTime == peak.getRetTime())
            representativeScan = num;
    }
    // Calculate peak area
    double area = 0.0;
    for (int i = 1; i < chromatogram.length; ++i) {
        double base = (chromatogram.xs[i] - chromatogram.xs[i - 1]) * 60d;
        double height = 0.5 * (chromatogram.ys[i] + chromatogram.ys[i - 1]);
        area += base * height;
    }
    // Create array of DataPoints
    DataPoint[] dataPoints = new DataPoint[chromatogram.length];
    count = 0;
    for (double intensity : chromatogram.ys) dataPoints[count++] = new SimpleDataPoint(peak.getMZ(), intensity);
    return new SimpleFeature(file, peak.getMZ(), peak.getRetTime(), peak.getIntensity(), area, scanNumbers, dataPoints, Feature.FeatureStatus.ESTIMATED, representativeScan, representativeScan, new int[] {}, Range.closed(peak.getFirstRetTime(), peak.getLastRetTime()), Range.closed(peak.getMZ() - 0.01, peak.getMZ() + 0.01), Range.closed(0.0, peak.getIntensity()));
}
Also used : SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) Chromatogram(dulab.adap.datamodel.Chromatogram) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) SimpleFeature(net.sf.mzmine.datamodel.impl.SimpleFeature) Nonnull(javax.annotation.Nonnull)

Aggregations

Chromatogram (dulab.adap.datamodel.Chromatogram)3 Nonnull (javax.annotation.Nonnull)3 BetterPeak (dulab.adap.datamodel.BetterPeak)2 DataPoint (net.sf.mzmine.datamodel.DataPoint)2 SimpleDataPoint (net.sf.mzmine.datamodel.impl.SimpleDataPoint)2 PeakInfo (dulab.adap.datamodel.PeakInfo)1 ArrayList (java.util.ArrayList)1 SimpleFeature (net.sf.mzmine.datamodel.impl.SimpleFeature)1