Search in sources :

Example 36 with Feature

use of net.sf.mzmine.datamodel.Feature in project mzmine2 by mzmine.

the class SavitzkyGolayPeakDetector 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;
    }
    // Calculate intensity statistics.
    double maxIntensity = 0.0;
    double avgIntensity = 0.0;
    for (final double intensity : intensities) {
        maxIntensity = Math.max(intensity, maxIntensity);
        avgIntensity += intensity;
    }
    avgIntensity /= scanCount;
    final List<Feature> resolvedPeaks = new ArrayList<Feature>(2);
    // noise return an empty array.
    if (avgIntensity <= maxIntensity / 2.0) {
        // Calculate second derivatives of intensity values.
        final double[] secondDerivative = SGDerivative.calculateDerivative(intensities, false, SG_FILTER_LEVEL);
        // Calculate noise threshold.
        final double noiseThreshold = calcDerivativeThreshold(secondDerivative, parameters.getParameter(DERIVATIVE_THRESHOLD_LEVEL).getValue());
        // Search for peaks.
        Arrays.sort(scanNumbers);
        final Feature[] resolvedOriginalPeaks = peaksSearch(chromatogram, scanNumbers, secondDerivative, noiseThreshold, mzCenterFunction, msmsRange, rTRangeMSMS);
        final Range<Double> peakDuration = parameters.getParameter(PEAK_DURATION).getValue();
        final double minimumPeakHeight = parameters.getParameter(MIN_PEAK_HEIGHT).getValue();
        // parameters.
        for (final Feature p : resolvedOriginalPeaks) {
            if (peakDuration.contains(RangeUtils.rangeLength(p.getRawDataPointsRTRange())) && p.getHeight() >= minimumPeakHeight) {
                resolvedPeaks.add(p);
            }
        }
    }
    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) Feature(net.sf.mzmine.datamodel.Feature) DataPoint(net.sf.mzmine.datamodel.DataPoint)

Example 37 with Feature

use of net.sf.mzmine.datamodel.Feature in project mzmine2 by mzmine.

the class QualityParameters method calculateQualityParameters.

public static void calculateQualityParameters(PeakList peakList) {
    Feature peak;
    double height, rt;
    for (int i = 0; i < peakList.getNumberOfRows(); i++) {
        for (int x = 0; x < peakList.getNumberOfRawDataFiles(); x++) {
            peak = peakList.getPeak(i, peakList.getRawDataFile(x));
            if (peak != null) {
                height = peak.getHeight();
                rt = peak.getRT();
                // FWHM
                double[] rtValues = PeakFindRTs(height / 2, rt, peak);
                Double fwhm = rtValues[1] - rtValues[0];
                if (fwhm <= 0 || Double.isNaN(fwhm) || Double.isInfinite(fwhm)) {
                    fwhm = null;
                }
                peak.setFWHM(fwhm);
                // Tailing Factor - TF
                double[] rtValues2 = PeakFindRTs(height * 0.05, rt, peak);
                Double tf = (rtValues2[1] - rtValues2[0]) / (2 * (rt - rtValues2[0]));
                if (tf <= 0 || Double.isNaN(tf) || Double.isInfinite(tf)) {
                    tf = null;
                }
                peak.setTailingFactor(tf);
                // Asymmetry factor - AF
                double[] rtValues3 = PeakFindRTs(height * 0.1, rt, peak);
                Double af = (rtValues3[1] - rt) / (rt - rtValues3[0]);
                if (af <= 0 || Double.isNaN(af) || Double.isInfinite(af)) {
                    af = null;
                }
                peak.setAsymmetryFactor(af);
            }
        }
    }
}
Also used : Feature(net.sf.mzmine.datamodel.Feature)

Example 38 with Feature

use of net.sf.mzmine.datamodel.Feature in project mzmine2 by mzmine.

the class MultiSpectraVisualizerWindow method addSpectra.

private JPanel addSpectra(int scan) {
    JPanel panel = new JPanel(new BorderLayout());
    // Split pane for eic plot (top) and spectrum (bottom)
    JSplitPane bottomPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    // Create EIC plot
    // labels for TIC visualizer
    Map<Feature, String> labelsMap = new HashMap<Feature, String>(0);
    Feature peak = row.getPeak(activeRaw);
    // scan selection
    ScanSelection scanSelection = new ScanSelection(activeRaw.getDataRTRange(1), 1);
    // mz range
    Range<Double> mzRange = null;
    mzRange = peak.getRawDataPointsMZRange();
    // optimize output by extending the range
    double upper = mzRange.upperEndpoint();
    double lower = mzRange.lowerEndpoint();
    double fiveppm = (upper * 5E-6);
    mzRange = Range.closed(lower - fiveppm, upper + fiveppm);
    // labels
    labelsMap.put(peak, peak.toString());
    // get EIC window
    TICVisualizerWindow window = new // raw
    TICVisualizerWindow(// raw
    new RawDataFile[] { activeRaw }, // plot type
    TICPlotType.BASEPEAK, // scan selection
    scanSelection, // mz range
    mzRange, // selected features
    new Feature[] { peak }, // labels
    labelsMap);
    // get EIC Plot
    TICPlot ticPlot = window.getTICPlot();
    ticPlot.setPreferredSize(new Dimension(600, 200));
    ticPlot.getChart().getLegend().setVisible(false);
    // add a retention time Marker to the EIC
    ValueMarker marker = new ValueMarker(activeRaw.getScan(scan).getRetentionTime());
    marker.setPaint(Color.RED);
    marker.setStroke(new BasicStroke(3.0f));
    XYPlot plot = (XYPlot) ticPlot.getChart().getPlot();
    plot.addDomainMarker(marker);
    bottomPane.add(ticPlot);
    bottomPane.setResizeWeight(0.5);
    bottomPane.setEnabled(true);
    bottomPane.setDividerSize(5);
    bottomPane.setDividerLocation(200);
    JSplitPane spectrumPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    // get MS/MS spectra window
    SpectraVisualizerWindow spectraWindow = new SpectraVisualizerWindow(activeRaw);
    spectraWindow.loadRawData(activeRaw.getScan(scan));
    // get MS/MS spectra plot
    SpectraPlot spectrumPlot = spectraWindow.getSpectrumPlot();
    spectrumPlot.getChart().getLegend().setVisible(false);
    spectrumPlot.setPreferredSize(new Dimension(600, 400));
    spectrumPane.add(spectrumPlot);
    spectrumPane.add(spectraWindow.getToolBar());
    spectrumPane.setResizeWeight(1);
    spectrumPane.setEnabled(false);
    spectrumPane.setDividerSize(0);
    bottomPane.add(spectrumPane);
    panel.add(bottomPane);
    panel.setBorder(BorderFactory.createLineBorder(Color.black));
    return panel;
}
Also used : BasicStroke(java.awt.BasicStroke) JPanel(javax.swing.JPanel) ScanSelection(net.sf.mzmine.parameters.parametertypes.selectors.ScanSelection) HashMap(java.util.HashMap) Dimension(java.awt.Dimension) Feature(net.sf.mzmine.datamodel.Feature) TICVisualizerWindow(net.sf.mzmine.modules.visualization.tic.TICVisualizerWindow) BorderLayout(java.awt.BorderLayout) XYPlot(org.jfree.chart.plot.XYPlot) JSplitPane(javax.swing.JSplitPane) TICPlot(net.sf.mzmine.modules.visualization.tic.TICPlot) ValueMarker(org.jfree.chart.plot.ValueMarker)

