Search in sources :

Example 1 with RawDataFilesSelection

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

the class XICManualPickerModule method runManualDetection.

// public static ExitCode runManualDetection(RawDataFile dataFile, PeakListRow peakListRow,
// PeakList peakList, PeakListTable table) {
// return runManualDetection(new RawDataFile[] {dataFile}, peakListRow, peakList, table);
// }
public static ExitCode runManualDetection(RawDataFile dataFile, PeakListRow peakListRow, PeakList peakList, PeakListTable table) {
    Range<Double> mzRange = null, rtRange = null;
    mzRange = Range.closed(peakListRow.getAverageMZ(), peakListRow.getAverageMZ());
    rtRange = Range.closed(peakListRow.getAverageRT(), peakListRow.getAverageRT());
    for (Feature peak : peakListRow.getPeaks()) {
        if (peak == null)
            continue;
        // if the peak exists in the file, then we just use that one as a base
        if (peak.getDataFile() == dataFile) {
            mzRange = peak.getRawDataPointsMZRange();
            rtRange = peak.getRawDataPointsRTRange();
            break;
        }
        // if it does not exist, we set up on basis of the other peaks
        if (peak != null) {
            mzRange = mzRange.span(peak.getRawDataPointsMZRange());
            rtRange = rtRange.span(peak.getRawDataPointsRTRange());
        }
    }
    XICManualPickerParameters parameters = new XICManualPickerParameters();
    if (mzRange != null) {
        parameters.getParameter(XICManualPickerParameters.rtRange).setValue(rtRange);
        parameters.getParameter(XICManualPickerParameters.mzRange).setValue(mzRange);
    }
    if (dataFile != null) {
        RawDataFilesSelection selection = new RawDataFilesSelection();
        selection.setSpecificFiles(new RawDataFile[] { dataFile });
        selection.setSelectionType(RawDataFilesSelectionType.SPECIFIC_FILES);
        parameters.getParameter(XICManualPickerParameters.rawDataFiles).setValue(selection);
    }
    ExitCode exitCode = parameters.showSetupDialog(MZmineCore.getDesktop().getMainWindow(), true);
    if (exitCode != ExitCode.OK)
        return exitCode;
    ManualPickerParameters param = new ManualPickerParameters();
    param.getParameter(ManualPickerParameters.mzRange).setValue(parameters.getParameter(XICManualPickerParameters.mzRange).getValue());
    param.getParameter(ManualPickerParameters.retentionTimeRange).setValue(parameters.getParameter(XICManualPickerParameters.rtRange).getValue());
    ManualPickerTask task = new ManualPickerTask(MZmineCore.getProjectManager().getCurrentProject(), peakListRow, new RawDataFile[] { dataFile }, param, peakList, table);
    MZmineCore.getTaskController().addTask(task);
    return exitCode;
}
Also used : RawDataFilesSelection(net.sf.mzmine.parameters.parametertypes.selectors.RawDataFilesSelection) ExitCode(net.sf.mzmine.util.ExitCode) Feature(net.sf.mzmine.datamodel.Feature)

Example 2 with RawDataFilesSelection

use of net.sf.mzmine.parameters.parametertypes.selectors.RawDataFilesSelection 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 3 with RawDataFilesSelection

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

the class KovatsIndexExtractionDialog method initRawDataFileSelection.

/**
 * Init raw data selection to last used raw data file or "kovats" or "dro"
 */
