Search in sources :

Example 1 with SimpleParameterSet

use of net.sf.mzmine.parameters.impl.SimpleParameterSet in project mzmine2 by mzmine.

the class PeakListsComponent method actionPerformed.

public void actionPerformed(ActionEvent event) {
    Object src = event.getSource();
    if (src == detailsButton) {
        PeakListsSelectionType type = (PeakListsSelectionType) typeCombo.getSelectedItem();
        if (type == PeakListsSelectionType.SPECIFIC_PEAKLISTS) {
            final MultiChoiceParameter<PeakList> plsParameter = new MultiChoiceParameter<PeakList>("Select feature lists", "Select feature lists", MZmineCore.getProjectManager().getCurrentProject().getPeakLists(), currentValue.getSpecificPeakLists());
            final SimpleParameterSet paramSet = new SimpleParameterSet(new Parameter[] { plsParameter });
            final Window parent = (Window) SwingUtilities.getAncestorOfClass(Window.class, this);
            final ExitCode exitCode = paramSet.showSetupDialog(parent, true);
            if (exitCode == ExitCode.OK) {
                PeakList[] pls = paramSet.getParameter(plsParameter).getValue();
                currentValue.setSpecificPeakLists(pls);
            }
        }
        if (type == PeakListsSelectionType.NAME_PATTERN) {
            final StringParameter nameParameter = new StringParameter("Name pattern", "Set name pattern that may include wildcards (*), e.g. *mouse* matches any name that contains mouse", currentValue.getNamePattern());
            final SimpleParameterSet paramSet = new SimpleParameterSet(new Parameter[] { nameParameter });
            final Window parent = (Window) SwingUtilities.getAncestorOfClass(Window.class, this);
            final ExitCode exitCode = paramSet.showSetupDialog(parent, true);
            if (exitCode == ExitCode.OK) {
                String namePattern = paramSet.getParameter(nameParameter).getValue();
                currentValue.setNamePattern(namePattern);
            }
        }
    }
    if (src == typeCombo) {
        PeakListsSelectionType type = (PeakListsSelectionType) typeCombo.getSelectedItem();
        currentValue.setSelectionType(type);
        detailsButton.setEnabled((type == PeakListsSelectionType.NAME_PATTERN) || (type == PeakListsSelectionType.SPECIFIC_PEAKLISTS));
    }
    updateNumPeakLists();
}
Also used : Window(java.awt.Window) StringParameter(net.sf.mzmine.parameters.parametertypes.StringParameter) SimpleParameterSet(net.sf.mzmine.parameters.impl.SimpleParameterSet) ExitCode(net.sf.mzmine.util.ExitCode) PeakList(net.sf.mzmine.datamodel.PeakList) MultiChoiceParameter(net.sf.mzmine.parameters.parametertypes.MultiChoiceParameter)

Example 2 with SimpleParameterSet

use of net.sf.mzmine.parameters.impl.SimpleParameterSet in project mzmine2 by mzmine.

the class RawDataFilesComponent method actionPerformed.

public void actionPerformed(ActionEvent event) {
    Object src = event.getSource();
    if (src == detailsButton) {
        RawDataFilesSelectionType type = (RawDataFilesSelectionType) typeCombo.getSelectedItem();
        if (type == RawDataFilesSelectionType.SPECIFIC_FILES) {
            final MultiChoiceParameter<RawDataFile> filesParameter = new MultiChoiceParameter<RawDataFile>("Select files", "Select files", MZmineCore.getProjectManager().getCurrentProject().getDataFiles(), currentValue.getSpecificFiles());
            final SimpleParameterSet paramSet = new SimpleParameterSet(new Parameter[] { filesParameter });
            final Window parent = (Window) SwingUtilities.getAncestorOfClass(Window.class, this);
            final ExitCode exitCode = paramSet.showSetupDialog(parent, true);
            if (exitCode == ExitCode.OK) {
                RawDataFile[] files = paramSet.getParameter(filesParameter).getValue();
                currentValue.setSpecificFiles(files);
            }
        }
        if (type == RawDataFilesSelectionType.NAME_PATTERN) {
            final StringParameter nameParameter = new StringParameter("Name pattern", "Set name pattern that may include wildcards (*), e.g. *mouse* matches any name that contains mouse", currentValue.getNamePattern());
            final SimpleParameterSet paramSet = new SimpleParameterSet(new Parameter[] { nameParameter });
            final Window parent = (Window) SwingUtilities.getAncestorOfClass(Window.class, this);
            final ExitCode exitCode = paramSet.showSetupDialog(parent, true);
            if (exitCode == ExitCode.OK) {
                String namePattern = paramSet.getParameter(nameParameter).getValue();
                currentValue.setNamePattern(namePattern);
            }
        }
    }
    if (src == typeCombo) {
        RawDataFilesSelectionType type = (RawDataFilesSelectionType) typeCombo.getSelectedItem();
        currentValue.setSelectionType(type);
        detailsButton.setEnabled((type == RawDataFilesSelectionType.NAME_PATTERN) || (type == RawDataFilesSelectionType.SPECIFIC_FILES));
    }
    updateNumFiles();
}
Also used : Window(java.awt.Window) StringParameter(net.sf.mzmine.parameters.parametertypes.StringParameter) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) SimpleParameterSet(net.sf.mzmine.parameters.impl.SimpleParameterSet) ExitCode(net.sf.mzmine.util.ExitCode) MultiChoiceParameter(net.sf.mzmine.parameters.parametertypes.MultiChoiceParameter)

