Search in sources :

Example 11 with HeadLessDesktop

use of net.sf.mzmine.desktop.impl.HeadLessDesktop 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)

Example 12 with HeadLessDesktop

use of net.sf.mzmine.desktop.impl.HeadLessDesktop in project mzmine2 by mzmine.

the class CameraSearchTask method run.

@Override
public void run() {
    try {
        setStatus(TaskStatus.PROCESSING);
        // Check number of raw data files.
        if (peakList.getNumberOfRawDataFiles() != 1) {
            throw new IllegalStateException("CAMERA can only process feature lists for a single raw data file, i.e. non-aligned feature lists.");
        }
        // Run the search.
        cameraSearch(peakList.getRawDataFile(0));
        // Create new list with IsotopePattern information
        PeakList newPeakList = null;
        if (parameters.getParameter(CameraSearchParameters.CREATE_NEW_LIST).getValue()) {
            switch(groupBy) {
                case CameraSearchParameters.GROUP_BY_PCGROUP:
                    newPeakList = groupPeaksByPCGroup(peakList);
                    break;
                default:
                    newPeakList = groupPeaksByIsotope(peakList);
            }
        }
        if (!isCanceled()) {
            if (newPeakList != null) {
                project.addPeakList(newPeakList);
                QualityParameters.calculateQualityParameters(newPeakList);
            }
            // Finished.
            setStatus(TaskStatus.FINISHED);
            LOG.info("CAMERA Search completed");
        }
        // Repaint the window to reflect the change in the feature list
        Desktop desktop = MZmineCore.getDesktop();
        if (!(desktop instanceof HeadLessDesktop))
            desktop.getMainWindow().repaint();
    } catch (Throwable t) {
        LOG.log(Level.SEVERE, "CAMERA Search error", t);
        setErrorMessage(t.getMessage());
        setStatus(TaskStatus.ERROR);
    }
}
Also used : HeadLessDesktop(net.sf.mzmine.desktop.impl.HeadLessDesktop) Desktop(net.sf.mzmine.desktop.Desktop) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList) PeakList(net.sf.mzmine.datamodel.PeakList) HeadLessDesktop(net.sf.mzmine.desktop.impl.HeadLessDesktop)

Example 13 with HeadLessDesktop

use of net.sf.mzmine.desktop.impl.HeadLessDesktop in project mzmine2 by mzmine.

the class ComplexSearchTask method run.

/**
 * @see java.lang.Runnable#run()
 */
public void run() {
    setStatus(TaskStatus.PROCESSING);
    logger.info("Starting complex search in " + peakList);
    PeakListRow[] rows = peakList.getRows();
    totalRows = rows.length;
    // Sort the array by m/z so we start with biggest peak (possible
    // complex)
    Arrays.sort(rows, new PeakListRowSorter(SortingProperty.MZ, SortingDirection.Descending));
    // Compare each three rows against each other
    for (int i = 0; i < totalRows; i++) {
        Range<Double> testRTRange = rtTolerance.getToleranceRange(rows[i].getAverageRT());
        PeakListRow[] testRows = peakList.getRowsInsideScanRange(testRTRange);
        for (int j = 0; j < testRows.length; j++) {
            for (int k = j; k < testRows.length; k++) {
                // Task canceled?
                if (isCanceled())
                    return;
                // very small m/z peak
                if ((rows[i] == testRows[j]) || (rows[i] == testRows[k]))
                    continue;
                if (checkComplex(rows[i], testRows[j], testRows[k]))
                    addComplexInfo(rows[i], testRows[j], testRows[k]);
            }
        }
        finishedRows++;
    }
    // Add task description to peakList
    ((SimplePeakList) peakList).addDescriptionOfAppliedTask(new SimplePeakListAppliedMethod("Identification of complexes", parameters));
    // Repaint the window to reflect the change in the feature list
    Desktop desktop = MZmineCore.getDesktop();
    if (!(desktop instanceof HeadLessDesktop))
        desktop.getMainWindow().repaint();
    setStatus(TaskStatus.FINISHED);
    logger.info("Finished complexes search in " + peakList);
}
Also used : PeakListRow(net.sf.mzmine.datamodel.PeakListRow) HeadLessDesktop(net.sf.mzmine.desktop.impl.HeadLessDesktop) Desktop(net.sf.mzmine.desktop.Desktop) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList) SimplePeakListAppliedMethod(net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod) PeakListRowSorter(net.sf.mzmine.util.PeakListRowSorter) HeadLessDesktop(net.sf.mzmine.desktop.impl.HeadLessDesktop)

