Search in sources :

Example 11 with ProcessedDataPoint

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

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

the class DPPAnyElementIsotopeGrouperTask method run.

@Override
public void run() {
    if (!checkParameterSet() || !checkValues()) {
        setStatus(TaskStatus.ERROR);
        return;
    }
    // check formula
    if (elements == null || elements.equals("") || !FormulaUtils.checkMolecularFormula(elements)) {
        setErrorMessage("Invalid element parameter in " + getTaskDescription());
        setStatus(TaskStatus.ERROR);
        logger.warning("Invalid element parameter in " + getTaskDescription());
        return;
    }
    if (!FormulaUtils.checkMolecularFormula(elements)) {
        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);
    ExtendedIsotopePattern[] elementPattern = getIsotopePatterns(elements, mergeWidth, minAbundance);
    ProcessedDataPoint[] originalDataPoints = (ProcessedDataPoint[]) getDataPoints();
    totalSteps = originalDataPoints.length * 2 + 1;
    // one loop for every element
    for (ExtendedIsotopePattern pattern : elementPattern) {
        // we search by ascending mz
        for (int i_dp = 0; i_dp < originalDataPoints.length; i_dp++) {
            // dp is the peak we are currently searching an isotope pattern for
            ProcessedDataPoint dp = originalDataPoints[i_dp];
            if (!mzrange.contains(dp.getMZ()))
                continue;
            IsotopePatternUtils.findIsotopicPeaks(dp, originalDataPoints, mzTolerance, pattern, mzrange, maxCharge);
            processedSteps++;
        }
        if (isCanceled())
            return;
    }
    for (int x = 0; x < originalDataPoints.length; x++) {
        ProcessedDataPoint dp = originalDataPoints[x];
        if (!mzrange.contains(dp.getMZ()))
            continue;
        if (isCanceled())
            return;
        IsotopePatternUtils.mergeIsotopicPeakResults(dp);
    }
    for (int x = 0; x < originalDataPoints.length; x++) {
        ProcessedDataPoint dp = originalDataPoints[x];
        if (!mzrange.contains(dp.getMZ()))
            continue;
        if (isCanceled())
            return;
        IsotopePatternUtils.convertIsotopicPeakResultsToPattern(dp, false);
    }
    List<ProcessedDataPoint> results = new ArrayList<>();
    for (ProcessedDataPoint dp : originalDataPoints) {
        if (autoRemove) {
            if (dp.resultTypeExists(ResultType.ISOTOPEPATTERN))
                results.add(dp);
        } else
            results.add(dp);
    }
    setResults(results.toArray(new ProcessedDataPoint[0]));
    setStatus(TaskStatus.FINISHED);
}
Also used : ProcessedDataPoint(net.sf.mzmine.modules.visualization.spectra.simplespectra.datapointprocessing.datamodel.ProcessedDataPoint) ArrayList(java.util.ArrayList) ExtendedIsotopePattern(net.sf.mzmine.datamodel.impl.ExtendedIsotopePattern) DataPoint(net.sf.mzmine.datamodel.DataPoint) ProcessedDataPoint(net.sf.mzmine.modules.visualization.spectra.simplespectra.datapointprocessing.datamodel.ProcessedDataPoint)

Example 13 with ProcessedDataPoint

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

the class DPPAnyElementIsotopeGrouperTask method displayResults.

@Override
public void displayResults() {
    if (displayResults || getController().isLastTaskRunning()) {
        // getTargetPlot().addDataSet(compressIsotopeDataSets(getResults()), Color.GREEN, false);
        int i = 0;
        for (ProcessedDataPoint result : getResults()) if (result.resultTypeExists(ResultType.ISOTOPEPATTERN))
            i++;
        if (i == 0)
            i = 1;
        List<Color> clr = generateRainbowColors(i);
        int j = 0;
        for (ProcessedDataPoint result : getResults()) if (result.resultTypeExists(ResultType.ISOTOPEPATTERN)) {
            getTargetPlot().addDataSet(new IsotopesDataSet((IsotopePattern) result.getFirstResultByType(ResultType.ISOTOPEPATTERN).getValue()), clr.get(j), false);
            j++;
        }
    // getTargetPlot().addDataSet(new DPPResultsDataSet("Isotopes (" + getResults().length + ")",
    // getResults()), color, false);
    }
}
Also used : ProcessedDataPoint(net.sf.mzmine.modules.visualization.spectra.simplespectra.datapointprocessing.datamodel.ProcessedDataPoint) Color(java.awt.Color) IsotopesDataSet(net.sf.mzmine.modules.visualization.spectra.simplespectra.datasets.IsotopesDataSet) DataPoint(net.sf.mzmine.datamodel.DataPoint) ProcessedDataPoint(net.sf.mzmine.modules.visualization.spectra.simplespectra.datapointprocessing.datamodel.ProcessedDataPoint)

Example 14 with ProcessedDataPoint

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

the class DPPSumFormulaPredictionTask method run.

