Search in sources :

Example 16 with Desktop

use of net.sf.mzmine.desktop.Desktop in project mzmine2 by mzmine.

the class AddProjectParameterDialog method actionPerformed.

public void actionPerformed(ActionEvent actionEvent) {
    Object src = actionEvent.getSource();
    Desktop desktop = MZmineCore.getDesktop();
    if (src == buttonAddParameter) {
        if (fieldName.getText().length() == 0) {
            desktop.displayErrorMessage(this, "Give a name for the parameter first.");
            return;
        }
        String paramName = fieldName.getText();
        UserParameter<?, ?> parameter = null;
        if (radiobuttonNumerical.isSelected()) {
            parameter = new DoubleParameter(paramName, null);
        }
        if (radiobuttonFreeText.isSelected()) {
            parameter = new StringParameter(paramName, null);
        }
        if (radiobuttonCategorical.isSelected()) {
            String[] possibleValues = new String[categories.size()];
            if (possibleValues.length == 0) {
                desktop.displayErrorMessage(this, "Give at least a single parameter value.");
                return;
            }
            for (int valueIndex = 0; valueIndex < categories.size(); valueIndex++) possibleValues[valueIndex] = (String) categories.get(valueIndex);
            parameter = new ComboParameter<String>(paramName, null, possibleValues);
        }
        mainDialog.addParameter(parameter);
        dispose();
    }
    if (src == buttonCancel) {
        dispose();
    }
    if ((src == radiobuttonNumerical) || (src == radiobuttonCategorical) || (src == radiobuttonFreeText)) {
        if (radiobuttonCategorical.isSelected()) {
            switchCategoricalFields(true);
        } else {
            switchCategoricalFields(false);
        }
    }
    if (src == buttonAddCategory) {
        String inputValue = JOptionPane.showInputDialog("Please input a new value");
        if ((inputValue == null) || (inputValue.trim().length() == 0))
            return;
        if (((DefaultListModel<String>) listCategories.getModel()).contains(inputValue)) {
            desktop.displayErrorMessage(this, "Value already exists.");
            return;
        }
        ((DefaultListModel<String>) listCategories.getModel()).addElement(inputValue);
    }
    if (src == buttonRemoveCategory) {
        int[] selectedIndices = listCategories.getSelectedIndices();
        if ((selectedIndices == null) || (selectedIndices.length == 0)) {
            desktop.displayErrorMessage(this, "Select at least one value first.");
            return;
        }
        for (int selectedIndex : selectedIndices) {
            ((DefaultListModel<String>) listCategories.getModel()).removeElementAt(selectedIndex);
        }
    }
}
Also used : StringParameter(net.sf.mzmine.parameters.parametertypes.StringParameter) DoubleParameter(net.sf.mzmine.parameters.parametertypes.DoubleParameter) Desktop(net.sf.mzmine.desktop.Desktop) DefaultListModel(javax.swing.DefaultListModel)

Example 17 with Desktop

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

Example 18 with Desktop

use of net.sf.mzmine.desktop.Desktop in project mzmine2 by mzmine.

the class LipidSearchTask method run.

/**
 * @see java.lang.Runnable#run()
 */
@Override
public void run() {
    setStatus(TaskStatus.PROCESSING);
    logger.info("Starting lipid search in " + peakList);
    PeakListRow[] rows = peakList.getRows();
    // Check if lipids should be modified
    if (searchForModifications == true) {
        lipidModificationMasses = getLipidModificationMasses(lipidModification);
    }
    // Calculate how many possible lipids we will try
    totalSteps = ((maxChainLength - minChainLength + 1) * (maxDoubleBonds - minDoubleBonds + 1)) * selectedLipids.length;
    // Try all combinations of fatty acid lengths and double bonds
    for (int i = 0; i < selectedLipids.length; i++) {
        int numberOfAcylChains = selectedLipids[i].getNumberOfAcylChains();
        int numberOfAlkylChains = selectedLipids[i].getNumberofAlkyChains();
        for (int chainLength = minChainLength; chainLength <= maxChainLength; chainLength++) {
            for (int chainDoubleBonds = minDoubleBonds; chainDoubleBonds <= maxDoubleBonds; chainDoubleBonds++) {
                // Task canceled?
                if (isCanceled())
                    return;
                // than minimal length, skip this lipid
                if (((chainLength > 0) && (chainLength < minChainLength))) {
                    finishedSteps++;
                    continue;
                }
                // doesn't make sense, so let's skip such lipids
                if (((chainDoubleBonds > 0) && (chainDoubleBonds > chainLength - 1))) {
                    finishedSteps++;
                    continue;
                }
                // Prepare a lipid instance
                LipidIdentity lipidChain = new LipidIdentity(selectedLipids[i], chainLength, chainDoubleBonds, numberOfAcylChains, numberOfAlkylChains);
                // Find all rows that match this lipid
                findPossibleLipid(lipidChain, rows);
                finishedSteps++;
            }
        }
    }
    // Add task description to peakList
    ((SimplePeakList) peakList).addDescriptionOfAppliedTask(new SimplePeakListAppliedMethod("Lipid search", parameters));
    // Repaint the window to reflect the change in the peak list
    Desktop desktop = MZmineCore.getDesktop();
    if (!(desktop instanceof HeadLessDesktop))
        desktop.getMainWindow().repaint();
    setStatus(TaskStatus.FINISHED);
    logger.info("Finished lipid search task in " + peakList);
}
Also used : LipidIdentity(net.sf.mzmine.modules.peaklistmethods.identification.lipididentification.lipidutils.LipidIdentity) 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) DataPoint(net.sf.mzmine.datamodel.DataPoint) HeadLessDesktop(net.sf.mzmine.desktop.impl.HeadLessDesktop)

