Search in sources :

Example 91 with Feature

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

the class PeakUtils method copyPeakRow.

/**
 * Creates a copy of a PeakListRow.
 * @param row A row.
 * @return A copy of row.
 */
public 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) SimpleFeature(net.sf.mzmine.datamodel.impl.SimpleFeature) Feature(net.sf.mzmine.datamodel.Feature) SimpleFeature(net.sf.mzmine.datamodel.impl.SimpleFeature)

Example 92 with Feature

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

the class ADAPInterface method getComponent.

public static Component getComponent(final PeakListRow row) {
    if (row.getNumberOfPeaks() == 0)
        throw new IllegalArgumentException("No peaks found");
    NavigableMap<Double, Double> spectrum = new TreeMap<>();
    // Read Spectrum information
    IsotopePattern ip = row.getBestIsotopePattern();
    if (ip != null) {
        for (DataPoint dataPoint : ip.getDataPoints()) spectrum.put(dataPoint.getMZ(), dataPoint.getIntensity());
    }
    // Read Chromatogram
    final Feature peak = row.getBestPeak();
    final RawDataFile dataFile = peak.getDataFile();
    NavigableMap<Double, Double> chromatogram = new TreeMap<>();
    for (final int scan : peak.getScanNumbers()) {
        final DataPoint dataPoint = peak.getDataPoint(scan);
        if (dataPoint != null)
            chromatogram.put(dataFile.getScan(scan).getRetentionTime(), dataPoint.getIntensity());
    }
    return new Component(null, new Peak(chromatogram, new PeakInfo().mzValue(peak.getMZ()).peakID(row.getID())), spectrum, null);
}
Also used : DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) IsotopePattern(net.sf.mzmine.datamodel.IsotopePattern) Peak(dulab.adap.datamodel.Peak) BetterPeak(dulab.adap.datamodel.BetterPeak) TreeMap(java.util.TreeMap) Component(dulab.adap.datamodel.Component) Feature(net.sf.mzmine.datamodel.Feature) SimpleFeature(net.sf.mzmine.datamodel.impl.SimpleFeature) PeakInfo(dulab.adap.datamodel.PeakInfo) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint)

Example 93 with Feature

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

the class FormulaPredictionPeakListTask method checkConstraints.

private boolean checkConstraints(IMolecularFormula cdkFormula, PeakListRow peakListRow) {
    // Check elemental ratios
    if (checkRatios) {
        boolean check = ElementalHeuristicChecker.checkFormula(cdkFormula, ratiosParameters);
        if (!check) {
            return false;
        }
    }
    Double rdbeValue = RDBERestrictionChecker.calculateRDBE(cdkFormula);
    // Check RDBE condition
    if (checkRDBE && (rdbeValue != null)) {
        boolean check = RDBERestrictionChecker.checkRDBE(rdbeValue, rdbeParameters);
        if (!check) {
            return false;
        }
    }
    // Calculate isotope similarity score
    IsotopePattern detectedPattern = peakListRow.getBestIsotopePattern();
    IsotopePattern predictedIsotopePattern = null;
    Double isotopeScore = null;
    if ((checkIsotopes) && (detectedPattern != null)) {
        String stringFormula = MolecularFormulaManipulator.getString(cdkFormula);
        String adjustedFormula = FormulaUtils.ionizeFormula(stringFormula, ionType, charge);
        final double isotopeNoiseLevel = isotopeParameters.getParameter(IsotopePatternScoreParameters.isotopeNoiseLevel).getValue();
        final double detectedPatternHeight = detectedPattern.getHighestDataPoint().getIntensity();
        final double minPredictedAbundance = isotopeNoiseLevel / detectedPatternHeight;
        predictedIsotopePattern = IsotopePatternCalculator.calculateIsotopePattern(adjustedFormula, minPredictedAbundance, charge, ionType.getPolarity());
        isotopeScore = IsotopePatternScoreCalculator.getSimilarityScore(detectedPattern, predictedIsotopePattern, isotopeParameters);
        final double minScore = isotopeParameters.getParameter(IsotopePatternScoreParameters.isotopePatternScoreThreshold).getValue();
        if (isotopeScore < minScore) {
            return false;
        }
    }
    // MS/MS evaluation is slowest, so let's do it last
    Double msmsScore = null;
    Feature bestPeak = peakListRow.getBestPeak();
    RawDataFile dataFile = bestPeak.getDataFile();
    int msmsScanNumber = bestPeak.getMostIntenseFragmentScanNumber();
    if ((checkMSMS) && (msmsScanNumber > 0)) {
        Scan msmsScan = dataFile.getScan(msmsScanNumber);
        String massListName = msmsParameters.getParameter(MSMSScoreParameters.massList).getValue();
        MassList ms2MassList = msmsScan.getMassList(massListName);
        if (ms2MassList == null) {
            setStatus(TaskStatus.ERROR);
            setErrorMessage("The MS/MS scan #" + msmsScanNumber + " in file " + dataFile.getName() + " does not have a mass list called '" + massListName + "'");
            return false;
        }
        MSMSScore score = MSMSScoreCalculator.evaluateMSMS(cdkFormula, msmsScan, msmsParameters);
        double minMSMSScore = msmsParameters.getParameter(MSMSScoreParameters.msmsMinScore).getValue();
        if (score != null) {
            msmsScore = score.getScore();
            // Check the MS/MS condition
            if (msmsScore < minMSMSScore) {
                return false;
            }
        }
    }
    return true;
}
Also used : RawDataFile(net.sf.mzmine.datamodel.RawDataFile) IsotopePattern(net.sf.mzmine.datamodel.IsotopePattern) Scan(net.sf.mzmine.datamodel.Scan) Feature(net.sf.mzmine.datamodel.Feature) MassList(net.sf.mzmine.datamodel.MassList) MSMSScore(net.sf.mzmine.modules.peaklistmethods.msms.msmsscore.MSMSScore)

