Search in sources :

Example 86 with DataPoint

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

the class RowsSpectralMatchTask method run.

/**
 * @see java.lang.Runnable#run()
 */
@Override
public void run() {
    setStatus(TaskStatus.PROCESSING);
    for (PeakListRow row : rows) {
        if (isCanceled()) {
            logger.info("Added " + count + " spectral library matches (before being cancelled)");
            repaintWindow();
            return;
        }
        try {
            // All MS2 or only best MS2 scan
            // best MS1 scan
            // check for MS1 or MSMS scan
            List<Scan> scans = getScans(row);
            List<DataPoint[]> rowMassLists = new ArrayList<>();
            for (Scan scan : scans) {
                // get mass list and perform deisotoping if active
                DataPoint[] rowMassList = getDataPoints(scan, true);
                if (removeIsotopes)
                    rowMassList = removeIsotopes(rowMassList);
                rowMassLists.add(rowMassList);
            }
            // match against all library entries
            for (SpectralDBEntry ident : list) {
                SpectralDBPeakIdentity best = null;
                // match all scans against this ident to find best match
                for (int i = 0; i < scans.size(); i++) {
                    SpectralSimilarity sim = spectraDBMatch(row, rowMassLists.get(i), ident);
                    if (sim != null && (!needsIsotopePattern || SpectralMatchTask.checkForIsotopePattern(sim, mzToleranceSpectra, minMatchedIsoSignals)) && (best == null || best.getSimilarity().getScore() < sim.getScore())) {
                        best = new SpectralDBPeakIdentity(scans.get(i), massListName, ident, sim, METHOD);
                    }
                }
                // has match?
                if (best != null) {
                    addIdentity(row, best);
                    count++;
                }
            }
            // sort identities based on similarity score
            SortSpectralDBIdentitiesTask.sortIdentities(row);
        } catch (MissingMassListException e) {
            logger.log(Level.WARNING, "No mass list in spectrum for rowID=" + row.getID(), e);
            errorCounter++;
        }
        // check for max error (missing masslist)
        if (errorCounter > MAX_ERROR) {
            logger.log(Level.WARNING, "Data base matching failed. To many missing mass lists ");
            setStatus(TaskStatus.ERROR);
            setErrorMessage("Data base matching failed. To many missing mass lists ");
            list = null;
            return;
        }
        // next row
        finishedRows++;
    }
    if (count > 0)
        logger.info("Added " + count + " spectral library matches");
    // Repaint the window to reflect the change in the feature list
    repaintWindow();
    list = null;
    setStatus(TaskStatus.FINISHED);
}
Also used : PeakListRow(net.sf.mzmine.datamodel.PeakListRow) DataPoint(net.sf.mzmine.datamodel.DataPoint) SpectralDBPeakIdentity(net.sf.mzmine.util.spectraldb.entry.SpectralDBPeakIdentity) ArrayList(java.util.ArrayList) SpectralSimilarity(net.sf.mzmine.util.scans.similarity.SpectralSimilarity) Scan(net.sf.mzmine.datamodel.Scan) SpectralDBEntry(net.sf.mzmine.util.spectraldb.entry.SpectralDBEntry) DataPoint(net.sf.mzmine.datamodel.DataPoint) MissingMassListException(net.sf.mzmine.util.exceptions.MissingMassListException)

Example 87 with DataPoint

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

the class RowsSpectralMatchTask method spectraDBMatch.

/**
 * @param row
 * @param ident
 * @return spectral similarity or null if no match
 */
private SpectralSimilarity spectraDBMatch(PeakListRow row, DataPoint[] rowMassList, SpectralDBEntry ident) {
    // MS level 1 or check precursorMZ
    if (checkRT(row, ident) && (msLevel == 1 || checkPrecursorMZ(row, ident))) {
        DataPoint[] library = ident.getDataPoints();
        if (removeIsotopes)
            library = removeIsotopes(library);
        // crop the spectra to their overlapping mz range
        // helpful when comparing spectra, acquired with different fragmentation energy
        DataPoint[] query = rowMassList;
        if (cropSpectraToOverlap) {
            DataPoint[][] cropped = ScanAlignment.cropToOverlap(mzToleranceSpectra, library, query);
            library = cropped[0];
            query = cropped[1];
        }
        // check spectra similarity
        SpectralSimilarity sim = createSimilarity(library, query);
        if (sim != null) {
            return sim;
        }
    }
    return null;
}
Also used : DataPoint(net.sf.mzmine.datamodel.DataPoint) SpectralSimilarity(net.sf.mzmine.util.scans.similarity.SpectralSimilarity)

