Search in sources :

Example 1 with StringChoiceParameter

use of com.genericworkflownodes.knime.parameter.StringChoiceParameter in project GenericKnimeNodes by genericworkflownodes.

the class GalaxyNodeConfigurationReaderTest method testReader.

@Test
public void testReader() throws Exception {
    INodeConfiguration config = null;
    GalaxyNodeConfigurationReader reader = new GalaxyNodeConfigurationReader();
    config = reader.read(TestDataSource.class.getResourceAsStream("emboss_water.xml"));
    assertEquals("Smith-Waterman local alignment", config.getDescription());
    assertEquals("water", config.getName());
    assertEquals("5.0.0", config.getVersion());
    assertEquals("help text", config.getManual());
    assertEquals(2, config.getNumberOfInputPorts());
    assertEquals(1, config.getNumberOfOutputPorts());
    assertNotNull(config.getParameter("gapopen"));
    assertNotNull(config.getParameter("gapextend"));
    Parameter<?> p1 = config.getParameter("gapopen");
    Parameter<?> p2 = config.getParameter("gapextend");
    StringChoiceParameter p3 = (StringChoiceParameter) config.getParameter("menu");
    assertTrue(p1 instanceof StringParameter);
    assertTrue(p2 instanceof DoubleParameter);
    assertTrue(p3 instanceof StringChoiceParameter);
    assertEquals(p1.getValue(), "10.0");
    assertEquals(p2.getValue(), 0.5);
    assertEquals("1", p3.getValue());
    assertEquals("A", p3.getLabels().get(0));
    assertEquals("B", p3.getLabels().get(1));
    assertEquals("C", p3.getLabels().get(2));
}
Also used : StringParameter(com.genericworkflownodes.knime.parameter.StringParameter) DoubleParameter(com.genericworkflownodes.knime.parameter.DoubleParameter) GalaxyNodeConfigurationReader(com.genericworkflownodes.knime.config.impl.GalaxyNodeConfigurationReader) StringChoiceParameter(com.genericworkflownodes.knime.parameter.StringChoiceParameter) Test(org.junit.Test)

Example 2 with StringChoiceParameter

use of com.genericworkflownodes.knime.parameter.StringChoiceParameter in project GenericKnimeNodes by genericworkflownodes.

the class CTDHandlerTest method testParamHandler.

@Test
public void testParamHandler() throws ParserConfigurationException, SAXException, IOException {
    SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    Schema ctdSchema = schemaFactory.newSchema(SchemaProvider.class.getResource("CTD.xsd"));
    SAXParserFactory spfac = SAXParserFactory.newInstance();
    spfac.setValidating(false);
    spfac.setSchema(ctdSchema);
    // Now use the parser factory to create a SAXParser object
    SAXParser sp = spfac.newSAXParser();
    CTDHandler handler = new CTDHandler(sp.getXMLReader());
    sp.parse(TestDataSource.class.getResourceAsStream("FileFilter.ctd"), handler);
    INodeConfiguration config = handler.getNodeConfiguration();
    StringParameter mz = (StringParameter) config.getParameter("FileFilter.1.mz");
    assertEquals("m/z range to extract (applies to ALL ms levels!)", mz.getDescription());
    assertEquals(":", mz.getValue());
    assertEquals("mz", mz.getKey());
    IntegerListParameter levels = (IntegerListParameter) config.getParameter("FileFilter.1.peak_options.level");
    assertEquals("MS levels to extract", levels.getDescription());
    assertEquals(3, levels.getValue().size());
    assertEquals(1, levels.getValue().get(0).intValue());
    assertEquals(2, levels.getValue().get(1).intValue());
    assertEquals(3, levels.getValue().get(2).intValue());
    assertEquals(false, levels.isAdvanced());
    StringChoiceParameter int_precision = (StringChoiceParameter) config.getParameter("FileFilter.1.peak_options.int_precision");
    assertEquals("32", int_precision.getValue());
    assertEquals(3, int_precision.getAllowedValues().size());
    BoolParameter no_progress = (BoolParameter) config.getParameter("FileFilter.1.no_progress");
    assertEquals(false, no_progress.getValue());
    assertEquals(true, no_progress.isAdvanced());
    assertEquals(3, config.getInputPorts().size());
    assertEquals("FileFilter.1.in", config.getInputPorts().get(0).getName());
}
Also used : SchemaFactory(javax.xml.validation.SchemaFactory) StringParameter(com.genericworkflownodes.knime.parameter.StringParameter) Schema(javax.xml.validation.Schema) CTDHandler(com.genericworkflownodes.knime.config.reader.handler.CTDHandler) TestDataSource(com.genericworkflownodes.knime.test.data.TestDataSource) INodeConfiguration(com.genericworkflownodes.knime.config.INodeConfiguration) SchemaProvider(com.genericworkflownodes.knime.schemas.SchemaProvider) SAXParser(javax.xml.parsers.SAXParser) StringChoiceParameter(com.genericworkflownodes.knime.parameter.StringChoiceParameter) IntegerListParameter(com.genericworkflownodes.knime.parameter.IntegerListParameter) BoolParameter(com.genericworkflownodes.knime.parameter.BoolParameter) SAXParserFactory(javax.xml.parsers.SAXParserFactory) Test(org.junit.Test)

