Search in sources :

Example 26 with MassList

use of net.sf.mzmine.datamodel.MassList 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)

Example 27 with MassList

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

the class SingleRowIdentificationTask method buildMSDKSpectrum.

/**
 * Construct MsSpectrum object from DataPoint array
 *
 * @param points MZ/Intensity pairs
 * @return new MsSpectrum
 */
private MsSpectrum buildMSDKSpectrum(Scan scan, String massListName) throws MissingMassListException {
    MassList ml = scan.getMassList(massListName);
    if (ml == null)
        throw new MissingMassListException("Scan #" + scan.getScanNumber() + " does not have mass list", massListName);
    DataPoint[] points = ml.getDataPoints();
    SimpleMsSpectrum spectrum = new SimpleMsSpectrum();
    double[] mz = new double[points.length];
    float[] intensity = new float[points.length];
    for (int i = 0; i < points.length; i++) {
        mz[i] = points[i].getMZ();
        intensity[i] = (float) points[i].getIntensity();
    }
    DataPointSorter.sortDataPoints(mz, intensity, points.length, SortingProperty.MZ, SortingDirection.ASCENDING);
    spectrum.setDataPoints(mz, intensity, points.length);
    return spectrum;
}
Also used : SimpleMsSpectrum(io.github.msdk.datamodel.SimpleMsSpectrum) DataPoint(net.sf.mzmine.datamodel.DataPoint) MassList(net.sf.mzmine.datamodel.MassList) MissingMassListException(net.sf.mzmine.util.exceptions.MissingMassListException) DataPoint(net.sf.mzmine.datamodel.DataPoint)

Example 28 with MassList

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

the class ScanSorter method compare.

@Override
public int compare(Scan a, Scan b) {
    MassList ma = ScanUtils.getMassListOrFirst(a, massListName);
    MassList mb = ScanUtils.getMassListOrFirst(b, massListName);
    if (ma == null || mb == null)
        throw new RuntimeException(new MissingMassListException(massListName));
    return comp.compare(ma.getDataPoints(), mb.getDataPoints());
}
Also used : MassList(net.sf.mzmine.datamodel.MassList) MissingMassListException(net.sf.mzmine.util.exceptions.MissingMassListException)

Example 29 with MassList

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

the class MSMSScoreCalculator method evaluateMSMS.

/**
 * Returns a calculated similarity score of
 */
public static MSMSScore evaluateMSMS(IMolecularFormula parentFormula, Scan msmsScan, ParameterSet parameters) {
    MZTolerance msmsTolerance = parameters.getParameter(MSMSScoreParameters.msmsTolerance).getValue();
    String massListName = parameters.getParameter(MSMSScoreParameters.massList).getValue();
    MassList massList = msmsScan.getMassList(massListName);
    if (massList == null) {
        throw new IllegalArgumentException("Scan #" + msmsScan.getScanNumber() + " does not have a mass list called '" + massListName + "'");
    }
    DataPoint[] msmsIons = massList.getDataPoints();
    if (msmsIons == null) {
        throw new IllegalArgumentException("Mass list " + massList + " does not contain data for scan #" + msmsScan.getScanNumber());
    }
    MolecularFormulaRange msmsElementRange = new MolecularFormulaRange();
    for (IIsotope isotope : parentFormula.isotopes()) {
        msmsElementRange.addIsotope(isotope, 0, parentFormula.getIsotopeCount(isotope));
    }
    int totalMSMSpeaks = 0, interpretedMSMSpeaks = 0;
    Map<DataPoint, String> msmsAnnotations = new Hashtable<DataPoint, String>();
    msmsCycle: for (DataPoint dp : msmsIons) {
        // Check if this is an isotope
        Range<Double> isotopeCheckRange = Range.closed(dp.getMZ() - 1.4, dp.getMZ() - 0.6);
        for (DataPoint dpCheck : msmsIons) {
            // isotope and we should ignore it
            if (isotopeCheckRange.contains(dpCheck.getMZ()) && (dpCheck.getIntensity() > dp.getIntensity())) {
                continue msmsCycle;
            }
        }
        // If getPrecursorCharge() returns 0, it means charge is unknown. In
        // that case let's assume charge 1
        int precursorCharge = msmsScan.getPrecursorCharge();
        if (precursorCharge == 0)
            precursorCharge = 1;
        // We don't know the charge of the fragment, so we will simply
        // assume 1
        double neutralLoss = msmsScan.getPrecursorMZ() * precursorCharge - dp.getMZ();
        // good threshold
        if (neutralLoss < 5) {
            continue;
        }
        Range<Double> msmsTargetRange = msmsTolerance.getToleranceRange(neutralLoss);
        IChemObjectBuilder builder = SilentChemObjectBuilder.getInstance();
        MolecularFormulaGenerator msmsEngine = new MolecularFormulaGenerator(builder, msmsTargetRange.lowerEndpoint(), msmsTargetRange.upperEndpoint(), msmsElementRange);
        IMolecularFormula formula = msmsEngine.getNextFormula();
        if (formula != null) {
            String formulaString = MolecularFormulaManipulator.getString(formula);
            msmsAnnotations.put(dp, formulaString);
            interpretedMSMSpeaks++;
        }
        totalMSMSpeaks++;
    }
    // If we did not evaluate any MS/MS peaks, we cannot calculate a score
    if (totalMSMSpeaks == 0) {
        return null;
    }
    double msmsScore = (double) interpretedMSMSpeaks / totalMSMSpeaks;
    MSMSScore result = new MSMSScore(msmsScore, msmsAnnotations);
    return result;
}
Also used : IIsotope(org.openscience.cdk.interfaces.IIsotope) MZTolerance(net.sf.mzmine.parameters.parametertypes.tolerances.MZTolerance) MolecularFormulaRange(org.openscience.cdk.formula.MolecularFormulaRange) Hashtable(java.util.Hashtable) IMolecularFormula(org.openscience.cdk.interfaces.IMolecularFormula) Range(com.google.common.collect.Range) MolecularFormulaRange(org.openscience.cdk.formula.MolecularFormulaRange) DataPoint(net.sf.mzmine.datamodel.DataPoint) IChemObjectBuilder(org.openscience.cdk.interfaces.IChemObjectBuilder) MolecularFormulaGenerator(org.openscience.cdk.formula.MolecularFormulaGenerator) DataPoint(net.sf.mzmine.datamodel.DataPoint) MassList(net.sf.mzmine.datamodel.MassList)

