Search in sources :

Example 21 with IsotopePattern

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

the class DPPIsotopeGrouperTask method run.

@Override
public void run() {
    if (!checkParameterSet() || !checkValues()) {
        setStatus(TaskStatus.ERROR);
        return;
    }
    if (!FormulaUtils.checkMolecularFormula(element)) {
        setStatus(TaskStatus.ERROR);
        logger.warning("Data point/Spectra processing: Invalid element parameter in " + getTaskDescription());
    }
    if (getDataPoints().length == 0) {
        logger.info("Data point/Spectra processing: 0 data points were passed to " + getTaskDescription() + " Please check the parameters.");
        setStatus(TaskStatus.CANCELED);
        return;
    }
    if (!(getDataPoints() instanceof ProcessedDataPoint[])) {
        logger.warning("Data point/Spectra processing: The data points passed to Isotope Grouper were not an instance of processed data points." + " Make sure to run mass detection first.");
        setStatus(TaskStatus.CANCELED);
        return;
    }
    setStatus(TaskStatus.PROCESSING);
    ProcessedDataPoint[] dataPoints = (ProcessedDataPoint[]) getDataPoints();
    int[] charges = new int[maximumCharge];
    for (int i = 0; i < maximumCharge; i++) charges[i] = i + 1;
    IsotopePattern pattern = IsotopePatternCalculator.calculateIsotopePattern(element, 0.01, 1, PolarityType.POSITIVE);
    double isotopeDistance = pattern.getDataPoints()[1].getMZ() - pattern.getDataPoints()[0].getMZ();
    ProcessedDataPoint[] sortedDataPoints = dataPoints.clone();
    Arrays.sort(sortedDataPoints, (d1, d2) -> {
        // *-1 to sort descending
        return -1 * Double.compare(d1.getIntensity(), d2.getIntensity());
    });
    List<ProcessedDataPoint> deisotopedDataPoints = new ArrayList<>();
    for (int i = 0; i < sortedDataPoints.length; i++) {
        if (isCanceled())
            return;
        DataPoint aPeak = sortedDataPoints[i];
        if (aPeak == null) {
            processedPeaks++;
            continue;
        }
        // Check which charge state fits best around this peak
        int bestFitCharge = 0;
        int bestFitScore = -1;
        Vector<DataPoint> bestFitPeaks = null;
        for (int charge : charges) {
            Vector<DataPoint> fittedPeaks = new Vector<DataPoint>();
            fittedPeaks.add(aPeak);
            fitPattern(fittedPeaks, aPeak, charge, sortedDataPoints, isotopeDistance);
            int score = fittedPeaks.size();
            if ((score > bestFitScore) || ((score == bestFitScore) && (bestFitCharge > charge))) {
                bestFitScore = score;
                bestFitCharge = charge;
                bestFitPeaks = fittedPeaks;
            }
        }
        assert bestFitPeaks != null;
        // isotope, we skip this left the original peak in the feature list.
        if (bestFitPeaks.size() == 1) {
            if (!autoRemove)
                deisotopedDataPoints.add(sortedDataPoints[i]);
            processedPeaks++;
            continue;
        }
        DataPoint[] originalPeaks = bestFitPeaks.toArray(new DataPoint[0]);
        SimpleIsotopePattern newPattern = new SimpleIsotopePattern(originalPeaks, IsotopePatternStatus.DETECTED, aPeak.toString());
        sortedDataPoints[i].addResult(new DPPIsotopePatternResult(newPattern, bestFitCharge));
        deisotopedDataPoints.add(sortedDataPoints[i]);
        for (int j = 0; j < sortedDataPoints.length; j++) {
            if (bestFitPeaks.contains(sortedDataPoints[j]))
                sortedDataPoints[j] = null;
        }
        // Update completion rate
        processedPeaks++;
    }
    deisotopedDataPoints.sort((d1, d2) -> {
        return Double.compare(d1.getMZ(), d2.getMZ());
    });
    setResults(deisotopedDataPoints.toArray(new ProcessedDataPoint[0]));
    setStatus(TaskStatus.FINISHED);
}
Also used : ProcessedDataPoint(net.sf.mzmine.modules.visualization.spectra.simplespectra.datapointprocessing.datamodel.ProcessedDataPoint) DPPIsotopePatternResult(net.sf.mzmine.modules.visualization.spectra.simplespectra.datapointprocessing.datamodel.results.DPPIsotopePatternResult) ArrayList(java.util.ArrayList) IsotopePattern(net.sf.mzmine.datamodel.IsotopePattern) SimpleIsotopePattern(net.sf.mzmine.datamodel.impl.SimpleIsotopePattern) DataPoint(net.sf.mzmine.datamodel.DataPoint) ProcessedDataPoint(net.sf.mzmine.modules.visualization.spectra.simplespectra.datapointprocessing.datamodel.ProcessedDataPoint) DataPoint(net.sf.mzmine.datamodel.DataPoint) ProcessedDataPoint(net.sf.mzmine.modules.visualization.spectra.simplespectra.datapointprocessing.datamodel.ProcessedDataPoint) SimpleIsotopePattern(net.sf.mzmine.datamodel.impl.SimpleIsotopePattern) Vector(java.util.Vector)

Example 22 with IsotopePattern

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

the class SpectraToolTipGenerator method generateToolTip.

/**
 * @see org.jfree.chart.labels.XYToolTipGenerator#generateToolTip(org.jfree.data.xy.XYDataset,
 *      int, int)
 */
