Search in sources :

Example 36 with DataPoint

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

the class RndResampleFilter method filterScan.

public Scan filterScan(Scan scan, ParameterSet parameters) {
    boolean sum_duplicates = parameters.getParameter(RndResampleFilterParameters.SUM_DUPLICATES).getValue();
    boolean remove_zero_intensity = parameters.getParameter(RndResampleFilterParameters.REMOVE_ZERO_INTENSITY).getValue();
    // If CENTROIDED scan, use it as-is
    Scan inputScan;
    if (scan.getSpectrumType() == MassSpectrumType.CENTROIDED)
        inputScan = scan;
    else
        // Otherwise, detect local maxima
        inputScan = new LocMaxCentroidingAlgorithm(scan).centroidScan();
    DataPoint[] dps = inputScan.getDataPoints();
    // Cleanup first: Remove zero intensity data points (if requested)
    // Reuse dps array
    int newNumOfDataPoints = 0;
    for (int i = 0; i < dps.length; ++i) {
        if (!remove_zero_intensity || dps[i].getIntensity() > 0.0) {
            dps[newNumOfDataPoints] = dps[i];
            ++newNumOfDataPoints;
        }
    }
    // Getting started
    SimpleDataPoint[] newDps = new SimpleDataPoint[newNumOfDataPoints];
    for (int i = 0; i < newNumOfDataPoints; ++i) {
        // Set the new m/z value to nearest integer / unit value
        int newMz = (int) Math.round(dps[i].getMZ());
        // Create new DataPoint accordingly (intensity untouched)
        newDps[i] = new SimpleDataPoint(newMz, dps[i].getIntensity());
    }
    // Post-treatments
    // Cleanup: Merge duplicates/overlap
    // ArrayList<SimpleDataPoint> dpsList = new
    // ArrayList<SimpleDataPoint>();
    double prevMz = -1.0, curMz = -1.0;
    double newIntensity = 0.0;
    double divider = 1.0;
    // Reuse dps array
    newNumOfDataPoints = 0;
    for (int i = 0; i < newDps.length; ++i) {
        curMz = newDps[i].getMZ();
        if (i > 0) {
            // Handle duplicates
            if (curMz == prevMz) {
                if (sum_duplicates) {
                    // Use sum
                    newIntensity += newDps[i].getIntensity();
                    dps[newNumOfDataPoints - 1] = new SimpleDataPoint(prevMz, newIntensity);
                } else {
                    // Use average
                    newIntensity += newDps[i].getIntensity();
                    dps[newNumOfDataPoints - 1] = new SimpleDataPoint(prevMz, newIntensity);
                    divider += 1.0;
                }
            } else {
                dps[newNumOfDataPoints - 1] = new SimpleDataPoint(prevMz, newIntensity / divider);
                dps[newNumOfDataPoints] = newDps[i];
                ++newNumOfDataPoints;
                newIntensity = dps[newNumOfDataPoints - 1].getIntensity();
                divider = 1.0;
            }
        } else {
            dps[newNumOfDataPoints] = newDps[i];
            ++newNumOfDataPoints;
        }
        prevMz = newDps[i].getMZ();
    }
    // Create updated scan
    SimpleScan newScan = new SimpleScan(inputScan);
    newScan.setDataPoints(Arrays.copyOfRange(dps, 0, newNumOfDataPoints));
    newScan.setSpectrumType(MassSpectrumType.CENTROIDED);
    return newScan;
}
Also used : SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) SimpleScan(net.sf.mzmine.datamodel.impl.SimpleScan) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) DataPoint(net.sf.mzmine.datamodel.DataPoint) Scan(net.sf.mzmine.datamodel.Scan) SimpleScan(net.sf.mzmine.datamodel.impl.SimpleScan) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) DataPoint(net.sf.mzmine.datamodel.DataPoint)

Example 37 with DataPoint

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

the class SGFilter method filterScan.

