Search in sources :

Example 21 with ExitCode

use of net.sf.mzmine.util.ExitCode in project mzmine2 by mzmine.

the class SiriusExportModule method exportSinglePeakList.

public static void exportSinglePeakList(PeakListRow row) {
    try {
        ParameterSet parameters = MZmineCore.getConfiguration().getModuleParameters(SiriusExportModule.class);
        ExitCode exitCode = parameters.showSetupDialog(MZmineCore.getDesktop().getMainWindow(), true);
        if (exitCode != ExitCode.OK)
            return;
        // Open file
        final SiriusExportTask task = new SiriusExportTask(parameters);
        task.runSingleRow(row);
    } catch (Exception e) {
        e.printStackTrace();
        MZmineCore.getDesktop().displayErrorMessage(MZmineCore.getDesktop().getMainWindow(), "Error while exporting feature to SIRIUS: " + ExceptionUtils.exceptionToString(e));
    }
}
Also used : ParameterSet(net.sf.mzmine.parameters.ParameterSet) ExitCode(net.sf.mzmine.util.ExitCode)

Example 22 with ExitCode

use of net.sf.mzmine.util.ExitCode in project mzmine2 by mzmine.

the class SiriusExportModule method exportSingleRows.

public static void exportSingleRows(PeakListRow[] row) {
    try {
        ParameterSet parameters = MZmineCore.getConfiguration().getModuleParameters(SiriusExportModule.class);
        ExitCode exitCode = parameters.showSetupDialog(MZmineCore.getDesktop().getMainWindow(), true);
        if (exitCode != ExitCode.OK)
            return;
        // Open file
        final SiriusExportTask task = new SiriusExportTask(parameters);
        task.runSingleRows(row);
    } catch (Exception e) {
        e.printStackTrace();
        MZmineCore.getDesktop().displayErrorMessage(MZmineCore.getDesktop().getMainWindow(), "Error while exporting feature to SIRIUS: " + ExceptionUtils.exceptionToString(e));
    }
}
Also used : ParameterSet(net.sf.mzmine.parameters.ParameterSet) ExitCode(net.sf.mzmine.util.ExitCode)

Example 23 with ExitCode

use of net.sf.mzmine.util.ExitCode in project mzmine2 by mzmine.

the class DeconvolutionModule method runModule.

@Override
@Nonnull
public ExitCode runModule(@Nonnull MZmineProject project, @Nonnull final ParameterSet parameters, @Nonnull final Collection<Task> tasks) {
    PeakList[] peakLists = parameters.getParameter(DeconvolutionParameters.PEAK_LISTS).getValue().getMatchingPeakLists();
    // function to calculate center mz
    CenterFunction mzCenterFunction = parameters.getParameter(DeconvolutionParameters.MZ_CENTER_FUNCTION).getValue();
    // use a LOG weighted, noise corrected, maximum weight capped function
    if (mzCenterFunction.getMeasure().equals(CenterMeasure.AUTO)) {
        // data point with lowest intensity
        // weight = LOG(value) - LOG(noise) (maxed to maxWeight)
        double noise = Arrays.stream(peakLists).flatMap(pkl -> Arrays.stream(pkl.getRows())).map(r -> r.getPeaks()[0]).mapToDouble(peak -> peak.getRawDataPointsIntensityRange().lowerEndpoint()).filter(v -> v != 0).min().orElse(0);
        // maxWeight 4 corresponds to a linear range of 4 orders of magnitude
        // everything higher than this will be capped to this weight
        // do not overestimate influence of very high data points on mass accuracy
        double maxWeight = 4;
        // use a LOG weighted, noise corrected, maximum weight capped function
        mzCenterFunction = new CenterFunction(CenterMeasure.AVG, Weighting.LOG10, noise, maxWeight);
    }
    for (final PeakList peakList : peakLists) {
        tasks.add(new DeconvolutionTask(project, peakList, parameters, mzCenterFunction));
    }
    return ExitCode.OK;
}
Also used : Arrays(java.util.Arrays) Collection(java.util.Collection) CenterFunction(net.sf.mzmine.util.maths.CenterFunction) MZmineModuleCategory(net.sf.mzmine.modules.MZmineModuleCategory) PeakList(net.sf.mzmine.datamodel.PeakList) CenterMeasure(net.sf.mzmine.util.maths.CenterMeasure) Task(net.sf.mzmine.taskcontrol.Task) MZmineProcessingModule(net.sf.mzmine.modules.MZmineProcessingModule) ParameterSet(net.sf.mzmine.parameters.ParameterSet) Weighting(net.sf.mzmine.util.maths.Weighting) MZmineProject(net.sf.mzmine.datamodel.MZmineProject) ExitCode(net.sf.mzmine.util.ExitCode) Nonnull(javax.annotation.Nonnull) PeakList(net.sf.mzmine.datamodel.PeakList) CenterFunction(net.sf.mzmine.util.maths.CenterFunction) Nonnull(javax.annotation.Nonnull)

