Search in sources :

Example 11 with ExitCode

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

the class FormulaPredictionModule method showSingleRowIdentificationDialog.

public static void showSingleRowIdentificationDialog(PeakListRow row) {
    ParameterSet parameters = MZmineCore.getConfiguration().getModuleParameters(FormulaPredictionModule.class);
    double mzValue = row.getAverageMZ();
    parameters.getParameter(FormulaPredictionParameters.neutralMass).setIonMass(mzValue);
    int bestScanNum = row.getBestPeak().getRepresentativeScanNumber();
    if (bestScanNum > 0) {
        RawDataFile dataFile = row.getBestPeak().getDataFile();
        Scan bestScan = dataFile.getScan(bestScanNum);
        PolarityType scanPolarity = bestScan.getPolarity();
        switch(scanPolarity) {
            case POSITIVE:
                parameters.getParameter(FormulaPredictionParameters.neutralMass).setIonType(IonizationType.POSITIVE_HYDROGEN);
                break;
            case NEGATIVE:
                parameters.getParameter(FormulaPredictionParameters.neutralMass).setIonType(IonizationType.NEGATIVE_HYDROGEN);
                break;
            default:
                break;
        }
    }
    int charge = row.getBestPeak().getCharge();
    if (charge > 0) {
        parameters.getParameter(FormulaPredictionParameters.neutralMass).setCharge(charge);
    }
    ExitCode exitCode = parameters.showSetupDialog(MZmineCore.getDesktop().getMainWindow(), true);
    if (exitCode != ExitCode.OK) {
        return;
    }
    SingleRowPredictionTask newTask = new SingleRowPredictionTask(parameters.cloneParameterSet(), row);
    // execute the sequence
    MZmineCore.getTaskController().addTask(newTask);
}
Also used : ParameterSet(net.sf.mzmine.parameters.ParameterSet) PolarityType(net.sf.mzmine.datamodel.PolarityType) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) ExitCode(net.sf.mzmine.util.ExitCode) Scan(net.sf.mzmine.datamodel.Scan)

Example 12 with ExitCode

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

the class MassDetectionParameters method showSetupDialog.

@Override
public ExitCode showSetupDialog(Window parent, boolean valueCheckRequired) {
    ExitCode exitCode = super.showSetupDialog(parent, valueCheckRequired);
    // If the parameters are not complete, let's just stop here
    if (exitCode != ExitCode.OK)
        return exitCode;
    RawDataFile[] selectedFiles = getParameter(dataFiles).getValue().getMatchingRawDataFiles();
    // If no file selected (e.g. in batch mode setup), just return
    if ((selectedFiles == null) || (selectedFiles.length == 0))
        return exitCode;
    // Do an additional check for centroid/continuous data and show a
    // warning if there is a potential problem
    long numCentroided = 0, numProfile = 0;
    ScanSelection scanSel = getParameter(scanSelection).getValue();
    for (RawDataFile file : selectedFiles) {
        Scan[] scans = scanSel.getMatchingScans(file);
        for (Scan s : scans) {
            if (s.getSpectrumType() == MassSpectrumType.CENTROIDED)
                numCentroided++;
            else
                numProfile++;
        }
    }
    // If no scans found, let's just stop here
    if (numCentroided + numProfile == 0)
        return exitCode;
    // Do we have mostly centroided scans?
    final double proportionCentroided = (double) numCentroided / (numCentroided + numProfile);
    final boolean mostlyCentroided = proportionCentroided > 0.5;
    logger.finest("Proportion of scans estimated to be centroided: " + proportionCentroided);
    // Check the selected mass detector
    String massDetectorName = getParameter(massDetector).getValue().toString();
    if (mostlyCentroided && (!massDetectorName.startsWith("Centroid"))) {
        String msg = "MZmine thinks you are running the profile mode mass detector on (mostly) centroided scans. This will likely produce wrong results. Try the Centroid mass detector instead.";
        MZmineCore.getDesktop().displayMessage(null, msg);
    }
    if ((!mostlyCentroided) && (massDetectorName.startsWith("Centroid"))) {
        String msg = "MZmine thinks you are running the centroid mass detector on (mostly) profile scans. This will likely produce wrong results.";
        MZmineCore.getDesktop().displayMessage(null, msg);
    }
    return exitCode;
}
Also used : ScanSelection(net.sf.mzmine.parameters.parametertypes.selectors.ScanSelection) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) ExitCode(net.sf.mzmine.util.ExitCode) Scan(net.sf.mzmine.datamodel.Scan)

Example 13 with ExitCode

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

