Search in sources :

Example 1 with AbstractTask

use of net.sf.mzmine.taskcontrol.AbstractTask in project mzmine2 by mzmine.

the class SpectraIdentificationSpectralDatabaseTask method run.

/**
 * @see java.lang.Runnable#run()
 */
@Override
public void run() {
    setStatus(TaskStatus.PROCESSING);
    int count = 0;
    // add result frame
    resultWindow = new SpectraIdentificationResultsWindow();
    resultWindow.setVisible(true);
    try {
        tasks = parseFile(dataBaseFile);
        totalTasks = tasks.size();
        if (!tasks.isEmpty()) {
            // wait for the tasks to finish
            while (!isCanceled() && !tasks.isEmpty()) {
                for (int i = 0; i < tasks.size(); i++) {
                    if (tasks.get(i).isFinished() || tasks.get(i).isCanceled()) {
                        count += tasks.get(i).getCount();
                        tasks.remove(i);
                        i--;
                    }
                }
                // wait for all sub tasks to finish
                try {
                    Thread.sleep(100);
                } catch (Exception e) {
                    cancel();
                }
            }
            // cancelled
            if (isCanceled()) {
                tasks.stream().forEach(AbstractTask::cancel);
            }
        } else {
            setStatus(TaskStatus.ERROR);
            setErrorMessage("DB file was empty - or error while parsing " + dataBaseFile);
            return;
        }
    } catch (Exception e) {
        logger.log(Level.SEVERE, "Could not read file " + dataBaseFile, e);
        setStatus(TaskStatus.ERROR);
        setErrorMessage(e.toString());
    }
    logger.info("Added " + count + " spectral library matches");
    resultWindow.setTitle("Matched " + count + " compounds for scan#" + currentScan.getScanNumber());
    resultWindow.setMatchingFinished();
    resultWindow.revalidate();
    resultWindow.repaint();
    // Repaint the window
    Desktop desktop = MZmineCore.getDesktop();
    if (!(desktop instanceof HeadLessDesktop))
        desktop.getMainWindow().repaint();
    setStatus(TaskStatus.FINISHED);
}
Also used : AbstractTask(net.sf.mzmine.taskcontrol.AbstractTask) HeadLessDesktop(net.sf.mzmine.desktop.impl.HeadLessDesktop) Desktop(net.sf.mzmine.desktop.Desktop) SpectraIdentificationResultsWindow(net.sf.mzmine.modules.visualization.spectra.spectralmatchresults.SpectraIdentificationResultsWindow) IOException(java.io.IOException) UnsupportedFormatException(net.sf.mzmine.util.spectraldb.parser.UnsupportedFormatException) HeadLessDesktop(net.sf.mzmine.desktop.impl.HeadLessDesktop)

Example 2 with AbstractTask

use of net.sf.mzmine.taskcontrol.AbstractTask in project mzmine2 by mzmine.

the class MultiThreadPeakFinderMainTask method run.

@Override
public void run() {
    setStatus(TaskStatus.PROCESSING);
    logger.info("Running multithreaded gap filler on " + peakList);
    // Create new results feature list
    processedPeakList = createResultsPeakList();
    progress = 0.5;
    // split raw data files into groups for each thread (task)
    // Obtain the settings of max concurrent threads
    // as this task uses one thread
    int maxRunningThreads = getMaxThreads();
    // raw files
    int raw = peakList.getNumberOfRawDataFiles();
    // create consumer of resultpeaklist
    SubTaskFinishListener listener = new SubTaskFinishListener(project, parameters, peakList, removeOriginal, maxRunningThreads);
    // Submit the tasks to the task controller for processing
    Task[] tasks = createSubTasks(raw, maxRunningThreads, listener);
    // listener for status change: Cancel / error
    TaskStatusListener list = new TaskStatusListener() {

        @Override
        public void taskStatusChanged(Task task, TaskStatus newStatus, TaskStatus oldStatus) {
            if (newStatus.equals(TaskStatus.CANCELED) || newStatus.equals(TaskStatus.ERROR)) {
                // if one is cancelled, stop all
                synchronized (this) {
                    // cancel all
                    for (Task t : tasks) {
                        if (t instanceof AbstractTask)
                            ((AbstractTask) t).removeTaskStatusListener(this);
                        t.cancel();
                    }
                }
            }
        }
    };
    // add listener to all sub tasks
    for (Task t : tasks) {
        if (t instanceof AbstractTask)
            ((AbstractTask) t).addTaskStatusListener(list);
        // add to batchMode collection
        if (batchTasks != null)
            batchTasks.add(t);
    }
    // start
    MZmineCore.getTaskController().addTasks(tasks);
    // listener will take care of adding the final list
    progress = 1;
    // end
    logger.info("All sub tasks started for multithreaded gap-filling on " + peakList);
    setStatus(TaskStatus.FINISHED);
}
Also used : Task(net.sf.mzmine.taskcontrol.Task) AbstractTask(net.sf.mzmine.taskcontrol.AbstractTask) AbstractTask(net.sf.mzmine.taskcontrol.AbstractTask) TaskStatus(net.sf.mzmine.taskcontrol.TaskStatus) TaskStatusListener(net.sf.mzmine.taskcontrol.TaskStatusListener)