Example 24 with ExitCode

use of net.sf.mzmine.util.ExitCode in project mzmine2 by mzmine.

the class MzRangeFormulaCalculatorModule method showRangeCalculationDialog.

/**
 * Shows the calculation dialog and returns the calculated m/z range. May return null in case user
 * clicked Cancel.
 */
@Nullable
public static Range<Double> showRangeCalculationDialog() {
    ParameterSet myParameters = MZmineCore.getConfiguration().getModuleParameters(MzRangeFormulaCalculatorModule.class);
    if (myParameters == null)
        return null;
    ExitCode exitCode = myParameters.showSetupDialog(null, true);
    if (exitCode != ExitCode.OK)
        return null;
    return getMzRangeFromFormula(myParameters);
}
Also used : ParameterSet(net.sf.mzmine.parameters.ParameterSet) ExitCode(net.sf.mzmine.util.ExitCode) Nullable(javax.annotation.Nullable)

Example 25 with ExitCode

use of net.sf.mzmine.util.ExitCode in project mzmine2 by mzmine.

the class SpectraVisualizerWindow method actionPerformed.

@Override
public void actionPerformed(ActionEvent event) {
    String command = event.getActionCommand();
    if (command.equals("PEAKLIST_CHANGE")) {
        // If no scan is loaded yet, ignore
        if (currentScan == null)
            return;
        PeakList selectedPeakList = bottomPanel.getSelectedPeakList();
        loadPeaks(selectedPeakList);
    }
    if (command.equals("PREVIOUS_SCAN")) {
        if (dataFile == null)
            return;
        int msLevel = currentScan.getMSLevel();
        int[] scanNumbers = dataFile.getScanNumbers(msLevel);
        int scanIndex = Arrays.binarySearch(scanNumbers, currentScan.getScanNumber());
        if (scanIndex > 0) {
            final int prevScanIndex = scanNumbers[scanIndex - 1];
            Runnable newThreadRunnable = new Runnable() {

                @Override
                public void run() {
                    loadRawData(dataFile.getScan(prevScanIndex));
                }
            };
            Thread newThread = new Thread(newThreadRunnable);
            newThread.start();
        }
    }
    if (command.equals("NEXT_SCAN")) {
        if (dataFile == null)
            return;
        int msLevel = currentScan.getMSLevel();
        int[] scanNumbers = dataFile.getScanNumbers(msLevel);
        int scanIndex = Arrays.binarySearch(scanNumbers, currentScan.getScanNumber());
        if (scanIndex < (scanNumbers.length - 1)) {
            final int nextScanIndex = scanNumbers[scanIndex + 1];
            Runnable newThreadRunnable = new Runnable() {

                @Override
                public void run() {
                    loadRawData(dataFile.getScan(nextScanIndex));
                }
            };
            Thread newThread = new Thread(newThreadRunnable);
            newThread.start();
        }
    }
    if (command.equals("SHOW_MSMS")) {
        String selectedScanString = (String) bottomPanel.getMSMSSelector().getSelectedItem();
        if (selectedScanString == null)
            return;
        int sharpIndex = selectedScanString.indexOf('#');
        int commaIndex = selectedScanString.indexOf(',');
        selectedScanString = selectedScanString.substring(sharpIndex + 1, commaIndex);
        int selectedScan = Integer.valueOf(selectedScanString);
        SpectraVisualizerModule.showNewSpectrumWindow(dataFile, selectedScan);
    }
    if (command.equals("TOGGLE_PLOT_MODE")) {
        if (spectrumPlot.getPlotMode() == MassSpectrumType.CENTROIDED) {
            spectrumPlot.setPlotMode(MassSpectrumType.PROFILE);
            toolBar.setCentroidButton(MassSpectrumType.PROFILE);
        } else {
            spectrumPlot.setPlotMode(MassSpectrumType.CENTROIDED);
            toolBar.setCentroidButton(MassSpectrumType.CENTROIDED);
        }
    }
    if (command.equals("SHOW_DATA_POINTS")) {
        spectrumPlot.switchDataPointsVisible();
    }
    if (command.equals("SHOW_ANNOTATIONS")) {
        spectrumPlot.switchItemLabelsVisible();
    }
    if (command.equals("SHOW_PICKED_PEAKS")) {
        spectrumPlot.switchPickedPeaksVisible();
    }
    if (command.equals("SHOW_ISOTOPE_PEAKS")) {
        spectrumPlot.switchIsotopePeaksVisible();
    }
    if (command.equals("SETUP_AXES")) {
        AxesSetupDialog dialog = new AxesSetupDialog(this, spectrumPlot.getXYPlot());
        dialog.setVisible(true);
    }
    // library entry creation
    if (command.equals("CREATE_LIBRARY_ENTRY")) {
        // open window with all selected rows
        MSMSLibrarySubmissionWindow libraryWindow = new MSMSLibrarySubmissionWindow();
        libraryWindow.setData(currentScan);
        libraryWindow.setVisible(true);
    }
    if (command.equals("EXPORT_SPECTRA")) {
        ExportScansModule.showSetupDialog(currentScan);
    }
    if (command.equals("ADD_ISOTOPE_PATTERN")) {
        IsotopePattern newPattern = IsotopePatternCalculator.showIsotopePredictionDialog(this, true);
        if (newPattern == null)
            return;
        loadIsotopes(newPattern);
    }
    if ((command.equals("ZOOM_IN")) || (command.equals("ZOOM_IN_BOTH_COMMAND"))) {
        spectrumPlot.getXYPlot().getDomainAxis().resizeRange(1 / zoomCoefficient);
    }
    if ((command.equals("ZOOM_OUT")) || (command.equals("ZOOM_OUT_BOTH_COMMAND"))) {
        spectrumPlot.getXYPlot().getDomainAxis().resizeRange(zoomCoefficient);
    }
    if (command.equals("SET_SAME_RANGE")) {
        // Get current axes range
        NumberAxis xAxis = (NumberAxis) spectrumPlot.getXYPlot().getDomainAxis();
        NumberAxis yAxis = (NumberAxis) spectrumPlot.getXYPlot().getRangeAxis();
        double xMin = xAxis.getRange().getLowerBound();
        double xMax = xAxis.getRange().getUpperBound();
        double xTick = xAxis.getTickUnit().getSize();
        double yMin = yAxis.getRange().getLowerBound();
        double yMax = yAxis.getRange().getUpperBound();
        double yTick = yAxis.getTickUnit().getSize();
        // Get all frames of my class
        Window[] spectraFrames = JFrame.getWindows();
        // Set the range of these frames
        for (Window frame : spectraFrames) {
            if (!(frame instanceof SpectraVisualizerWindow))
                continue;
            SpectraVisualizerWindow spectraFrame = (SpectraVisualizerWindow) frame;
            spectraFrame.setAxesRange(xMin, xMax, xTick, yMin, yMax, yTick);
        }
    }
    if (command.equals("ONLINEDATABASESEARCH")) {
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                OnlineDBSpectraSearchModule.showSpectraIdentificationDialog(currentScan, spectrumPlot);
            }
        });
    }
    if (command.equals("CUSTOMDATABASESEARCH")) {
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                CustomDBSpectraSearchModule.showSpectraIdentificationDialog(currentScan, spectrumPlot);
            }
        });
    }
    if (command.equals("LIPIDSEARCH")) {
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                LipidSpectraSearchModule.showSpectraIdentificationDialog(currentScan, spectrumPlot);
            }
        });
    }
    if (command.equals("SUMFORMULA")) {
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                SumFormulaSpectraSearchModule.showSpectraIdentificationDialog(currentScan, spectrumPlot);
            }
        });
    }
    if (command.equals("SPECTRALDATABASESEARCH")) {
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                SpectraIdentificationSpectralDatabaseModule.showSpectraIdentificationDialog(currentScan, spectrumPlot);
            }
        });
    }
    if (command.equals("SET_PROCESSING_PARAMETERS")) {
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                if (!dppmWindowOpen) {
                    dppmWindowOpen = true;
                    ExitCode exitCode = DataPointProcessingManager.getInst().getParameters().showSetupDialog(MZmineCore.getDesktop().getMainWindow(), true);
                    dppmWindowOpen = false;
                    if (exitCode == ExitCode.OK && DataPointProcessingManager.getInst().isEnabled()) {
                        // if processing was run before, this removes the previous results.
                        getSpectrumPlot().removeDataPointProcessingResultDataSets();
                        getSpectrumPlot().checkAndRunController();
                    }
                }
            }
        });
    }
    if (command.equals("ENABLE_PROCESSING")) {
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                DataPointProcessingManager inst = DataPointProcessingManager.getInst();
                inst.setEnabled(!inst.isEnabled());
                bottomPanel.updateProcessingButton();
                getSpectrumPlot().checkAndRunController();
                // if the tick is removed, set the data back to default
                if (!inst.isEnabled()) {
                    getSpectrumPlot().removeDataPointProcessingResultDataSets();
                // loadRawData(currentScan);
                }
            }
        });
    }
}
Also used : MSMSLibrarySubmissionWindow(net.sf.mzmine.modules.peaklistmethods.io.spectraldbsubmit.view.MSMSLibrarySubmissionWindow) Window(java.awt.Window) NumberAxis(org.jfree.chart.axis.NumberAxis) MSMSLibrarySubmissionWindow(net.sf.mzmine.modules.peaklistmethods.io.spectraldbsubmit.view.MSMSLibrarySubmissionWindow) ExitCode(net.sf.mzmine.util.ExitCode) IsotopePattern(net.sf.mzmine.datamodel.IsotopePattern) DataPoint(net.sf.mzmine.datamodel.DataPoint) AxesSetupDialog(net.sf.mzmine.util.dialogs.AxesSetupDialog) DataPointProcessingManager(net.sf.mzmine.modules.visualization.spectra.simplespectra.datapointprocessing.DataPointProcessingManager) PeakList(net.sf.mzmine.datamodel.PeakList)

