Search in sources :

Example 31 with SimplePeakListAppliedMethod

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

the class PeakListBlankSubtractionMasterTask method run.

@Override
public void run() {
    if (!checkBlankSelection(alignedFeatureList, blankRaws)) {
        setErrorMessage("Peak list " + alignedFeatureList.getName() + " does no contain all selected blank raw data files.");
        setStatus(TaskStatus.ERROR);
        return;
    }
    setStatus(TaskStatus.PROCESSING);
    // PeakListRow[] rowsInBlanks =
    // getFeatureRowsContainedBlanks(alignedFeatureList, blankRaws, minBlankDetections);
    PeakListRow[] rows = PeakUtils.copyPeakRows(alignedFeatureList.getRows());
    rows = PeakUtils.sortRowsMzAsc(rows);
    for (RawDataFile raw : alignedFeatureList.getRawDataFiles()) {
        // only create a task for every file that is not a blank
        if (Arrays.asList(blankRaws).contains(raw))
            continue;
        // these tasks will access the passed array and remove the features that appear in their raw
        // data file and the blanks from these rows
        AbstractTask task = new PeakListBlankSubtractionSingleTask(parameters, raw, rows);
        MZmineCore.getTaskController().addTask(task);
        subTasks.add(task);
        if (getStatus() == TaskStatus.CANCELED)
            return;
    }
    // wait for tasks to finish
    boolean allTasksFinished = false;
    while (!allTasksFinished) {
        allTasksFinished = true;
        for (AbstractTask task : subTasks) {
            if (task.getStatus() != TaskStatus.FINISHED)
                allTasksFinished = false;
        }
        try {
            TimeUnit.MILLISECONDS.sleep(5);
        } catch (InterruptedException e) {
            e.printStackTrace();
            setErrorMessage(e.getMessage());
            setStatus(TaskStatus.ERROR);
            return;
        }
        if (getStatus() == TaskStatus.CANCELED)
            return;
    }
    // remove rows that only contain blankRaws
    List<RawDataFile> blankRawsList = Arrays.asList(blankRaws);
    int onlyBlankRows = 0;
    for (int i = 0; i < rows.length; i++) {
        PeakListRow row = rows[i];
        if (blankRawsList.containsAll(Arrays.asList(row.getRawDataFiles()))) {
            onlyBlankRows++;
            rows[i] = null;
        }
        if (getStatus() == TaskStatus.CANCELED)
            return;
    }
    logger.finest("Removed " + onlyBlankRows + " rows that only existed in blankfiles.");
    PeakList result = new SimplePeakList(alignedFeatureList.getName() + " sbtrctd", alignedFeatureList.getRawDataFiles());
    for (PeakListRow row : rows) {
        if (row != null) {
            result.addRow(row);
        }
    }
    PeakListUtils.copyPeakListAppliedMethods(alignedFeatureList, result);
    result.addDescriptionOfAppliedTask(new SimplePeakListAppliedMethod(PeakListBlankSubtractionModule.MODULE_NAME, parameters));
    project.addPeakList(result);
    setStatus(TaskStatus.FINISHED);
}
Also used : PeakListRow(net.sf.mzmine.datamodel.PeakListRow) AbstractTask(net.sf.mzmine.taskcontrol.AbstractTask) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) 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)

Example 32 with SimplePeakListAppliedMethod

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

the class GNPSResultsImportTask method run.

/**
 * @see java.lang.Runnable#run()
 */
@Override
public void run() {
    setStatus(TaskStatus.PROCESSING);
    logger.info("Importing GNPS results for " + peakList);
    // remove zero ids from edges to prevent exception
    removeZeroIDFromEdge(file);
    Graph graph = new DefaultGraph("GNPS");
    if (importGraphData(graph, file)) {
        // import library matches from nodes
        importLibraryMatches(graph);
        // 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 import of GNPS results for " + peakList);
    }
}
Also used : DefaultGraph(org.graphstream.graph.implementations.DefaultGraph) Graph(org.graphstream.graph.Graph) HeadLessDesktop(net.sf.mzmine.desktop.impl.HeadLessDesktop) Desktop(net.sf.mzmine.desktop.Desktop) DefaultGraph(org.graphstream.graph.implementations.DefaultGraph) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList) SimplePeakListAppliedMethod(net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod) HeadLessDesktop(net.sf.mzmine.desktop.impl.HeadLessDesktop)

Example 33 with SimplePeakListAppliedMethod

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

the class LipidSearchTask method run.

/**
 * @see java.lang.Runnable#run()
 */