Example 30 with MassList

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

the class Candidates method calcAvgPeakHeight.

/**
 * needed by calcTemporaryAvgRating
 *
 * @param ID
 * @return avPeakHeight
 */
private double calcAvgPeakHeight(int ID) {
    PeakListRow row = plh.getRowByID(ID);
    RawDataFile[] raws = row.getRawDataFiles();
    if (raws.length < 1)
        return 0.0;
    double mz = row.getAverageMZ();
    double avgIntensity = 0.0;
    int pointsAdded = 0;
    for (RawDataFile raw : raws) {
        if (!raw.getDataMZRange().contains(mz))
            continue;
        int[] scanNums = raw.getScanNumbers();
        for (int i = 0; i < scanNums.length; i++) {
            Scan scan = raw.getScan(scanNums[i]);
            MassList list = scan.getMassList(massListName);
            if (list == null)
                continue;
            DataPoint[] points = getMassListDataPointsByMass(list, mzTolerance.getToleranceRange(mz));
            if (points.length == 0)
                continue;
            DataPoint dp = getClosestDataPoint(points, mz, minHeight);
            if (dp != null) {
                avgIntensity += dp.getIntensity();
                pointsAdded++;
            }
        }
    }
    if (pointsAdded != 0)
        return avgIntensity / pointsAdded;
    else
        return -1.0;
}
Also used : PeakListRow(net.sf.mzmine.datamodel.PeakListRow) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) Scan(net.sf.mzmine.datamodel.Scan) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) MassList(net.sf.mzmine.datamodel.MassList)

Aggregations

MassList (net.sf.mzmine.datamodel.MassList)36 Scan (net.sf.mzmine.datamodel.Scan)25 DataPoint (net.sf.mzmine.datamodel.DataPoint)24 RawDataFile (net.sf.mzmine.datamodel.RawDataFile)14 Feature (net.sf.mzmine.datamodel.Feature)9 PeakListRow (net.sf.mzmine.datamodel.PeakListRow)9 ArrayList (java.util.ArrayList)6 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)5 PeakList (net.sf.mzmine.datamodel.PeakList)5 SimpleDataPoint (net.sf.mzmine.datamodel.impl.SimpleDataPoint)4 SimplePeakListRow (net.sf.mzmine.datamodel.impl.SimplePeakListRow)4 Range (com.google.common.collect.Range)3 FileWriter (java.io.FileWriter)3 IOException (java.io.IOException)3 TreePath (javax.swing.tree.TreePath)3 IsotopePattern (net.sf.mzmine.datamodel.IsotopePattern)3 MZmineProject (net.sf.mzmine.datamodel.MZmineProject)3 MergedSpectrum (net.sf.mzmine.modules.tools.msmsspectramerge.MergedSpectrum)3 MsMsSpectraMergeModule (net.sf.mzmine.modules.tools.msmsspectramerge.MsMsSpectraMergeModule)3 BufferedWriter (java.io.BufferedWriter)2