@Override
public Scan filterScan(Scan scan, ParameterSet parameters) {
    int numOfDataPoints = parameters.getParameter(SGFilterParameters.datapoints).getValue();
    assert Avalues.containsKey(numOfDataPoints);
    assert Hvalues.containsKey(numOfDataPoints);
    int[] aVals = Avalues.get(numOfDataPoints);
    int h = Hvalues.get(numOfDataPoints).intValue();
    // changed to also allow MS2 if selected in ScanSelection
    int marginSize = (numOfDataPoints + 1) / 2 - 1;
    double sumOfInts;
    DataPoint[] oldDataPoints = scan.getDataPoints();
    int newDataPointsLength = oldDataPoints.length - (marginSize * 2);
    // only process scans with datapoints
    if (newDataPointsLength < 1) {
        return scan;
    }
    DataPoint[] newDataPoints = new DataPoint[newDataPointsLength];
    for (int spectrumInd = marginSize; spectrumInd < (oldDataPoints.length - marginSize); spectrumInd++) {
        // zero intensity data points must be left unchanged
        if (oldDataPoints[spectrumInd].getIntensity() == 0) {
            newDataPoints[spectrumInd - marginSize] = oldDataPoints[spectrumInd];
            continue;
        }
        sumOfInts = aVals[0] * oldDataPoints[spectrumInd].getIntensity();
        for (int windowInd = 1; windowInd <= marginSize; windowInd++) {
            sumOfInts += aVals[windowInd] * (oldDataPoints[spectrumInd + windowInd].getIntensity() + oldDataPoints[spectrumInd - windowInd].getIntensity());
        }
        sumOfInts = sumOfInts / h;
        if (sumOfInts < 0) {
            sumOfInts = 0;
        }
        newDataPoints[spectrumInd - marginSize] = new SimpleDataPoint(oldDataPoints[spectrumInd].getMZ(), sumOfInts);
    }
    SimpleScan newScan = new SimpleScan(scan);
    newScan.setDataPoints(newDataPoints);
    return newScan;
}
Also used : SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) SimpleScan(net.sf.mzmine.datamodel.impl.SimpleScan) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) DataPoint(net.sf.mzmine.datamodel.DataPoint)

Example 38 with DataPoint

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

the class CropFilterTask method run.

/**
 * @see Runnable#run()
 */
@Override
public void run() {
    setStatus(TaskStatus.PROCESSING);
    logger.info("Started crop filter on " + dataFile);
    scans = scanSelection.getMatchingScans(dataFile);
    totalScans = scans.length;
    // Check if we have any scans
    if (totalScans == 0) {
        setStatus(TaskStatus.ERROR);
        setErrorMessage("No scans match the selected criteria");
        return;
    }
    try {
        RawDataFileWriter rawDataFileWriter = MZmineCore.createNewFile(dataFile.getName() + " " + suffix);
        for (Scan scan : scans) {
            SimpleScan scanCopy = new SimpleScan(scan);
            // Check if we have something to crop
            if (!mzRange.encloses(scan.getDataPointMZRange())) {
                DataPoint[] croppedDataPoints = scan.getDataPointsByMass(mzRange);
                scanCopy.setDataPoints(croppedDataPoints);
            }
            rawDataFileWriter.addScan(scanCopy);
            processedScans++;
        }
        RawDataFile filteredRawDataFile = rawDataFileWriter.finishWriting();
        project.addFile(filteredRawDataFile);
        // Remove the original file if requested
        if (removeOriginal) {
            project.removeFile(dataFile);
        }
        setStatus(TaskStatus.FINISHED);
    } catch (Exception e) {
        setStatus(TaskStatus.ERROR);
        setErrorMessage(e.toString());
        e.printStackTrace();
    }
}
Also used : SimpleScan(net.sf.mzmine.datamodel.impl.SimpleScan) DataPoint(net.sf.mzmine.datamodel.DataPoint) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) Scan(net.sf.mzmine.datamodel.Scan) SimpleScan(net.sf.mzmine.datamodel.impl.SimpleScan) RawDataFileWriter(net.sf.mzmine.datamodel.RawDataFileWriter)

Example 39 with DataPoint

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

the class DPPResultsLabelGenerator method generateLabel.

/**
 * @see org.jfree.chart.labels.XYItemLabelGenerator#generateLabel(org.jfree.data.xy.XYDataset,
 *      int, int)
 */
