Search in sources :

Example 1 with MergedSpectrum

use of net.sf.mzmine.modules.tools.msmsspectramerge.MergedSpectrum 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 2 with MergedSpectrum

use of net.sf.mzmine.modules.tools.msmsspectramerge.MergedSpectrum in project mzmine2 by mzmine.

the class SiriusExportTask method exportPeakListRow.

private void exportPeakListRow(PeakListRow row, BufferedWriter writer) throws IOException {
    // get row charge and polarity
    char polarity = 0;
    for (Feature f : row.getPeaks()) {
        char pol = f.getDataFile().getScan(f.getRepresentativeScanNumber()).getPolarity().asSingleChar().charAt(0);
        if (pol != polarity && polarity != 0) {
            setErrorMessage("Joined features have different polarity. This is most likely a bug. If not, please separate them as individual features and/or write a feature request on github.");
            setStatus(TaskStatus.ERROR);
            return;
        } else {
            polarity = pol;
        }
    }
    if (mergeEnabled) {
        MergeMode mergeMode = mergeParameters.getParameter(MsMsSpectraMergeParameters.MERGE_MODE).getValue();
        MsMsSpectraMergeModule merger = MZmineCore.getModuleInstance(MsMsSpectraMergeModule.class);
        if (mergeMode != MergeMode.ACROSS_SAMPLES) {
            for (Feature f : row.getPeaks()) {
                if (f.getFeatureStatus() == Feature.FeatureStatus.DETECTED && f.getMostIntenseFragmentScanNumber() >= 0) {
                    // write correlation spectrum
                    writeHeader(writer, row, f.getDataFile(), polarity, MsType.CORRELATED, -1);
                    writeCorrelationSpectrum(writer, f);
                    if (mergeMode == MergeMode.CONSECUTIVE_SCANS) {
                        // merge MS/MS
                        List<MergedSpectrum> spectra = merger.mergeConsecutiveScans(mergeParameters, f, massListName);
                        for (MergedSpectrum spectrum : spectra) {
                            writeHeader(writer, row, f.getDataFile(), polarity, MsType.MSMS, spectrum.filterByRelativeNumberOfScans(mergeParameters.getParameter(MsMsSpectraMergeParameters.PEAK_COUNT_PARAMETER).getValue()));
                            writeSpectrum(writer, spectrum.data);
                        }
                    } else {
                        MergedSpectrum spectrum = merger.mergeFromSameSample(mergeParameters, f, massListName).filterByRelativeNumberOfScans(mergeParameters.getParameter(MsMsSpectraMergeParameters.PEAK_COUNT_PARAMETER).getValue());
                        if (spectrum.data.length > 0) {
                            writeHeader(writer, row, f.getDataFile(), polarity, MsType.MSMS, spectrum);
                            writeSpectrum(writer, spectrum.data);
                        }
                    }
                }
            }
        } else {
            // write correlation spectrum
            writeHeader(writer, row, row.getBestPeak().getDataFile(), polarity, MsType.CORRELATED, -1);
            writeCorrelationSpectrum(writer, row.getBestPeak());
            // merge everything into one
            MergedSpectrum spectrum = merger.mergeAcrossSamples(mergeParameters, row, massListName).filterByRelativeNumberOfScans(mergeParameters.getParameter(MsMsSpectraMergeParameters.PEAK_COUNT_PARAMETER).getValue());
            if (spectrum.data.length > 0) {
                writeHeader(writer, row, row.getBestPeak().getDataFile(), polarity, MsType.MSMS, spectrum);
                writeSpectrum(writer, spectrum.data);
            }
        }
    } else {
        // No merging
        Feature bestPeak = row.getBestPeak();
        MassList ms1MassList = bestPeak.getRepresentativeScan().getMassList(massListName);
        if (ms1MassList != null) {
            writeHeader(writer, row, bestPeak.getDataFile(), polarity, MsType.MS, bestPeak.getRepresentativeScanNumber());
            writeSpectrum(writer, ms1MassList.getDataPoints());
        }
        for (Feature f : row.getPeaks()) {
            for (int ms2scan : f.getAllMS2FragmentScanNumbers()) {
                writeHeader(writer, row, f.getDataFile(), polarity, MsType.MSMS, ms2scan);
                MassList ms2MassList = f.getDataFile().getScan(ms2scan).getMassList(massListName);
                if (ms2MassList == null)
                    continue;
                writeSpectrum(writer, ms2MassList.getDataPoints());
            }
        }
    }
}
Also used : MergeMode(net.sf.mzmine.modules.tools.msmsspectramerge.MergeMode) MsMsSpectraMergeModule(net.sf.mzmine.modules.tools.msmsspectramerge.MsMsSpectraMergeModule) MergedSpectrum(net.sf.mzmine.modules.tools.msmsspectramerge.MergedSpectrum) Feature(net.sf.mzmine.datamodel.Feature) MassList(net.sf.mzmine.datamodel.MassList) DataPoint(net.sf.mzmine.datamodel.DataPoint)

