use of net.sf.mzmine.parameters.parametertypes.selectors.PeakListsParameter in project mzmine2 by mzmine.
the class BatchSetupComponent method actionPerformed.
@Override
public void actionPerformed(final ActionEvent e) {
final Object src = e.getSource();
if (btnAdd.equals(src)) {
// Processing module selected?
final Object selectedItem = methodsCombo.getSelectedItem();
if (selectedItem instanceof BatchModuleWrapper) {
// Show method's set-up dialog.
final BatchModuleWrapper wrappedModule = (BatchModuleWrapper) selectedItem;
final MZmineProcessingModule selectedMethod = (MZmineProcessingModule) wrappedModule.getModule();
final ParameterSet methodParams = MZmineCore.getConfiguration().getModuleParameters(selectedMethod.getClass());
// Clone the parameter set
final ParameterSet stepParams = methodParams.cloneParameterSet();
// data file and feature list selection
if (!batchQueue.isEmpty()) {
for (Parameter<?> param : stepParams.getParameters()) {
if (param instanceof RawDataFilesParameter) {
final RawDataFilesParameter rdfp = (RawDataFilesParameter) param;
final RawDataFilesSelection selection = new RawDataFilesSelection();
selection.setSelectionType(RawDataFilesSelectionType.BATCH_LAST_FILES);
rdfp.setValue(selection);
}
if (param instanceof PeakListsParameter) {
final PeakListsParameter plp = (PeakListsParameter) param;
final PeakListsSelection selection = new PeakListsSelection();
selection.setSelectionType(PeakListsSelectionType.BATCH_LAST_PEAKLISTS);
plp.setValue(selection);
}
}
}
// Configure parameters
if (stepParams.getParameters().length > 0) {
Window parent = (Window) SwingUtilities.getAncestorOfClass(Window.class, this);
ExitCode exitCode = stepParams.showSetupDialog(parent, false);
if (exitCode != ExitCode.OK)
return;
}
// Make a new batch step
final MZmineProcessingStep<MZmineProcessingModule> step = new MZmineProcessingStepImpl<MZmineProcessingModule>(selectedMethod, stepParams);
// Add step to queue.
batchQueue.add(step);
currentStepsList.setListData(batchQueue);
currentStepsList.setSelectedIndex(currentStepsList.getModel().getSize() - 1);
}
}
if (btnRemove.equals(src)) {
// Remove selected step.
final MZmineProcessingStep<?> selected = (MZmineProcessingStep<?>) currentStepsList.getSelectedValue();
if (selected != null) {
final int index = currentStepsList.getSelectedIndex();
batchQueue.remove(selected);
currentStepsList.setListData(batchQueue);
selectStep(index);
}
}
if (btnClear.equals(src)) {
// Clear the queue.
batchQueue.clear();
currentStepsList.setListData(batchQueue);
}
if (btnConfig.equals(src)) {
// Configure the selected item.
final MZmineProcessingStep<?> selected = (MZmineProcessingStep<?>) currentStepsList.getSelectedValue();
final ParameterSet parameters = selected == null ? null : selected.getParameterSet();
if (parameters != null) {
Window parent = (Window) SwingUtilities.getAncestorOfClass(Window.class, this);
parameters.showSetupDialog(parent, false);
}
}
if (btnSave.equals(src)) {
try {
final File file = chooser.getSaveFile(this, XML_EXTENSION);
if (file != null) {
saveBatchSteps(file);
}
} catch (Exception ex) {
JOptionPane.showMessageDialog(this, "A problem occurred saving the file.\n" + ex.getMessage(), "Saving Failed", JOptionPane.ERROR_MESSAGE);
}
}
if (btnLoad.equals(src)) {
try {
// Load the steps.
final File file = chooser.getLoadFile(this);
if (file != null) {
// Load the batch steps.
loadBatchSteps(file);
}
} catch (Exception ex) {
JOptionPane.showMessageDialog(this, "A problem occurred loading the file.\n" + ex.getMessage(), "Loading Failed", JOptionPane.ERROR_MESSAGE);
}
}
}
use of net.sf.mzmine.parameters.parametertypes.selectors.PeakListsParameter in project mzmine2 by mzmine.
the class BatchQueueParameter method checkValue.
@Override
public boolean checkValue(final Collection<String> errorMessages) {
boolean allParamsOK = true;
if (value == null) {
// Parameters not set.
errorMessages.add(getName() + " is not set");
allParamsOK = false;
} else {
// Check each step.
for (final MZmineProcessingStep<?> batchStep : value) {
// Check step's parameters.
final ParameterSet params = batchStep.getParameterSet();
if (params == null)
continue;
for (final Parameter<?> parameter : params.getParameters()) {
// Ignore the raw data files and feature lists parameters
if (!(parameter instanceof RawDataFilesParameter) && !(parameter instanceof PeakListsParameter) && !parameter.checkValue(errorMessages)) {
allParamsOK = false;
}
}
}
}
return allParamsOK;
}
use of net.sf.mzmine.parameters.parametertypes.selectors.PeakListsParameter in project mzmine2 by mzmine.
the class BatchTask method processQueueStep.
private void processQueueStep(int stepNumber) {
logger.info("Starting step # " + (stepNumber + 1));
// Run next step of the batch
MZmineProcessingStep<?> currentStep = queue.get(stepNumber);
MZmineProcessingModule method = (MZmineProcessingModule) currentStep.getModule();
ParameterSet batchStepParameters = currentStep.getParameterSet();
// the ones from the previous step
if (createdDataFiles.isEmpty())
createdDataFiles.addAll(previousCreatedDataFiles);
if (createdPeakLists.isEmpty())
createdPeakLists.addAll(previousCreatedPeakLists);
// state of the batch
for (Parameter<?> p : batchStepParameters.getParameters()) {
if (p instanceof RawDataFilesParameter) {
RawDataFilesParameter rdp = (RawDataFilesParameter) p;
RawDataFile[] createdFiles = createdDataFiles.toArray(new RawDataFile[0]);
final RawDataFilesSelection selectedFiles = rdp.getValue();
if (selectedFiles == null) {
setStatus(TaskStatus.ERROR);
setErrorMessage("Invalid parameter settings for module " + method.getName() + ": " + "Missing parameter value for " + p.getName());
return;
}
selectedFiles.setBatchLastFiles(createdFiles);
}
}
// state of the batch
for (Parameter<?> p : batchStepParameters.getParameters()) {
if (p instanceof PeakListsParameter) {
PeakListsParameter rdp = (PeakListsParameter) p;
PeakList[] createdPls = createdPeakLists.toArray(new PeakList[0]);
final PeakListsSelection selectedPeakLists = rdp.getValue();
if (selectedPeakLists == null) {
setStatus(TaskStatus.ERROR);
setErrorMessage("Invalid parameter settings for module " + method.getName() + ": " + "Missing parameter value for " + p.getName());
return;
}
selectedPeakLists.setBatchLastPeakLists(createdPls);
}
}
// Clear the saved data files and feature lists. Save them to the
// "previous" lists, in case the next step does not produce any new data
previousCreatedDataFiles.clear();
previousCreatedDataFiles.addAll(createdDataFiles);
previousCreatedPeakLists.clear();
previousCreatedPeakLists.addAll(createdPeakLists);
createdDataFiles.clear();
createdPeakLists.clear();
// Check if the parameter settings are valid
ArrayList<String> messages = new ArrayList<String>();
boolean paramsCheck = batchStepParameters.checkParameterValues(messages);
if (!paramsCheck) {
setStatus(TaskStatus.ERROR);
setErrorMessage("Invalid parameter settings for module " + method.getName() + ": " + Arrays.toString(messages.toArray()));
}
ArrayList<Task> currentStepTasks = new ArrayList<Task>();
ExitCode exitCode = method.runModule(project, batchStepParameters, currentStepTasks);
if (exitCode != ExitCode.OK) {
setStatus(TaskStatus.ERROR);
setErrorMessage("Could not start batch step " + method.getName());
return;
}
// If current step didn't produce any tasks, continue with next step
if (currentStepTasks.isEmpty())
return;
boolean allTasksFinished = false;
// Submit the tasks to the task controller for processing
MZmineCore.getTaskController().addTasks(currentStepTasks.toArray(new Task[0]));
while (!allTasksFinished) {
// If we canceled the batch, cancel all running tasks
if (isCanceled()) {
for (Task stepTask : currentStepTasks) stepTask.cancel();
return;
}
// First set to true, then check all tasks
allTasksFinished = true;
for (Task stepTask : currentStepTasks) {
TaskStatus stepStatus = stepTask.getStatus();
// If any of them is not finished, keep checking
if (stepStatus != TaskStatus.FINISHED)
allTasksFinished = false;
// If there was an error, we have to stop the whole batch
if (stepStatus == TaskStatus.ERROR) {
setStatus(TaskStatus.ERROR);
setErrorMessage(stepTask.getTaskDescription() + ": " + stepTask.getErrorMessage());
return;
}
// whole batch
if (stepStatus == TaskStatus.CANCELED) {
setStatus(TaskStatus.CANCELED);
for (Task t : currentStepTasks) t.cancel();
return;
}
}
// Wait 1s before checking the tasks again
if (!allTasksFinished) {
synchronized (this) {
try {
this.wait(1000);
} catch (InterruptedException e) {
// ignore
}
}
}
}
}
use of net.sf.mzmine.parameters.parametertypes.selectors.PeakListsParameter in project mzmine2 by mzmine.
the class MainMenu method actionPerformed.
/**
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
@Override
public void actionPerformed(ActionEvent e) {
Object src = e.getSource();
MZmineRunnableModule module = moduleMenuItems.get(src);
if (module != null) {
ParameterSet moduleParameters = MZmineCore.getConfiguration().getModuleParameters(module.getClass());
RawDataFile[] selectedFiles = MZmineCore.getDesktop().getSelectedDataFiles();
if (selectedFiles.length > 0) {
for (Parameter<?> p : moduleParameters.getParameters()) {
if (p instanceof RawDataFilesParameter) {
RawDataFilesParameter rdp = (RawDataFilesParameter) p;
rdp.setValue(RawDataFilesSelectionType.GUI_SELECTED_FILES);
}
}
}
PeakList[] selectedPeakLists = MZmineCore.getDesktop().getSelectedPeakLists();
if (selectedPeakLists.length > 0) {
for (Parameter<?> p : moduleParameters.getParameters()) {
if (p instanceof PeakListsParameter) {
PeakListsParameter plp = (PeakListsParameter) p;
plp.setValue(PeakListsSelectionType.GUI_SELECTED_PEAKLISTS);
}
}
}
logger.finest("Setting parameters for module " + module.getName());
ExitCode exitCode = moduleParameters.showSetupDialog(MZmineCore.getDesktop().getMainWindow(), true);
if (exitCode == ExitCode.OK) {
ParameterSet parametersCopy = moduleParameters.cloneParameterSet();
logger.finest("Starting module " + module.getName() + " with parameters " + parametersCopy);
ArrayList<Task> tasks = new ArrayList<Task>();
MZmineProject project = MZmineCore.getProjectManager().getCurrentProject();
module.runModule(project, parametersCopy, tasks);
MZmineCore.getTaskController().addTasks(tasks.toArray(new Task[0]));
}
return;
}
if (src == projectExit) {
MZmineCore.getDesktop().exitMZmine();
}
if (src == projectSaveParameters) {
JFileChooser chooser = new JFileChooser();
int returnVal = chooser.showSaveDialog(MZmineCore.getDesktop().getMainWindow());
if (returnVal == JFileChooser.APPROVE_OPTION) {
File configFile = chooser.getSelectedFile();
try {
MZmineCore.getConfiguration().saveConfiguration(configFile);
} catch (Exception ex) {
MZmineCore.getDesktop().displayException(MZmineCore.getDesktop().getMainWindow(), ex);
}
}
}
if (src == projectLoadParameters) {
JFileChooser chooser = new JFileChooser();
int returnVal = chooser.showOpenDialog(MZmineCore.getDesktop().getMainWindow());
if (returnVal == JFileChooser.APPROVE_OPTION) {
File configFile = chooser.getSelectedFile();
try {
MZmineCore.getConfiguration().loadConfiguration(configFile);
} catch (Exception ex) {
MZmineCore.getDesktop().displayException(MZmineCore.getDesktop().getMainWindow(), ex);
}
}
}
if (src == projectSampleParameters) {
ProjectParametersSetupDialog dialog = new ProjectParametersSetupDialog();
dialog.setVisible(true);
}
if (src == projectPreferences) {
MZminePreferences preferences = MZmineCore.getConfiguration().getPreferences();
preferences.showSetupDialog(MZmineCore.getDesktop().getMainWindow(), true);
}
if (src == showAbout) {
MainWindow mainWindow = (MainWindow) MZmineCore.getDesktop();
mainWindow.showAboutDialog();
}
if (src == checkUpdate) {
// Check for updated version
NewVersionCheck NVC = new NewVersionCheck(CheckType.MENU);
new Thread(NVC).start();
}
}
Aggregations