Example 3 with StringChoiceParameter

use of com.genericworkflownodes.knime.parameter.StringChoiceParameter in project GenericKnimeNodes by genericworkflownodes.

the class CTDConfigurationWriterTest method testWrite.

@Test
public void testWrite() throws Exception {
    CTDConfigurationReader reader = new CTDConfigurationReader();
    INodeConfiguration config = reader.read(TestDataSource.class.getResourceAsStream("FileFilter.ctd"));
    // write to test file
    File tmp = File.createTempFile("testing_", ".ini");
    tmp.deleteOnExit();
    BufferedWriter buffered_file_writer = new BufferedWriter(new FileWriter(tmp));
    CTDConfigurationWriter file_writer = new CTDConfigurationWriter(buffered_file_writer);
    file_writer.write(config);
    config = reader.read(new FileInputStream(tmp));
    StringParameter mz = (StringParameter) config.getParameter("FileFilter.1.mz");
    assertEquals("m/z range to extract (applies to ALL ms levels!)", mz.getDescription());
    assertEquals(":", mz.getValue());
    assertEquals("mz", mz.getKey());
    IntegerListParameter levels = (IntegerListParameter) config.getParameter("FileFilter.1.peak_options.level");
    assertNotNull(levels);
    assertEquals("MS levels to extract", levels.getDescription());
    assertEquals(3, levels.getValue().size());
    assertEquals(1, levels.getValue().get(0).intValue());
    assertEquals(2, levels.getValue().get(1).intValue());
    assertEquals(3, levels.getValue().get(2).intValue());
    assertEquals(false, levels.isAdvanced());
    assertEquals(Integer.valueOf(1), levels.getLowerBound());
    StringChoiceParameter int_precision = (StringChoiceParameter) config.getParameter("FileFilter.1.peak_options.int_precision");
    assertEquals("32", int_precision.getValue());
    assertEquals(3, int_precision.getAllowedValues().size());
    BoolParameter no_progress = (BoolParameter) config.getParameter("FileFilter.1.no_progress");
    assertEquals(false, no_progress.getValue());
    assertEquals(true, no_progress.isAdvanced());
    // Three inputs, one required, one optional with default, one optional without default
    assertEquals(2, config.getInputPorts().size());
    assertEquals("FileFilter.1.in", config.getInputPorts().get(0).getName());
}
Also used : CTDConfigurationReader(com.genericworkflownodes.knime.config.reader.CTDConfigurationReader) StringParameter(com.genericworkflownodes.knime.parameter.StringParameter) TestDataSource(com.genericworkflownodes.knime.test.data.TestDataSource) FileWriter(java.io.FileWriter) INodeConfiguration(com.genericworkflownodes.knime.config.INodeConfiguration) StringChoiceParameter(com.genericworkflownodes.knime.parameter.StringChoiceParameter) IntegerListParameter(com.genericworkflownodes.knime.parameter.IntegerListParameter) BoolParameter(com.genericworkflownodes.knime.parameter.BoolParameter) File(java.io.File) FileInputStream(java.io.FileInputStream) BufferedWriter(java.io.BufferedWriter) Test(org.junit.Test)