@Override
public void run() {
    setStatus(TaskStatus.PROCESSING);
    logger.info("Starting lipid search in " + peakList);
    PeakListRow[] rows = peakList.getRows();
    // Check if lipids should be modified
    if (searchForModifications == true) {
        lipidModificationMasses = getLipidModificationMasses(lipidModification);
    }
    // Calculate how many possible lipids we will try
    totalSteps = ((maxChainLength - minChainLength + 1) * (maxDoubleBonds - minDoubleBonds + 1)) * selectedLipids.length;
    // Try all combinations of fatty acid lengths and double bonds
    for (int i = 0; i < selectedLipids.length; i++) {
        int numberOfAcylChains = selectedLipids[i].getNumberOfAcylChains();
        int numberOfAlkylChains = selectedLipids[i].getNumberofAlkyChains();
        for (int chainLength = minChainLength; chainLength <= maxChainLength; chainLength++) {
            for (int chainDoubleBonds = minDoubleBonds; chainDoubleBonds <= maxDoubleBonds; chainDoubleBonds++) {
                // Task canceled?
                if (isCanceled())
                    return;
                // than minimal length, skip this lipid
                if (((chainLength > 0) && (chainLength < minChainLength))) {
                    finishedSteps++;
                    continue;
                }
                // doesn't make sense, so let's skip such lipids
                if (((chainDoubleBonds > 0) && (chainDoubleBonds > chainLength - 1))) {
                    finishedSteps++;
                    continue;
                }
                // Prepare a lipid instance
                LipidIdentity lipidChain = new LipidIdentity(selectedLipids[i], chainLength, chainDoubleBonds, numberOfAcylChains, numberOfAlkylChains);
                // Find all rows that match this lipid
                findPossibleLipid(lipidChain, rows);
                finishedSteps++;
            }
        }
    }
    // Add task description to peakList
    ((SimplePeakList) peakList).addDescriptionOfAppliedTask(new SimplePeakListAppliedMethod("Lipid search", parameters));
    // Repaint the window to reflect the change in the peak list
    Desktop desktop = MZmineCore.getDesktop();
    if (!(desktop instanceof HeadLessDesktop))
        desktop.getMainWindow().repaint();
    setStatus(TaskStatus.FINISHED);
    logger.info("Finished lipid search task in " + peakList);
}
Also used : LipidIdentity(net.sf.mzmine.modules.peaklistmethods.identification.lipididentification.lipidutils.LipidIdentity) 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) DataPoint(net.sf.mzmine.datamodel.DataPoint) HeadLessDesktop(net.sf.mzmine.desktop.impl.HeadLessDesktop)

Example 34 with SimplePeakListAppliedMethod

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

the class SortSpectralDBIdentitiesTask method run.

/**
 * @see java.lang.Runnable#run()
 */
