Search in sources :

Example 1 with PeakSorter

use of net.sf.mzmine.util.PeakSorter in project mzmine2 by mzmine.

the class SimplePeakListRow method getBestIsotopePattern.

/**
 * Returns the highest isotope pattern of a peak in this row
 */
@Override
public IsotopePattern getBestIsotopePattern() {
    Feature[] peaks = getPeaks();
    Arrays.sort(peaks, new PeakSorter(SortingProperty.Height, SortingDirection.Descending));
    for (Feature peak : peaks) {
        IsotopePattern ip = peak.getIsotopePattern();
        if (ip != null)
            return ip;
    }
    return null;
}
Also used : PeakSorter(net.sf.mzmine.util.PeakSorter) IsotopePattern(net.sf.mzmine.datamodel.IsotopePattern) Feature(net.sf.mzmine.datamodel.Feature)

Example 2 with PeakSorter

use of net.sf.mzmine.util.PeakSorter in project mzmine2 by mzmine.

the class SimplePeakListRow method getBestPeak.

/**
 * Returns the highest peak in this row
 */
@Override
public Feature getBestPeak() {
    Feature[] peaks = getPeaks();
    Arrays.sort(peaks, new PeakSorter(SortingProperty.Height, SortingDirection.Descending));
    if (peaks.length == 0)
        return null;
    return peaks[0];
}
Also used : PeakSorter(net.sf.mzmine.util.PeakSorter) Feature(net.sf.mzmine.datamodel.Feature)

Example 3 with PeakSorter

use of net.sf.mzmine.util.PeakSorter in project mzmine2 by mzmine.

the class IsotopeGrouperTask method run.

/**
 * @see Runnable#run()
 */
public void run() {
    setStatus(TaskStatus.PROCESSING);
    logger.info("Running isotopic peak grouper on " + peakList);
    // We assume source peakList contains one datafile
    RawDataFile dataFile = peakList.getRawDataFile(0);
    // Create a new deisotoped peakList
    deisotopedPeakList = new SimplePeakList(peakList + " " + suffix, peakList.getRawDataFiles());
    // Collect all selected charge states
    int[] charges = new int[maximumCharge];
    for (int i = 0; i < maximumCharge; i++) charges[i] = i + 1;
    // Sort peaks by descending height
    Feature[] sortedPeaks = peakList.getPeaks(dataFile);
    Arrays.sort(sortedPeaks, new PeakSorter(SortingProperty.Height, SortingDirection.Descending));
    // Loop through all peaks
    totalPeaks = sortedPeaks.length;
    for (int ind = 0; ind < totalPeaks; ind++) {
        if (isCanceled())
            return;
        Feature aPeak = sortedPeaks[ind];
        // Check if peak was already deleted
        if (aPeak == null) {
            processedPeaks++;
            continue;
        }
        // Check which charge state fits best around this peak
        int bestFitCharge = 0;
        int bestFitScore = -1;
        Vector<Feature> bestFitPeaks = null;
        for (int charge : charges) {
            Vector<Feature> fittedPeaks = new Vector<Feature>();
            fittedPeaks.add(aPeak);
            fitPattern(fittedPeaks, aPeak, charge, sortedPeaks);
            int score = fittedPeaks.size();
            if ((score > bestFitScore) || ((score == bestFitScore) && (bestFitCharge > charge))) {
                bestFitScore = score;
                bestFitCharge = charge;
                bestFitPeaks = fittedPeaks;
            }
        }
        PeakListRow oldRow = peakList.getPeakRow(aPeak);
        assert bestFitPeaks != null;
        // isotope, we skip this left the original peak in the feature list.
        if (bestFitPeaks.size() == 1) {
            deisotopedPeakList.addRow(oldRow);
            processedPeaks++;
            continue;
        }
        // Convert the peak pattern to array
        Feature[] originalPeaks = bestFitPeaks.toArray(new Feature[0]);
        // Create a new SimpleIsotopePattern
        DataPoint[] isotopes = new DataPoint[bestFitPeaks.size()];
        for (int i = 0; i < isotopes.length; i++) {
            Feature p = originalPeaks[i];
            isotopes[i] = new SimpleDataPoint(p.getMZ(), p.getHeight());
        }
        SimpleIsotopePattern newPattern = new SimpleIsotopePattern(isotopes, IsotopePatternStatus.DETECTED, aPeak.toString());
        // the lowest m/z peak
        if (chooseMostIntense) {
            Arrays.sort(originalPeaks, new PeakSorter(SortingProperty.Height, SortingDirection.Descending));
        } else {
            Arrays.sort(originalPeaks, new PeakSorter(SortingProperty.MZ, SortingDirection.Ascending));
        }
        Feature newPeak = new SimpleFeature(originalPeaks[0]);
        newPeak.setIsotopePattern(newPattern);
        newPeak.setCharge(bestFitCharge);
        // Keep old ID
        int oldID = oldRow.getID();
        SimplePeakListRow newRow = new SimplePeakListRow(oldID);
        PeakUtils.copyPeakListRowProperties(oldRow, newRow);
        newRow.addPeak(dataFile, newPeak);
        deisotopedPeakList.addRow(newRow);
        // Remove all peaks already assigned to isotope pattern
        for (int i = 0; i < sortedPeaks.length; i++) {
            if (bestFitPeaks.contains(sortedPeaks[i]))
                sortedPeaks[i] = null;
        }
        // Update completion rate
        processedPeaks++;
    }
    // Add new peakList to the project
    project.addPeakList(deisotopedPeakList);
    // Load previous applied methods
    for (PeakListAppliedMethod proc : peakList.getAppliedMethods()) {
        deisotopedPeakList.addDescriptionOfAppliedTask(proc);
    }
    // Add task description to peakList
    deisotopedPeakList.addDescriptionOfAppliedTask(new SimplePeakListAppliedMethod("Isotopic peaks grouper", parameters));
    // Remove the original peakList if requested
    if (removeOriginal)
        project.removePeakList(peakList);
    logger.info("Finished isotopic peak grouper on " + peakList);
    setStatus(TaskStatus.FINISHED);
}
Also used : SimplePeakListAppliedMethod(net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod) PeakListAppliedMethod(net.sf.mzmine.datamodel.PeakList.PeakListAppliedMethod) SimplePeakListAppliedMethod(net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod) Feature(net.sf.mzmine.datamodel.Feature) SimpleFeature(net.sf.mzmine.datamodel.impl.SimpleFeature) SimplePeakListRow(net.sf.mzmine.datamodel.impl.SimplePeakListRow) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) SimpleFeature(net.sf.mzmine.datamodel.impl.SimpleFeature) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) SimplePeakListRow(net.sf.mzmine.datamodel.impl.SimplePeakListRow) PeakListRow(net.sf.mzmine.datamodel.PeakListRow) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) PeakSorter(net.sf.mzmine.util.PeakSorter) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList) SimpleIsotopePattern(net.sf.mzmine.datamodel.impl.SimpleIsotopePattern) Vector(java.util.Vector)