Example 4 with StringChoiceParameter

use of com.genericworkflownodes.knime.parameter.StringChoiceParameter in project GenericKnimeNodes by genericworkflownodes.

the class ParamHandler method handleStringType.

/**
 * Convert the current element into a StringParameter.
 *
 * @param paramName
 *            The name of the Parameter
 * @param paramValue
 *            The value of the Parameter as given in the param file.
 * @param attributes
 *            Attributes of the Parameter.
 */
private void handleStringType(String paramName, String paramValue, Attributes attributes) {
    if (isPort(attributes)) {
        createPort(paramName, attributes, false);
    } else {
        // check if we have a boolean
        String restrictions = attributes.getValue(ATTR_RESTRICTIONS);
        if (isBooleanParameter(restrictions)) {
            m_currentParameter = new BoolParameter(paramName, paramValue);
        } else {
            if (restrictions != null && restrictions.length() > 0) {
                m_currentParameter = new StringChoiceParameter(paramName, restrictions.split(","));
                ((StringChoiceParameter) m_currentParameter).setValue(paramValue);
            } else {
                m_currentParameter = new StringParameter(paramName, paramValue);
            }
        }
    }
}
Also used : StringParameter(com.genericworkflownodes.knime.parameter.StringParameter) StringChoiceParameter(com.genericworkflownodes.knime.parameter.StringChoiceParameter) BoolParameter(com.genericworkflownodes.knime.parameter.BoolParameter)

Example 5 with StringChoiceParameter

use of com.genericworkflownodes.knime.parameter.StringChoiceParameter in project GenericKnimeNodes by genericworkflownodes.

the class CTDConfigurationWriter method addStringChoices.

private void addStringChoices(StringBuffer item, Parameter<?> p) {
    StringChoiceParameter scp = (StringChoiceParameter) p;
    // the list of allowed values will contain the empty string depending on
    // whether the parameter is optional or not
    List<String> values = scp.getAllowedValues();
    item.append(" restrictions=\"");
    String sep = "";
    for (String rv : values) {
        if (scp.isOptional() && "".equals(rv)) {
            continue;
        }
        item.append(sep);
        item.append(rv);
        sep = ",";
    }
    item.append('\"');
}
Also used : StringChoiceParameter(com.genericworkflownodes.knime.parameter.StringChoiceParameter)

Aggregations

StringChoiceParameter (com.genericworkflownodes.knime.parameter.StringChoiceParameter)8 StringParameter (com.genericworkflownodes.knime.parameter.StringParameter)7 BoolParameter (com.genericworkflownodes.knime.parameter.BoolParameter)6 DoubleParameter (com.genericworkflownodes.knime.parameter.DoubleParameter)4 IntegerParameter (com.genericworkflownodes.knime.parameter.IntegerParameter)3 Test (org.junit.Test)3 INodeConfiguration (com.genericworkflownodes.knime.config.INodeConfiguration)2 ParameterVerifier (com.genericworkflownodes.knime.generic_node.dialogs.param_dialog.verifier.ParameterVerifier)2 IntegerListParameter (com.genericworkflownodes.knime.parameter.IntegerListParameter)2 ListParameter (com.genericworkflownodes.knime.parameter.ListParameter)2 TestDataSource (com.genericworkflownodes.knime.test.data.TestDataSource)2 GalaxyNodeConfigurationReader (com.genericworkflownodes.knime.config.impl.GalaxyNodeConfigurationReader)1 CTDConfigurationReader (com.genericworkflownodes.knime.config.reader.CTDConfigurationReader)1 CTDHandler (com.genericworkflownodes.knime.config.reader.handler.CTDHandler)1 ListEditorComponent (com.genericworkflownodes.knime.generic_node.dialogs.param_dialog.list_editor.ListEditorComponent)1 InvalidParameterValueException (com.genericworkflownodes.knime.parameter.InvalidParameterValueException)1 SchemaProvider (com.genericworkflownodes.knime.schemas.SchemaProvider)1 BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1