the class MzRangeMassCalculatorModule 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(MzRangeMassCalculatorModule.class);
    if (myParameters == null)
        return null;
    ExitCode exitCode = myParameters.showSetupDialog(null, true);
    if (exitCode != ExitCode.OK)
        return null;
    Double mz = myParameters.getParameter(MzRangeMassCalculatorParameters.mz).getValue();
    MZTolerance mzTolerance = myParameters.getParameter(MzRangeMassCalculatorParameters.mzTolerance).getValue();
    if ((mz == null) || (mzTolerance == null))
        return null;
    Range<Double> mzRange = mzTolerance.getToleranceRange(mz);
    return mzRange;
}
Also used : ParameterSet(net.sf.mzmine.parameters.ParameterSet) MZTolerance(net.sf.mzmine.parameters.parametertypes.tolerances.MZTolerance) ExitCode(net.sf.mzmine.util.ExitCode) Nullable(javax.annotation.Nullable)

Example 14 with ExitCode

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

the class TwoDVisualizerModule method show2DVisualizerSetupDialog.

public static void show2DVisualizerSetupDialog(RawDataFile dataFile, Range<Double> mzRange, Range<Double> rtRange) {
    ParameterSet parameters = MZmineCore.getConfiguration().getModuleParameters(TwoDVisualizerModule.class);
    parameters.getParameter(TwoDVisualizerParameters.dataFiles).setValue(RawDataFilesSelectionType.SPECIFIC_FILES, new RawDataFile[] { dataFile });
    if (rtRange != null)
        parameters.getParameter(TwoDVisualizerParameters.scanSelection).setValue(new ScanSelection(rtRange, 1));
    if (mzRange != null)
        parameters.getParameter(TwoDVisualizerParameters.mzRange).setValue(mzRange);
    ExitCode exitCode = parameters.showSetupDialog(MZmineCore.getDesktop().getMainWindow(), true);
    if (exitCode != ExitCode.OK)
        return;
    ScanSelection scanSel = parameters.getParameter(TwoDVisualizerParameters.scanSelection).getValue();
    Scan[] scans = scanSel.getMatchingScans(dataFile);
    rtRange = ScanUtils.findRtRange(scans);
    mzRange = parameters.getParameter(TwoDVisualizerParameters.mzRange).getValue();
    TwoDVisualizerWindow newWindow = new TwoDVisualizerWindow(dataFile, scans, rtRange, mzRange, parameters);
    newWindow.setVisible(true);
}
Also used : ParameterSet(net.sf.mzmine.parameters.ParameterSet) ScanSelection(net.sf.mzmine.parameters.parametertypes.selectors.ScanSelection) ExitCode(net.sf.mzmine.util.ExitCode) Scan(net.sf.mzmine.datamodel.Scan)

Example 15 with ExitCode

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

the class MZmineCore method main.

/**
 * Main method
 */