Example 3 with AbstractTask

use of net.sf.mzmine.taskcontrol.AbstractTask in project mzmine2 by mzmine.

the class XICManualPickerDialog method calcArea.

private void calcArea() {
    if (!checkRanges())
        return;
    Task integration = new AbstractTask() {

        @Override
        public void run() {
            setStatus(TaskStatus.PROCESSING);
            double area = PeakUtils.integrateOverMzRtRange(rawDataFile, rtRange, mzRange);
            SwingUtilities.invokeLater(new Runnable() {

                @Override
                public void run() {
                    txtArea.setText(intensityFormat.format(area));
                }
            });
            setStatus(TaskStatus.FINISHED);
        }

        @Override
        public String getTaskDescription() {
            return "Manual integration of m/z " + mzFormat.format((mzRange.lowerEndpoint() + mzRange.upperEndpoint()) / 2);
        }

        @Override
        public double getFinishedPercentage() {
            return 0;
        }
    };
    MZmineCore.getTaskController().addTask(integration);
}
Also used : Task(net.sf.mzmine.taskcontrol.Task) AbstractTask(net.sf.mzmine.taskcontrol.AbstractTask) AbstractTask(net.sf.mzmine.taskcontrol.AbstractTask)

Example 4 with AbstractTask

use of net.sf.mzmine.taskcontrol.AbstractTask in project mzmine2 by mzmine.

the class PrecursorDBSearchTask method run.

/**
 * @see java.lang.Runnable#run()
 */
