Search in sources :

Example 1 with DPPIsotopePatternResult

use of net.sf.mzmine.modules.visualization.spectra.simplespectra.datapointprocessing.datamodel.results.DPPIsotopePatternResult in project mzmine2 by mzmine.

the class DynamicParameterUtils method buildFormulaRangeOnIsotopePatternResults.

/**
 * Creates an ElementParameter based on the previous processing results. If no results were
 * detected, the default value is returned. Upper and lower boundaries are chosen according to
 * lowerElementBoundaryPercentage and upperElementBoundaryPercentage values of this utility class.
 * These values can be set via {@link #setLowerElementBoundaryPercentage} and
 * {@link #setUpperElementBoundaryPercentage}. The elements contained in
 *
 * @param dp The data point to build a parameter for.
 * @param def The default set of parameters.
 * @return The built ElementsParameter
 */
public static MolecularFormulaRange buildFormulaRangeOnIsotopePatternResults(ProcessedDataPoint dp, MolecularFormulaRange def) {
    DPPIsotopePatternResult result = (DPPIsotopePatternResult) dp.getFirstResultByType(ResultType.ISOTOPEPATTERN);
    if (result == null)
        return def;
    if (!(result.getValue() instanceof ExtendedIsotopePattern))
        return def;
    ExtendedIsotopePattern pattern = (ExtendedIsotopePattern) result.getValue();
    String form = IsotopePatternUtils.makePatternSuggestion(pattern.getIsotopeCompositions());
    MolecularFormulaRange range = new MolecularFormulaRange();
    IMolecularFormula formula = FormulaUtils.createMajorIsotopeMolFormula(form);
    if (formula == null) {
        logger.finest("could not generate formula for m/z " + dp.getMZ() + " " + form);
        return def;
    }
    for (IIsotope isotope : def.isotopes()) range.addIsotope(isotope, def.getIsotopeCountMin(isotope), def.getIsotopeCountMax(isotope));
    for (IIsotope isotope : formula.isotopes()) {
        if (range.contains(isotope))
            continue;
        int count = formula.getIsotopeCount(isotope);
        range.addIsotope(isotope, (int) (count * lowerElementBoundaryPercentage), (int) (count * upperElementBoundaryPercentage));
    }
    for (IIsotope isotope : range.isotopes()) {
        int min = range.getIsotopeCountMin(isotope);
        int max = range.getIsotopeCountMax(isotope);
    // logger.info("m/z = " + dp.getMZ() + " " + isotope.getSymbol() + " " + min + " - " + max);
    }
    return range;
}
Also used : IIsotope(org.openscience.cdk.interfaces.IIsotope) MolecularFormulaRange(org.openscience.cdk.formula.MolecularFormulaRange) DPPIsotopePatternResult(net.sf.mzmine.modules.visualization.spectra.simplespectra.datapointprocessing.datamodel.results.DPPIsotopePatternResult) IMolecularFormula(org.openscience.cdk.interfaces.IMolecularFormula) ExtendedIsotopePattern(net.sf.mzmine.datamodel.impl.ExtendedIsotopePattern) ProcessedDataPoint(net.sf.mzmine.modules.visualization.spectra.simplespectra.datapointprocessing.datamodel.ProcessedDataPoint)

Example 2 with DPPIsotopePatternResult

use of net.sf.mzmine.modules.visualization.spectra.simplespectra.datapointprocessing.datamodel.results.DPPIsotopePatternResult in project mzmine2 by mzmine.

the class IsotopePatternUtils method convertIsotopicPeakResultsToPattern.

/**
 * Takes all DPPIsotopicPeakResults of one charge and puts them into one isotope pattern (per
 * charge).
 *
 * @param dp A ProcessedDataPoint
 * @param keepResults if false, all DPPIsotopicPeakResults will be removed from this data point.
 */
public static void convertIsotopicPeakResultsToPattern(ProcessedDataPoint dp, boolean keepResults) {
    sortAndRemoveDuplicateIsotopicPeakResult(dp);
    List<DPPIsotopicPeakResult> iprs = getIsotopicPeakResults(dp);
    if (iprs.isEmpty())
        return;
    List<Integer> charges = getChargeStates(iprs);
    List<ProcessedDataPoint> peaks = new ArrayList<>();
    List<String> isotopes = new ArrayList<>();
    peaks.add(dp);
    isotopes.add("");
    for (int charge : charges) {
        for (DPPIsotopicPeakResult ipr : iprs) {
            if (ipr.getCharge() == charge) {
                peaks.add(ipr.getValue());
                isotopes.add(mergeIsotopicPeakDescription(ipr.getIsotope()));
            }
        }
        ProcessedDataPoint[] dps = peaks.toArray(new ProcessedDataPoint[0]);
        String[] isos = isotopes.toArray(new String[0]);
        ExtendedIsotopePattern pattern = new ExtendedIsotopePattern(dps, IsotopePatternStatus.DETECTED, format.format(dp.getMZ()), /*+ Arrays.toString(isos)*/
        isos);
        dp.addResult(new DPPIsotopePatternResult(pattern, (ProcessedDataPoint[]) pattern.getDataPoints(), charge));
        peaks.clear();
        isotopes.clear();
    }
    if (!keepResults)
        dp.removeAllResultsByType(ResultType.ISOTOPICPEAK);
}
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) DPPIsotopicPeakResult(net.sf.mzmine.modules.visualization.spectra.simplespectra.datapointprocessing.datamodel.results.DPPIsotopicPeakResult) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) ProcessedDataPoint(net.sf.mzmine.modules.visualization.spectra.simplespectra.datapointprocessing.datamodel.ProcessedDataPoint) ExtendedIsotopePattern(net.sf.mzmine.datamodel.impl.ExtendedIsotopePattern)

