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]);
}
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();
}
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();
}
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);
}
}
}
}
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());
}
}
Aggregations