Search in sources :

Example 1 with MZmineProcessingStep

use of net.sf.mzmine.modules.MZmineProcessingStep 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);
        }
    }
}
Also used : ParameterSet(net.sf.mzmine.parameters.ParameterSet) Window(java.awt.Window) ExitCode(net.sf.mzmine.util.ExitCode) MZmineProcessingStepImpl(net.sf.mzmine.modules.impl.MZmineProcessingStepImpl) MZmineProcessingModule(net.sf.mzmine.modules.MZmineProcessingModule) FileNotFoundException(java.io.FileNotFoundException) SAXException(org.xml.sax.SAXException) TransformerException(javax.xml.transform.TransformerException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) MZmineProcessingStep(net.sf.mzmine.modules.MZmineProcessingStep) RawDataFilesSelection(net.sf.mzmine.parameters.parametertypes.selectors.RawDataFilesSelection) PeakListsSelection(net.sf.mzmine.parameters.parametertypes.selectors.PeakListsSelection) PeakListsParameter(net.sf.mzmine.parameters.parametertypes.selectors.PeakListsParameter) File(java.io.File) RawDataFilesParameter(net.sf.mzmine.parameters.parametertypes.selectors.RawDataFilesParameter)

Example 2 with MZmineProcessingStep

use of net.sf.mzmine.modules.MZmineProcessingStep in project mzmine2 by mzmine.

the class DataPointProcessingController method execute.

/**
 * This will execute the modules associated with the plot. It will start with the first one and
 * execute the following ones afterwards automatically. This method is called by the public method
 * execute(). The status listener in this method starts the next task recursively after the
 * previous one has finished.
 *
 * @param dp
 * @param module
 * @param plot
 */
private void execute(DataPoint[] dp, MZmineProcessingStep<DataPointProcessingModule> step, SpectraPlot plot) {
    if (queue == null || queue.isEmpty() || plot == null) {
        logger.warning("execute called, without queue or plot being set.");
        setStatus(ControllerStatus.FINISHED);
        return;
    }
    if (getForcedStatus() == ForcedControllerStatus.CANCEL || getStatus() == ControllerStatus.CANCELED) {
        setResults(ProcessedDataPoint.convert(dp));
        logger.finest("Canceled controller, not starting new tasks. Results are set to latest array.");
        setStatus(ControllerStatus.CANCELED);
        return;
    }
    List<String> err = new ArrayList<>();
    if (!step.getParameterSet().checkParameterValues(err)) {
        setResults(ProcessedDataPoint.convert(dp));
        setStatus(ControllerStatus.CANCELED);
        logger.warning(step.getModule().getName() + " - Not all parameters set." + Arrays.toString(err.toArray(new String[0])));
        return;
    }
    if (step.getModule() instanceof DataPointProcessingModule) {
        DataPointProcessingModule inst = step.getModule();
        ParameterSet parameters = step.getParameterSet();
        Task t = ((DataPointProcessingModule) inst).createTask(dp, parameters, plot, this, new TaskStatusListener() {

            @Override
            public void taskStatusChanged(Task task, TaskStatus newStatus, TaskStatus oldStatus) {
                if (!(task instanceof DataPointProcessingTask)) {
                    // TODO: Throw exception?
                    logger.warning("This should have been a DataPointProcessingTask.");
                    return;
                }
                // logger.finest("Task status changed to " + newStatus.toString());
                switch(newStatus) {
                    case FINISHED:
                        if (queue.hasNextStep(step)) {
                            if (DataPointProcessingManager.getInst().isRunning(((DataPointProcessingTask) task).getController())) {
                                MZmineProcessingStep<DataPointProcessingModule> next = queue.getNextStep(step);
                                // pass results to next task and start recursively
                                ProcessedDataPoint[] result = ((DataPointProcessingTask) task).getResults();
                                ((DataPointProcessingTask) task).displayResults();
                                execute(result, next, plot);
                            } else {
                                logger.warning("This controller was already removed from the running list, although it " + "had not finished processing. Exiting");
                                break;
                            }
                        } else {
                            setResults(((DataPointProcessingTask) task).getResults());
                            ((DataPointProcessingTask) task).displayResults();
                            setStatus(ControllerStatus.FINISHED);
                        }
                        break;
                    case PROCESSING:
                        setStatus(ControllerStatus.PROCESSING);
                        break;
                    case WAITING:
                        // should we even set to WAITING here?
                        break;
                    case ERROR:
                        setStatus(ControllerStatus.ERROR);
                        break;
                    case CANCELED:
                        setStatus(ControllerStatus.CANCELED);
                        break;
                }
            }
        });
        logger.finest("Start processing of " + t.getClass().getName());
        MZmineCore.getTaskController().addTask(t);
        // maybe we need this some time
        setCurrentTask((DataPointProcessingTask) t);
        setCurrentStep(step);
    }
}
Also used : ParameterSet(net.sf.mzmine.parameters.ParameterSet) Task(net.sf.mzmine.taskcontrol.Task) ArrayList(java.util.ArrayList) TaskStatus(net.sf.mzmine.taskcontrol.TaskStatus) TaskStatusListener(net.sf.mzmine.taskcontrol.TaskStatusListener) MZmineProcessingStep(net.sf.mzmine.modules.MZmineProcessingStep)

