Search in sources :

Example 1 with ADAP3DFeatureDetectionParameters

use of io.github.msdk.featuredetection.adap3d.ADAP3DFeatureDetectionParameters in project mzmine2 by mzmine.

the class ADAP3DTask method run.

/**
 * @see Runnable#run()
 */
public void run() {
    setStatus(TaskStatus.PROCESSING);
    logger.info("Started ADAP3D on " + dataFile);
    List<Scan> selectedScans = Arrays.asList(scanSelection.getMatchingScans(dataFile));
    // Check if we have any scans
    if (selectedScans.size() == 0) {
        setStatus(TaskStatus.ERROR);
        setErrorMessage("No scans match the selected criteria");
        return;
    }
    // Check if the scans are properly ordered by RT
    double prevRT = Double.NEGATIVE_INFINITY;
    for (Scan s : selectedScans) {
        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();
    }
    // Run MSDK module
    MZmineToMSDKRawDataFile msdkRawDataFile = new MZmineToMSDKRawDataFile(dataFile);
    Predicate<MsScan> scanSelectionPredicate = scan -> selectedScans.contains(((MZmineToMSDKMsScan) scan).getMzmineScan());
    msdkADAP3DMethod = new ADAP3DFeatureDetectionMethod(msdkRawDataFile, scanSelectionPredicate, new ADAP3DFeatureDetectionParameters());
    List<Feature> features = null;
    try {
        if (isCanceled())
            return;
        features = msdkADAP3DMethod.execute();
        if (isCanceled())
            return;
    } catch (Exception e) {
        e.printStackTrace();
        setStatus(TaskStatus.ERROR);
        setErrorMessage("Error in ADAP3D: " + e.getMessage());
    }
    if (features == null)
        features = new ArrayList<>(0);
    logger.info("ADAP3D detected " + features.size() + " features in " + dataFile + ", converting to MZmine peaklist");
    // Create new MZmine 2 feature list
    SimplePeakList newPeakList = new SimplePeakList(dataFile + " " + suffix, dataFile);
    int rowId = 1;
    for (Feature msdkFeature : features) {
        if (isCanceled())
            return;
        SimpleFeature mzmineFeature = new SimpleFeature(dataFile, FeatureStatus.DETECTED, msdkFeature);
        PeakListRow row = new SimplePeakListRow(rowId);
        row.addPeak(dataFile, mzmineFeature);
        newPeakList.addRow(row);
        rowId++;
    }
    // Add new peaklist to the project
    project.addPeakList(newPeakList);
    // Add quality parameters to peaks
    QualityParameters.calculateQualityParameters(newPeakList);
    setStatus(TaskStatus.FINISHED);
    logger.info("Finished ADAP3D feature detection on " + dataFile);
}
Also used : FeatureStatus(net.sf.mzmine.datamodel.Feature.FeatureStatus) Scan(net.sf.mzmine.datamodel.Scan) SimplePeakListRow(net.sf.mzmine.datamodel.impl.SimplePeakListRow) Arrays(java.util.Arrays) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList) Feature(io.github.msdk.datamodel.Feature) Predicate(java.util.function.Predicate) TaskStatus(net.sf.mzmine.taskcontrol.TaskStatus) SimpleFeature(net.sf.mzmine.datamodel.impl.SimpleFeature) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) Logger(java.util.logging.Logger) MZmineToMSDKRawDataFile(net.sf.mzmine.datamodel.impl.MZmineToMSDKRawDataFile) ArrayList(java.util.ArrayList) PeakListRow(net.sf.mzmine.datamodel.PeakListRow) MZmineToMSDKMsScan(net.sf.mzmine.datamodel.impl.MZmineToMSDKMsScan) MsScan(io.github.msdk.datamodel.MsScan) List(java.util.List) ParameterSet(net.sf.mzmine.parameters.ParameterSet) AbstractTask(net.sf.mzmine.taskcontrol.AbstractTask) QualityParameters(net.sf.mzmine.modules.peaklistmethods.qualityparameters.QualityParameters) MZmineProject(net.sf.mzmine.datamodel.MZmineProject) ADAP3DFeatureDetectionMethod(io.github.msdk.featuredetection.adap3d.ADAP3DFeatureDetectionMethod) ADAP3DFeatureDetectionParameters(io.github.msdk.featuredetection.adap3d.ADAP3DFeatureDetectionParameters) ScanSelection(net.sf.mzmine.parameters.parametertypes.selectors.ScanSelection) MZmineToMSDKMsScan(net.sf.mzmine.datamodel.impl.MZmineToMSDKMsScan) MsScan(io.github.msdk.datamodel.MsScan) ArrayList(java.util.ArrayList) MZmineToMSDKRawDataFile(net.sf.mzmine.datamodel.impl.MZmineToMSDKRawDataFile) Feature(io.github.msdk.datamodel.Feature) SimpleFeature(net.sf.mzmine.datamodel.impl.SimpleFeature) SimplePeakListRow(net.sf.mzmine.datamodel.impl.SimplePeakListRow) SimpleFeature(net.sf.mzmine.datamodel.impl.SimpleFeature) ADAP3DFeatureDetectionParameters(io.github.msdk.featuredetection.adap3d.ADAP3DFeatureDetectionParameters) SimplePeakListRow(net.sf.mzmine.datamodel.impl.SimplePeakListRow) PeakListRow(net.sf.mzmine.datamodel.PeakListRow) Scan(net.sf.mzmine.datamodel.Scan) MZmineToMSDKMsScan(net.sf.mzmine.datamodel.impl.MZmineToMSDKMsScan) MsScan(io.github.msdk.datamodel.MsScan) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList) ADAP3DFeatureDetectionMethod(io.github.msdk.featuredetection.adap3d.ADAP3DFeatureDetectionMethod)

Aggregations

Feature (io.github.msdk.datamodel.Feature)1 MsScan (io.github.msdk.datamodel.MsScan)1 ADAP3DFeatureDetectionMethod (io.github.msdk.featuredetection.adap3d.ADAP3DFeatureDetectionMethod)1 ADAP3DFeatureDetectionParameters (io.github.msdk.featuredetection.adap3d.ADAP3DFeatureDetectionParameters)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Predicate (java.util.function.Predicate)1 Logger (java.util.logging.Logger)1 FeatureStatus (net.sf.mzmine.datamodel.Feature.FeatureStatus)1 MZmineProject (net.sf.mzmine.datamodel.MZmineProject)1 PeakListRow (net.sf.mzmine.datamodel.PeakListRow)1 RawDataFile (net.sf.mzmine.datamodel.RawDataFile)1 Scan (net.sf.mzmine.datamodel.Scan)1 MZmineToMSDKMsScan (net.sf.mzmine.datamodel.impl.MZmineToMSDKMsScan)1 MZmineToMSDKRawDataFile (net.sf.mzmine.datamodel.impl.MZmineToMSDKRawDataFile)1 SimpleFeature (net.sf.mzmine.datamodel.impl.SimpleFeature)1 SimplePeakList (net.sf.mzmine.datamodel.impl.SimplePeakList)1 SimplePeakListRow (net.sf.mzmine.datamodel.impl.SimplePeakListRow)1 QualityParameters (net.sf.mzmine.modules.peaklistmethods.qualityparameters.QualityParameters)1