Example 94 with Feature

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

the class MzTabImportTask method importSmallMolecules.

private void importSmallMolecules(PeakList newPeakList, MZTabFile mzTabFile, Map<Integer, RawDataFile> rawDataFiles) {
    SortedMap<Integer, Assay> assayMap = mzTabFile.getMetadata().getAssayMap();
    Collection<SmallMolecule> smallMolecules = mzTabFile.getSmallMolecules();
    // Loop through SML data
    String formula, description, database, url = "";
    double mzExp = 0, abundance = 0, peak_mz = 0, peak_rt = 0, peak_height = 0, rtValue = 0;
    // int charge = 0;
    int rowCounter = 0;
    for (SmallMolecule smallMolecule : smallMolecules) {
        // Stop the process if cancel() was called
        if (isCanceled())
            return;
        rowCounter++;
        formula = smallMolecule.getChemicalFormula();
        // smile = smallMolecule.getSmiles();
        // inchiKey = smallMolecule.getInchiKey();
        description = smallMolecule.getDescription();
        // species = smallMolecule.getSpecies();
        database = smallMolecule.getDatabase();
        if (smallMolecule.getURI() != null) {
            url = smallMolecule.getURI().toString();
        }
        String identifier = smallMolecule.getIdentifier().toString();
        SplitList<Double> rt = smallMolecule.getRetentionTime();
        if (smallMolecule.getExpMassToCharge() != null) {
            mzExp = smallMolecule.getExpMassToCharge();
        }
        // Calculate average RT if multiple values are available
        if (rt != null && !rt.isEmpty()) {
            rtValue = DoubleMath.mean(rt);
        }
        if ((url != null) && (url.equals("null"))) {
            url = null;
        }
        if (identifier.equals("null")) {
            identifier = null;
        }
        if (description == null && identifier != null) {
            description = identifier;
        }
        // Add shared information to row
        SimplePeakListRow newRow = new SimplePeakListRow(rowCounter);
        newRow.setAverageMZ(mzExp);
        newRow.setAverageRT(rtValue);
        if (description != null) {
            SimplePeakIdentity newIdentity = new SimplePeakIdentity(description, formula, database, identifier, url);
            newRow.addPeakIdentity(newIdentity, false);
        }
        // Add raw data file entries to row
        for (Entry<Integer, RawDataFile> rawDataEntry : rawDataFiles.entrySet()) {
            RawDataFile rawData = rawDataEntry.getValue();
            Assay dataFileAssay = assayMap.get(rawDataEntry.getKey());
            abundance = 0;
            peak_mz = 0;
            peak_rt = 0;
            peak_height = 0;
            if (smallMolecule.getAbundanceColumnValue(dataFileAssay) != null) {
                abundance = smallMolecule.getAbundanceColumnValue(dataFileAssay);
            }
            if (smallMolecule.getOptionColumnValue(dataFileAssay, "peak_mz") != null) {
                peak_mz = Double.parseDouble(smallMolecule.getOptionColumnValue(dataFileAssay, "peak_mz"));
            } else {
                peak_mz = mzExp;
            }
            if (smallMolecule.getOptionColumnValue(dataFileAssay, "peak_rt") != null) {
                peak_rt = Double.parseDouble(smallMolecule.getOptionColumnValue(dataFileAssay, "peak_rt"));
            } else {
                peak_rt = rtValue;
            }
            if (smallMolecule.getOptionColumnValue(dataFileAssay, "peak_height") != null) {
                peak_height = Double.parseDouble(smallMolecule.getOptionColumnValue(dataFileAssay, "peak_height"));
            } else {
                peak_height = 0.0;
            }
            int[] scanNumbers = {};
            DataPoint[] finalDataPoint = new DataPoint[1];
            finalDataPoint[0] = new SimpleDataPoint(peak_mz, peak_height);
            int representativeScan = 0;
            int fragmentScan = 0;
            int[] allFragmentScans = new int[] { 0 };
            Range<Double> finalRTRange = Range.singleton(peak_rt);
            Range<Double> finalMZRange = Range.singleton(peak_mz);
            Range<Double> finalIntensityRange = Range.singleton(peak_height);
            FeatureStatus status = FeatureStatus.DETECTED;
            Feature peak = new SimpleFeature(rawData, peak_mz, peak_rt, peak_height, abundance, scanNumbers, finalDataPoint, status, representativeScan, fragmentScan, allFragmentScans, finalRTRange, finalMZRange, finalIntensityRange);
            if (abundance > 0) {
                newRow.addPeak(rawData, peak);
            }
        }
        // Add row to feature list
        newPeakList.addRow(newRow);
    }
}
Also used : FeatureStatus(net.sf.mzmine.datamodel.Feature.FeatureStatus) SimplePeakIdentity(net.sf.mzmine.datamodel.impl.SimplePeakIdentity) SimplePeakListRow(net.sf.mzmine.datamodel.impl.SimplePeakListRow) Feature(net.sf.mzmine.datamodel.Feature) SimpleFeature(net.sf.mzmine.datamodel.impl.SimpleFeature) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) SimpleFeature(net.sf.mzmine.datamodel.impl.SimpleFeature) Assay(uk.ac.ebi.pride.jmztab.model.Assay) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) SmallMolecule(uk.ac.ebi.pride.jmztab.model.SmallMolecule) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint)