Example 14 with HeadLessDesktop

use of net.sf.mzmine.desktop.impl.HeadLessDesktop in project mzmine2 by mzmine.

the class NistMsSearchTask method run.

@Override
public void run() {
    try {
        // Run the search.
        nistSearch();
        if (!isCanceled()) {
            // Finished.
            setStatus(TaskStatus.FINISHED);
            LOG.info("NIST MS Search completed");
        }
        // Repaint the window to reflect the change in the feature list
        Desktop desktop = MZmineCore.getDesktop();
        if (!(desktop instanceof HeadLessDesktop))
            desktop.getMainWindow().repaint();
    } catch (Throwable t) {
        LOG.log(Level.SEVERE, "NIST MS Search error", t);
        setErrorMessage(t.getMessage());
        setStatus(TaskStatus.ERROR);
    }
}
Also used : HeadLessDesktop(net.sf.mzmine.desktop.impl.HeadLessDesktop) Desktop(net.sf.mzmine.desktop.Desktop) HeadLessDesktop(net.sf.mzmine.desktop.impl.HeadLessDesktop)

Example 15 with HeadLessDesktop

use of net.sf.mzmine.desktop.impl.HeadLessDesktop in project mzmine2 by mzmine.

the class GNPSResultsImportTask method run.

/**
 * @see java.lang.Runnable#run()
 */
@Override
public void run() {
    setStatus(TaskStatus.PROCESSING);
    logger.info("Importing GNPS results for " + peakList);
    // remove zero ids from edges to prevent exception
    removeZeroIDFromEdge(file);
    Graph graph = new DefaultGraph("GNPS");
    if (importGraphData(graph, file)) {
        // import library matches from nodes
        importLibraryMatches(graph);
        // Add task description to peakList
        ((SimplePeakList) peakList).addDescriptionOfAppliedTask(new SimplePeakListAppliedMethod("Identification of complexes", parameters));
        // Repaint the window to reflect the change in the feature list
        Desktop desktop = MZmineCore.getDesktop();
        if (!(desktop instanceof HeadLessDesktop))
            desktop.getMainWindow().repaint();
        setStatus(TaskStatus.FINISHED);
        logger.info("Finished import of GNPS results for " + peakList);
    }
}
Also used : DefaultGraph(org.graphstream.graph.implementations.DefaultGraph) Graph(org.graphstream.graph.Graph) HeadLessDesktop(net.sf.mzmine.desktop.impl.HeadLessDesktop) Desktop(net.sf.mzmine.desktop.Desktop) DefaultGraph(org.graphstream.graph.implementations.DefaultGraph) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList) SimplePeakListAppliedMethod(net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod) HeadLessDesktop(net.sf.mzmine.desktop.impl.HeadLessDesktop)

Aggregations

Desktop (net.sf.mzmine.desktop.Desktop)17 HeadLessDesktop (net.sf.mzmine.desktop.impl.HeadLessDesktop)17 SimplePeakListAppliedMethod (net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod)10 SimplePeakList (net.sf.mzmine.datamodel.impl.SimplePeakList)6 IOException (java.io.IOException)5 PeakListRow (net.sf.mzmine.datamodel.PeakListRow)5 AbstractTask (net.sf.mzmine.taskcontrol.AbstractTask)4 UnsupportedFormatException (net.sf.mzmine.util.spectraldb.parser.UnsupportedFormatException)4 DataPoint (net.sf.mzmine.datamodel.DataPoint)3 Feature (net.sf.mzmine.datamodel.Feature)2 SpectraIdentificationResultsWindow (net.sf.mzmine.modules.visualization.spectra.spectralmatchresults.SpectraIdentificationResultsWindow)2 PeakListRowSorter (net.sf.mzmine.util.PeakListRowSorter)2 File (java.io.File)1 FileReader (java.io.FileReader)1 Locale (java.util.Locale)1 IsotopePattern (net.sf.mzmine.datamodel.IsotopePattern)1 PeakList (net.sf.mzmine.datamodel.PeakList)1 Scan (net.sf.mzmine.datamodel.Scan)1 MainWindow (net.sf.mzmine.desktop.impl.MainWindow)1 MZmineConfigurationImpl (net.sf.mzmine.main.impl.MZmineConfigurationImpl)1