Search in sources :

Example 46 with PeakListRow

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

the class GnpsFbmnExportTask method export.

private void export(PeakList peakList, FileWriter writer, File curFile) throws IOException {
    final String newLine = System.lineSeparator();
    for (PeakListRow row : peakList.getRows()) {
        String rowID = Integer.toString(row.getID());
        String retTimeInSeconds = Double.toString(Math.round(row.getAverageRT() * 60 * 100) / 100.);
        // Get the MS/MS scan number
        Feature bestPeak = row.getBestPeak();
        if (bestPeak == null)
            continue;
        int msmsScanNumber = bestPeak.getMostIntenseFragmentScanNumber();
        if (rowID != null) {
            PeakListRow copyRow = copyPeakRow(row);
            // Best peak always exists, because feature list row has at least one peak
            bestPeak = copyRow.getBestPeak();
            // Get the MS/MS scan number
            msmsScanNumber = bestPeak.getMostIntenseFragmentScanNumber();
            while (msmsScanNumber < 1) {
                copyRow.removePeak(bestPeak.getDataFile());
                if (copyRow.getPeaks().length == 0)
                    break;
                bestPeak = copyRow.getBestPeak();
                msmsScanNumber = bestPeak.getMostIntenseFragmentScanNumber();
            }
        }
        if (msmsScanNumber >= 1) {
            // MS/MS scan must exist, because msmsScanNumber was > 0
            Scan msmsScan = bestPeak.getDataFile().getScan(msmsScanNumber);
            MassList massList = msmsScan.getMassList(massListName);
            if (massList == null) {
                MZmineCore.getDesktop().displayErrorMessage(MZmineCore.getDesktop().getMainWindow(), "There is no mass list called " + massListName + " for MS/MS scan #" + msmsScanNumber + " (" + bestPeak.getDataFile() + ")");
                return;
            }
            writer.write("BEGIN IONS" + newLine);
            if (rowID != null)
                writer.write("FEATURE_ID=" + rowID + newLine);
            String mass = Double.toString(Math.round(row.getAverageMZ() * 10000) / 10000.);
            if (mass != null)
                writer.write("PEPMASS=" + mass + newLine);
            if (rowID != null) {
                writer.write("SCANS=" + rowID + newLine);
                writer.write("RTINSECONDS=" + retTimeInSeconds + newLine);
            }
            int msmsCharge = msmsScan.getPrecursorCharge();
            String msmsPolarity = msmsScan.getPolarity().asSingleChar();
            if (msmsPolarity.equals("0"))
                msmsPolarity = "";
            if (msmsCharge == 0) {
                msmsCharge = 1;
                msmsPolarity = "";
            }
            writer.write("CHARGE=" + msmsCharge + msmsPolarity + newLine);
            writer.write("MSLEVEL=2" + newLine);
            DataPoint[] dataPoints = massList.getDataPoints();
            if (mergeParameters != null) {
                MsMsSpectraMergeModule merger = MZmineCore.getModuleInstance(MsMsSpectraMergeModule.class);
                MergedSpectrum spectrum = merger.getBestMergedSpectrum(mergeParameters, row, massListName);
                if (spectrum != null) {
                    dataPoints = spectrum.data;
                    writer.write("MERGED_STATS=");
                    writer.write(spectrum.getMergeStatsDescription());
                    writer.write(newLine);
                }
            }
            for (DataPoint peak : dataPoints) {
                writer.write(peak.getMZ() + " " + peak.getIntensity() + newLine);
            }
            writer.write("END IONS" + newLine);
            writer.write(newLine);
        }
    }
}
Also used : SimplePeakListRow(net.sf.mzmine.datamodel.impl.SimplePeakListRow) PeakListRow(net.sf.mzmine.datamodel.PeakListRow) DataPoint(net.sf.mzmine.datamodel.DataPoint) MsMsSpectraMergeModule(net.sf.mzmine.modules.tools.msmsspectramerge.MsMsSpectraMergeModule) MergedSpectrum(net.sf.mzmine.modules.tools.msmsspectramerge.MergedSpectrum) Scan(net.sf.mzmine.datamodel.Scan) SimpleFeature(net.sf.mzmine.datamodel.impl.SimpleFeature) Feature(net.sf.mzmine.datamodel.Feature) DataPoint(net.sf.mzmine.datamodel.DataPoint) MassList(net.sf.mzmine.datamodel.MassList)

Example 47 with PeakListRow