Example 3 with MZmineProcessingStep

use of net.sf.mzmine.modules.MZmineProcessingStep in project mzmine2 by mzmine.

the class ModuleComboComponent method actionPerformed.

public void actionPerformed(ActionEvent event) {
    Object src = event.getSource();
    MZmineProcessingStep<?> selected = (MZmineProcessingStep<?>) comboBox.getSelectedItem();
    if (src == comboBox) {
        if (selected == null) {
            setButton.setEnabled(false);
            return;
        }
        ParameterSet parameterSet = selected.getParameterSet();
        int numOfParameters = parameterSet.getParameters().length;
        setButton.setEnabled(numOfParameters > 0);
    }
    if (src == setButton) {
        if (selected == null)
            return;
        ParameterSetupDialog dialog = (ParameterSetupDialog) SwingUtilities.getAncestorOfClass(ParameterSetupDialog.class, this);
        if (dialog == null)
            return;
        ParameterSet parameterSet = selected.getParameterSet();
        parameterSet.showSetupDialog(dialog, dialog.isValueCheckRequired());
    }
}
Also used : ParameterSet(net.sf.mzmine.parameters.ParameterSet) MZmineProcessingStep(net.sf.mzmine.modules.MZmineProcessingStep) ParameterSetupDialog(net.sf.mzmine.parameters.dialogs.ParameterSetupDialog)

Example 4 with MZmineProcessingStep

use of net.sf.mzmine.modules.MZmineProcessingStep in project mzmine2 by mzmine.

the class ModuleComboParameter method cloneParameter.

@SuppressWarnings("unchecked")
@Override
public ModuleComboParameter<ModuleType> cloneParameter() {
    MZmineProcessingStep<ModuleType>[] newModules = new MZmineProcessingStep[modulesWithParams.length];
    MZmineProcessingStep<ModuleType> newValue = null;
    for (int i = 0; i < modulesWithParams.length; i++) {
        ModuleType module = modulesWithParams[i].getModule();
        ParameterSet params = modulesWithParams[i].getParameterSet();
        params = params.cloneParameterSet();
        newModules[i] = new MZmineProcessingStepImpl<ModuleType>(module, params);
        if (value == modulesWithParams[i])
            newValue = newModules[i];
    }
    ModuleComboParameter<ModuleType> copy = new ModuleComboParameter<ModuleType>(name, description, newModules);
    copy.setValue(newValue);
    return copy;
}
Also used : ParameterSet(net.sf.mzmine.parameters.ParameterSet) MZmineProcessingStep(net.sf.mzmine.modules.MZmineProcessingStep)

Aggregations

MZmineProcessingStep (net.sf.mzmine.modules.MZmineProcessingStep)4 ParameterSet (net.sf.mzmine.parameters.ParameterSet)4 Window (java.awt.Window)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 TransformerException (javax.xml.transform.TransformerException)1 MZmineProcessingModule (net.sf.mzmine.modules.MZmineProcessingModule)1 MZmineProcessingStepImpl (net.sf.mzmine.modules.impl.MZmineProcessingStepImpl)1 ParameterSetupDialog (net.sf.mzmine.parameters.dialogs.ParameterSetupDialog)1 PeakListsParameter (net.sf.mzmine.parameters.parametertypes.selectors.PeakListsParameter)1 PeakListsSelection (net.sf.mzmine.parameters.parametertypes.selectors.PeakListsSelection)1 RawDataFilesParameter (net.sf.mzmine.parameters.parametertypes.selectors.RawDataFilesParameter)1 RawDataFilesSelection (net.sf.mzmine.parameters.parametertypes.selectors.RawDataFilesSelection)1 Task (net.sf.mzmine.taskcontrol.Task)1 TaskStatus (net.sf.mzmine.taskcontrol.TaskStatus)1 TaskStatusListener (net.sf.mzmine.taskcontrol.TaskStatusListener)1 ExitCode (net.sf.mzmine.util.ExitCode)1