public String generateLabel(XYDataset dataset, int series, int item) {
    // X and Y values of current data point
    double originalX = dataset.getX(series, item).doubleValue();
    double originalY = dataset.getY(series, item).doubleValue();
    // Calculate data size of 1 screen pixel
    double xLength = (double) plot.getXYPlot().getDomainAxis().getRange().getLength();
    double pixelX = xLength / plot.getWidth();
    // Size of data set
    int itemCount = dataset.getItemCount(series);
    // Search for data points higher than this one in the interval
    // from limitLeft to limitRight
    double limitLeft = originalX - ((POINTS_RESERVE_X / 2) * pixelX);
    double limitRight = originalX + ((POINTS_RESERVE_X / 2) * pixelX);
    // Iterate data points to the left and right
    for (int i = 1; (item - i > 0) || (item + i < itemCount); i++) {
        // If we get out of the limit we can stop searching
        if ((item - i > 0) && (dataset.getXValue(series, item - i) < limitLeft) && ((item + i >= itemCount) || (dataset.getXValue(series, item + i) > limitRight)))
            break;
        if ((item + i < itemCount) && (dataset.getXValue(series, item + i) > limitRight) && ((item - i <= 0) || (dataset.getXValue(series, item - i) < limitLeft)))
            break;
        // If we find higher data point, bail out
        if ((item - i > 0) && (originalY <= dataset.getYValue(series, item - i)))
            return null;
        if ((item + i < itemCount) && (originalY <= dataset.getYValue(series, item + i)))
            return null;
    }
    // Create label
    String label = null;
    if (dataset instanceof ScanDataSet) {
        label = ((ScanDataSet) dataset).getAnnotation(item);
    } else if (dataset instanceof DPPResultsDataSet) {
        DataPoint[] dps = ((DPPResultsDataSet) dataset).getDataPoints();
        if (dps[item] instanceof ProcessedDataPoint) {
            ProcessedDataPoint p = (ProcessedDataPoint) dps[item];
            label = createLabel(p);
        }
    }
    if (label == null || label.equals("")) {
        double mzValue = dataset.getXValue(series, item);
        label = mzFormat.format(mzValue);
    }
    return label;
}
Also used : ScanDataSet(net.sf.mzmine.modules.visualization.spectra.simplespectra.datasets.ScanDataSet) ProcessedDataPoint(net.sf.mzmine.modules.visualization.spectra.simplespectra.datapointprocessing.datamodel.ProcessedDataPoint) ProcessedDataPoint(net.sf.mzmine.modules.visualization.spectra.simplespectra.datapointprocessing.datamodel.ProcessedDataPoint) DataPoint(net.sf.mzmine.datamodel.DataPoint)

Example 40 with DataPoint

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

the class MirrorScanWindow method setScans.

/**
 * Based on a data base match to a spectral library
 *
 * @param row
 * @param db
 */
