use of io.github.msdk.MSDKRuntimeException in project mzmine2 by mzmine.
the class RawFileMergeTask method run.
@Override
public void run() {
try {
setStatus(TaskStatus.PROCESSING);
// total number of scans
StringBuilder s = new StringBuilder();
s.append("Merge files: ");
for (RawDataFile r : raw) {
s.append(r.getName());
s.append(", ");
}
LOG.info(s.toString());
// put all in a list and sort by rt
List<Scan> scans = new ArrayList<>();
for (RawDataFile r : raw) {
// some files are only for MS2
boolean isMS2Only = useMS2Marker && r.getName().contains(ms2Marker);
int[] snarray = r.getScanNumbers();
for (int sn : snarray) {
if (isCanceled())
return;
Scan scan = r.getScan(sn);
if (!isMS2Only || scan.getMSLevel() > 1) {
scans.add(scan);
}
}
}
// sort by rt
scans.sort(new Comparator<Scan>() {
@Override
public int compare(Scan a, Scan b) {
return Double.compare(a.getRetentionTime(), b.getRetentionTime());
}
});
// create new file
RawDataFileWriter rawDataFileWriter = MZmineCore.createNewFile(raw[0].getName() + " " + suffix);
int i = 0;
for (Scan scan : scans) {
if (isCanceled())
return;
// copy, reset scan number
SimpleScan scanCopy = new SimpleScan(scan);
scanCopy.setScanNumber(i);
rawDataFileWriter.addScan(scanCopy);
i++;
}
RawDataFile filteredRawDataFile = rawDataFileWriter.finishWriting();
project.addFile(filteredRawDataFile);
if (getStatus() == TaskStatus.PROCESSING)
setStatus(TaskStatus.FINISHED);
} catch (IOException e) {
throw new MSDKRuntimeException(e);
}
}
use of io.github.msdk.MSDKRuntimeException 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 io.github.msdk.MSDKRuntimeException in project mzmine2 by mzmine.
the class SortPeakListsModule method runModule.
@Override
@Nonnull
public ExitCode runModule(@Nonnull MZmineProject project, @Nonnull ParameterSet parameters, @Nonnull Collection<Task> tasks) {
List<PeakList> peakLists = Arrays.asList(parameters.getParameter(SortPeakListsParameters.peakLists).getValue().getMatchingPeakLists());
PeakListTreeModel model = null;
if (project instanceof MZmineProjectImpl) {
model = ((MZmineProjectImpl) project).getPeakListTreeModel();
} else if (MZmineCore.getDesktop() instanceof MainWindow) {
ProjectTree tree = ((MainWindow) MZmineCore.getDesktop()).getMainPanel().getPeakListTree();
model = (PeakListTreeModel) tree.getModel();
}
if (model == null)
throw new MSDKRuntimeException("Cannot find feature list tree model for sorting. Different MZmine project impl?");
final DefaultMutableTreeNode rootNode = model.getRoot();
// Get all tree nodes that represent selected feature lists, and remove
// them from
final ArrayList<DefaultMutableTreeNode> selectedNodes = new ArrayList<DefaultMutableTreeNode>();
for (int row = 0; row < rootNode.getChildCount(); row++) {
DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) rootNode.getChildAt(row);
Object selectedObject = selectedNode.getUserObject();
if (peakLists.contains(selectedObject)) {
selectedNodes.add(selectedNode);
}
}
// Get the index of the first selected item
final ArrayList<Integer> positions = new ArrayList<Integer>();
for (DefaultMutableTreeNode node : selectedNodes) {
int nodeIndex = rootNode.getIndex(node);
if (nodeIndex != -1)
positions.add(nodeIndex);
}
if (positions.isEmpty())
return ExitCode.ERROR;
int insertPosition = Collections.min(positions);
// Sort the feature lists by name
Collections.sort(selectedNodes, new Comparator<DefaultMutableTreeNode>() {
@Override
public int compare(DefaultMutableTreeNode o1, DefaultMutableTreeNode o2) {
return o1.getUserObject().toString().compareTo(o2.getUserObject().toString());
}
});
// Reorder the nodes in the tree model
for (DefaultMutableTreeNode node : selectedNodes) {
model.removeNodeFromParent(node);
model.insertNodeInto(node, rootNode, insertPosition);
insertPosition++;
}
return ExitCode.OK;
}
use of io.github.msdk.MSDKRuntimeException in project mzmine2 by mzmine.
the class RawDataExportModule method runModule.
@Override
@Nonnull
public ExitCode runModule(@Nonnull final MZmineProject project, @Nonnull ParameterSet parameters, @Nonnull Collection<Task> tasks) {
RawDataFileType type = parameters.getParameter(RawDataExportParameters.type).getValue();
String extension = "";
switch(type) {
case MZML:
extension = "mzML";
break;
case NETCDF:
extension = "cdf";
break;
default:
throw new MSDKRuntimeException("This format is not covered in the export module");
}
File folder = parameters.getParameter(RawDataExportParameters.fileName).getValue();
if (!folder.isDirectory())
folder = folder.getParentFile();
RawDataFile[] dataFile = parameters.getParameter(RawDataExportParameters.dataFiles).getValue().getMatchingRawDataFiles();
for (RawDataFile r : dataFile) {
File fullName = FileAndPathUtil.getRealFilePath(folder, r.getName(), extension);
Task newTask = new RawDataExportTask(r, fullName);
tasks.add(newTask);
}
return ExitCode.OK;
}
Aggregations