Search in sources :

Example 36 with SimplePeakList

use of net.sf.mzmine.datamodel.impl.SimplePeakList in project mzmine2 by mzmine.

the class SmoothingTask method run.

@Override
public void run() {
    setStatus(TaskStatus.PROCESSING);
    try {
        // Get filter weights.
        final double[] filterWeights = SavitzkyGolayFilter.getNormalizedWeights(filterWidth);
        // Create new feature list
        newPeakList = new SimplePeakList(origPeakList + " " + suffix, origPeakList.getRawDataFiles());
        // Process each row.
        for (final PeakListRow row : origPeakList.getRows()) {
            if (!isCanceled()) {
                // Create a new peak-list row.
                final int originalID = row.getID();
                final PeakListRow newRow = new SimplePeakListRow(originalID);
                // Process each peak.
                for (final Feature peak : row.getPeaks()) {
                    if (!isCanceled()) {
                        // Copy original peak intensities.
                        final int[] scanNumbers = peak.getScanNumbers();
                        final int numScans = scanNumbers.length;
                        final double[] intensities = new double[numScans];
                        for (int i = 0; i < numScans; i++) {
                            final DataPoint dataPoint = peak.getDataPoint(scanNumbers[i]);
                            intensities[i] = dataPoint == null ? 0.0 : dataPoint.getIntensity();
                        }
                        // Smooth peak.
                        final double[] smoothed = convolve(intensities, filterWeights);
                        // Measure peak (max, ranges, area etc.)
                        final RawDataFile dataFile = peak.getDataFile();
                        final DataPoint[] newDataPoints = new DataPoint[numScans];
                        double maxIntensity = 0.0;
                        int maxScanNumber = -1;
                        DataPoint maxDataPoint = null;
                        Range<Double> intensityRange = null;
                        double area = 0.0;
                        for (int i = 0; i < numScans; i++) {
                            final int scanNumber = scanNumbers[i];
                            final DataPoint dataPoint = peak.getDataPoint(scanNumber);
                            final double intensity = smoothed[i];
                            if (dataPoint != null && intensity > 0.0) {
                                // Create a new data point.
                                final double mz = dataPoint.getMZ();
                                final double rt = dataFile.getScan(scanNumber).getRetentionTime();
                                final DataPoint newDataPoint = new SimpleDataPoint(mz, intensity);
                                newDataPoints[i] = newDataPoint;
                                // Track maximum intensity data point.
                                if (intensity > maxIntensity) {
                                    maxIntensity = intensity;
                                    maxScanNumber = scanNumber;
                                    maxDataPoint = newDataPoint;
                                }
                                // Update ranges.
                                if (intensityRange == null) {
                                    intensityRange = Range.singleton(intensity);
                                } else {
                                    intensityRange = intensityRange.span(Range.singleton(intensity));
                                }
                                // Accumulate peak area.
                                if (i != 0) {
                                    final DataPoint lastDP = newDataPoints[i - 1];
                                    final double lastIntensity = lastDP == null ? 0.0 : lastDP.getIntensity();
                                    final double lastRT = dataFile.getScan(scanNumbers[i - 1]).getRetentionTime();
                                    area += (rt - lastRT) * 60d * (intensity + lastIntensity) / 2.0;
                                }
                            }
                        }
                        assert maxDataPoint != null;
                        if (!isCanceled() && maxScanNumber >= 0) {
                            // Create a new peak.
                            newRow.addPeak(dataFile, new SimpleFeature(dataFile, maxDataPoint.getMZ(), peak.getRT(), maxIntensity, area, scanNumbers, newDataPoints, peak.getFeatureStatus(), maxScanNumber, peak.getMostIntenseFragmentScanNumber(), peak.getAllMS2FragmentScanNumbers(), peak.getRawDataPointsRTRange(), peak.getRawDataPointsMZRange(), intensityRange));
                        }
                    }
                }
                newPeakList.addRow(newRow);
                progress++;
            }
        }
        // Finish up.
        if (!isCanceled()) {
            // Add new peak-list to the project.
            project.addPeakList(newPeakList);
            // Add quality parameters to peaks
            QualityParameters.calculateQualityParameters(newPeakList);
            // Remove the original peak-list if requested.
            if (removeOriginal) {
                project.removePeakList(origPeakList);
            }
            // Copy previously applied methods
            for (final PeakListAppliedMethod method : origPeakList.getAppliedMethods()) {
                newPeakList.addDescriptionOfAppliedTask(method);
            }
            // Add task description to peak-list.
            newPeakList.addDescriptionOfAppliedTask(new SimplePeakListAppliedMethod("Peaks smoothed by Savitzky-Golay filter", parameters));
            LOG.finest("Finished peak smoothing: " + progress + " rows processed");
            setStatus(TaskStatus.FINISHED);
        }
    } catch (Throwable t) {
        LOG.log(Level.SEVERE, "Smoothing error", t);
        setErrorMessage(t.getMessage());
        setStatus(TaskStatus.ERROR);
    }
}
Also used : SimplePeakListAppliedMethod(net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod) PeakListAppliedMethod(net.sf.mzmine.datamodel.PeakList.PeakListAppliedMethod) SimplePeakListAppliedMethod(net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod) SimplePeakListRow(net.sf.mzmine.datamodel.impl.SimplePeakListRow) SimpleFeature(net.sf.mzmine.datamodel.impl.SimpleFeature) Feature(net.sf.mzmine.datamodel.Feature) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) SimpleFeature(net.sf.mzmine.datamodel.impl.SimpleFeature) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) SimplePeakListRow(net.sf.mzmine.datamodel.impl.SimplePeakListRow) PeakListRow(net.sf.mzmine.datamodel.PeakListRow) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList)