Example 95 with Feature

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

Feature (net.sf.mzmine.datamodel.Feature)115 PeakListRow (net.sf.mzmine.datamodel.PeakListRow)70 RawDataFile (net.sf.mzmine.datamodel.RawDataFile)60 SimplePeakListRow (net.sf.mzmine.datamodel.impl.SimplePeakListRow)41 DataPoint (net.sf.mzmine.datamodel.DataPoint)35 SimpleFeature (net.sf.mzmine.datamodel.impl.SimpleFeature)35 SimplePeakList (net.sf.mzmine.datamodel.impl.SimplePeakList)25 Scan (net.sf.mzmine.datamodel.Scan)22 PeakList (net.sf.mzmine.datamodel.PeakList)20 ArrayList (java.util.ArrayList)17 SimplePeakListAppliedMethod (net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod)16 IsotopePattern (net.sf.mzmine.datamodel.IsotopePattern)15 PeakIdentity (net.sf.mzmine.datamodel.PeakIdentity)15 SimpleDataPoint (net.sf.mzmine.datamodel.impl.SimpleDataPoint)13 PeakListAppliedMethod (net.sf.mzmine.datamodel.PeakList.PeakListAppliedMethod)10 MassList (net.sf.mzmine.datamodel.MassList)9 HashMap (java.util.HashMap)8 Vector (java.util.Vector)8 ScanSelection (net.sf.mzmine.parameters.parametertypes.selectors.ScanSelection)7 TreeMap (java.util.TreeMap)6