@SuppressWarnings("unchecked")
public static void main(String[] args) {
    // In the beginning, set the default locale to English, to avoid
    // problems with conversion of numbers etc. (e.g. decimal separator may
    // be . or , depending on the locale)
    Locale.setDefault(new Locale("en", "US"));
    logger.info("Starting MZmine " + getMZmineVersion());
    // Remove old temporary files, if we find any
    TmpFileCleanup.removeOldTemporaryFiles();
    logger.fine("Loading core classes..");
    // create instance of configuration
    configuration = new MZmineConfigurationImpl();
    // create instances of core modules
    projectManager = new ProjectManagerImpl();
    taskController = new TaskControllerImpl();
    logger.fine("Initializing core classes..");
    projectManager.initModule();
    taskController.initModule();
    logger.fine("Loading modules");
    for (Class<?> moduleClass : MZmineModulesList.MODULES) {
        try {
            logger.finest("Loading module " + moduleClass.getName());
            // Create instance and init module
            MZmineModule moduleInstance = (MZmineModule) moduleClass.newInstance();
            // Add to the module list
            initializedModules.put(moduleClass, moduleInstance);
            // Create an instance of parameter set
            Class<? extends ParameterSet> parameterSetClass = moduleInstance.getParameterSetClass();
            ParameterSet parameterSetInstance = parameterSetClass.newInstance();
            // Add the parameter set to the configuration
            configuration.setModuleParameters((Class<MZmineModule>) moduleClass, parameterSetInstance);
        } catch (Throwable e) {
            logger.log(Level.SEVERE, "Could not load module " + moduleClass, e);
            e.printStackTrace();
            continue;
        }
    }
    // If we have no arguments, run in GUI mode, otherwise run in batch mode
    if (args.length == 0) {
        // Create the Swing GUI in the event-dispatching thread, as is
        // generally recommended
        Runnable desktopInit = new Runnable() {

            @Override
            public void run() {
                logger.fine("Initializing GUI");
                MainWindow mainWindow = new MainWindow();
                desktop = mainWindow;
                mainWindow.initModule();
                // Activate project - bind it to the desktop's project tree
                MZmineProjectImpl currentProject = (MZmineProjectImpl) projectManager.getCurrentProject();
                currentProject.activateProject();
                // add desktop menu icon
                for (Class<?> moduleClass : MZmineModulesList.MODULES) {
                    MZmineModule module = initializedModules.get(moduleClass);
                    if (module instanceof MZmineRunnableModule) {
                        mainWindow.getMainMenu().addMenuItemForModule((MZmineRunnableModule) module);
                    }
                }
            }
        };
        try {
            SwingUtilities.invokeAndWait(desktopInit);
        } catch (Exception e) {
            logger.log(Level.SEVERE, "Could not initialize GUI", e);
            e.printStackTrace();
            System.exit(1);
        }
    } else {
        desktop = new HeadLessDesktop();
    }
    // load configuration
    if (MZmineConfiguration.CONFIG_FILE.exists() && MZmineConfiguration.CONFIG_FILE.canRead()) {
        try {
            configuration.loadConfiguration(MZmineConfiguration.CONFIG_FILE);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    // if we have GUI, show it now
    if (desktop.getMainWindow() != null && !(desktop instanceof HeadLessDesktop)) {
        // update the size and position of the main window
        ParameterSet paramSet = configuration.getPreferences();
        WindowSettingsParameter settings = paramSet.getParameter(MZminePreferences.windowSetttings);
        settings.applySettingsToWindow(desktop.getMainWindow());
        // add last project menu items
        if (desktop instanceof MainWindow) {
            ((MainWindow) desktop).createLastUsedProjectsMenu(configuration.getLastProjects());
            // listen for changes
            configuration.getLastProjectsParameter().addFileListChangedListener(list -> {
                // new list of last used projects
                Desktop desk = getDesktop();
                if (desk instanceof MainWindow) {
                    ((MainWindow) desk).createLastUsedProjectsMenu(list);
                }
            });
        }
        // show the GUI
        logger.info("Showing main window");
        desktop.getMainWindow().setVisible(true);
        // show the welcome message
        desktop.setStatusBarText("Welcome to MZmine 2!");
        // Check for updated version
        NewVersionCheck NVC = new NewVersionCheck(CheckType.DESKTOP);
        Thread nvcThread = new Thread(NVC);
        nvcThread.setPriority(Thread.MIN_PRIORITY);
        nvcThread.start();
        // Tracker
        GoogleAnalyticsTracker GAT = new GoogleAnalyticsTracker("MZmine Loaded (GUI mode)", "/JAVA/Main/GUI");
        Thread gatThread = new Thread(GAT);
        gatThread.setPriority(Thread.MIN_PRIORITY);
        gatThread.start();
        // register shutdown hook only if we have GUI - we don't want to
        // save configuration on exit if we only run a batch
        ShutDownHook shutDownHook = new ShutDownHook();
        Runtime.getRuntime().addShutdownHook(shutDownHook);
    }
    // mode
    if (args.length > 0 && desktop instanceof HeadLessDesktop) {
        // Tracker
        GoogleAnalyticsTracker GAT = new GoogleAnalyticsTracker("MZmine Loaded (Headless mode)", "/JAVA/Main/GUI");
        Thread gatThread = new Thread(GAT);
        gatThread.setPriority(Thread.MIN_PRIORITY);
        gatThread.start();
        File batchFile = new File(args[0]);
        if ((!batchFile.exists()) || (!batchFile.canRead())) {
            logger.severe("Cannot read batch file " + batchFile);
            System.exit(1);
        }
        ExitCode exitCode = BatchModeModule.runBatch(projectManager.getCurrentProject(), batchFile);
        if (exitCode == ExitCode.OK)
            System.exit(0);
        else
            System.exit(1);
    }
}
Also used : Locale(java.util.Locale) ParameterSet(net.sf.mzmine.parameters.ParameterSet) MZmineRunnableModule(net.sf.mzmine.modules.MZmineRunnableModule) ExitCode(net.sf.mzmine.util.ExitCode) MZmineConfigurationImpl(net.sf.mzmine.main.impl.MZmineConfigurationImpl) TaskControllerImpl(net.sf.mzmine.taskcontrol.impl.TaskControllerImpl) IOException(java.io.IOException) ProjectManagerImpl(net.sf.mzmine.project.impl.ProjectManagerImpl) HeadLessDesktop(net.sf.mzmine.desktop.impl.HeadLessDesktop) WindowSettingsParameter(net.sf.mzmine.parameters.parametertypes.WindowSettingsParameter) HeadLessDesktop(net.sf.mzmine.desktop.impl.HeadLessDesktop) Desktop(net.sf.mzmine.desktop.Desktop) MainWindow(net.sf.mzmine.desktop.impl.MainWindow) File(java.io.File) MZmineModule(net.sf.mzmine.modules.MZmineModule) MZmineProjectImpl(net.sf.mzmine.project.impl.MZmineProjectImpl)

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