@Override
public void run() {
    setStatus(TaskStatus.PROCESSING);
    int count = 0;
    try {
        tasks = parseFile(dataBaseFile);
        totalTasks = tasks.size();
        if (!tasks.isEmpty()) {
            // wait for the tasks to finish
            while (!isCanceled() && !tasks.isEmpty()) {
                for (int i = 0; i < tasks.size(); i++) {
                    if (tasks.get(i).isFinished() || tasks.get(i).isCanceled()) {
                        tasks.remove(i);
                        i--;
                    }
                }
                // wait for all sub tasks to finish
                try {
                    Thread.sleep(100);
                } catch (Exception e) {
                    cancel();
                }
            }
            // cancelled
            if (isCanceled()) {
                tasks.stream().forEach(AbstractTask::cancel);
            }
        } else {
            setStatus(TaskStatus.ERROR);
            setErrorMessage("DB file was empty - or error while parsing " + dataBaseFile);
        }
    } catch (Exception e) {
        logger.log(Level.SEVERE, "Could not read file " + dataBaseFile, e);
        setStatus(TaskStatus.ERROR);
        setErrorMessage(e.toString());
    }
    logger.info("Added " + matches.get() + " matches to possible precursors in library: " + dataBaseFile.getAbsolutePath());
    // Add task description to peakList
    peakList.addDescriptionOfAppliedTask(new SimplePeakListAppliedMethod("Possible precursor identification using MS/MS spectral database " + dataBaseFile, 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 : AbstractTask(net.sf.mzmine.taskcontrol.AbstractTask) HeadLessDesktop(net.sf.mzmine.desktop.impl.HeadLessDesktop) Desktop(net.sf.mzmine.desktop.Desktop) SimplePeakListAppliedMethod(net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod) IOException(java.io.IOException) UnsupportedFormatException(net.sf.mzmine.util.spectraldb.parser.UnsupportedFormatException) HeadLessDesktop(net.sf.mzmine.desktop.impl.HeadLessDesktop)

Example 5 with AbstractTask

use of net.sf.mzmine.taskcontrol.AbstractTask in project mzmine2 by mzmine.

the class SelectedRowsLocalSpectralDBSearchTask method run.

/**
 * @see java.lang.Runnable#run()
 */
@Override
public void run() {
    setStatus(TaskStatus.PROCESSING);
    int count = 0;
    if (peakListRows.length == 1) {
        // add result frame
        resultWindow = new SpectraIdentificationResultsWindow();
        resultWindow.setVisible(true);
    } else {
        resultWindow = null;
    }
    try {
        tasks = parseFile(dataBaseFile);
        totalTasks = tasks.size();
        if (!tasks.isEmpty()) {
            // wait for the tasks to finish
            while (!isCanceled() && !tasks.isEmpty()) {
                for (int i = 0; i < tasks.size(); i++) {
                    if (tasks.get(i).isFinished() || tasks.get(i).isCanceled()) {
                        count += tasks.get(i).getCount();
                        tasks.remove(i);
                        i--;
                    }
                }
                // wait for all sub tasks to finish
                try {
                    Thread.sleep(100);
                } catch (Exception e) {
                    cancel();
                }
            }
            // cancelled
            if (isCanceled()) {
                tasks.stream().forEach(AbstractTask::cancel);
            }
        } else {
            setStatus(TaskStatus.ERROR);
            setErrorMessage("DB file was empty - or error while parsing " + dataBaseFile);
        }
    } catch (Exception e) {
        logger.log(Level.SEVERE, "Could not read file " + dataBaseFile, e);
        setStatus(TaskStatus.ERROR);
        setErrorMessage(e.toString());
    }
    logger.info("Added " + count + " spectral library matches");
    if (resultWindow != null) {
        resultWindow.setTitle("Matched " + count + " compounds for feature list row: " + peakListRows[0]);
        resultWindow.setMatchingFinished();
        resultWindow.revalidate();
        resultWindow.repaint();
    }
    // Repaint the window to reflect the change in the feature list
    Desktop desktop = MZmineCore.getDesktop();
    if (!(desktop instanceof HeadLessDesktop))
        desktop.getMainWindow().repaint();
    // work around to update feature list identities
    if (table.getRowCount() > 0)
        table.setRowSelectionInterval(0, 0);
    setStatus(TaskStatus.FINISHED);
}
Also used : AbstractTask(net.sf.mzmine.taskcontrol.AbstractTask) HeadLessDesktop(net.sf.mzmine.desktop.impl.HeadLessDesktop) Desktop(net.sf.mzmine.desktop.Desktop) SpectraIdentificationResultsWindow(net.sf.mzmine.modules.visualization.spectra.spectralmatchresults.SpectraIdentificationResultsWindow) IOException(java.io.IOException) UnsupportedFormatException(net.sf.mzmine.util.spectraldb.parser.UnsupportedFormatException) HeadLessDesktop(net.sf.mzmine.desktop.impl.HeadLessDesktop)

Aggregations

AbstractTask (net.sf.mzmine.taskcontrol.AbstractTask)10 IOException (java.io.IOException)4 Desktop (net.sf.mzmine.desktop.Desktop)4 HeadLessDesktop (net.sf.mzmine.desktop.impl.HeadLessDesktop)4 Task (net.sf.mzmine.taskcontrol.Task)4 UnsupportedFormatException (net.sf.mzmine.util.spectraldb.parser.UnsupportedFormatException)4 ArrayList (java.util.ArrayList)3 SimplePeakListAppliedMethod (net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod)3 TaskStatus (net.sf.mzmine.taskcontrol.TaskStatus)3 MSDKRuntimeException (io.github.msdk.MSDKRuntimeException)2 File (java.io.File)2 PeakListRow (net.sf.mzmine.datamodel.PeakListRow)2 CSVExportTask (net.sf.mzmine.modules.peaklistmethods.io.csvexport.CSVExportTask)2 SpectraIdentificationResultsWindow (net.sf.mzmine.modules.visualization.spectra.spectralmatchresults.SpectraIdentificationResultsWindow)2 AllTasksFinishedListener (net.sf.mzmine.taskcontrol.AllTasksFinishedListener)2 PeakList (net.sf.mzmine.datamodel.PeakList)1 RawDataFile (net.sf.mzmine.datamodel.RawDataFile)1 SimplePeakList (net.sf.mzmine.datamodel.impl.SimplePeakList)1 AdapMgfExportTask (net.sf.mzmine.modules.peaklistmethods.io.adap.mgfexport.AdapMgfExportTask)1 TaskStatusListener (net.sf.mzmine.taskcontrol.TaskStatusListener)1