Aggregations

ExitCode (net.sf.mzmine.util.ExitCode)32 ParameterSet (net.sf.mzmine.parameters.ParameterSet)19 Window (java.awt.Window)7 RawDataFile (net.sf.mzmine.datamodel.RawDataFile)7 PeakList (net.sf.mzmine.datamodel.PeakList)6 SimpleParameterSet (net.sf.mzmine.parameters.impl.SimpleParameterSet)6 File (java.io.File)5 DataPoint (net.sf.mzmine.datamodel.DataPoint)4 Scan (net.sf.mzmine.datamodel.Scan)4 StringParameter (net.sf.mzmine.parameters.parametertypes.StringParameter)4 PeakListsParameter (net.sf.mzmine.parameters.parametertypes.selectors.PeakListsParameter)4 Task (net.sf.mzmine.taskcontrol.Task)4 ArrayList (java.util.ArrayList)3 Feature (net.sf.mzmine.datamodel.Feature)3 IsotopePattern (net.sf.mzmine.datamodel.IsotopePattern)3 MZmineProject (net.sf.mzmine.datamodel.MZmineProject)3 MZmineProcessingModule (net.sf.mzmine.modules.MZmineProcessingModule)3 Parameter (net.sf.mzmine.parameters.Parameter)3 RawDataFilesParameter (net.sf.mzmine.parameters.parametertypes.selectors.RawDataFilesParameter)3 BufferedWriter (java.io.BufferedWriter)2