Search in sources :

Example 1 with StringParameter

use of net.sf.mzmine.parameters.parametertypes.StringParameter in project mzmine2 by mzmine.

the class ProjectParametersImporter method processParameters.

private UserParameter<?, ?>[] processParameters(File parameterFile) {
    ArrayList<UserParameter<?, ?>> parameters = new ArrayList<UserParameter<?, ?>>();
    // Open reader
    BufferedReader parameterFileReader;
    try {
        parameterFileReader = new BufferedReader(new FileReader(parameterFile));
        // Read column headers which are used as parameter names
        String firstRow = parameterFileReader.readLine();
        StringTokenizer st = new StringTokenizer(firstRow, ",");
        // Assume first column contains file names
        st.nextToken();
        ArrayList<String> parameterNames = new ArrayList<String>();
        Hashtable<String, ArrayList<String>> parameterValues = new Hashtable<String, ArrayList<String>>();
        while (st.hasMoreTokens()) {
            String paramName = st.nextToken();
            if (parameterValues.containsKey(paramName)) {
                logger.severe("Did not import parameters because of a non-unique parameter name: " + paramName);
                desktop.displayErrorMessage(MZmineCore.getDesktop().getMainWindow(), "Could not open file " + parameterFile);
                parameterFileReader.close();
                return null;
            }
            parameterNames.add(paramName);
            parameterValues.put(paramName, new ArrayList<String>());
        }
        // Read rest of the rows which contain file name in the first column
        // and parameter values in the rest of the columns
        String nextRow = parameterFileReader.readLine();
        int rowNumber = 2;
        while (nextRow != null) {
            st = new StringTokenizer(nextRow, ",");
            // Skip first column (File name)
            if (st.hasMoreTokens())
                st.nextToken();
            Iterator<String> parameterNameIterator = parameterNames.iterator();
            while (st.hasMoreTokens()) {
                if (st.hasMoreTokens() ^ parameterNameIterator.hasNext()) {
                    logger.severe("Incorrect number of parameter values on row " + rowNumber);
                    desktop.displayErrorMessage(MZmineCore.getDesktop().getMainWindow(), "Incorrect number of parameter values on row " + rowNumber);
                    parameterFileReader.close();
                    return null;
                }
                parameterValues.get(parameterNameIterator.next()).add(st.nextToken());
            }
            nextRow = parameterFileReader.readLine();
            rowNumber++;
        }
        // Decide parameter types (all numeric => Double, all unique string
        // => String, at least one duplicate string => Object with possible
        // values
        Iterator<String> parameterNameIterator = parameterNames.iterator();
        while (parameterNameIterator.hasNext()) {
            String name = parameterNameIterator.next();
            ArrayList<String> vals = parameterValues.get(name);
            // Test for all numeric
            Iterator<String> valIterator = vals.iterator();
            boolean isAllNumeric = true;
            while (valIterator.hasNext()) {
                try {
                    Double.valueOf(valIterator.next());
                } catch (NumberFormatException ex) {
                    isAllNumeric = false;
                    break;
                }
            }
            if (isAllNumeric) {
                parameters.add(new DoubleParameter(name, null));
                continue;
            }
            // Test for "set of values"
            ArrayList<String> uniqueValues = new ArrayList<String>();
            valIterator = vals.iterator();
            while (valIterator.hasNext()) {
                String val = valIterator.next();
                if (!uniqueValues.contains(val))
                    uniqueValues.add(val);
            }
            if (uniqueValues.size() < vals.size()) {
                parameters.add(new ComboParameter<String>(name, null, uniqueValues.toArray(new String[0])));
                continue;
            }
            // Otherwise it is a free text parameter
            parameters.add(new StringParameter(name, null));
        }
        // Close reader
        parameterFileReader.close();
    } catch (IOException ex) {
        logger.severe("Could not read file " + parameterFile);
        desktop.displayErrorMessage(MZmineCore.getDesktop().getMainWindow(), "Could not open file " + parameterFile);
        return null;
    }
    return parameters.toArray(new UserParameter[0]);
}
Also used : StringParameter(net.sf.mzmine.parameters.parametertypes.StringParameter) DoubleParameter(net.sf.mzmine.parameters.parametertypes.DoubleParameter) Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) IOException(java.io.IOException) UserParameter(net.sf.mzmine.parameters.UserParameter) StringTokenizer(java.util.StringTokenizer) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader)

Example 2 with StringParameter

use of net.sf.mzmine.parameters.parametertypes.StringParameter 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 3 with StringParameter

use of net.sf.mzmine.parameters.parametertypes.StringParameter 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 4 with StringParameter

use of net.sf.mzmine.parameters.parametertypes.StringParameter in project mzmine2 by mzmine.

the class ProjectParametersSetupDialog method copyParameterValuesToRawDataFiles.