private void initRawDataFileSelection() {
    if (dataFiles != null && dataFiles.length <= 0)
        return;
    RawDataFilesSelection select = parameterSet.getParameter(KovatsIndexExtractionParameters.dataFiles).getValue();
    RawDataFile[] raw = null;
    // set to parameters files - if they exist in this project
    if (select != null && select.getMatchingRawDataFiles().length > 0) {
        RawDataFile[] exists = Arrays.stream(select.getMatchingRawDataFiles()).filter(r -> Arrays.stream(dataFiles).anyMatch(d -> r.getName().equals(d.getName()))).toArray(RawDataFile[]::new);
        if (exists.length > 0)
            raw = exists;
    }
    if (raw == null) {
        // find kovats or dro file
        // first use all kovats named files and then dro (max 2)
        RawDataFile[] kovats = Arrays.stream(dataFiles).filter(d -> d.getName().toLowerCase().contains("kovats")).toArray(RawDataFile[]::new);
        RawDataFile[] dro = Arrays.stream(dataFiles).filter(d -> d.getName().toLowerCase().contains("dro")).toArray(RawDataFile[]::new);
        // maximum of two files are chosen (0,1,2)
        int size = Math.min(2, kovats.length + dro.length);
        raw = new RawDataFile[size];
        for (int i = 0; i < raw.length; i++) {
            if (i < kovats.length)
                raw[i] = kovats[i];
            else
                raw[i] = dro[i - kovats.length];
        }
    }
    if (raw.length > 0) {
        selectedDataFile = raw;
        comboDataFileName.setSelectedItem(selectedDataFile[0]);
        if (raw.length > 1) {
            comboDataFileName2.setSelectedItem(selectedDataFile[1]);
        }
    }
}
Also used : Color(java.awt.Color) StringComponent(net.sf.mzmine.parameters.parametertypes.StringComponent) Arrays(java.util.Arrays) FileAndPathUtil(net.sf.mzmine.util.files.FileAndPathUtil) ChartGestureHandler(net.sf.mzmine.chartbasics.gestures.ChartGestureHandler) ValueMarker(org.jfree.chart.plot.ValueMarker) MultiChoiceComponent(net.sf.mzmine.parameters.parametertypes.MultiChoiceComponent) ParameterSet(net.sf.mzmine.parameters.ParameterSet) Event(net.sf.mzmine.chartbasics.gestures.ChartGesture.Event) JFileChooser(javax.swing.JFileChooser) BorderLayout(java.awt.BorderLayout) JComboBox(javax.swing.JComboBox) Image(java.awt.Image) Key(net.sf.mzmine.chartbasics.gestures.ChartGesture.Key) Font(java.awt.Font) Range(com.google.common.collect.Range) MZRangeComponent(net.sf.mzmine.parameters.parametertypes.ranges.MZRangeComponent) Icon(javax.swing.Icon) Logger(java.util.logging.Logger) StandardCharsets(java.nio.charset.StandardCharsets) Box(javax.swing.Box) ChartGestureDragDiffEvent(net.sf.mzmine.chartbasics.gestures.ChartGestureDragDiffEvent) Dimension(java.awt.Dimension) List(java.util.List) Stream(java.util.stream.Stream) XYDataset(org.jfree.data.xy.XYDataset) Entry(java.util.Map.Entry) JCheckBox(javax.swing.JCheckBox) Entity(net.sf.mzmine.chartbasics.gestures.ChartGesture.Entity) RTRangeComponent(net.sf.mzmine.parameters.parametertypes.ranges.RTRangeComponent) BasicStroke(java.awt.BasicStroke) JPanel(javax.swing.JPanel) MZmineCore(net.sf.mzmine.main.MZmineCore) ColorPalettes(net.sf.mzmine.util.ColorPalettes) JTextField(javax.swing.JTextField) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) MzRangeFormulaCalculatorModule(net.sf.mzmine.modules.tools.mzrangecalculator.MzRangeFormulaCalculatorModule) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) ArrayUtils(org.apache.commons.lang3.ArrayUtils) NumberFormat(java.text.NumberFormat) Button(net.sf.mzmine.chartbasics.gestures.ChartGesture.Button) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) GridLayout(java.awt.GridLayout) IntegerComponent(net.sf.mzmine.parameters.parametertypes.IntegerComponent) FileNameComponent(net.sf.mzmine.parameters.parametertypes.filenames.FileNameComponent) DelayedDocumentListener(net.sf.mzmine.framework.listener.DelayedDocumentListener) Files(com.google.common.io.Files) ChartGesture(net.sf.mzmine.chartbasics.gestures.ChartGesture) TxtWriter(net.sf.mzmine.util.io.TxtWriter) ImageIcon(javax.swing.ImageIcon) TICPlot(net.sf.mzmine.modules.visualization.tic.TICPlot) ParameterSetupDialog(net.sf.mzmine.parameters.dialogs.ParameterSetupDialog) BoxLayout(javax.swing.BoxLayout) Stroke(java.awt.Stroke) FlowLayout(java.awt.FlowLayout) MZTolerance(net.sf.mzmine.parameters.parametertypes.tolerances.MZTolerance) JButton(javax.swing.JButton) KovatsIndex(net.sf.mzmine.modules.tools.kovats.KovatsValues.KovatsIndex) TICPlotType(net.sf.mzmine.modules.visualization.tic.TICPlotType) MigLayout(net.miginfocom.swing.MigLayout) Window(java.awt.Window) DecimalFormat(java.text.DecimalFormat) RawDataFilesSelection(net.sf.mzmine.parameters.parametertypes.selectors.RawDataFilesSelection) TICSumDataSet(net.sf.mzmine.modules.visualization.tic.TICSumDataSet) IOException(java.io.IOException) IonizationType(net.sf.mzmine.datamodel.IonizationType) File(java.io.File) Consumer(java.util.function.Consumer) RectangleInsets(org.jfree.chart.ui.RectangleInsets) TreeMap(java.util.TreeMap) ChartGestureDragDiffHandler(net.sf.mzmine.chartbasics.gestures.ChartGestureDragDiffHandler) JLabel(javax.swing.JLabel) RawDataFilesSelectionType(net.sf.mzmine.parameters.parametertypes.selectors.RawDataFilesSelectionType) DialogLoggerUtil(net.sf.mzmine.util.DialogLoggerUtil) DoubleComponent(net.sf.mzmine.parameters.parametertypes.DoubleComponent) RawDataFilesSelection(net.sf.mzmine.parameters.parametertypes.selectors.RawDataFilesSelection) RawDataFile(net.sf.mzmine.datamodel.RawDataFile)

Example 4 with RawDataFilesSelection

use of net.sf.mzmine.parameters.parametertypes.selectors.RawDataFilesSelection 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)

Aggregations

RawDataFilesSelection (net.sf.mzmine.parameters.parametertypes.selectors.RawDataFilesSelection)4 ParameterSet (net.sf.mzmine.parameters.ParameterSet)3 ExitCode (net.sf.mzmine.util.ExitCode)3 Window (java.awt.Window)2 File (java.io.File)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Range (com.google.common.collect.Range)1 Files (com.google.common.io.Files)1 BasicStroke (java.awt.BasicStroke)1 BorderLayout (java.awt.BorderLayout)1 Color (java.awt.Color)1 Dimension (java.awt.Dimension)1 FlowLayout (java.awt.FlowLayout)1 Font (java.awt.Font)1 GridLayout (java.awt.GridLayout)1 Image (java.awt.Image)1 Stroke (java.awt.Stroke)1 FileNotFoundException (java.io.FileNotFoundException)1 StandardCharsets (java.nio.charset.StandardCharsets)1