Example 4 with PeakSorter

use of net.sf.mzmine.util.PeakSorter in project mzmine2 by mzmine.

the class PeakLearnerTask method run.

/**
 * @see Runnable#run()
 */
@Override
public void run() {
    setStatus(TaskStatus.PROCESSING);
    logger.info("Running learner task on " + peakList);
    // Create a new results peakList which is added at the end
    resultPeakList = new SimplePeakList(peakList + " " + suffix, peakList.getRawDataFiles());
    /**
     * - A PeakList is a list of Features (peak in retention time dimension with accurate m/z)<br>
     * ---- contains one or multiple RawDataFiles <br>
     * ---- access mean retention time, mean m/z, maximum intensity, ...<br>
     * - A RawDataFile holds a full chromatographic run with all ms scans<br>
     * ---- Each Scan and the underlying raw data can be accessed <br>
     * ---- Scans can be filtered by MS level, polarity, ...<br>
     */
    // is the data provided by peaklist enough for this task or
    // do you want to work on one raw data file or on all files?
    RawDataFile dataFile = peakList.getRawDataFile(0);
    // get all peaks of a raw data file
    // Sort peaks by ascending mz
    Feature[] sortedPeaks = peakList.getPeaks(dataFile);
    Arrays.sort(sortedPeaks, new PeakSorter(SortingProperty.MZ, SortingDirection.Ascending));
    // Loop through all peaks
    totalPeaks = sortedPeaks.length;
    for (int i = 0; i < totalPeaks; i++) {
        // check for cancelled state and stop
        if (isCanceled())
            return;
        // current peak
        Feature aPeak = sortedPeaks[i];
        // do stuff
        // ...
        // add row to result feature list
        PeakListRow row = peakList.getPeakRow(aPeak);
        row = copyPeakRow(row);
        resultPeakList.addRow(row);
        // Update completion rate
        processedPeaks++;
    }
    // add to project
    addResultToProject();
    logger.info("Finished on " + peakList);
    setStatus(TaskStatus.FINISHED);
}
Also used : SimplePeakListRow(net.sf.mzmine.datamodel.impl.SimplePeakListRow) PeakListRow(net.sf.mzmine.datamodel.PeakListRow) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) PeakSorter(net.sf.mzmine.util.PeakSorter) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList) SimpleFeature(net.sf.mzmine.datamodel.impl.SimpleFeature) Feature(net.sf.mzmine.datamodel.Feature)

Example 5 with PeakSorter