Example 39 with Feature

use of net.sf.mzmine.datamodel.Feature in project mzmine2 by mzmine.

the class ScatterPlotAxisSelection method getValue.

public double getValue(PeakListRow row) {
    if (file != null) {
        Feature peak = row.getPeak(file);
        if (peak == null)
            return 0;
        else
            return peak.getArea();
    }
    double totalArea = 0;
    int numOfFiles = 0;
    for (RawDataFile dataFile : row.getRawDataFiles()) {
        Object fileValue = MZmineCore.getProjectManager().getCurrentProject().getParameterValue(parameter, dataFile);
        if (fileValue == null)
            continue;
        if (fileValue.toString().equals(parameterValue.toString())) {
            Feature peak = row.getPeak(dataFile);
            if ((peak != null) && (peak.getArea() > 0)) {
                totalArea += peak.getArea();
                numOfFiles++;
            }
        }
    }
    if (numOfFiles == 0)
        return 0;
    totalArea /= numOfFiles;
    return totalArea;
}
Also used : RawDataFile(net.sf.mzmine.datamodel.RawDataFile) Feature(net.sf.mzmine.datamodel.Feature)

Example 40 with Feature

use of net.sf.mzmine.datamodel.Feature in project mzmine2 by mzmine.

the class PeakUtils method getPeakListRowAvgRtRange.

/**
 * @param row The row.
 * @return The average retention time range of all features contained in this peak list row across
 *         all raw data files. Empty range (0,0) if the row is null or has no feature assigned to
 *         it.
 */
@Nonnull
public static Range<Double> getPeakListRowAvgRtRange(PeakListRow row) {
    if (row == null || row.getBestPeak() == null)
        return Range.closed(0.d, 0.d);
    int size = row.getPeaks().length;
    double[] lower = new double[size];
    double[] upper = new double[size];
    Feature[] f = row.getPeaks();
    for (int i = 0; i < size; i++) {
        if (f[i] == null)
            continue;
        Range<Double> r = f[i].getRawDataPointsRTRange();
        lower[i] = r.lowerEndpoint();
        upper[i] = r.upperEndpoint();
    }
    double avgL = 0, avgU = 0;
    for (int i = 0; i < size; i++) {
        avgL += lower[i];
        avgU += upper[i];
    }
    avgL /= size;
    avgU /= size;
    return Range.closed(avgL, avgU);
}
Also used : 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) Nonnull(javax.annotation.Nonnull)

Aggregations

Feature (net.sf.mzmine.datamodel.Feature)115 PeakListRow (net.sf.mzmine.datamodel.PeakListRow)70 RawDataFile (net.sf.mzmine.datamodel.RawDataFile)60 SimplePeakListRow (net.sf.mzmine.datamodel.impl.SimplePeakListRow)41 DataPoint (net.sf.mzmine.datamodel.DataPoint)35 SimpleFeature (net.sf.mzmine.datamodel.impl.SimpleFeature)35 SimplePeakList (net.sf.mzmine.datamodel.impl.SimplePeakList)25 Scan (net.sf.mzmine.datamodel.Scan)22 PeakList (net.sf.mzmine.datamodel.PeakList)20 ArrayList (java.util.ArrayList)17 SimplePeakListAppliedMethod (net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod)16 IsotopePattern (net.sf.mzmine.datamodel.IsotopePattern)15 PeakIdentity (net.sf.mzmine.datamodel.PeakIdentity)15 SimpleDataPoint (net.sf.mzmine.datamodel.impl.SimpleDataPoint)13 PeakListAppliedMethod (net.sf.mzmine.datamodel.PeakList.PeakListAppliedMethod)10 MassList (net.sf.mzmine.datamodel.MassList)9 HashMap (java.util.HashMap)8 Vector (java.util.Vector)8 ScanSelection (net.sf.mzmine.parameters.parametertypes.selectors.ScanSelection)7 TreeMap (java.util.TreeMap)6