Example 19 with Desktop

use of net.sf.mzmine.desktop.Desktop 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 20 with Desktop

use of net.sf.mzmine.desktop.Desktop in project mzmine2 by mzmine.

the class ClusteringTask method run.

@Override
public void run() {
    status = TaskStatus.PROCESSING;
    logger.info("Clustering");
    double[][] rawData;
    if (typeOfData == ClusteringDataType.VARIABLES) {
        rawData = createMatrix(false);
        dataset = createVariableWekaDataset(rawData);
    } else {
        rawData = createMatrix(true);
        dataset = createSampleWekaDataset(rawData);
    }
    // Run the clustering algorithm
    ClusteringAlgorithm clusteringAlgorithm = clusteringStep.getModule();
    ParameterSet clusteringParameters = clusteringStep.getParameterSet();
    ClusteringResult result = clusteringAlgorithm.performClustering(dataset, clusteringParameters);
    String cluster = "";
    if (clusteringAlgorithm.getName().toString().equals("Hierarchical clusterer")) {
        progress = 0;
        // Getting the result of the clustering in Newick format
        cluster = result.getHiearchicalCluster();
        // Getting the number of clusters counting the number of times the
        // word "cluster" is in the result
        Pattern p = Pattern.compile("Cluster", Pattern.LITERAL | Pattern.CASE_INSENSITIVE);
        int numberOfClusters = p.split(cluster, -1).length - 1;
        if (numberOfClusters == 0) {
            numberOfClusters = 1;
        }
        // Visualization window for each cluster
        for (int i = 0; i < numberOfClusters; i++) {
            String c = null;
            String clusterNumber = "Cluster " + i;
            if (cluster.indexOf(clusterNumber) > 0) {
                int nextNumber = i + 1;
                String clusterNumber2 = "Cluster " + nextNumber;
                if (cluster.indexOf(clusterNumber2) < 0) {
                    c = cluster.substring(cluster.indexOf(clusterNumber) + clusterNumber.length(), cluster.length());
                } else {
                    c = cluster.substring(cluster.indexOf(clusterNumber) + clusterNumber.length(), cluster.indexOf(clusterNumber2));
                }
            } else {
                c = cluster;
            }
            JFrame visualizationWindow = new JFrame(clusterNumber);
            visualizationWindow.setSize(600, 500);
            visualizationWindow.setLayout(new BorderLayout());
            HierarchyVisualizer visualizer = new HierarchyVisualizer(c);
            visualizationWindow.add(visualizer, BorderLayout.CENTER);
            visualizer.fitToScreen();
            // Text field with the clustering result in Newick format
            JTextField data = new JTextField(c);
            visualizationWindow.add(data, BorderLayout.SOUTH);
            visualizationWindow.setVisible(true);
            visualizationWindow.pack();
            visualizationWindow.setVisible(true);
        }
        progress = 100;
    } else {
        List<Integer> clusteringResult = result.getClusters();
        // Report window
        Desktop desktop = MZmineCore.getDesktop();
        if (typeOfData == ClusteringDataType.SAMPLES) {
            String[] sampleNames = new String[selectedRawDataFiles.length];
            for (int i = 0; i < selectedRawDataFiles.length; i++) {
                sampleNames[i] = selectedRawDataFiles[i].getName();
            }
            ClusteringReportWindow reportWindow = new ClusteringReportWindow(sampleNames, clusteringResult.toArray(new Integer[0]), "Clustering Report");
            reportWindow.setVisible(true);
        } else {
            String[] variableNames = new String[selectedRows.length];
            for (int i = 0; i < selectedRows.length; i++) {
                variableNames[i] = selectedRows[i].getID() + " - " + selectedRows[i].getAverageMZ() + " - " + selectedRows[i].getAverageRT();
                if (selectedRows[i].getPeakIdentities() != null && selectedRows[i].getPeakIdentities().length > 0) {
                    variableNames[i] += " - " + selectedRows[i].getPeakIdentities()[0].getName();
                }
            }
            ClusteringReportWindow reportWindow = new ClusteringReportWindow(variableNames, clusteringResult.toArray(new Integer[0]), "Clustering Report");
            reportWindow.setVisible(true);
        }
        // Visualization
        if (typeOfData == ClusteringDataType.VARIABLES) {
            for (int ind = 0; ind < selectedRows.length; ind++) {
                groupsForSelectedVariables[ind] = clusteringResult.get(ind);
            }
        } else {
            for (int ind = 0; ind < selectedRawDataFiles.length; ind++) {
                groupsForSelectedRawDataFiles[ind] = clusteringResult.get(ind);
            }
        }
        this.finalNumberOfGroups = result.getNumberOfGroups();
        parameterValuesForGroups = new Object[finalNumberOfGroups];
        for (int i = 0; i < finalNumberOfGroups; i++) {
            parameterValuesForGroups[i] = "Group " + i;
        }
        int numComponents = xAxisDimension;
        if (yAxisDimension > numComponents) {
            numComponents = yAxisDimension;
        }
        if (result.getVisualizationType() == VisualizationType.PCA) {
            // Scale data and do PCA
            Preprocess.scaleToUnityVariance(rawData);
            PCA pcaProj = new PCA(rawData, numComponents);
            projectionStatus = pcaProj.getProjectionStatus();
            double[][] pcaResult = pcaProj.getState();
            if (status == TaskStatus.CANCELED) {
                return;
            }
            component1Coords = pcaResult[xAxisDimension - 1];
            component2Coords = pcaResult[yAxisDimension - 1];
        } else if (result.getVisualizationType() == VisualizationType.SAMMONS) {
            // Scale data and do Sammon's mapping
            Preprocess.scaleToUnityVariance(rawData);
            Sammons sammonsProj = new Sammons(rawData);
            projectionStatus = sammonsProj.getProjectionStatus();
            sammonsProj.iterate(100);
            double[][] sammonsResult = sammonsProj.getState();
            if (status == TaskStatus.CANCELED) {
                return;
            }
            component1Coords = sammonsResult[xAxisDimension - 1];
            component2Coords = sammonsResult[yAxisDimension - 1];
        }
        ProjectionPlotWindow newFrame = new ProjectionPlotWindow(desktop.getSelectedPeakLists()[0], this, parameters);
        newFrame.setVisible(true);
    }
    status = TaskStatus.FINISHED;
    logger.info("Finished computing Clustering visualization.");
}
Also used : ParameterSet(net.sf.mzmine.parameters.ParameterSet) Pattern(java.util.regex.Pattern) HierarchyVisualizer(weka.gui.hierarchyvisualizer.HierarchyVisualizer) JTextField(javax.swing.JTextField) PCA(jmprojection.PCA) ProjectionPlotWindow(net.sf.mzmine.modules.peaklistmethods.dataanalysis.projectionplots.ProjectionPlotWindow) BorderLayout(java.awt.BorderLayout) Desktop(net.sf.mzmine.desktop.Desktop) JFrame(javax.swing.JFrame) Sammons(jmprojection.Sammons)

Aggregations

Desktop (net.sf.mzmine.desktop.Desktop)22 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 DataPoint (net.sf.mzmine.datamodel.DataPoint)4 AbstractTask (net.sf.mzmine.taskcontrol.AbstractTask)4 UnsupportedFormatException (net.sf.mzmine.util.spectraldb.parser.UnsupportedFormatException)4 Feature (net.sf.mzmine.datamodel.Feature)2 Scan (net.sf.mzmine.datamodel.Scan)2 SpectraIdentificationResultsWindow (net.sf.mzmine.modules.visualization.spectra.spectralmatchresults.SpectraIdentificationResultsWindow)2 ParameterSet (net.sf.mzmine.parameters.ParameterSet)2 PeakListRowSorter (net.sf.mzmine.util.PeakListRowSorter)2 BorderLayout (java.awt.BorderLayout)1 Color (java.awt.Color)1 File (java.io.File)1 FileReader (java.io.FileReader)1 URL (java.net.URL)1 Date (java.util.Date)1