Example 3 with SimpleParameterSet

use of net.sf.mzmine.parameters.impl.SimpleParameterSet in project mzmine2 by mzmine.

the class MZmineConfigurationImpl method loadConfiguration.

@Override
public void loadConfiguration(File file) throws IOException {
    try {
        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
        Document configuration = dBuilder.parse(file);
        XPathFactory factory = XPathFactory.newInstance();
        XPath xpath = factory.newXPath();
        logger.finest("Loading desktop configuration");
        XPathExpression expr = xpath.compile("//configuration/preferences");
        NodeList nodes = (NodeList) expr.evaluate(configuration, XPathConstants.NODESET);
        if (nodes.getLength() == 1) {
            Element preferencesElement = (Element) nodes.item(0);
            // that needs this key for encryption
            if (file.equals(MZmineConfiguration.CONFIG_FILE))
                new SimpleParameterSet(new Parameter[] { globalEncrypter }).loadValuesFromXML(preferencesElement);
            preferences.loadValuesFromXML(preferencesElement);
        }
        logger.finest("Loading last projects");
        expr = xpath.compile("//configuration/lastprojects");
        nodes = (NodeList) expr.evaluate(configuration, XPathConstants.NODESET);
        if (nodes.getLength() == 1) {
            Element lastProjectsElement = (Element) nodes.item(0);
            lastProjects.loadValueFromXML(lastProjectsElement);
        }
        logger.finest("Loading modules configuration");
        for (MZmineModule module : MZmineCore.getAllModules()) {
            String className = module.getClass().getName();
            expr = xpath.compile("//configuration/modules/module[@class='" + className + "']/parameters");
            nodes = (NodeList) expr.evaluate(configuration, XPathConstants.NODESET);
            if (nodes.getLength() != 1)
                continue;
            Element moduleElement = (Element) nodes.item(0);
            ParameterSet moduleParameters = getModuleParameters(module.getClass());
            moduleParameters.loadValuesFromXML(moduleElement);
        }
        logger.info("Loaded configuration from file " + file);
    } catch (Exception e) {
        throw new IOException(e);
    }
}
Also used : XPath(javax.xml.xpath.XPath) XPathExpression(javax.xml.xpath.XPathExpression) ParameterSet(net.sf.mzmine.parameters.ParameterSet) SimpleParameterSet(net.sf.mzmine.parameters.impl.SimpleParameterSet) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) SimpleParameterSet(net.sf.mzmine.parameters.impl.SimpleParameterSet) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) IOException(java.io.IOException) Document(org.w3c.dom.Document) IOException(java.io.IOException) XPathFactory(javax.xml.xpath.XPathFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) MZmineModule(net.sf.mzmine.modules.MZmineModule)

Example 4 with SimpleParameterSet

use of net.sf.mzmine.parameters.impl.SimpleParameterSet in project mzmine2 by mzmine.

the class MZmineConfigurationImpl method saveConfiguration.