use of net.sf.mzmine.util.PeakSorter in project mzmine2 by mzmine.

the class ChromatogramBuilderTask method run.

/**
 * @see Runnable#run()
 */
public void run() {
    setStatus(TaskStatus.PROCESSING);
    logger.info("Started chromatogram builder on " + dataFile);
    scans = scanSelection.getMatchingScans(dataFile);
    int[] allScanNumbers = scanSelection.getMatchingScanNumbers(dataFile);
    totalScans = scans.length;
    // Check if the scans are properly ordered by RT
    double prevRT = Double.NEGATIVE_INFINITY;
    for (Scan s : scans) {
        if (s.getRetentionTime() < prevRT) {
            setStatus(TaskStatus.ERROR);
            final String msg = "Retention time of scan #" + s.getScanNumber() + " is smaller then the retention time of the previous scan." + " Please make sure you only use scans with increasing retention times." + " You can restrict the scan numbers in the parameters, or you can use the Crop filter module";
            setErrorMessage(msg);
            return;
        }
        prevRT = s.getRetentionTime();
    }
    // Create new feature list
    newPeakList = new SimplePeakList(dataFile + " " + suffix, dataFile);
    Chromatogram[] chromatograms;
    HighestDataPointConnector massConnector = new HighestDataPointConnector(dataFile, allScanNumbers, minimumTimeSpan, minimumHeight, mzTolerance);
    for (Scan scan : scans) {
        if (isCanceled())
            return;
        MassList massList = scan.getMassList(massListName);
        if (massList == null) {
            setStatus(TaskStatus.ERROR);
            setErrorMessage("Scan " + dataFile + " #" + scan.getScanNumber() + " does not have a mass list " + massListName);
            return;
        }
        DataPoint[] mzValues = massList.getDataPoints();
        if (mzValues == null) {
            setStatus(TaskStatus.ERROR);
            setErrorMessage("Mass list " + massListName + " does not contain m/z values for scan #" + scan.getScanNumber() + " of file " + dataFile);
            return;
        }
        massConnector.addScan(scan.getScanNumber(), mzValues);
        processedScans++;
    }
    chromatograms = massConnector.finishChromatograms();
    // Sort the final chromatograms by m/z
    Arrays.sort(chromatograms, new PeakSorter(SortingProperty.MZ, SortingDirection.Ascending));
    // Add the chromatograms to the new feature list
    for (Feature finishedPeak : chromatograms) {
        SimplePeakListRow newRow = new SimplePeakListRow(newPeakID);
        newPeakID++;
        newRow.addPeak(dataFile, finishedPeak);
        newPeakList.addRow(newRow);
    }
    // Add new peaklist to the project
    project.addPeakList(newPeakList);
    // Add quality parameters to peaks
    QualityParameters.calculateQualityParameters(newPeakList);
    setStatus(TaskStatus.FINISHED);
    logger.info("Finished chromatogram builder on " + dataFile);
}
Also used : Feature(net.sf.mzmine.datamodel.Feature) SimplePeakListRow(net.sf.mzmine.datamodel.impl.SimplePeakListRow) DataPoint(net.sf.mzmine.datamodel.DataPoint) PeakSorter(net.sf.mzmine.util.PeakSorter) Scan(net.sf.mzmine.datamodel.Scan) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList) MassList(net.sf.mzmine.datamodel.MassList)

Aggregations

Feature (net.sf.mzmine.datamodel.Feature)7 PeakSorter (net.sf.mzmine.util.PeakSorter)7 SimplePeakList (net.sf.mzmine.datamodel.impl.SimplePeakList)5 SimplePeakListRow (net.sf.mzmine.datamodel.impl.SimplePeakListRow)5 DataPoint (net.sf.mzmine.datamodel.DataPoint)4 PeakListRow (net.sf.mzmine.datamodel.PeakListRow)3 RawDataFile (net.sf.mzmine.datamodel.RawDataFile)3 MassList (net.sf.mzmine.datamodel.MassList)2 PeakListAppliedMethod (net.sf.mzmine.datamodel.PeakList.PeakListAppliedMethod)2 Scan (net.sf.mzmine.datamodel.Scan)2 SimpleFeature (net.sf.mzmine.datamodel.impl.SimpleFeature)2 SimplePeakListAppliedMethod (net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod)2 Range (com.google.common.collect.Range)1 Vector (java.util.Vector)1 IsotopePattern (net.sf.mzmine.datamodel.IsotopePattern)1 SimpleDataPoint (net.sf.mzmine.datamodel.impl.SimpleDataPoint)1 SimpleIsotopePattern (net.sf.mzmine.datamodel.impl.SimpleIsotopePattern)1 DataPointSorter (net.sf.mzmine.util.DataPointSorter)1