@Override
public void run() {
    setStatus(TaskStatus.PROCESSING);
    totalRows = peakList.getNumberOfRows();
    finishedRows = 0;
    for (PeakListRow row : peakList.getRows()) {
        if (isCanceled()) {
            return;
        }
        // sort identities of row
        sortIdentities(row, filterByMinScore, minScore);
        finishedRows++;
    }
    // Add task description to peakList
    peakList.addDescriptionOfAppliedTask(new SimplePeakListAppliedMethod("Sorted spectral database identities of DB search ", 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);
}
Also used : PeakListRow(net.sf.mzmine.datamodel.PeakListRow) HeadLessDesktop(net.sf.mzmine.desktop.impl.HeadLessDesktop) Desktop(net.sf.mzmine.desktop.Desktop) SimplePeakListAppliedMethod(net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod) HeadLessDesktop(net.sf.mzmine.desktop.impl.HeadLessDesktop)

Example 35 with SimplePeakListAppliedMethod

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

the class SmoothingTask method run.

@Override
public void run() {
    setStatus(TaskStatus.PROCESSING);
    try {
        // Get filter weights.
        final double[] filterWeights = SavitzkyGolayFilter.getNormalizedWeights(filterWidth);
        // Create new feature list
        newPeakList = new SimplePeakList(origPeakList + " " + suffix, origPeakList.getRawDataFiles());
        // Process each row.
        for (final PeakListRow row : origPeakList.getRows()) {
            if (!isCanceled()) {
                // Create a new peak-list row.
                final int originalID = row.getID();
                final PeakListRow newRow = new SimplePeakListRow(originalID);
                // Process each peak.
                for (final Feature peak : row.getPeaks()) {
                    if (!isCanceled()) {
                        // Copy original peak intensities.
                        final int[] scanNumbers = peak.getScanNumbers();
                        final int numScans = scanNumbers.length;
                        final double[] intensities = new double[numScans];
                        for (int i = 0; i < numScans; i++) {
                            final DataPoint dataPoint = peak.getDataPoint(scanNumbers[i]);
                            intensities[i] = dataPoint == null ? 0.0 : dataPoint.getIntensity();
                        }
                        // Smooth peak.
                        final double[] smoothed = convolve(intensities, filterWeights);
                        // Measure peak (max, ranges, area etc.)
                        final RawDataFile dataFile = peak.getDataFile();
                        final DataPoint[] newDataPoints = new DataPoint[numScans];
                        double maxIntensity = 0.0;
                        int maxScanNumber = -1;
                        DataPoint maxDataPoint = null;
                        Range<Double> intensityRange = null;
                        double area = 0.0;
                        for (int i = 0; i < numScans; i++) {
                            final int scanNumber = scanNumbers[i];
                            final DataPoint dataPoint = peak.getDataPoint(scanNumber);
                            final double intensity = smoothed[i];
                            if (dataPoint != null && intensity > 0.0) {
                                // Create a new data point.
                                final double mz = dataPoint.getMZ();
                                final double rt = dataFile.getScan(scanNumber).getRetentionTime();
                                final DataPoint newDataPoint = new SimpleDataPoint(mz, intensity);
                                newDataPoints[i] = newDataPoint;
                                // Track maximum intensity data point.
                                if (intensity > maxIntensity) {
                                    maxIntensity = intensity;
                                    maxScanNumber = scanNumber;
                                    maxDataPoint = newDataPoint;
                                }
                                // Update ranges.
                                if (intensityRange == null) {
                                    intensityRange = Range.singleton(intensity);
                                } else {
                                    intensityRange = intensityRange.span(Range.singleton(intensity));
                                }
                                // Accumulate peak area.
                                if (i != 0) {
                                    final DataPoint lastDP = newDataPoints[i - 1];
                                    final double lastIntensity = lastDP == null ? 0.0 : lastDP.getIntensity();
                                    final double lastRT = dataFile.getScan(scanNumbers[i - 1]).getRetentionTime();
                                    area += (rt - lastRT) * 60d * (intensity + lastIntensity) / 2.0;
                                }
                            }
                        }
                        assert maxDataPoint != null;
                        if (!isCanceled() && maxScanNumber >= 0) {
                            // Create a new peak.
                            newRow.addPeak(dataFile, new SimpleFeature(dataFile, maxDataPoint.getMZ(), peak.getRT(), maxIntensity, area, scanNumbers, newDataPoints, peak.getFeatureStatus(), maxScanNumber, peak.getMostIntenseFragmentScanNumber(), peak.getAllMS2FragmentScanNumbers(), peak.getRawDataPointsRTRange(), peak.getRawDataPointsMZRange(), intensityRange));
                        }
                    }
                }
                newPeakList.addRow(newRow);
                progress++;
            }
        }
        // Finish up.
        if (!isCanceled()) {
            // Add new peak-list to the project.
            project.addPeakList(newPeakList);
            // Add quality parameters to peaks
            QualityParameters.calculateQualityParameters(newPeakList);
            // Remove the original peak-list if requested.
            if (removeOriginal) {
                project.removePeakList(origPeakList);
            }
            // Copy previously applied methods
            for (final PeakListAppliedMethod method : origPeakList.getAppliedMethods()) {
                newPeakList.addDescriptionOfAppliedTask(method);
            }
            // Add task description to peak-list.
            newPeakList.addDescriptionOfAppliedTask(new SimplePeakListAppliedMethod("Peaks smoothed by Savitzky-Golay filter", parameters));
            LOG.finest("Finished peak smoothing: " + progress + " rows processed");
            setStatus(TaskStatus.FINISHED);
        }
    } catch (Throwable t) {
        LOG.log(Level.SEVERE, "Smoothing error", t);
        setErrorMessage(t.getMessage());
        setStatus(TaskStatus.ERROR);
    }
}
Also used : SimplePeakListAppliedMethod(net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod) PeakListAppliedMethod(net.sf.mzmine.datamodel.PeakList.PeakListAppliedMethod) SimplePeakListAppliedMethod(net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod) SimplePeakListRow(net.sf.mzmine.datamodel.impl.SimplePeakListRow) SimpleFeature(net.sf.mzmine.datamodel.impl.SimpleFeature) Feature(net.sf.mzmine.datamodel.Feature) 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) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList)

Aggregations

SimplePeakListAppliedMethod (net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod)42 SimplePeakList (net.sf.mzmine.datamodel.impl.SimplePeakList)29 PeakListRow (net.sf.mzmine.datamodel.PeakListRow)26 PeakListAppliedMethod (net.sf.mzmine.datamodel.PeakList.PeakListAppliedMethod)20 RawDataFile (net.sf.mzmine.datamodel.RawDataFile)19 SimplePeakListRow (net.sf.mzmine.datamodel.impl.SimplePeakListRow)18 Feature (net.sf.mzmine.datamodel.Feature)16 DataPoint (net.sf.mzmine.datamodel.DataPoint)15 PeakList (net.sf.mzmine.datamodel.PeakList)11 Desktop (net.sf.mzmine.desktop.Desktop)10 HeadLessDesktop (net.sf.mzmine.desktop.impl.HeadLessDesktop)10 SimpleFeature (net.sf.mzmine.datamodel.impl.SimpleFeature)9 SimpleDataPoint (net.sf.mzmine.datamodel.impl.SimpleDataPoint)8 ArrayList (java.util.ArrayList)7 PeakIdentity (net.sf.mzmine.datamodel.PeakIdentity)6 Vector (java.util.Vector)4 IsotopePattern (net.sf.mzmine.datamodel.IsotopePattern)4 Scan (net.sf.mzmine.datamodel.Scan)4 SimpleIsotopePattern (net.sf.mzmine.datamodel.impl.SimpleIsotopePattern)4 IOException (java.io.IOException)3