Example 37 with SimplePeakList

use of net.sf.mzmine.datamodel.impl.SimplePeakList in project mzmine2 by mzmine.

the class DeconvolutionTask method resolvePeaks.

/**
 * Deconvolve a chromatogram into separate peaks.
 *
 * @param peakList holds the chromatogram to deconvolve.
 * @param mzCenterFunction2
 * @return a new feature list holding the resolved peaks.
 * @throws RSessionWrapperException
 */
private PeakList resolvePeaks(final PeakList peakList, RSessionWrapper rSession) throws RSessionWrapperException {
    // Get data file information.
    final RawDataFile dataFile = peakList.getRawDataFile(0);
    // Peak resolver.
    final MZmineProcessingStep<PeakResolver> resolver = parameters.getParameter(PEAK_RESOLVER).getValue();
    // set msms pairing range
    this.setMSMSRange = parameters.getParameter(mzRangeMSMS).getValue();
    if (setMSMSRange)
        this.msmsRange = parameters.getParameter(mzRangeMSMS).getEmbeddedParameter().getValue();
    else
        this.msmsRange = 0;
    this.setMSMSRT = parameters.getParameter(RetentionTimeMSMS).getValue();
    if (setMSMSRT)
        this.RTRangeMSMS = parameters.getParameter(RetentionTimeMSMS).getEmbeddedParameter().getValue();
    else
        this.RTRangeMSMS = 0;
    // Create new feature list.
    final PeakList resolvedPeaks = new SimplePeakList(peakList + " " + parameters.getParameter(SUFFIX).getValue(), dataFile);
    // Load previous applied methods.
    for (final PeakListAppliedMethod method : peakList.getAppliedMethods()) {
        resolvedPeaks.addDescriptionOfAppliedTask(method);
    }
    // Add task description to feature list.
    resolvedPeaks.addDescriptionOfAppliedTask(new SimplePeakListAppliedMethod("Peak deconvolution by " + resolver, resolver.getParameterSet()));
    // Initialise counters.
    processedRows = 0;
    totalRows = peakList.getNumberOfRows();
    int peakId = 1;
    // Process each chromatogram.
    final PeakListRow[] peakListRows = peakList.getRows();
    final int chromatogramCount = peakListRows.length;
    for (int index = 0; !isCanceled() && index < chromatogramCount; index++) {
        final PeakListRow currentRow = peakListRows[index];
        final Feature chromatogram = currentRow.getPeak(dataFile);
        // Resolve peaks.
        final PeakResolver resolverModule = resolver.getModule();
        final ParameterSet resolverParams = resolver.getParameterSet();
        final ResolvedPeak[] peaks = resolverModule.resolvePeaks(chromatogram, resolverParams, rSession, mzCenterFunction, msmsRange, RTRangeMSMS);
        // Add peaks to the new feature list.
        for (final ResolvedPeak peak : peaks) {
            peak.setParentChromatogramRowID(currentRow.getID());
            final PeakListRow newRow = new SimplePeakListRow(peakId++);
            newRow.addPeak(dataFile, peak);
            newRow.setPeakInformation(peak.getPeakInformation());
            resolvedPeaks.addRow(newRow);
        }
        processedRows++;
    }
    return resolvedPeaks;
}
Also used : ParameterSet(net.sf.mzmine.parameters.ParameterSet) SimplePeakListAppliedMethod(net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod) PeakListAppliedMethod(net.sf.mzmine.datamodel.PeakList.PeakListAppliedMethod) SimplePeakListAppliedMethod(net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod) Feature(net.sf.mzmine.datamodel.Feature) SimplePeakListRow(net.sf.mzmine.datamodel.impl.SimplePeakListRow) SimplePeakListRow(net.sf.mzmine.datamodel.impl.SimplePeakListRow) PeakListRow(net.sf.mzmine.datamodel.PeakListRow) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList) PeakList(net.sf.mzmine.datamodel.PeakList)