public void setScans(SpectralDBPeakIdentity db) {
    Scan scan = db.getQueryScan();
    if (scan == null)
        return;
    // get highest data intensity to calc relative intensity
    double mostIntenseQuery = Arrays.stream(db.getQueryDataPoints(DataPointsTag.ORIGINAL)).mapToDouble(DataPoint::getIntensity).max().orElse(0d);
    double mostIntenseDB = Arrays.stream(db.getLibraryDataPoints(DataPointsTag.ORIGINAL)).mapToDouble(DataPoint::getIntensity).max().orElse(0d);
    if (mostIntenseDB == 0d)
        logger.warning("This data set has no original data points in the library spectrum (development error)");
    if (mostIntenseQuery == 0d)
        logger.warning("This data set has no original data points in the query spectrum (development error)");
    if (mostIntenseDB == 0d || mostIntenseQuery == 0d)
        return;
    // get colors for vision
    Vision vision = MZmineCore.getConfiguration().getColorVision();
    // colors for the different DataPointsTags:
    final Color[] colors = new Color[] { // black = filtered
    Color.black, // unaligned
    ColorPalettes.getNegativeColor(vision), // aligned
    ColorPalettes.getPositiveColor(vision) };
    // scan a
    double precursorMZA = scan.getPrecursorMZ();
    double rtA = scan.getRetentionTime();
    Double precursorMZB = db.getEntry().getPrecursorMZ();
    Double rtB = (Double) db.getEntry().getField(DBEntryField.RT).orElse(0d);
    contentPane.removeAll();
    // create without data
    mirrorSpecrumPlot = SpectrumChartFactory.createMirrorChartPanel("Query: " + scan.getScanDefinition(), precursorMZA, rtA, null, "Library: " + db.getName(), precursorMZB == null ? 0 : precursorMZB, rtB, null, false, true);
    mirrorSpecrumPlot.setMaximumDrawWidth(4200);
    mirrorSpecrumPlot.setMaximumDrawHeight(2500);
    // add data
    DataPoint[][] query = new DataPoint[tags.length][];
    DataPoint[][] library = new DataPoint[tags.length][];
    for (int i = 0; i < tags.length; i++) {
        DataPointsTag tag = tags[i];
        query[i] = db.getQueryDataPoints(tag);
        library[i] = db.getLibraryDataPoints(tag);
    }
    // add datasets and renderer
    // set up renderer
    CombinedDomainXYPlot domainPlot = (CombinedDomainXYPlot) mirrorSpecrumPlot.getChart().getXYPlot();
    NumberAxis axis = (NumberAxis) domainPlot.getDomainAxis();
    axis.setLabel("m/z");
    XYPlot queryPlot = (XYPlot) domainPlot.getSubplots().get(0);
    XYPlot libraryPlot = (XYPlot) domainPlot.getSubplots().get(1);
    // add all datapoints to a dataset that are not present in subsequent masslist
    for (int i = 0; i < tags.length; i++) {
        DataPointsTag tag = tags[i];
        PseudoSpectrumDataSet qdata = new PseudoSpectrumDataSet(true, "Query " + tag.toRemainderString());
        for (DataPoint dp : query[i]) {
            // not contained in other
            if (notInSubsequentMassList(dp, query, i) && mostIntenseQuery > 0)
                qdata.addDP(dp.getMZ(), dp.getIntensity() / mostIntenseQuery * 100d, null);
        }
        PseudoSpectrumDataSet ldata = new PseudoSpectrumDataSet(true, "Library " + tag.toRemainderString());
        for (DataPoint dp : library[i]) {
            if (notInSubsequentMassList(dp, library, i) && mostIntenseDB > 0)
                ldata.addDP(dp.getMZ(), dp.getIntensity() / mostIntenseDB * 100d, null);
        }
        Color color = colors[i];
        PseudoSpectraRenderer renderer = new PseudoSpectraRenderer(color, false);
        PseudoSpectraRenderer renderer2 = new PseudoSpectraRenderer(color, false);
        queryPlot.setDataset(i, qdata);
        queryPlot.setRenderer(i, renderer);
        libraryPlot.setDataset(i, ldata);
        libraryPlot.setRenderer(i, renderer2);
    }
    // add legend
    LegendItem item;
    LegendItemCollection collection = new LegendItemCollection();
    for (int i = 0; i < tags.length; i++) {
        item = new LegendItem(tags[i].toRemainderString(), colors[i]);
        collection.add(item);
    }
    mirrorSpecrumPlot.getChart().removeLegend();
    LegendTitle legend = new LegendTitle(() -> collection);
    legend.setPosition(RectangleEdge.BOTTOM);
    mirrorSpecrumPlot.getChart().addLegend(legend);
    // set y axis title
    queryPlot.getRangeAxis().setLabel("rel. intensity [%] (query)");
    libraryPlot.getRangeAxis().setLabel("rel. intensity [%] (library)");
    contentPane.add(mirrorSpecrumPlot, BorderLayout.CENTER);
    contentPane.revalidate();
    contentPane.repaint();
}
Also used : PseudoSpectrumDataSet(net.sf.mzmine.modules.visualization.spectra.multimsms.pseudospectra.PseudoSpectrumDataSet) NumberAxis(org.jfree.chart.axis.NumberAxis) PseudoSpectraRenderer(net.sf.mzmine.modules.visualization.spectra.multimsms.pseudospectra.PseudoSpectraRenderer) LegendItemCollection(org.jfree.chart.LegendItemCollection) Color(java.awt.Color) LegendTitle(org.jfree.chart.title.LegendTitle) DataPoint(net.sf.mzmine.datamodel.DataPoint) XYPlot(org.jfree.chart.plot.XYPlot) CombinedDomainXYPlot(org.jfree.chart.plot.CombinedDomainXYPlot) DataPoint(net.sf.mzmine.datamodel.DataPoint) LegendItem(org.jfree.chart.LegendItem) Vision(net.sf.mzmine.util.ColorPalettes.Vision) Scan(net.sf.mzmine.datamodel.Scan) CombinedDomainXYPlot(org.jfree.chart.plot.CombinedDomainXYPlot) DataPointsTag(net.sf.mzmine.util.spectraldb.entry.DataPointsTag)

Aggregations

DataPoint (net.sf.mzmine.datamodel.DataPoint)214 SimpleDataPoint (net.sf.mzmine.datamodel.impl.SimpleDataPoint)98 Scan (net.sf.mzmine.datamodel.Scan)64 ArrayList (java.util.ArrayList)50 RawDataFile (net.sf.mzmine.datamodel.RawDataFile)44 Feature (net.sf.mzmine.datamodel.Feature)27 MassList (net.sf.mzmine.datamodel.MassList)24 PeakListRow (net.sf.mzmine.datamodel.PeakListRow)22 IOException (java.io.IOException)20 SimpleScan (net.sf.mzmine.datamodel.impl.SimpleScan)18 IsotopePattern (net.sf.mzmine.datamodel.IsotopePattern)17 SimpleIsotopePattern (net.sf.mzmine.datamodel.impl.SimpleIsotopePattern)16 SimpleFeature (net.sf.mzmine.datamodel.impl.SimpleFeature)15 SimplePeakListRow (net.sf.mzmine.datamodel.impl.SimplePeakListRow)15 SimplePeakList (net.sf.mzmine.datamodel.impl.SimplePeakList)12 DataPointSorter (net.sf.mzmine.util.DataPointSorter)12 HashMap (java.util.HashMap)10 Vector (java.util.Vector)10 Range (com.google.common.collect.Range)8 TreeMap (java.util.TreeMap)8