Search in sources :

Example 11 with PeakListRowSorter

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

the class StreamPeakListRowLearnerTask 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>
     */
    // use streams to filter, sort and create list
    List<PeakListRow> rowList = Arrays.stream(peakList.getRows()).filter(r -> r.getAverageHeight() > 5000).sorted(new PeakListRowSorter(SortingProperty.MZ, SortingDirection.Ascending)).collect(Collectors.toList());
    totalRows = rowList.size();
    // ###########################################################
    // OPTION 1: Streams
    // either use stream to process all rows
    rowList.stream().forEachOrdered(row -> {
        // check for cancelled state and stop
        if (isCanceled())
            return;
        // access details
        double mz = row.getAverageMZ();
        double intensity = row.getAverageHeight();
        double rt = row.getAverageRT();
        Feature peak = row.getBestPeak();
        // do stuff
        // ...
        // add row to peaklist result
        PeakListRow copy = copyPeakRow(row);
        resultPeakList.addRow(copy);
        // Update completion rate
        processedPeaks++;
    });
    // OPTION 2: For loop
    for (PeakListRow row : rowList) {
        // check for cancelled state and stop
        if (isCanceled())
            return;
        // access details
        double mz = row.getAverageMZ();
        double intensity = row.getAverageHeight();
        double rt = row.getAverageRT();
        Feature peak = row.getBestPeak();
        // do stuff
        // ...
        // add row to peaklist result
        PeakListRow copy = copyPeakRow(row);
        resultPeakList.addRow(copy);
        // 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) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList) SimpleFeature(net.sf.mzmine.datamodel.impl.SimpleFeature) Feature(net.sf.mzmine.datamodel.Feature) PeakListRowSorter(net.sf.mzmine.util.PeakListRowSorter)

Example 12 with PeakListRowSorter

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

the class ComplexSearchTask method run.

/**
 * @see java.lang.Runnable#run()
 */
public void run() {
    setStatus(TaskStatus.PROCESSING);
    logger.info("Starting complex search in " + peakList);
    PeakListRow[] rows = peakList.getRows();
    totalRows = rows.length;
    // Sort the array by m/z so we start with biggest peak (possible
    // complex)
    Arrays.sort(rows, new PeakListRowSorter(SortingProperty.MZ, SortingDirection.Descending));
    // Compare each three rows against each other
    for (int i = 0; i < totalRows; i++) {
        Range<Double> testRTRange = rtTolerance.getToleranceRange(rows[i].getAverageRT());
        PeakListRow[] testRows = peakList.getRowsInsideScanRange(testRTRange);
        for (int j = 0; j < testRows.length; j++) {
            for (int k = j; k < testRows.length; k++) {
                // Task canceled?
                if (isCanceled())
                    return;
                // very small m/z peak
                if ((rows[i] == testRows[j]) || (rows[i] == testRows[k]))
                    continue;
                if (checkComplex(rows[i], testRows[j], testRows[k]))
                    addComplexInfo(rows[i], testRows[j], testRows[k]);
            }
        }
        finishedRows++;
    }
    // Add task description to peakList
    ((SimplePeakList) peakList).addDescriptionOfAppliedTask(new SimplePeakListAppliedMethod("Identification of complexes", parameters));
    // Repaint the window to reflect the change in the feature list
    Desktop desktop = MZmineCore.getDesktop();
    if (!(desktop instanceof HeadLessDesktop))
        desktop.getMainWindow().repaint();
    setStatus(TaskStatus.FINISHED);
    logger.info("Finished complexes search in " + peakList);
}
Also used : PeakListRow(net.sf.mzmine.datamodel.PeakListRow) HeadLessDesktop(net.sf.mzmine.desktop.impl.HeadLessDesktop) Desktop(net.sf.mzmine.desktop.Desktop) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList) SimplePeakListAppliedMethod(net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod) PeakListRowSorter(net.sf.mzmine.util.PeakListRowSorter) HeadLessDesktop(net.sf.mzmine.desktop.impl.HeadLessDesktop)

Example 13 with PeakListRowSorter

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

the class PeakListIdentificationTask method run.