Example 38 with SimplePeakList

use of net.sf.mzmine.datamodel.impl.SimplePeakList in project mzmine2 by mzmine.

the class MsMsBottomPanel method getIntensityThresholdPeakList.

/**
 * Returns a feature list with the peaks which intensity is above the parameter "intensity"
 */
PeakList getIntensityThresholdPeakList(double intensity) {
    PeakList selectedPeakList = (PeakList) peakListSelector.getSelectedItem();
    if (selectedPeakList == null)
        return null;
    SimplePeakList newList = new SimplePeakList(selectedPeakList.getName(), selectedPeakList.getRawDataFiles());
    for (PeakListRow peakRow : selectedPeakList.getRows()) {
        Feature peak = peakRow.getPeak(dataFile);
        if (peak == null)
            continue;
        if (peak.getRawDataPointsIntensityRange().upperEndpoint() > intensity) {
            newList.addRow(peakRow);
        }
    }
    return newList;
}
Also used : PeakListRow(net.sf.mzmine.datamodel.PeakListRow) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList) PeakList(net.sf.mzmine.datamodel.PeakList) Feature(net.sf.mzmine.datamodel.Feature)

Example 39 with SimplePeakList

use of net.sf.mzmine.datamodel.impl.SimplePeakList in project mzmine2 by mzmine.

the class MsMsBottomPanel method getTopThresholdPeakList.

/**
 * Returns a feature list with the top peaks defined by the parameter "threshold"
 */