use of net.sf.mzmine.datamodel.PeakListRow 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 48 with PeakListRow

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

the class SiriusExportTask method runSingleRows.

public void runSingleRows(PeakListRow[] rows) {
    setStatus(TaskStatus.PROCESSING);
    // prefill statistics
    prefillStatistics(rows);
    try (final BufferedWriter bw = new BufferedWriter(new FileWriter(fileName, true))) {
        for (PeakListRow row : rows) exportPeakListRow(row, bw);
    } catch (IOException e) {
        setStatus(TaskStatus.ERROR);
        setErrorMessage("Could not open file " + fileName + " for writing.");
    }
    if (getStatus() == TaskStatus.PROCESSING)
        setStatus(TaskStatus.FINISHED);
}
Also used : PeakListRow(net.sf.mzmine.datamodel.PeakListRow) FileWriter(java.io.FileWriter) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter)

Example 49 with PeakListRow

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

the class GnpsFbmnMgfExportTask method copyPeakRow.

/**
 * Create a copy of a feature list row.
 */
private static PeakListRow copyPeakRow(final PeakListRow row) {
    // Copy the feature list row.
    final PeakListRow newRow = new SimplePeakListRow(row.getID());
    PeakUtils.copyPeakListRowProperties(row, newRow);
    // Copy the peaks.
    for (final Feature peak : row.getPeaks()) {
        final Feature newPeak = new SimpleFeature(peak);
        PeakUtils.copyPeakProperties(peak, newPeak);
        newRow.addPeak(peak.getDataFile(), newPeak);
    }
    return newRow;
}
Also used : SimplePeakListRow(net.sf.mzmine.datamodel.impl.SimplePeakListRow) PeakListRow(net.sf.mzmine.datamodel.PeakListRow) SimplePeakListRow(net.sf.mzmine.datamodel.impl.SimplePeakListRow) Feature(net.sf.mzmine.datamodel.Feature) SimpleFeature(net.sf.mzmine.datamodel.impl.SimpleFeature) SimpleFeature(net.sf.mzmine.datamodel.impl.SimpleFeature)

Example 50 with PeakListRow

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

the class VanKrevelenDiagramParameters method showSetupDialog.

@Override
public ExitCode showSetupDialog(Window parent, boolean valueCheckRequired) {
    PeakList[] selectedPeakLists = getParameter(peakList).getValue().getMatchingPeakLists();
    if (selectedPeakLists.length > 0) {
        PeakListRow[] plRows = selectedPeakLists[0].getRows();
        Arrays.sort(plRows, new PeakListRowSorter(SortingProperty.MZ, SortingDirection.Ascending));
    }
    return super.showSetupDialog(parent, valueCheckRequired);
}
Also used : PeakListRow(net.sf.mzmine.datamodel.PeakListRow) PeakList(net.sf.mzmine.datamodel.PeakList) PeakListRowSorter(net.sf.mzmine.util.PeakListRowSorter)

Aggregations

PeakListRow (net.sf.mzmine.datamodel.PeakListRow)148 Feature (net.sf.mzmine.datamodel.Feature)71 RawDataFile (net.sf.mzmine.datamodel.RawDataFile)55 SimplePeakListRow (net.sf.mzmine.datamodel.impl.SimplePeakListRow)54 PeakList (net.sf.mzmine.datamodel.PeakList)44 SimplePeakList (net.sf.mzmine.datamodel.impl.SimplePeakList)39 ArrayList (java.util.ArrayList)31 SimpleFeature (net.sf.mzmine.datamodel.impl.SimpleFeature)31 DataPoint (net.sf.mzmine.datamodel.DataPoint)29 SimplePeakListAppliedMethod (net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod)26 Scan (net.sf.mzmine.datamodel.Scan)25 PeakIdentity (net.sf.mzmine.datamodel.PeakIdentity)20 PeakListRowSorter (net.sf.mzmine.util.PeakListRowSorter)17 SimpleDataPoint (net.sf.mzmine.datamodel.impl.SimpleDataPoint)13 PeakListAppliedMethod (net.sf.mzmine.datamodel.PeakList.PeakListAppliedMethod)12 HashMap (java.util.HashMap)11 Vector (java.util.Vector)11 ParameterSet (net.sf.mzmine.parameters.ParameterSet)11 IsotopePattern (net.sf.mzmine.datamodel.IsotopePattern)10 MassList (net.sf.mzmine.datamodel.MassList)10