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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations