Search in sources :

Example 6 with RawDataFilesParameter

use of net.sf.mzmine.parameters.parametertypes.selectors.RawDataFilesParameter 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
                }
            }
        }
    }
}
Also used : ParameterSet(net.sf.mzmine.parameters.ParameterSet) Task(net.sf.mzmine.taskcontrol.Task) AbstractTask(net.sf.mzmine.taskcontrol.AbstractTask) ExitCode(net.sf.mzmine.util.ExitCode) ArrayList(java.util.ArrayList) MZmineProcessingModule(net.sf.mzmine.modules.MZmineProcessingModule) TaskStatus(net.sf.mzmine.taskcontrol.TaskStatus) RawDataFilesSelection(net.sf.mzmine.parameters.parametertypes.selectors.RawDataFilesSelection) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) PeakListsSelection(net.sf.mzmine.parameters.parametertypes.selectors.PeakListsSelection) PeakListsParameter(net.sf.mzmine.parameters.parametertypes.selectors.PeakListsParameter) PeakList(net.sf.mzmine.datamodel.PeakList) RawDataFilesParameter(net.sf.mzmine.parameters.parametertypes.selectors.RawDataFilesParameter)

Example 7 with RawDataFilesParameter

use of net.sf.mzmine.parameters.parametertypes.selectors.RawDataFilesParameter 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();
    }
}
Also used : ParameterSet(net.sf.mzmine.parameters.ParameterSet) ProjectOpeningTask(net.sf.mzmine.modules.projectmethods.projectload.ProjectOpeningTask) Task(net.sf.mzmine.taskcontrol.Task) MZmineRunnableModule(net.sf.mzmine.modules.MZmineRunnableModule) ProjectParametersSetupDialog(net.sf.mzmine.project.parameterssetup.ProjectParametersSetupDialog) ExitCode(net.sf.mzmine.util.ExitCode) ArrayList(java.util.ArrayList) NewVersionCheck(net.sf.mzmine.main.NewVersionCheck) MZminePreferences(net.sf.mzmine.desktop.preferences.MZminePreferences) JFileChooser(javax.swing.JFileChooser) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) MZmineProject(net.sf.mzmine.datamodel.MZmineProject) PeakListsParameter(net.sf.mzmine.parameters.parametertypes.selectors.PeakListsParameter) PeakList(net.sf.mzmine.datamodel.PeakList) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) File(java.io.File) RawDataFilesParameter(net.sf.mzmine.parameters.parametertypes.selectors.RawDataFilesParameter)

Example 8 with RawDataFilesParameter

use of net.sf.mzmine.parameters.parametertypes.selectors.RawDataFilesParameter in project mzmine2 by mzmine.

the class AlignScansModule method runModule.

@Override
@Nonnull
public ExitCode runModule(@Nonnull MZmineProject project, @Nonnull ParameterSet parameters, @Nonnull Collection<Task> tasks) {
    RawDataFile[] dataFiles = parameters.getParameter(new RawDataFilesParameter()).getValue().getMatchingRawDataFiles();
    for (int i = 0; i < dataFiles.length; i++) {
        Task newTask = new AlignScansTask(project, dataFiles[i], parameters.cloneParameterSet());
        tasks.add(newTask);
    }
    return ExitCode.OK;
}
Also used : Task(net.sf.mzmine.taskcontrol.Task) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) RawDataFilesParameter(net.sf.mzmine.parameters.parametertypes.selectors.RawDataFilesParameter) Nonnull(javax.annotation.Nonnull)

Example 9 with RawDataFilesParameter

use of net.sf.mzmine.parameters.parametertypes.selectors.RawDataFilesParameter in project mzmine2 by mzmine.

the class ScanSmoothingModule method runModule.

@Override
@Nonnull
public ExitCode runModule(@Nonnull MZmineProject project, @Nonnull ParameterSet parameters, @Nonnull Collection<Task> tasks) {
    RawDataFile[] dataFiles = parameters.getParameter(new RawDataFilesParameter()).getValue().getMatchingRawDataFiles();
    for (int i = 0; i < dataFiles.length; i++) {
        Task newTask = new ScanSmoothingTask(project, dataFiles[i], parameters.cloneParameterSet());
        tasks.add(newTask);
    }
    return ExitCode.OK;
}
Also used : Task(net.sf.mzmine.taskcontrol.Task) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) RawDataFilesParameter(net.sf.mzmine.parameters.parametertypes.selectors.RawDataFilesParameter) Nonnull(javax.annotation.Nonnull)

Example 10 with RawDataFilesParameter

use of net.sf.mzmine.parameters.parametertypes.selectors.RawDataFilesParameter in project mzmine2 by mzmine.

the class RTRangeComponent method actionPerformed.

@Override
public void actionPerformed(ActionEvent event) {
    Object src = event.getSource();
    if (src == setAutoButton) {
        RawDataFile[] currentFiles = MZmineCore.getProjectManager().getCurrentProject().getDataFiles();
        try {
            ParameterSetupDialog setupDialog = (ParameterSetupDialog) SwingUtilities.getWindowAncestor(this);
            RawDataFilesComponent rdc = (RawDataFilesComponent) setupDialog.getComponentForParameter(new RawDataFilesParameter());
            // is probably in the parent dialog, so let's check it
            if (rdc == null) {
                setupDialog = (ParameterSetupDialog) setupDialog.getParent();
                if (setupDialog != null) {
                    rdc = (RawDataFilesComponent) setupDialog.getComponentForParameter(new RawDataFilesParameter());
                }
            }
            if (rdc != null) {
                RawDataFile[] matchingFiles = rdc.getValue().getMatchingRawDataFiles();
                if (matchingFiles.length > 0)
                    currentFiles = matchingFiles;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        Range<Double> rtRange = null;
        for (RawDataFile file : currentFiles) {
            Range<Double> fileRange = file.getDataRTRange();
            if (rtRange == null)
                rtRange = fileRange;
            else
                rtRange = rtRange.span(fileRange);
        }
        setValue(rtRange);
    }
}
Also used : RawDataFilesComponent(net.sf.mzmine.parameters.parametertypes.selectors.RawDataFilesComponent) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) ParameterSetupDialog(net.sf.mzmine.parameters.dialogs.ParameterSetupDialog) RawDataFilesParameter(net.sf.mzmine.parameters.parametertypes.selectors.RawDataFilesParameter)

Aggregations

RawDataFilesParameter (net.sf.mzmine.parameters.parametertypes.selectors.RawDataFilesParameter)10 RawDataFile (net.sf.mzmine.datamodel.RawDataFile)8 Task (net.sf.mzmine.taskcontrol.Task)6 Nonnull (javax.annotation.Nonnull)4 ParameterSet (net.sf.mzmine.parameters.ParameterSet)4 PeakListsParameter (net.sf.mzmine.parameters.parametertypes.selectors.PeakListsParameter)4 ExitCode (net.sf.mzmine.util.ExitCode)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2 PeakList (net.sf.mzmine.datamodel.PeakList)2 MZmineProcessingModule (net.sf.mzmine.modules.MZmineProcessingModule)2 ParameterSetupDialog (net.sf.mzmine.parameters.dialogs.ParameterSetupDialog)2 PeakListsSelection (net.sf.mzmine.parameters.parametertypes.selectors.PeakListsSelection)2 RawDataFilesComponent (net.sf.mzmine.parameters.parametertypes.selectors.RawDataFilesComponent)2 RawDataFilesSelection (net.sf.mzmine.parameters.parametertypes.selectors.RawDataFilesSelection)2 Window (java.awt.Window)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 JFileChooser (javax.swing.JFileChooser)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1