PeakList getTopThresholdPeakList(int threshold) {
    PeakList selectedPeakList = (PeakList) peakListSelector.getSelectedItem();
    if (selectedPeakList == null)
        return null;
    SimplePeakList newList = new SimplePeakList(selectedPeakList.getName(), selectedPeakList.getRawDataFiles());
    Vector<PeakListRow> peakRows = new Vector<PeakListRow>();
    Range<Double> mzRange = selectedPeakList.getRowsMZRange();
    Range<Double> rtRange = selectedPeakList.getRowsRTRange();
    PeakThresholdMode selectedPeakOption = (PeakThresholdMode) thresholdCombo.getSelectedItem();
    if (selectedPeakOption == PeakThresholdMode.TOP_PEAKS_AREA) {
        XYPlot xyPlot = masterFrame.getPlot().getXYPlot();
        org.jfree.data.Range yAxis = xyPlot.getRangeAxis().getRange();
        org.jfree.data.Range xAxis = xyPlot.getDomainAxis().getRange();
        rtRange = Range.closed(xAxis.getLowerBound(), xAxis.getUpperBound());
        mzRange = Range.closed(yAxis.getLowerBound(), yAxis.getUpperBound());
    }
    for (PeakListRow peakRow : selectedPeakList.getRows()) {
        if (mzRange.contains(peakRow.getAverageMZ()) && rtRange.contains(peakRow.getAverageRT())) {
            peakRows.add(peakRow);
        }
    }
    Collections.sort(peakRows, new PeakListRowSorter(SortingProperty.Intensity, SortingDirection.Descending));
    if (threshold > peakRows.size())
        threshold = peakRows.size();
    for (int i = 0; i < threshold; i++) {
        newList.addRow(peakRows.elementAt(i));
    }
    return newList;
}
Also used : PeakListRowSorter(net.sf.mzmine.util.PeakListRowSorter) PeakListRow(net.sf.mzmine.datamodel.PeakListRow) XYPlot(org.jfree.chart.plot.XYPlot) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList) PeakList(net.sf.mzmine.datamodel.PeakList) Vector(java.util.Vector)

Example 40 with SimplePeakList

use of net.sf.mzmine.datamodel.impl.SimplePeakList in project mzmine2 by mzmine.

the class TwoDBottomPanel method getIntensityThresholdPeakList.

/**
 * Returns a feature list with the peaks which intensity is above the parameter "intensity"
 */
PeakList getIntensityThresholdPeakList(double intensity) {
    PeakList selectedPeakList = (PeakList) peakListSelector.getSelectedItem();
    if (selectedPeakList == null)
        return null;
    SimplePeakList newList = new SimplePeakList(selectedPeakList.getName(), selectedPeakList.getRawDataFiles());
    for (PeakListRow peakRow : selectedPeakList.getRows()) {
        Feature peak = peakRow.getPeak(dataFile);
        if (peak == null)
            continue;
        if (peak.getRawDataPointsIntensityRange().upperEndpoint() > intensity) {
            newList.addRow(peakRow);
        }
    }
    return newList;
}
Also used : PeakListRow(net.sf.mzmine.datamodel.PeakListRow) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList) PeakList(net.sf.mzmine.datamodel.PeakList) Feature(net.sf.mzmine.datamodel.Feature)

Aggregations

SimplePeakList (net.sf.mzmine.datamodel.impl.SimplePeakList)47 PeakListRow (net.sf.mzmine.datamodel.PeakListRow)39 SimplePeakListAppliedMethod (net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod)29 SimplePeakListRow (net.sf.mzmine.datamodel.impl.SimplePeakListRow)29 Feature (net.sf.mzmine.datamodel.Feature)25 RawDataFile (net.sf.mzmine.datamodel.RawDataFile)25 DataPoint (net.sf.mzmine.datamodel.DataPoint)19 PeakList (net.sf.mzmine.datamodel.PeakList)18 PeakListAppliedMethod (net.sf.mzmine.datamodel.PeakList.PeakListAppliedMethod)14 SimpleFeature (net.sf.mzmine.datamodel.impl.SimpleFeature)14 ArrayList (java.util.ArrayList)11 SimpleDataPoint (net.sf.mzmine.datamodel.impl.SimpleDataPoint)10 PeakListRowSorter (net.sf.mzmine.util.PeakListRowSorter)10 Scan (net.sf.mzmine.datamodel.Scan)8 Vector (java.util.Vector)7 PeakIdentity (net.sf.mzmine.datamodel.PeakIdentity)7 IsotopePattern (net.sf.mzmine.datamodel.IsotopePattern)5 Desktop (net.sf.mzmine.desktop.Desktop)5 HeadLessDesktop (net.sf.mzmine.desktop.impl.HeadLessDesktop)5 SimpleIsotopePattern (net.sf.mzmine.datamodel.impl.SimpleIsotopePattern)4