Search in sources :

Example 91 with PeakListRow

use of net.sf.mzmine.datamodel.PeakListRow in project mzmine2 by mzmine.

the class PeaklistClearAnnotationsTask method run.

@Override
public void run() {
    try {
        setStatus(TaskStatus.PROCESSING);
        LOG.info("Filtering feature list rows");
        totalRows = origPeakList.getRows().length;
        // Filter the feature list.
        for (PeakListRow row : origPeakList.getRows()) {
            if (parameters.getParameter(PeaklistClearAnnotationsParameters.CLEAR_IDENTITY).getValue()) {
                for (PeakIdentity identity : row.getPeakIdentities()) row.removePeakIdentity(identity);
            }
            if (parameters.getParameter(PeaklistClearAnnotationsParameters.CLEAR_COMMENT).getValue()) {
                row.setComment("");
            }
            processedRows += 1;
        }
        if (getStatus() == TaskStatus.ERROR)
            return;
        if (isCanceled())
            return;
        // Add new peaklist to the project
        project.addPeakList(filteredPeakList);
        // Remove the original peaklist if requested
        /*
       * if (parameters .getParameter(PeaklistClearAnnotationsParameters.AUTO_REMOVE) .getValue()) {
       * project.removePeakList(origPeakList); }
       */
        setStatus(TaskStatus.FINISHED);
        LOG.info("Finished peak comparison rows filter");
    } catch (Throwable t) {
        t.printStackTrace();
        setErrorMessage(t.getMessage());
        setStatus(TaskStatus.ERROR);
        LOG.log(Level.SEVERE, "Peak comparison row filter error", t);
    }
}
Also used : PeakIdentity(net.sf.mzmine.datamodel.PeakIdentity) SimplePeakListRow(net.sf.mzmine.datamodel.impl.SimplePeakListRow) PeakListRow(net.sf.mzmine.datamodel.PeakListRow)

Example 92 with PeakListRow

use of net.sf.mzmine.datamodel.PeakListRow in project mzmine2 by mzmine.

the class GroupMS2Task method run.

@Override
public void run() {
    try {
        setStatus(TaskStatus.PROCESSING);
        totalRows = list.getNumberOfRows();
        // for all features
        for (PeakListRow row : list.getRows()) {
            for (Feature f : row.getPeaks()) {
                if (getStatus() == TaskStatus.ERROR)
                    return;
                if (isCanceled())
                    return;
                RawDataFile raw = f.getDataFile();
                IntArrayList scans = new IntArrayList();
                int best = f.getRepresentativeScanNumber();
                double frt = f.getRT();
                double fmz = f.getMZ();
                Range<Double> rtRange = f.getRawDataPointsRTRange();
                int i = best;
                // left
                while (i > 1) {
                    i--;
                    Scan scan = raw.getScan(i);
                    if (scan != null) {
                        if ((!limitRTByFeature || rtRange.contains(scan.getRetentionTime())) && rtTol.checkWithinTolerance(frt, scan.getRetentionTime())) {
                            if (scan.getPrecursorMZ() != 0 && mzTol.checkWithinTolerance(fmz, scan.getPrecursorMZ()))
                                scans.add(i);
                        } else {
                            // end of loop - out of tolerance
                            break;
                        }
                    }
                }
                int[] scanNumbers = raw.getScanNumbers();
                // right
                while (i < scanNumbers[scanNumbers.length - 1]) {
                    i++;
                    Scan scan = raw.getScan(i);
                    // scanID does not have to be contiguous
                    if (scan != null) {
                        if ((!limitRTByFeature || rtRange.contains(scan.getRetentionTime())) && rtTol.checkWithinTolerance(frt, scan.getRetentionTime())) {
                            if (scan.getPrecursorMZ() != 0 && mzTol.checkWithinTolerance(fmz, scan.getPrecursorMZ()))
                                scans.add(i);
                        } else {
                            // end of loop - out of tolerance
                            break;
                        }
                    }
                }
                // set list to feature
                f.setAllMS2FragmentScanNumbers(scans.toIntArray());
            }
            processedRows++;
        }
        setStatus(TaskStatus.FINISHED);
        LOG.info("Finished adding all MS2 scans to their features in " + list.getName());
    } catch (Throwable t) {
        t.printStackTrace();
        setErrorMessage(t.getMessage());
        setStatus(TaskStatus.ERROR);
        LOG.log(Level.SEVERE, "Error while adding all MS2 scans to their feautres", t);
    }
}
Also used : PeakListRow(net.sf.mzmine.datamodel.PeakListRow) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) Scan(net.sf.mzmine.datamodel.Scan) IntArrayList(it.unimi.dsi.fastutil.ints.IntArrayList) Feature(net.sf.mzmine.datamodel.Feature)