Example 3 with DPPIsotopePatternResult

use of net.sf.mzmine.modules.visualization.spectra.simplespectra.datapointprocessing.datamodel.results.DPPIsotopePatternResult in project mzmine2 by mzmine.

the class IsotopePatternUtils method mergeIsotopePatternResults.

// -------------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------
// old-new
public static void mergeIsotopePatternResults(ProcessedDataPoint dp) {
    if (!dp.resultTypeExists(ResultType.ISOTOPEPATTERN))
        return;
    List<DPPIsotopePatternResult> patternResults = getIsotopePatternResults(dp);
    List<DPPResult<?>> newResults = new ArrayList<>();
    for (DPPIsotopePatternResult dpPatternResult : patternResults) {
        ProcessedDataPoint[] dpPattern = dpPatternResult.getLinkedDataPoints();
        int patternCharge = dpPatternResult.getCharge();
        for (ProcessedDataPoint p : dpPattern) {
            List<DPPIsotopePatternResult> pPatternResults = getIsotopePatternResults(p);
            for (DPPIsotopePatternResult pPatternResult : pPatternResults) {
                if (pPatternResult.getCharge() != patternCharge)
                    continue;
                ProcessedDataPoint[] dataPoints = pPatternResult.getLinkedDataPoints();
                p.removeResult(pPatternResult);
                newResults.add(new DPPIsotopePatternResult(new SimpleIsotopePattern(dataPoints, IsotopePatternStatus.DETECTED, ""), dataPoints, patternCharge));
            }
        }
    }
    dp.getAllResultsByType(ResultType.ISOTOPEPATTERN);
    dp.addAllResults(newResults);
    logger.finest("-------------------------");
    for (DPPResult<?> result : newResults) logger.finest("FINAL: " + format.format(dp.getMZ()) + " pattern: " + getResultIsoComp((DPPIsotopePatternResult) result));
// TODO: test
}
Also used : DPPResult(net.sf.mzmine.modules.visualization.spectra.simplespectra.datapointprocessing.datamodel.results.DPPResult) 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) SimpleIsotopePattern(net.sf.mzmine.datamodel.impl.SimpleIsotopePattern) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) ProcessedDataPoint(net.sf.mzmine.modules.visualization.spectra.simplespectra.datapointprocessing.datamodel.ProcessedDataPoint)

Example 4 with DPPIsotopePatternResult

use of net.sf.mzmine.modules.visualization.spectra.simplespectra.datapointprocessing.datamodel.results.DPPIsotopePatternResult 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 5 with DPPIsotopePatternResult

use of net.sf.mzmine.modules.visualization.spectra.simplespectra.datapointprocessing.datamodel.results.DPPIsotopePatternResult in project mzmine2 by mzmine.

the class IsotopePatternUtils method getIsotopePatternResults.

/**
 * Convenience method to get all isotope pattern results in a List<DPPIsotopePatternResult> list
 *
 * @param dp
 * @return
 */
@Nonnull
public static List<DPPIsotopePatternResult> getIsotopePatternResults(@Nonnull ProcessedDataPoint dp) {
    List<DPPIsotopePatternResult> results = new ArrayList<>();
    if (!dp.resultTypeExists(ResultType.ISOTOPEPATTERN))
        return results;
    List<DPPResult<?>> patternResults = dp.getAllResultsByType(ResultType.ISOTOPEPATTERN);
    for (int i = 0; i < patternResults.size(); i++) results.add((DPPIsotopePatternResult) patternResults.get(i));
    return results;
}
Also used : DPPResult(net.sf.mzmine.modules.visualization.spectra.simplespectra.datapointprocessing.datamodel.results.DPPResult) DPPIsotopePatternResult(net.sf.mzmine.modules.visualization.spectra.simplespectra.datapointprocessing.datamodel.results.DPPIsotopePatternResult) ArrayList(java.util.ArrayList) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) ProcessedDataPoint(net.sf.mzmine.modules.visualization.spectra.simplespectra.datapointprocessing.datamodel.ProcessedDataPoint) Nonnull(javax.annotation.Nonnull)

Aggregations

ProcessedDataPoint (net.sf.mzmine.modules.visualization.spectra.simplespectra.datapointprocessing.datamodel.ProcessedDataPoint)6 DPPIsotopePatternResult (net.sf.mzmine.modules.visualization.spectra.simplespectra.datapointprocessing.datamodel.results.DPPIsotopePatternResult)6 ArrayList (java.util.ArrayList)5 DataPoint (net.sf.mzmine.datamodel.DataPoint)5 SimpleDataPoint (net.sf.mzmine.datamodel.impl.SimpleDataPoint)4 DPPResult (net.sf.mzmine.modules.visualization.spectra.simplespectra.datapointprocessing.datamodel.results.DPPResult)3 ExtendedIsotopePattern (net.sf.mzmine.datamodel.impl.ExtendedIsotopePattern)2 SimpleIsotopePattern (net.sf.mzmine.datamodel.impl.SimpleIsotopePattern)2 Vector (java.util.Vector)1 Nonnull (javax.annotation.Nonnull)1 IsotopePattern (net.sf.mzmine.datamodel.IsotopePattern)1 DPPIsotopicPeakResult (net.sf.mzmine.modules.visualization.spectra.simplespectra.datapointprocessing.datamodel.results.DPPIsotopicPeakResult)1 MolecularFormulaRange (org.openscience.cdk.formula.MolecularFormulaRange)1 IIsotope (org.openscience.cdk.interfaces.IIsotope)1 IMolecularFormula (org.openscience.cdk.interfaces.IMolecularFormula)1