@Override
public void saveConfiguration(File file) throws IOException {
    try {
        // write sensitive parameters only to the local config file
        final boolean skipSensitive = !file.equals(MZmineConfiguration.CONFIG_FILE);
        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
        Document configuration = dBuilder.newDocument();
        Element configRoot = configuration.createElement("configuration");
        configuration.appendChild(configRoot);
        Element prefElement = configuration.createElement("preferences");
        configRoot.appendChild(prefElement);
        preferences.setSkipSensitiveParameters(skipSensitive);
        preferences.saveValuesToXML(prefElement);
        Element lastFilesElement = configuration.createElement("lastprojects");
        configRoot.appendChild(lastFilesElement);
        lastProjects.saveValueToXML(lastFilesElement);
        Element modulesElement = configuration.createElement("modules");
        configRoot.appendChild(modulesElement);
        // traverse modules
        for (MZmineModule module : MZmineCore.getAllModules()) {
            String className = module.getClass().getName();
            Element moduleElement = configuration.createElement("module");
            moduleElement.setAttribute("class", className);
            modulesElement.appendChild(moduleElement);
            Element paramElement = configuration.createElement("parameters");
            moduleElement.appendChild(paramElement);
            ParameterSet moduleParameters = getModuleParameters(module.getClass());
            moduleParameters.setSkipSensitiveParameters(skipSensitive);
            moduleParameters.saveValuesToXML(paramElement);
        }
        // save encryption key to local config only
        // ATTENTION: this should to be written after all other configs
        final SimpleParameterSet encSet = new SimpleParameterSet(new Parameter[] { globalEncrypter });
        encSet.setSkipSensitiveParameters(skipSensitive);
        encSet.saveValuesToXML(prefElement);
        TransformerFactory transfac = TransformerFactory.newInstance();
        Transformer transformer = transfac.newTransformer();
        transformer.setOutputProperty(OutputKeys.METHOD, "xml");
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
        transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
        // Create parent folder if it does not exist
        File confParent = file.getParentFile();
        if ((confParent != null) && (!confParent.exists())) {
            confParent.mkdirs();
        }
        StreamResult result = new StreamResult(new FileOutputStream(file));
        DOMSource source = new DOMSource(configuration);
        transformer.transform(source, result);
        // make user home config file invisible on windows
        if ((!skipSensitive) && (System.getProperty("os.name").toLowerCase().contains("windows"))) {
            Files.setAttribute(file.toPath(), "dos:hidden", Boolean.TRUE, LinkOption.NOFOLLOW_LINKS);
        }
        logger.info("Saved configuration to file " + file);
    } catch (Exception e) {
        throw new IOException(e);
    }
}
Also used : ParameterSet(net.sf.mzmine.parameters.ParameterSet) SimpleParameterSet(net.sf.mzmine.parameters.impl.SimpleParameterSet) DOMSource(javax.xml.transform.dom.DOMSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) SimpleParameterSet(net.sf.mzmine.parameters.impl.SimpleParameterSet) Element(org.w3c.dom.Element) IOException(java.io.IOException) Document(org.w3c.dom.Document) IOException(java.io.IOException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) FileOutputStream(java.io.FileOutputStream) File(java.io.File) MZmineModule(net.sf.mzmine.modules.MZmineModule)

Example 5 with SimpleParameterSet

use of net.sf.mzmine.parameters.impl.SimpleParameterSet in project mzmine2 by mzmine.

the class MsMsVisualizerWindow method actionPerformed.

/**
 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
 */