Example 88 with DataPoint

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

the class AdapMgfExportTask method exportRow.

private void exportRow(FileWriter writer, PeakListRow row, IsotopePattern ip) throws IOException {
    // data points of this cluster
    DataPoint[] dataPoints = ip.getDataPoints();
    if (!fractionalMZ)
        dataPoints = integerDataPoints(dataPoints, roundMode);
    // get m/z and rt
    double mz = getRepresentativeMZ(row, dataPoints);
    String retTimeInSeconds = rtsForm.format(row.getAverageRT() * 60);
    // write
    writer.write("BEGIN IONS" + newLine);
    writer.write("FEATURE_ID=" + row.getID() + newLine);
    writer.write("PEPMASS=" + formatMZ(mz) + newLine);
    writer.write("RTINSECONDS=" + retTimeInSeconds + newLine);
    writer.write("SCANS=" + row.getID() + newLine);
    // needs to be MSLEVEL=2 for GC-GNPS (even for GC-EI-MS data)
    writer.write("MSLEVEL=2" + newLine);
    writer.write("CHARGE=1+" + newLine);
    for (DataPoint point : dataPoints) {
        String line = formatMZ(point.getMZ()) + " " + intensityForm.format(point.getIntensity());
        writer.write(line + newLine);
    }
    writer.write("END IONS" + newLine);
    writer.write(newLine);
}
Also used : DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint)

Example 89 with DataPoint

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

the class GnpsJsonGenerator method genJSONData.

/**
 * JSON of data points array
 *
 * @param dps
 * @return
 */
private static JsonArray genJSONData(DataPoint[] dps) {
    JsonArrayBuilder data = Json.createArrayBuilder();
    JsonArrayBuilder signal = Json.createArrayBuilder();
    for (DataPoint dp : dps) {
        // round to five digits. thats more than enough
        signal.add(((int) (dp.getMZ() * 1000000)) / 1000000.0);
        signal.add(dp.getIntensity());
        data.add(signal.build());
    }
    return data.build();
}
Also used : DataPoint(net.sf.mzmine.datamodel.DataPoint) JsonArrayBuilder(javax.json.JsonArrayBuilder)

Example 90 with DataPoint

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

the class TICDataSet method calculateValues.

private void calculateValues() {
    // Determine plot type (now done from constructor).
    final TICPlotType plotType = this.plotType;
    // Process each scan.
    for (int index = 0; status != TaskStatus.CANCELED && index < totalScans; index++) {
        // Current scan.
        final Scan scan = scans[index];
        // Determine base peak value.
        final DataPoint basePeak = mzRange.encloses(scan.getDataPointMZRange()) ? scan.getHighestDataPoint() : ScanUtils.findBasePeak(scan, mzRange);
        if (basePeak != null) {
            basePeakValues[index] = basePeak.getMZ();
        }
        // Determine peak intensity.
        double intensity = 0.0;
        if (plotType == TICPlotType.TIC) {
            // Total ion count.
            intensity = mzRange.encloses(scan.getDataPointMZRange()) ? scan.getTIC() : ScanUtils.calculateTIC(scan, mzRange);
        } else if (plotType == TICPlotType.BASEPEAK && basePeak != null) {
            intensity = basePeak.getIntensity();
        }
        intensityValues[index] = intensity;
        rtValues[index] = scan.getRetentionTime();
        // Update min and max.
        if (index == 0) {
            intensityMin = intensity;
            intensityMax = intensity;
        } else {
            intensityMin = Math.min(intensity, intensityMin);
            intensityMax = Math.max(intensity, intensityMax);
        }
        processedScans++;
        // Refresh every REDRAW_INTERVAL ms.
        synchronized (TICDataSet.class) {
            if (System.currentTimeMillis() - lastRedrawTime > REDRAW_INTERVAL) {
                refresh();
                lastRedrawTime = System.currentTimeMillis();
            }
        }
    }
}
Also used : DataPoint(net.sf.mzmine.datamodel.DataPoint) Scan(net.sf.mzmine.datamodel.Scan) DataPoint(net.sf.mzmine.datamodel.DataPoint)

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