public String generateToolTip(XYDataset dataset, int series, int item) {
    double intValue = dataset.getYValue(series, item);
    double mzValue = dataset.getXValue(series, item);
    if (dataset instanceof PeakListDataSet) {
        PeakListDataSet peakListDataSet = (PeakListDataSet) dataset;
        Feature peak = peakListDataSet.getPeak(series, item);
        PeakList peakList = peakListDataSet.getPeakList();
        PeakListRow row = peakList.getPeakRow(peak);
        String tooltip = "Peak: " + peak + "\nStatus: " + peak.getFeatureStatus() + "\nFeature list row: " + row + "\nData point m/z: " + mzFormat.format(mzValue) + "\nData point intensity: " + intensityFormat.format(intValue);
        return tooltip;
    }
    if (dataset instanceof IsotopesDataSet) {
        IsotopesDataSet isotopeDataSet = (IsotopesDataSet) dataset;
        IsotopePattern pattern = isotopeDataSet.getIsotopePattern();
        double relativeIntensity = intValue / pattern.getHighestDataPoint().getIntensity() * 100;
        String tooltip = "Isotope pattern: " + pattern.getDescription() + "\nStatus: " + pattern.getStatus() + "\nData point m/z: " + mzFormat.format(mzValue) + "\nData point intensity: " + intensityFormat.format(intValue) + "\nRelative intensity: " + percentFormat.format(relativeIntensity) + "%";
        return tooltip;
    }
    if (dataset instanceof ExtendedIsotopePatternDataSet) {
        return "Isotope pattern: " + ((ExtendedIsotopePatternDataSet) dataset).getIsotopePattern().getDescription() + "\nm/z: " + mzFormat.format(mzValue) + "\nIdentity: " + ((ExtendedIsotopePatternDataSet) dataset).getItemDescription(series, item) + "\nRelative intensity: " + percentFormat.format((dataset.getY(series, item).doubleValue() * 100)) + "%";
    }
    String tooltip = "m/z: " + mzFormat.format(mzValue) + "\nIntensity: " + intensityFormat.format(intValue);
    return tooltip;
}
Also used : ExtendedIsotopePatternDataSet(net.sf.mzmine.modules.visualization.spectra.simplespectra.datasets.ExtendedIsotopePatternDataSet) PeakListRow(net.sf.mzmine.datamodel.PeakListRow) PeakListDataSet(net.sf.mzmine.modules.visualization.spectra.simplespectra.datasets.PeakListDataSet) IsotopePattern(net.sf.mzmine.datamodel.IsotopePattern) IsotopesDataSet(net.sf.mzmine.modules.visualization.spectra.simplespectra.datasets.IsotopesDataSet) PeakList(net.sf.mzmine.datamodel.PeakList) Feature(net.sf.mzmine.datamodel.Feature)

Example 23 with IsotopePattern

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

the class DPPSumFormulaPredictionTask method getIsotopeSimilarityScore.

private double getIsotopeSimilarityScore(IMolecularFormula cdkFormula, IsotopePattern detectedPattern) {
    IsotopePattern predictedIsotopePattern = null;
    Double isotopeScore = 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);
    return isotopeScore;
}
Also used : IsotopePattern(net.sf.mzmine.datamodel.IsotopePattern)

Example 24 with IsotopePattern

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

the class PeakUtils method copyPeakProperties.

/**
 * Copies properties such as isotope pattern and charge from the source peak to the target peak
 */
public static void copyPeakProperties(Feature source, Feature target) {
    // Copy isotope pattern
    IsotopePattern originalPattern = source.getIsotopePattern();
    if (originalPattern != null)
        target.setIsotopePattern(originalPattern);
    // Copy charge
    int charge = source.getCharge();
    target.setCharge(charge);
}
Also used : IsotopePattern(net.sf.mzmine.datamodel.IsotopePattern) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint)

Example 25 with IsotopePattern

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

Aggregations

IsotopePattern (net.sf.mzmine.datamodel.IsotopePattern)31 DataPoint (net.sf.mzmine.datamodel.DataPoint)19 Feature (net.sf.mzmine.datamodel.Feature)14 RawDataFile (net.sf.mzmine.datamodel.RawDataFile)9 SimpleDataPoint (net.sf.mzmine.datamodel.impl.SimpleDataPoint)9 PeakListRow (net.sf.mzmine.datamodel.PeakListRow)8 ArrayList (java.util.ArrayList)7 SimpleIsotopePattern (net.sf.mzmine.datamodel.impl.SimpleIsotopePattern)7 PeakList (net.sf.mzmine.datamodel.PeakList)6 PeakIdentity (net.sf.mzmine.datamodel.PeakIdentity)5 SimplePeakList (net.sf.mzmine.datamodel.impl.SimplePeakList)5 SimplePeakListAppliedMethod (net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod)4 ParameterSet (net.sf.mzmine.parameters.ParameterSet)4 HashMap (java.util.HashMap)3 SimplePeakIdentity (net.sf.mzmine.datamodel.impl.SimplePeakIdentity)3 SimplePeakListRow (net.sf.mzmine.datamodel.impl.SimplePeakListRow)3 ExitCode (net.sf.mzmine.util.ExitCode)3 Component (dulab.adap.datamodel.Component)2 Peak (dulab.adap.datamodel.Peak)2 PeakInfo (dulab.adap.datamodel.PeakInfo)2