Search in sources :

Example 6 with PeakListRowSorter

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

the class DuplicateFilterTask method filterDuplicatePeakListRows.

/**
 * Filter our duplicate feature list rows.
 *
 * @param origPeakList the original feature list.
 * @param suffix the suffix to apply to the new feature list name.
 * @param mzTolerance m/z tolerance.
 * @param rtTolerance RT tolerance.
 * @param requireSameId must duplicate peaks have the same identities?
 * @return the filtered feature list.
 */
private PeakList filterDuplicatePeakListRows(final PeakList origPeakList, final String suffix, final MZTolerance mzTolerance, final RTTolerance rtTolerance, final boolean requireSameId, FilterMode mode) {
    final PeakListRow[] peakListRows = origPeakList.getRows();
    final int rowCount = peakListRows.length;
    RawDataFile[] rawFiles = origPeakList.getRawDataFiles();
    // Create the new feature list.
    final PeakList newPeakList = new SimplePeakList(origPeakList + " " + suffix, origPeakList.getRawDataFiles());
    // sort rows
    if (mode.equals(FilterMode.OLD_AVERAGE))
        Arrays.sort(peakListRows, new PeakListRowSorter(SortingProperty.Area, SortingDirection.Descending));
    else
        Arrays.sort(peakListRows, new PeakListRowSorter(SortingProperty.ID, SortingDirection.Ascending));
    // filter by average mz and rt
    boolean filterByAvgRTMZ = !mode.equals(FilterMode.SINGLE_FEATURE);
    // Loop through all feature list rows
    processedRows = 0;
    int n = 0;
    totalRows = rowCount;
    for (int firstRowIndex = 0; !isCanceled() && firstRowIndex < rowCount; firstRowIndex++) {
        final PeakListRow mainRow = peakListRows[firstRowIndex];
        if (mainRow != null) {
            // copy first row
            PeakListRow firstRow = copyRow(mainRow);
            for (int secondRowIndex = firstRowIndex + 1; !isCanceled() && secondRowIndex < rowCount; secondRowIndex++) {
                final PeakListRow secondRow = peakListRows[secondRowIndex];
                if (secondRow != null) {
                    // Compare identifications
                    final boolean sameID = !requireSameId || PeakUtils.compareIdentities(firstRow, secondRow);
                    boolean sameMZRT = // average or single feature
                    filterByAvgRTMZ ? checkSameAverageRTMZ(firstRow, secondRow, mzTolerance, rtTolerance) : checkSameSingleFeatureRTMZ(rawFiles, firstRow, secondRow, mzTolerance, rtTolerance);
                    // Duplicate peaks?
                    if (sameID && sameMZRT) {
                        // create consensus row in new filter
                        if (!mode.equals(FilterMode.OLD_AVERAGE)) {
                            // copy all detected features of row2 into row1
                            // to exchange gap-filled against detected features
                            createConsensusFirstRow(rawFiles, firstRow, secondRow);
                        }
                        // second row deleted
                        n++;
                        peakListRows[secondRowIndex] = null;
                    }
                }
            }
            // add to new list
            newPeakList.addRow(firstRow);
        }
        processedRows++;
    }
    // finalize
    if (!isCanceled()) {
        // Load previous applied methods.
        for (final PeakListAppliedMethod method : origPeakList.getAppliedMethods()) {
            newPeakList.addDescriptionOfAppliedTask(method);
        }
        // Add task description to peakList
        newPeakList.addDescriptionOfAppliedTask(new SimplePeakListAppliedMethod("Duplicate feature list rows filter", parameters));
        LOG.info("Removed " + n + " duplicate rows");
    }
    return newPeakList;
}
Also used : SimplePeakListRow(net.sf.mzmine.datamodel.impl.SimplePeakListRow) PeakListRow(net.sf.mzmine.datamodel.PeakListRow) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) SimplePeakListAppliedMethod(net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod) PeakListAppliedMethod(net.sf.mzmine.datamodel.PeakList.PeakListAppliedMethod) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList) PeakList(net.sf.mzmine.datamodel.PeakList) SimplePeakListAppliedMethod(net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod) PeakListRowSorter(net.sf.mzmine.util.PeakListRowSorter)

Example 7 with PeakListRowSorter

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

the class AdductSearchTask method searchAdducts.

/**
 * Search peak-list for adducts.
 */
private void searchAdducts() {
    // Get rows.
    final PeakListRow[] rows = peakList.getRows();
    totalRows = rows.length;
    // Start with the highest peaks.
    Arrays.sort(rows, new PeakListRowSorter(SortingProperty.Height, SortingDirection.Descending));
    // Compare each pair of rows against each other.
    for (int i = 0; !isCanceled() && i < totalRows; i++) {
        for (int j = 0; !isCanceled() && j < totalRows; j++) {
            if (i == j)
                continue;
            findAdducts(rows[i], rows[j]);
        }
        finishedRows++;
    }
}
Also used : PeakListRow(net.sf.mzmine.datamodel.PeakListRow) PeakListRowSorter(net.sf.mzmine.util.PeakListRowSorter)

Example 8 with PeakListRowSorter

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

the class VanKrevelenDiagramParameters 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)

Example 9 with PeakListRowSorter

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

the class FragmentSearchTask method run.

/**
 * @see java.lang.Runnable#run()
 */
public void run() {
    setStatus(TaskStatus.PROCESSING);
    logger.info("Starting fragments search in " + peakList);
    PeakListRow[] rows = peakList.getRows();
    totalRows = rows.length;
    // Start with the highest peaks
    Arrays.sort(rows, new PeakListRowSorter(SortingProperty.Height, SortingDirection.Descending));
    // Compare each two rows against each other
    for (int i = 0; i < totalRows; i++) {
        for (int j = i + 1; j < rows.length; j++) {
            // Task canceled?
            if (isCanceled())
                return;
            // smaller one may be a fragment
            if (rows[i].getAverageMZ() > rows[j].getAverageMZ()) {
                if (checkFragment(rows[i], rows[j]))
                    addFragmentInfo(rows[i], rows[j]);
            } else {
                if (checkFragment(rows[j], rows[i]))
                    addFragmentInfo(rows[j], rows[i]);
            }
        }
        finishedRows++;
    }
    // Add task description to peakList
    ((SimplePeakList) peakList).addDescriptionOfAppliedTask(new SimplePeakListAppliedMethod("Identification of fragments", 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 fragments 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) DataPoint(net.sf.mzmine.datamodel.DataPoint) HeadLessDesktop(net.sf.mzmine.desktop.impl.HeadLessDesktop)

Example 10 with PeakListRowSorter

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

the class PeakListRowLearnerTask 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>
     */
    // get all rows and sort by m/z
    PeakListRow[] rows = peakList.getRows();
    Arrays.sort(rows, new PeakListRowSorter(SortingProperty.MZ, SortingDirection.Ascending));
    totalRows = rows.length;
    for (int i = 0; i < totalRows; i++) {
        // check for cancelled state and stop
        if (isCanceled())
            return;
        PeakListRow row = rows[i];
        // 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)

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