Example 93 with PeakListRow

use of net.sf.mzmine.datamodel.PeakListRow in project mzmine2 by mzmine.

the class PeakListBlankSubtractionSingleTask method run.

@Override
public void run() {
    setStatus(TaskStatus.FINISHED);
    ArrayList<PeakListRow> rows = new ArrayList<>();
    // get the rows that contain peaks from the current raw data file
    for (PeakListRow row : alignedFeatureRows) {
        for (RawDataFile raw : row.getRawDataFiles()) {
            if (raw.equals(thisRaw)) {
                rows.add(row);
                break;
            }
        }
    }
    if (rows.isEmpty()) {
        logger.info("Raw data file " + thisRaw.getName() + " did not have any features in " + alignedFeatureList.getName());
        finishedRows = 1;
        totalRows = 1;
        setStatus(TaskStatus.FINISHED);
        return;
    }
    totalRows = rows.size();
    int featuresRemoved = 0;
    List<RawDataFile> blankRawsList = Arrays.asList(blankRaws);
    for (PeakListRow row : rows) {
        if (getStatus() == TaskStatus.CANCELED)
            return;
        if (checkFoldChange && (getIntensityIncrease(row, thisRaw, blankRaws) > foldChange)) {
            finishedRows++;
            continue;
        }
        int blankNum = 0;
        for (RawDataFile raw : row.getRawDataFiles()) {
            if (blankRawsList.contains(raw))
                blankNum++;
            if (blankNum >= minBlankDetections)
                break;
        }
        if (blankNum >= minBlankDetections) {
            // other threads are using the same array, so we have to do this synchronized.
            synchronized (row) {
                row.removePeak(thisRaw);
                featuresRemoved++;
            }
        }
        finishedRows++;
    }
    logger.finest(thisRaw.getName() + " - Removed " + featuresRemoved + " features.");
    setStatus(TaskStatus.FINISHED);
}
Also used : PeakListRow(net.sf.mzmine.datamodel.PeakListRow) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) ArrayList(java.util.ArrayList)

Example 94 with PeakListRow

use of net.sf.mzmine.datamodel.PeakListRow in project mzmine2 by mzmine.

the class CameraSearchTask method groupPeaksByPCGroup.

/**
 * Uses PCGroup-field in PeakIdentity to group peaks and build spectrum
 *
 * @param peakList a PeakList object
 * @return a new PeakList object
 */