@Override
public void run() {
    if (!checkParameterSet() || !checkValues()) {
        setStatus(TaskStatus.ERROR);
        return;
    }
    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.info("Data point/Spectra processing: The array of data points passed to " + getTaskDescription() + " is not an instance of ProcessedDataPoint. Make sure to run mass detection first.");
        setStatus(TaskStatus.CANCELED);
        return;
    }
    setStatus(TaskStatus.PROCESSING);
    List<ProcessedDataPoint> resultList = new ArrayList<>();
    IChemObjectBuilder builder = SilentChemObjectBuilder.getInstance();
    for (int i = 0; i < dataPoints.length; i++) {
        if (isCanceled())
            return;
        if (dataPoints[i].getIntensity() < noiseLevel)
            continue;
        massRange = mzTolerance.getToleranceRange((dataPoints[i].getMZ() - ionType.getAddedMass()) / charge);
        MolecularFormulaRange elCounts = DynamicParameterUtils.buildFormulaRangeOnIsotopePatternResults((ProcessedDataPoint) dataPoints[i], elementCounts);
        generator = new MolecularFormulaGenerator(builder, massRange.lowerEndpoint(), massRange.upperEndpoint(), elCounts);
        List<PredResult> formulas = generateFormulas((ProcessedDataPoint) dataPoints[i], massRange, charge, generator);
        DPPSumFormulaResult[] results = genereateResults(formulas, numResults);
        ((ProcessedDataPoint) dataPoints[i]).addAllResults(results);
        resultList.add((ProcessedDataPoint) dataPoints[i]);
        currentIndex++;
    }
    // setResults((ProcessedDataPoint[]) dataPoints);
    setResults(resultList.toArray(new ProcessedDataPoint[0]));
    setStatus(TaskStatus.FINISHED);
}
Also used : MolecularFormulaGenerator(org.openscience.cdk.formula.MolecularFormulaGenerator) ProcessedDataPoint(net.sf.mzmine.modules.visualization.spectra.simplespectra.datapointprocessing.datamodel.ProcessedDataPoint) MolecularFormulaRange(org.openscience.cdk.formula.MolecularFormulaRange) DPPSumFormulaResult(net.sf.mzmine.modules.visualization.spectra.simplespectra.datapointprocessing.datamodel.results.DPPSumFormulaResult) ArrayList(java.util.ArrayList) IChemObjectBuilder(org.openscience.cdk.interfaces.IChemObjectBuilder) DataPoint(net.sf.mzmine.datamodel.DataPoint) ProcessedDataPoint(net.sf.mzmine.modules.visualization.spectra.simplespectra.datapointprocessing.datamodel.ProcessedDataPoint)

Example 15 with ProcessedDataPoint

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

the class IsotopePatternUtils method getResultIsoComp.

private static String getResultIsoComp(DPPIsotopePatternResult result) {
    String str = "";
    for (ProcessedDataPoint dp : result.getLinkedDataPoints()) {
        String c = "";
        DPPIsotopeCompositionResult comps = (DPPIsotopeCompositionResult) dp.getFirstResultByType(ResultType.ISOTOPECOMPOSITION);
        for (String comp : comps.getValue()) c += comp + ", ";
        if (c.length() > 2)
            c = c.substring(0, c.length() - 2);
        str += format.format(dp.getMZ()) + " (" + c + "), ";
    }
    str = str.substring(0, str.length() - 2);
    return str;
}
Also used : DPPIsotopeCompositionResult(net.sf.mzmine.modules.visualization.spectra.simplespectra.datapointprocessing.datamodel.results.DPPIsotopeCompositionResult) ProcessedDataPoint(net.sf.mzmine.modules.visualization.spectra.simplespectra.datapointprocessing.datamodel.ProcessedDataPoint)

Aggregations

ProcessedDataPoint (net.sf.mzmine.modules.visualization.spectra.simplespectra.datapointprocessing.datamodel.ProcessedDataPoint)17 DataPoint (net.sf.mzmine.datamodel.DataPoint)14 ArrayList (java.util.ArrayList)9 SimpleDataPoint (net.sf.mzmine.datamodel.impl.SimpleDataPoint)7 DPPIsotopePatternResult (net.sf.mzmine.modules.visualization.spectra.simplespectra.datapointprocessing.datamodel.results.DPPIsotopePatternResult)6 DPPIsotopicPeakResult (net.sf.mzmine.modules.visualization.spectra.simplespectra.datapointprocessing.datamodel.results.DPPIsotopicPeakResult)5 DPPResult (net.sf.mzmine.modules.visualization.spectra.simplespectra.datapointprocessing.datamodel.results.DPPResult)4 ExtendedIsotopePattern (net.sf.mzmine.datamodel.impl.ExtendedIsotopePattern)3 SimpleIsotopePattern (net.sf.mzmine.datamodel.impl.SimpleIsotopePattern)3 Nonnull (javax.annotation.Nonnull)2 IsotopePattern (net.sf.mzmine.datamodel.IsotopePattern)2 IsotopesDataSet (net.sf.mzmine.modules.visualization.spectra.simplespectra.datasets.IsotopesDataSet)2 MolecularFormulaRange (org.openscience.cdk.formula.MolecularFormulaRange)2 Color (java.awt.Color)1 Vector (java.util.Vector)1 MassDetector (net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.MassDetector)1 DPPIsotopeCompositionResult (net.sf.mzmine.modules.visualization.spectra.simplespectra.datapointprocessing.datamodel.results.DPPIsotopeCompositionResult)1 DPPSumFormulaResult (net.sf.mzmine.modules.visualization.spectra.simplespectra.datapointprocessing.datamodel.results.DPPSumFormulaResult)1 ScanDataSet (net.sf.mzmine.modules.visualization.spectra.simplespectra.datasets.ScanDataSet)1 MolecularFormulaGenerator (org.openscience.cdk.formula.MolecularFormulaGenerator)1