private void copyParameterValuesToRawDataFiles() {
    MZmineProject currentProject = MZmineCore.getProjectManager().getCurrentProject();
    // Remove all previous parameters from project
    UserParameter<?, ?>[] parameters = currentProject.getParameters();
    for (UserParameter<?, ?> parameter : parameters) {
        currentProject.removeParameter(parameter);
    }
    // Add new parameters
    parameters = parameterValues.keySet().toArray(new UserParameter[0]);
    for (UserParameter<?, ?> parameter : parameters) {
        currentProject.addParameter(parameter);
    }
    // Set values for new parameters
    for (int columnIndex = 0; columnIndex < parameterValues.keySet().size(); columnIndex++) {
        UserParameter<?, ?> parameter = tablemodelParameterValues.getParameter(columnIndex + 1);
        for (int dataFileIndex = 0; dataFileIndex < dataFiles.length; dataFileIndex++) {
            RawDataFile file = dataFiles[dataFileIndex];
            Object value = tablemodelParameterValues.getValueAt(dataFileIndex, columnIndex + 1);
            if (parameter instanceof DoubleParameter) {
                Double doubleValue = null;
                if (value instanceof Double)
                    doubleValue = (Double) value;
                if (value instanceof String)
                    doubleValue = Double.parseDouble((String) value);
                currentProject.setParameterValue(parameter, file, doubleValue);
            }
            if (parameter instanceof StringParameter) {
                if (value == null)
                    value = "";
                currentProject.setParameterValue(parameter, file, (String) value);
            }
            if (parameter instanceof ComboParameter) {
                if (value == null)
                    value = "";
                currentProject.setParameterValue(parameter, file, (String) value);
            }
        }
    }
}
Also used : UserParameter(net.sf.mzmine.parameters.UserParameter) StringParameter(net.sf.mzmine.parameters.parametertypes.StringParameter) DoubleParameter(net.sf.mzmine.parameters.parametertypes.DoubleParameter) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) MZmineProject(net.sf.mzmine.datamodel.MZmineProject) ComboParameter(net.sf.mzmine.parameters.parametertypes.ComboParameter)

Example 5 with StringParameter

use of net.sf.mzmine.parameters.parametertypes.StringParameter in project mzmine2 by mzmine.

the class UserParameterOpenHandler_2_3 method startElement.

/**
 * @see org.xml.sax.helpers.DefaultHandler#startElement(java.lang.String, java.lang.String,
 *      java.lang.String, org.xml.sax.Attributes)
 */
public void startElement(String namespaceURI, String lName, String qName, Attributes attrs) throws SAXException {
    if (canceled)
        throw new SAXException("Parsing canceled");
    // <PARAMETERS>
    if (qName.equals(UserParameterElementName_2_3.PARAMETERS.getElementName())) {
        String count = attrs.getValue(UserParameterElementName_2_3.COUNT.getElementName());
        totalParams = Integer.parseInt(count);
    }
    // <PARAMETER>
    if (qName.equals(UserParameterElementName_2_3.PARAMETER.getElementName())) {
        String name = attrs.getValue(UserParameterElementName_2_3.NAME.getElementName());
        String type = attrs.getValue(UserParameterElementName_2_3.TYPE.getElementName());
        if (type.equals(DoubleParameter.class.getSimpleName())) {
            currentParameter = new DoubleParameter(name, null);
        } else if (type.equals(StringParameter.class.getSimpleName())) {
            currentParameter = new StringParameter(name, null);
        } else if (type.equals(ComboParameter.class.getSimpleName())) {
            currentParameter = new ComboParameter<String>(name, null, new String[0]);
        } else {
            throw new SAXException("Unknown parameter type: " + type);
        }
        logger.finest("Loading parameter " + name);
        currentOptions.clear();
        currentValues.clear();
    }
    // <VALUE>
    if (qName.equals(UserParameterElementName_2_3.VALUE.getElementName())) {
        currentDataFileID = attrs.getValue(UserParameterElementName_2_3.DATA_FILE.getElementName());
    }
}
Also used : StringParameter(net.sf.mzmine.parameters.parametertypes.StringParameter) DoubleParameter(net.sf.mzmine.parameters.parametertypes.DoubleParameter) SAXException(org.xml.sax.SAXException) ComboParameter(net.sf.mzmine.parameters.parametertypes.ComboParameter)

Aggregations

StringParameter (net.sf.mzmine.parameters.parametertypes.StringParameter)10 DoubleParameter (net.sf.mzmine.parameters.parametertypes.DoubleParameter)5 Window (java.awt.Window)4 SimpleParameterSet (net.sf.mzmine.parameters.impl.SimpleParameterSet)4 ComboParameter (net.sf.mzmine.parameters.parametertypes.ComboParameter)4 ExitCode (net.sf.mzmine.util.ExitCode)4 RawDataFile (net.sf.mzmine.datamodel.RawDataFile)3 UserParameter (net.sf.mzmine.parameters.UserParameter)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 SAXException (org.xml.sax.SAXException)2 BufferedReader (java.io.BufferedReader)1 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Hashtable (java.util.Hashtable)1 StringTokenizer (java.util.StringTokenizer)1 DefaultListModel (javax.swing.DefaultListModel)1 MZmineProject (net.sf.mzmine.datamodel.MZmineProject)1