@Override
public void run() {
    if (!isCanceled()) {
        try {
            setStatus(TaskStatus.PROCESSING);
            // Create database gateway.
            gateway = db.getModule().getGatewayClass().newInstance();
            // Identify the feature list rows starting from the biggest peaks.
            final PeakListRow[] rows = peakList.getRows();
            Arrays.sort(rows, new PeakListRowSorter(SortingProperty.Area, SortingDirection.Descending));
            // Initialize counters.
            numItems = rows.length;
            // Process rows.
            for (finishedItems = 0; !isCanceled() && finishedItems < numItems; finishedItems++) {
                // Retrieve results for each row.
                retrieveIdentification(rows[finishedItems]);
            }
            if (!isCanceled()) {
                setStatus(TaskStatus.FINISHED);
            }
        } catch (Throwable t) {
            final String msg = "Could not search " + db;
            LOG.log(Level.WARNING, msg, t);
            setStatus(TaskStatus.ERROR);
            setErrorMessage(msg + ": " + ExceptionUtils.exceptionToString(t));
        }
    }
}
Also used : PeakListRow(net.sf.mzmine.datamodel.PeakListRow) PeakListRowSorter(net.sf.mzmine.util.PeakListRowSorter)

Example 14 with PeakListRowSorter

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

the class IntensityPlotParameters method showSetupDialog.

@Override
public ExitCode showSetupDialog(Window parent, boolean valueCheckRequired) {
    PeakList[] selectedPeakLists = getParameter(peakList).getValue().getMatchingPeakLists();
    if (selectedPeakLists.length > 0) {
        RawDataFile[] plDataFiles = selectedPeakLists[0].getRawDataFiles();
        PeakListRow[] plRows = selectedPeakLists[0].getRows();
        Arrays.sort(plRows, new PeakListRowSorter(SortingProperty.MZ, SortingDirection.Ascending));
        getParameter(dataFiles).setChoices(plDataFiles);
        getParameter(dataFiles).setValue(plDataFiles);
    }
    return super.showSetupDialog(parent, valueCheckRequired);
}
Also used : PeakListRow(net.sf.mzmine.datamodel.PeakListRow) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) PeakList(net.sf.mzmine.datamodel.PeakList) PeakListRowSorter(net.sf.mzmine.util.PeakListRowSorter)

Example 15 with PeakListRowSorter

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

the class KendrickMassPlotParameters method showSetupDialog.

@Override
public ExitCode showSetupDialog(Window parent, boolean valueCheckRequired) {
    PeakList[] selectedPeakLists = getParameter(peakList).getValue().getMatchingPeakLists();
    if (selectedPeakLists.length > 0) {
        PeakListRow[] plRows = selectedPeakLists[0].getRows();
        Arrays.sort(plRows, new PeakListRowSorter(SortingProperty.MZ, SortingDirection.Ascending));
    }
    return super.showSetupDialog(parent, valueCheckRequired);
}
Also used : PeakListRow(net.sf.mzmine.datamodel.PeakListRow) PeakList(net.sf.mzmine.datamodel.PeakList) PeakListRowSorter(net.sf.mzmine.util.PeakListRowSorter)

Aggregations

PeakListRowSorter (net.sf.mzmine.util.PeakListRowSorter)18 PeakListRow (net.sf.mzmine.datamodel.PeakListRow)16 SimplePeakList (net.sf.mzmine.datamodel.impl.SimplePeakList)10 PeakList (net.sf.mzmine.datamodel.PeakList)6 SimplePeakListRow (net.sf.mzmine.datamodel.impl.SimplePeakListRow)5 Feature (net.sf.mzmine.datamodel.Feature)3 RawDataFile (net.sf.mzmine.datamodel.RawDataFile)3 SimplePeakListAppliedMethod (net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod)3 ArrayList (java.util.ArrayList)2 Vector (java.util.Vector)2 DataPoint (net.sf.mzmine.datamodel.DataPoint)2 SimpleFeature (net.sf.mzmine.datamodel.impl.SimpleFeature)2 Desktop (net.sf.mzmine.desktop.Desktop)2 HeadLessDesktop (net.sf.mzmine.desktop.impl.HeadLessDesktop)2 IsotopePattern (net.sf.mzmine.datamodel.IsotopePattern)1 PeakListAppliedMethod (net.sf.mzmine.datamodel.PeakList.PeakListAppliedMethod)1 ExtendedIsotopePattern (net.sf.mzmine.datamodel.impl.ExtendedIsotopePattern)1 SimpleDataPoint (net.sf.mzmine.datamodel.impl.SimpleDataPoint)1 SimpleIsotopePattern (net.sf.mzmine.datamodel.impl.SimpleIsotopePattern)1 Candidates (net.sf.mzmine.modules.peaklistmethods.isotopes.isotopepeakscanner.Candidates)1