private PeakList groupPeaksByPCGroup(PeakList peakList) {
    // Create new feature list.
    final PeakList combinedPeakList = new SimplePeakList(peakList + " " + parameters.getParameter(CameraSearchParameters.SUFFIX).getValue(), peakList.getRawDataFiles());
    // Load previous applied methods.
    for (final PeakList.PeakListAppliedMethod method : peakList.getAppliedMethods()) {
        combinedPeakList.addDescriptionOfAppliedTask(method);
    }
    // Add task description to feature list.
    combinedPeakList.addDescriptionOfAppliedTask(new SimplePeakListAppliedMethod("Bioconductor CAMERA", parameters));
    // --------------------
    // Find unique PCGroups
    // --------------------
    Set<String> pcGroups = new HashSet<>();
    for (PeakListRow row : peakList.getRows()) {
        PeakIdentity identity = row.getPreferredPeakIdentity();
        if (identity == null)
            continue;
        String groupName = identity.getName();
        if (groupName == null || groupName.length() == 0)
            continue;
        pcGroups.add(groupName);
    }
    List<PeakListRow> groupRows = new ArrayList<>();
    // Set <String> groupNames = new HashSet <> ();
    Map<Double, Double> spectrum = new HashMap<>();
    List<PeakListRow> newPeakListRows = new ArrayList<>();
    for (String groupName : pcGroups) {
        // -----------------------------------------
        // Find all peaks belonging to isotopeGroups
        // -----------------------------------------
        groupRows.clear();
        // groupNames.clear();
        spectrum.clear();
        double maxIntensity = 0.0;
        PeakListRow groupRow = null;
        for (PeakListRow row : peakList.getRows()) {
            PeakIdentity identity = row.getPreferredPeakIdentity();
            if (identity == null)
                continue;
            String name = identity.getName();
            if (name.equals(groupName)) {
                double intensity = row.getAverageHeight();
                groupRows.add(row);
                // groupNames.add(name);
                spectrum.put(row.getAverageMZ(), intensity);
                if (intensity > maxIntensity) {
                    maxIntensity = intensity;
                    groupRow = row;
                }
            }
        }
        if (groupRow == null || spectrum.size() <= 1)
            continue;
        PeakIdentity identity = groupRow.getPreferredPeakIdentity();
        if (identity == null)
            continue;
        DataPoint[] dataPoints = new DataPoint[spectrum.size()];
        int count = 0;
        for (Entry<Double, Double> e : spectrum.entrySet()) dataPoints[count++] = new SimpleDataPoint(e.getKey(), e.getValue());
        IsotopePattern pattern = new SimpleIsotopePattern(dataPoints, IsotopePatternStatus.PREDICTED, "Spectrum");
        groupRow.getBestPeak().setIsotopePattern(pattern);
        // combinedPeakList.addRow(groupRow);
        newPeakListRows.add(groupRow);
    }
    // ------------------------------------
    // Sort new peak rows by retention time
    // ------------------------------------
    Collections.sort(newPeakListRows, new Comparator<PeakListRow>() {

        @Override
        public int compare(PeakListRow row1, PeakListRow row2) {
            double retTime1 = row1.getAverageRT();
            double retTime2 = row2.getAverageRT();
            return Double.compare(retTime1, retTime2);
        }
    });
    for (PeakListRow row : newPeakListRows) combinedPeakList.addRow(row);
    return combinedPeakList;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IsotopePattern(net.sf.mzmine.datamodel.IsotopePattern) SimpleIsotopePattern(net.sf.mzmine.datamodel.impl.SimpleIsotopePattern) SimplePeakListAppliedMethod(net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) SimplePeakIdentity(net.sf.mzmine.datamodel.impl.SimplePeakIdentity) PeakIdentity(net.sf.mzmine.datamodel.PeakIdentity) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) PeakListRow(net.sf.mzmine.datamodel.PeakListRow) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList) SimpleIsotopePattern(net.sf.mzmine.datamodel.impl.SimpleIsotopePattern) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList) PeakList(net.sf.mzmine.datamodel.PeakList) HashSet(java.util.HashSet)

Example 95 with PeakListRow

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

Aggregations

PeakListRow (net.sf.mzmine.datamodel.PeakListRow)148 Feature (net.sf.mzmine.datamodel.Feature)71 RawDataFile (net.sf.mzmine.datamodel.RawDataFile)55 SimplePeakListRow (net.sf.mzmine.datamodel.impl.SimplePeakListRow)54 PeakList (net.sf.mzmine.datamodel.PeakList)44 SimplePeakList (net.sf.mzmine.datamodel.impl.SimplePeakList)39 ArrayList (java.util.ArrayList)31 SimpleFeature (net.sf.mzmine.datamodel.impl.SimpleFeature)31 DataPoint (net.sf.mzmine.datamodel.DataPoint)29 SimplePeakListAppliedMethod (net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod)26 Scan (net.sf.mzmine.datamodel.Scan)25 PeakIdentity (net.sf.mzmine.datamodel.PeakIdentity)20 PeakListRowSorter (net.sf.mzmine.util.PeakListRowSorter)17 SimpleDataPoint (net.sf.mzmine.datamodel.impl.SimpleDataPoint)13 PeakListAppliedMethod (net.sf.mzmine.datamodel.PeakList.PeakListAppliedMethod)12 HashMap (java.util.HashMap)11 Vector (java.util.Vector)11 ParameterSet (net.sf.mzmine.parameters.ParameterSet)11 IsotopePattern (net.sf.mzmine.datamodel.IsotopePattern)10 MassList (net.sf.mzmine.datamodel.MassList)10