use of net.sf.mzmine.taskcontrol.AbstractTask in project mzmine2 by mzmine.
the class GnpsGcExportAndSubmitTask method run.
@Override
public void run() {
final AbstractTask thistask = this;
setStatus(TaskStatus.PROCESSING);
List<AbstractTask> list = new ArrayList<>(3);
// add mgf export task
list.add(addAdapMgfTask(parameters));
// add csv quant table
list.add(addQuantTableTask(parameters, null));
// finish listener to submit
final File fileName = file;
final File folder = file.getParentFile();
new AllTasksFinishedListener(list, true, // succeed
l -> {
try {
LOG.info("succeed" + thistask.getStatus().toString());
if (submit) {
GnpsGcSubmitParameters param = parameters.getParameter(GnpsGcExportAndSubmitParameters.SUBMIT).getEmbeddedParameters();
submit(fileName, param);
}
// open folder
try {
if (openFolder && Desktop.isDesktopSupported()) {
Desktop.getDesktop().open(folder);
}
} catch (Exception ex) {
}
} finally {
// finish task
if (thistask.getStatus() == TaskStatus.PROCESSING)
thistask.setStatus(TaskStatus.FINISHED);
}
}, lerror -> {
setErrorMessage("GNPS-GC submit was not started due too errors while file export");
thistask.setStatus(TaskStatus.ERROR);
throw new MSDKRuntimeException("GNPS-GC submit was not started due too errors while file export");
}, // cancel if one was cancelled
listCancelled -> cancel()) {
@Override
public void taskStatusChanged(Task task, TaskStatus newStatus, TaskStatus oldStatus) {
super.taskStatusChanged(task, newStatus, oldStatus);
// show progress
progress.getAndSet(getProgress());
}
};
MZmineCore.getTaskController().addTasks(list.toArray(new AbstractTask[list.size()]));
// wait till finish
while (!(isCanceled() || isFinished())) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
LOG.log(Level.SEVERE, "Error in GNPS-GC export/submit task", e);
}
}
}
use of net.sf.mzmine.taskcontrol.AbstractTask in project mzmine2 by mzmine.
the class LocalSpectralDBSearchTask 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()) {
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");
// Add task description to peakList
peakList.addDescriptionOfAppliedTask(new SimplePeakListAppliedMethod("Peak 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 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);
}
use of net.sf.mzmine.taskcontrol.AbstractTask in project mzmine2 by mzmine.
the class GnpsFbmnExportAndSubmitTask method run.
@Override
public void run() {
final AbstractTask thistask = this;
setStatus(TaskStatus.PROCESSING);
boolean openFolder = parameters.getParameter(GnpsFbmnExportAndSubmitParameters.OPEN_FOLDER).getValue();
boolean submit = parameters.getParameter(GnpsFbmnExportAndSubmitParameters.SUBMIT).getValue();
File file = parameters.getParameter(GnpsFbmnExportAndSubmitParameters.FILENAME).getValue();
file = FileAndPathUtil.eraseFormat(file);
parameters.getParameter(GnpsFbmnExportAndSubmitParameters.FILENAME).setValue(file);
List<AbstractTask> list = new ArrayList<>(3);
GnpsFbmnMgfExportTask task = new GnpsFbmnMgfExportTask(parameters);
list.add(task);
// add csv quant table
list.add(addQuantTableTask(parameters, null));
// finish listener to submit
final File fileName = file;
final File folder = file.getParentFile();
new AllTasksFinishedListener(list, true, // succeed
l -> {
try {
LOG.info("succeed" + thistask.getStatus().toString());
if (submit) {
GnpsFbmnSubmitParameters param = parameters.getParameter(GnpsFbmnExportAndSubmitParameters.SUBMIT).getEmbeddedParameters();
submit(fileName, param);
}
// open folder
try {
if (openFolder && Desktop.isDesktopSupported()) {
Desktop.getDesktop().open(folder);
}
} catch (Exception ex) {
}
} finally {
// finish task
if (thistask.getStatus() == TaskStatus.PROCESSING)
thistask.setStatus(TaskStatus.FINISHED);
}
}, lerror -> {
setErrorMessage("GNPS submit was not started due too errors while file export");
thistask.setStatus(TaskStatus.ERROR);
throw new MSDKRuntimeException("GNPS submit was not started due too errors while file export");
}, // cancel if one was cancelled
listCancelled -> cancel()) {
@Override
public void taskStatusChanged(Task task, TaskStatus newStatus, TaskStatus oldStatus) {
super.taskStatusChanged(task, newStatus, oldStatus);
// show progress
progress.getAndSet(getProgress());
}
};
MZmineCore.getTaskController().addTasks(list.toArray(new AbstractTask[list.size()]));
// wait till finish
while (!(isCanceled() || isFinished())) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
LOG.log(Level.SEVERE, "Error in GNPS export/submit task", e);
}
}
}
use of net.sf.mzmine.taskcontrol.AbstractTask in project mzmine2 by mzmine.
the class PrecursorDBSearchTask method parseFile.
/**
* Load all library entries from data base file
*
* @param dataBaseFile
* @return
*/
private List<AbstractTask> parseFile(File dataBaseFile) throws UnsupportedFormatException, IOException {
//
List<AbstractTask> tasks = new ArrayList<>();
AutoLibraryParser parser = new AutoLibraryParser(100, new LibraryEntryProcessor() {
@Override
public void processNextEntries(List<SpectralDBEntry> list, int alreadyProcessed) {
AbstractTask task = new AbstractTask() {
private int total = peakList.getNumberOfRows();
private int done = 0;
@Override
public void run() {
for (PeakListRow row : peakList.getRows()) {
if (this.isCanceled())
break;
for (SpectralDBEntry db : list) {
if (this.isCanceled())
break;
if (checkRT(row, (Double) db.getField(DBEntryField.RT).orElse(null)) && checkMZ(row, db.getPrecursorMZ())) {
// add identity
row.addPeakIdentity(new PrecursorDBPeakIdentity(db, PrecursorDBSearchModule.MODULE_NAME), false);
matches.getAndIncrement();
}
}
done++;
}
if (!this.isCanceled())
setStatus(TaskStatus.FINISHED);
}
@Override
public String getTaskDescription() {
return "Checking for precursors: " + alreadyProcessed + 1 + " - " + alreadyProcessed + list.size();
}
@Override
public double getFinishedPercentage() {
if (total == 0)
return 0;
return done / (double) total;
}
};
// start last task
MZmineCore.getTaskController().addTask(task);
tasks.add(task);
}
});
// return tasks
parser.parse(this, dataBaseFile);
return tasks;
}
Aggregations