public void actionPerformed(ActionEvent event) {
    String command = event.getActionCommand();
    if (command.equals("SHOW_SPECTRUM")) {
        CursorPosition pos = getCursorPosition();
        if (pos != null) {
            SpectraVisualizerModule.showNewSpectrumWindow(pos.getDataFile(), pos.getScanNumber());
        }
    }
    if (command.equals("SETUP_AXES")) {
        AxesSetupDialog dialog = new AxesSetupDialog(this, IDAPlot.getXYPlot());
        dialog.setVisible(true);
    }
    if (command.equals("SHOW_DATA_POINTS")) {
        IDAPlot.switchDataPointsVisible();
    }
    if (command.equals("SWITCH_TOOLTIPS")) {
        if (tooltipMode) {
            IDAPlot.showPeaksTooltips(false);
            toolBar.setTooltipButton(false);
            tooltipMode = false;
        } else {
            IDAPlot.showPeaksTooltips(true);
            toolBar.setTooltipButton(true);
            tooltipMode = true;
        }
    }
    if (command.equals("FIND_SPECTRA")) {
        // Parameters
        final DoubleParameter inputMZ = new DoubleParameter("Ion m/z", "m/z value of ion to search for.");
        final MZToleranceParameter inputMZTolerance = new MZToleranceParameter();
        final DoubleParameter inputIntensity = new DoubleParameter("Min. ion intensity", "Only ions with intensities above this value will be searched for.");
        final BooleanParameter inputNL = new BooleanParameter("Neutral Loss", "If selected, the ion to be searched for will be a neutral loss ion.\nIn this case, only ions above the min. intensity will be examined.", false);
        final ComboParameter<Colors> inputColors = new ComboParameter<Colors>("Color", "The color which the data points will be marked with.", Colors.values());
        Parameter<?>[] parameters = new Parameter<?>[5];
        parameters[0] = inputMZ;
        parameters[1] = inputMZTolerance;
        parameters[2] = inputIntensity;
        parameters[3] = inputNL;
        parameters[4] = inputColors;
        final ParameterSet parametersSearch = new SimpleParameterSet(parameters);
        ExitCode exitCode = parametersSearch.showSetupDialog(this, true);
        if (exitCode != ExitCode.OK)
            return;
        double searchMZ = parametersSearch.getParameter(inputMZ).getValue();
        MZTolerance searchMZTolerance = parametersSearch.getParameter(inputMZTolerance).getValue();
        double minIntensity = parametersSearch.getParameter(inputIntensity).getValue();
        boolean neutralLoss = parametersSearch.getParameter(inputNL).getValue();
        Color highligtColor = Color.red;
        ;
        if (parametersSearch.getParameter(inputColors).getValue().equals(Colors.green)) {
            highligtColor = Color.green;
        }
        if (parametersSearch.getParameter(inputColors).getValue().equals(Colors.blue)) {
            highligtColor = Color.blue;
        }
        // Find and highlight spectra with specific ion
        dataset.highlightSpectra(searchMZ, searchMZTolerance, minIntensity, neutralLoss, highligtColor);
        // Add legend entry
        LegendItemCollection chartLegend = IDAPlot.getXYPlot().getLegendItems();
        chartLegend.add(new LegendItem("Ion: " + searchMZ, "", "MS/MS spectra which contain the " + searchMZ + " ion\nTolerance: " + searchMZTolerance.toString() + "\nMin intensity: " + minIntensity, "", new Ellipse2D.Double(0, 0, 7, 7), highligtColor));
        IDAPlot.getXYPlot().setFixedLegendItems(chartLegend);
    }
}
Also used : ParameterSet(net.sf.mzmine.parameters.ParameterSet) SimpleParameterSet(net.sf.mzmine.parameters.impl.SimpleParameterSet) MZTolerance(net.sf.mzmine.parameters.parametertypes.tolerances.MZTolerance) DoubleParameter(net.sf.mzmine.parameters.parametertypes.DoubleParameter) MZToleranceParameter(net.sf.mzmine.parameters.parametertypes.tolerances.MZToleranceParameter) SimpleParameterSet(net.sf.mzmine.parameters.impl.SimpleParameterSet) LegendItemCollection(org.jfree.chart.LegendItemCollection) ExitCode(net.sf.mzmine.util.ExitCode) Color(java.awt.Color) BooleanParameter(net.sf.mzmine.parameters.parametertypes.BooleanParameter) AxesSetupDialog(net.sf.mzmine.util.dialogs.AxesSetupDialog) ComboParameter(net.sf.mzmine.parameters.parametertypes.ComboParameter) LegendItem(org.jfree.chart.LegendItem) Parameter(net.sf.mzmine.parameters.Parameter) WindowSettingsParameter(net.sf.mzmine.parameters.parametertypes.WindowSettingsParameter) DoubleParameter(net.sf.mzmine.parameters.parametertypes.DoubleParameter) ComboParameter(net.sf.mzmine.parameters.parametertypes.ComboParameter) BooleanParameter(net.sf.mzmine.parameters.parametertypes.BooleanParameter) MZToleranceParameter(net.sf.mzmine.parameters.parametertypes.tolerances.MZToleranceParameter) CursorPosition(net.sf.mzmine.modules.visualization.tic.CursorPosition)

Aggregations

SimpleParameterSet (net.sf.mzmine.parameters.impl.SimpleParameterSet)7 ExitCode (net.sf.mzmine.util.ExitCode)5 Window (java.awt.Window)4 StringParameter (net.sf.mzmine.parameters.parametertypes.StringParameter)4 ParameterSet (net.sf.mzmine.parameters.ParameterSet)3 IOException (java.io.IOException)2 DocumentBuilder (javax.xml.parsers.DocumentBuilder)2 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)2 MZmineModule (net.sf.mzmine.modules.MZmineModule)2 Parameter (net.sf.mzmine.parameters.Parameter)2 ComboParameter (net.sf.mzmine.parameters.parametertypes.ComboParameter)2 MultiChoiceParameter (net.sf.mzmine.parameters.parametertypes.MultiChoiceParameter)2 IntRangeParameter (net.sf.mzmine.parameters.parametertypes.ranges.IntRangeParameter)2 RTRangeParameter (net.sf.mzmine.parameters.parametertypes.ranges.RTRangeParameter)2 Document (org.w3c.dom.Document)2 Element (org.w3c.dom.Element)2 Color (java.awt.Color)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 Transformer (javax.xml.transform.Transformer)1