Search in sources :

Example 16 with SimpleIsotopePattern

use of net.sf.mzmine.datamodel.impl.SimpleIsotopePattern in project mzmine2 by mzmine.

the class IsotopePatternCalculator method removeDataPointsBelowIntensity.

public static IsotopePattern removeDataPointsBelowIntensity(IsotopePattern pattern, double minIntensity) {
    DataPoint[] dp = pattern.getDataPoints();
    for (int i = 0; i < pattern.getNumberOfDataPoints(); i++) {
        if (dp[i].getIntensity() < minIntensity) {
            dp[i] = null;
        }
    }
    ArrayList<DataPoint> newDP = new ArrayList<DataPoint>();
    ArrayList<String> newComp = new ArrayList<String>();
    for (int i = 0; i < dp.length; i++) {
        DataPoint p = dp[i];
        if (dp[i] != null) {
            newDP.add(p);
            if (pattern instanceof ExtendedIsotopePattern) {
                newComp.add(((ExtendedIsotopePattern) pattern).getIsotopeComposition(i));
            }
        }
    }
    if (pattern instanceof ExtendedIsotopePattern)
        return new ExtendedIsotopePattern(newDP.toArray(new DataPoint[0]), pattern.getStatus(), pattern.getDescription(), newComp.toArray(new String[0]));
    else
        return new SimpleIsotopePattern(newDP.toArray(new DataPoint[0]), pattern.getStatus(), pattern.getDescription());
}
Also used : DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) ArrayList(java.util.ArrayList) SimpleIsotopePattern(net.sf.mzmine.datamodel.impl.SimpleIsotopePattern) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) ExtendedIsotopePattern(net.sf.mzmine.datamodel.impl.ExtendedIsotopePattern)

Example 17 with SimpleIsotopePattern

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

Aggregations

DataPoint (net.sf.mzmine.datamodel.DataPoint)17 SimpleIsotopePattern (net.sf.mzmine.datamodel.impl.SimpleIsotopePattern)17 SimpleDataPoint (net.sf.mzmine.datamodel.impl.SimpleDataPoint)15 ArrayList (java.util.ArrayList)11 IsotopePattern (net.sf.mzmine.datamodel.IsotopePattern)6 RawDataFile (net.sf.mzmine.datamodel.RawDataFile)6 PeakListRow (net.sf.mzmine.datamodel.PeakListRow)5 ExtendedIsotopePattern (net.sf.mzmine.datamodel.impl.ExtendedIsotopePattern)5 SimpleFeature (net.sf.mzmine.datamodel.impl.SimpleFeature)5 SimplePeakIdentity (net.sf.mzmine.datamodel.impl.SimplePeakIdentity)5 SimplePeakList (net.sf.mzmine.datamodel.impl.SimplePeakList)5 HashMap (java.util.HashMap)4 SimplePeakListAppliedMethod (net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod)4 ProcessedDataPoint (net.sf.mzmine.modules.visualization.spectra.simplespectra.datapointprocessing.datamodel.ProcessedDataPoint)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 DataInputStream (java.io.DataInputStream)3 IOException (java.io.IOException)3 Feature (net.sf.mzmine.datamodel.Feature)3 FeatureStatus (net.sf.mzmine.datamodel.Feature.FeatureStatus)3 PeakIdentity (net.sf.mzmine.datamodel.PeakIdentity)3