Example 3 with MergedSpectrum

use of net.sf.mzmine.modules.tools.msmsspectramerge.MergedSpectrum in project mzmine2 by mzmine.

the class GnpsFbmnMgfExportTask method export.

private int export(PeakList peakList, FileWriter writer, File curFile) throws IOException {
    final String newLine = System.lineSeparator();
    // count exported
    int count = 0;
    int countMissingMassList = 0;
    for (PeakListRow row : peakList.getRows()) {
        // do not export if no MSMS
        if (!filter.filter(row))
            continue;
        String rowID = Integer.toString(row.getID());
        double retTimeInSeconds = ((row.getAverageRT() * 60 * 100.0) / 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 heighest peak with a MS/MS scan number (with mass list)
            boolean missingMassList = false;
            msmsScanNumber = bestPeak.getMostIntenseFragmentScanNumber();
            while (msmsScanNumber < 1 || getScan(bestPeak, msmsScanNumber).getMassList(massListName) == null) {
                // missing masslist
                if (msmsScanNumber > 0)
                    missingMassList = true;
                copyRow.removePeak(bestPeak.getDataFile());
                if (copyRow.getPeaks().length == 0)
                    break;
                bestPeak = copyRow.getBestPeak();
                msmsScanNumber = bestPeak.getMostIntenseFragmentScanNumber();
            }
            if (missingMassList)
                countMissingMassList++;
        }
        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) {
                continue;
            }
            writer.write("BEGIN IONS" + newLine);
            if (rowID != null)
                writer.write("FEATURE_ID=" + rowID + newLine);
            String mass = mzForm.format(row.getAverageMZ());
            if (mass != null)
                writer.write("PEPMASS=" + mass + newLine);
            if (rowID != null) {
                writer.write("SCANS=" + rowID + newLine);
                writer.write("RTINSECONDS=" + rtsForm.format(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(mzForm.format(peak.getMZ()) + " " + intensityForm.format(peak.getIntensity()) + newLine);
            }
            writer.write("END IONS" + newLine);
            writer.write(newLine);
            count++;
        }
    }
    if (count == 0)
        LOG.log(Level.WARNING, "No MS/MS scans exported.");
    else
        LOG.info(MessageFormat.format("Total of {0} feature rows (MS/MS mass lists) were exported ({1})", count, peakList.getName()));
    if (countMissingMassList > 0)
        LOG.warning(MessageFormat.format("WARNING: Total of {0} feature rows have an MS/MS scan but NO mass list (this shouldn't be a problem if a scan filter was applied in the mass detection step) ({1})", countMissingMassList, peakList.getName()));
    return count;
}
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) Feature(net.sf.mzmine.datamodel.Feature) SimpleFeature(net.sf.mzmine.datamodel.impl.SimpleFeature) DataPoint(net.sf.mzmine.datamodel.DataPoint) MassList(net.sf.mzmine.datamodel.MassList)

Aggregations

DataPoint (net.sf.mzmine.datamodel.DataPoint)3 Feature (net.sf.mzmine.datamodel.Feature)3 MassList (net.sf.mzmine.datamodel.MassList)3 MergedSpectrum (net.sf.mzmine.modules.tools.msmsspectramerge.MergedSpectrum)3 MsMsSpectraMergeModule (net.sf.mzmine.modules.tools.msmsspectramerge.MsMsSpectraMergeModule)3 PeakListRow (net.sf.mzmine.datamodel.PeakListRow)2 Scan (net.sf.mzmine.datamodel.Scan)2 SimpleFeature (net.sf.mzmine.datamodel.impl.SimpleFeature)2 SimplePeakListRow (net.sf.mzmine.datamodel.impl.SimplePeakListRow)2 MergeMode (net.sf.mzmine.modules.tools.msmsspectramerge.MergeMode)1