Search in sources :

Example 1 with MZmineToMSDKMsScan

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

the class ExportScansTask method exportmzML.

/**
 * Export the chromatogram - mzML format
 *
 * @throws IOException if there are i/o problems.
 */
public void exportmzML() throws MSDKException {
    // Initialize objects
    SimpleRawDataFile msdkRawFile = new SimpleRawDataFile("MZmine 2 mzML export", Optional.empty(), FileType.MZML);
    for (Scan scan : scans) {
        MsScan MSDKscan = new MZmineToMSDKMsScan(scan);
        msdkRawFile.addScan(MSDKscan);
    }
    // Actually write to disk
    MzMLFileExportMethod method = new MzMLFileExportMethod(msdkRawFile, exportFile, MzMLCompressionType.ZLIB, MzMLCompressionType.ZLIB);
    method.execute();
}
Also used : MZmineToMSDKMsScan(net.sf.mzmine.datamodel.impl.MZmineToMSDKMsScan) MsScan(io.github.msdk.datamodel.MsScan) MzMLFileExportMethod(io.github.msdk.io.mzml.MzMLFileExportMethod) Scan(net.sf.mzmine.datamodel.Scan) MZmineToMSDKMsScan(net.sf.mzmine.datamodel.impl.MZmineToMSDKMsScan) MsScan(io.github.msdk.datamodel.MsScan) MZmineToMSDKMsScan(net.sf.mzmine.datamodel.impl.MZmineToMSDKMsScan) SimpleRawDataFile(io.github.msdk.datamodel.SimpleRawDataFile)

Example 2 with MZmineToMSDKMsScan

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

the class SiriusThread method run.

@Override
public void run() {
    List<MsSpectrum> ms1list = new ArrayList<>(), ms2list = new ArrayList<>();
    try {
        Scan ms1Scan = peakListRow.getBestPeak().getRepresentativeScan();
        Collection<Scan> top10ms2Scans = ScanUtils.selectBestMS2Scans(peakListRow, massListName, 10);
        // Convert to MSDK data model
        ms1list.add(new MZmineToMSDKMsScan(ms1Scan));
        for (Scan s : top10ms2Scans) {
            ms2list.add(new MZmineToMSDKMsScan(s));
        }
    } catch (MissingMassListException f) {
        releaseResources();
        task.remoteCancel("Scan does not have requested Mass List name [" + massListName + "]");
        return;
    }
    FormulaConstraints constraints = ConstraintsGenerator.generateConstraint(range);
    IonType siriusIon = IonTypeUtil.createIonType(ionType.toString());
    List<IonAnnotation> siriusResults = null;
    SiriusIdentificationMethod siriusMethod = null;
    /*
     * Code block below gives SiriusMethod specific amount of time to be executed, if it expires ->
     * log error and continue
     */
    try {
        final SiriusIdentificationMethod method = new SiriusIdentificationMethod(ms1list, ms2list, peakListRow.getAverageMZ(), siriusIon, siriusCandidates, constraints, deviationPpm);
        // On some spectra it may never stop (halting problem), that's why interruptable thread is
        // used
        final Future<List<IonAnnotation>> f = service.submit(() -> {
            return method.execute();
        });
        siriusResults = f.get(siriusTimer, TimeUnit.SECONDS);
        siriusMethod = method;
        if (ms2list.isEmpty()) {
            /* If no MSMS spectra - add sirius results */
            addSiriusCompounds(siriusResults, peakListRow, siriusCandidates);
        } else {
            /* Initiate FingerId processing */
            Ms2Experiment experiment = siriusMethod.getExperiment();
            for (int index = 0; index < siriusCandidates; index++) {
                SiriusIonAnnotation annotation = (SiriusIonAnnotation) siriusResults.get(index);
                try {
                    FingerIdWebMethodTask task = new FingerIdWebMethodTask(annotation, experiment, fingeridCandidates, peakListRow);
                    MZmineCore.getTaskController().addTask(task, TaskPriority.NORMAL);
                    Thread.sleep(1000);
                } catch (InterruptedException interrupt) {
                    logger.error("Processing of FingerWebMethods were interrupted");
                    /* If interrupted, store last item */
                    List<IonAnnotation> lastItem = new LinkedList<>();
                    lastItem.add(annotation);
                    addSiriusCompounds(lastItem, peakListRow, 1);
                }
            }
        }
    } catch (InterruptedException | TimeoutException ie) {
        logger.error("Timeout on Sirius method expired, abort. Row id = {}", peakListRow.getID());
    } catch (ExecutionException ce) {
        logger.error("Concurrency error during Sirius method.  Row id = {}", peakListRow.getID());
    } finally {
        // Do not forget to release resources!
        releaseResources();
    }
}
Also used : MsSpectrum(io.github.msdk.datamodel.MsSpectrum) IonType(io.github.msdk.datamodel.IonType) ArrayList(java.util.ArrayList) MissingMassListException(net.sf.mzmine.util.exceptions.MissingMassListException) SiriusIonAnnotation(io.github.msdk.id.sirius.SiriusIonAnnotation) FormulaConstraints(de.unijena.bioinf.ChemistryBase.chem.FormulaConstraints) Ms2Experiment(de.unijena.bioinf.ChemistryBase.ms.Ms2Experiment) Scan(net.sf.mzmine.datamodel.Scan) MZmineToMSDKMsScan(net.sf.mzmine.datamodel.impl.MZmineToMSDKMsScan) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) MZmineToMSDKMsScan(net.sf.mzmine.datamodel.impl.MZmineToMSDKMsScan) ExecutionException(java.util.concurrent.ExecutionException) SiriusIonAnnotation(io.github.msdk.id.sirius.SiriusIonAnnotation) IonAnnotation(io.github.msdk.datamodel.IonAnnotation) SiriusIdentificationMethod(io.github.msdk.id.sirius.SiriusIdentificationMethod) TimeoutException(java.util.concurrent.TimeoutException)

Example 3 with MZmineToMSDKMsScan

use of net.sf.mzmine.datamodel.impl.MZmineToMSDKMsScan 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

Scan (net.sf.mzmine.datamodel.Scan)3 MZmineToMSDKMsScan (net.sf.mzmine.datamodel.impl.MZmineToMSDKMsScan)3 MsScan (io.github.msdk.datamodel.MsScan)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 FormulaConstraints (de.unijena.bioinf.ChemistryBase.chem.FormulaConstraints)1 Ms2Experiment (de.unijena.bioinf.ChemistryBase.ms.Ms2Experiment)1 Feature (io.github.msdk.datamodel.Feature)1 IonAnnotation (io.github.msdk.datamodel.IonAnnotation)1 IonType (io.github.msdk.datamodel.IonType)1 MsSpectrum (io.github.msdk.datamodel.MsSpectrum)1 SimpleRawDataFile (io.github.msdk.datamodel.SimpleRawDataFile)1 ADAP3DFeatureDetectionMethod (io.github.msdk.featuredetection.adap3d.ADAP3DFeatureDetectionMethod)1 ADAP3DFeatureDetectionParameters (io.github.msdk.featuredetection.adap3d.ADAP3DFeatureDetectionParameters)1 SiriusIdentificationMethod (io.github.msdk.id.sirius.SiriusIdentificationMethod)1 SiriusIonAnnotation (io.github.msdk.id.sirius.SiriusIonAnnotation)1 MzMLFileExportMethod (io.github.msdk.io.mzml.MzMLFileExportMethod)1 Arrays (java.util.Arrays)1 LinkedList (java.util.LinkedList)1 ExecutionException (java.util.concurrent.ExecutionException)1