Search in sources :

Example 1 with IridaWorkflowParameter

use of ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowParameter in project irida by phac-nml.

the class IridaWorkflowLoaderServiceIT method testLoadWorkflowWithParameters.

/**
 * Test to make sure we can load a workflow with parameters.
 *
 * @throws IridaWorkflowLoadException
 * @throws IOException
 */
@Test
public void testLoadWorkflowWithParameters() throws IridaWorkflowLoadException, IOException {
    IridaWorkflow iridaWorkflowFromFile = workflowLoaderService.loadIridaWorkflowFromDirectory(workflowDirectoryPathWithParameters);
    assertTrue("workflow loaded with no parameters", iridaWorkflowFromFile.getWorkflowDescription().acceptsParameters());
    List<IridaWorkflowParameter> parameters = iridaWorkflowFromFile.getWorkflowDescription().getParameters();
    assertNotNull("parameters should not be null", parameters);
    assertEquals("parameters does not have the correct size", 1, parameters.size());
    IridaWorkflowParameter parameter = parameters.get(0);
    assertEquals("parameter does not have the correct name", "test-parameter", parameter.getName());
    assertEquals("default value is not correct", "1", parameter.getDefaultValue());
    assertEquals("parameter does not have correct number of tool parameters", 1, parameter.getToolParameters().size());
}
Also used : IridaWorkflow(ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow) IridaWorkflowParameter(ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowParameter) Test(org.junit.Test)

Example 2 with IridaWorkflowParameter

use of ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowParameter in project irida by phac-nml.

the class IridaWorkflowLoaderServiceIT method testLoadWorkflowWithParametersNoDefaultValueIsRequiredSuccess.

/**
 * Test to make sure we fail to load a workflow with no default value and without a required="true" attribute.
 *
 * @throws IridaWorkflowLoadException
 * @throws IOException
 */
@Test
public void testLoadWorkflowWithParametersNoDefaultValueIsRequiredSuccess() throws IridaWorkflowLoadException, IOException {
    IridaWorkflow iridaWorkflow = workflowLoaderService.loadIridaWorkflowFromDirectory(workflowDirectoryPathWithParametersNoDefaultIsRequired);
    IridaWorkflowParameter parameter = iridaWorkflow.getWorkflowDescription().getParameters().get(0);
    assertNull("defaultValue should be null if none provided", parameter.getDefaultValue());
    assertTrue("parameter should be required", parameter.isRequired());
}
Also used : IridaWorkflow(ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow) IridaWorkflowParameter(ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowParameter) Test(org.junit.Test)

Example 3 with IridaWorkflowParameter

use of ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowParameter in project irida by phac-nml.

the class AnalysisParameterServiceGalaxyTest method testPrepareParametersOverrideMultipleLevelSuccess.

/**
 * Tests preparing workflow parameters with multiple levels and overriding
 * with custom value successfully.
 *
 * @throws IridaWorkflowParameterException
 */
@Test
public void testPrepareParametersOverrideMultipleLevelSuccess() throws IridaWorkflowParameterException {
    IridaToolParameter iridaToolParameter = new IridaToolParameter("galaxy-tool1", "level1.parameter1");
    IridaWorkflowParameter parameter1 = new IridaWorkflowParameter("parameter1", "0", Lists.newArrayList(iridaToolParameter));
    List<IridaWorkflowParameter> iridaWorkflowParameters = Lists.newArrayList(parameter1);
    when(iridaWorkflowDescription.getParameters()).thenReturn(iridaWorkflowParameters);
    Map<String, String> parameters = Maps.newHashMap();
    parameters.put("parameter1", "1");
    WorkflowInputsGalaxy workflowInputsGalaxy = analysisParameterService.prepareAnalysisParameters(parameters, iridaWorkflow);
    assertNotNull("workflowInputsGalaxy is null", workflowInputsGalaxy);
    WorkflowInputs workflowInputs = workflowInputsGalaxy.getInputsObject();
    Map<Object, Map<String, Object>> workflowParameters = workflowInputs.getParameters();
    Map<String, Object> tool1Parameters = workflowParameters.get("galaxy-tool1");
    assertNotNull("parameters for galaxy-tool1 should not be null", tool1Parameters);
    assertEquals("parameter not properly defined", ImmutableMap.of("level1", ImmutableMap.of("parameter1", "1")), tool1Parameters);
}
Also used : IridaWorkflowParameter(ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowParameter) IridaToolParameter(ca.corefacility.bioinformatics.irida.model.workflow.description.IridaToolParameter) WorkflowInputs(com.github.jmchilton.blend4j.galaxy.beans.WorkflowInputs) WorkflowInputsGalaxy(ca.corefacility.bioinformatics.irida.model.workflow.execution.galaxy.WorkflowInputsGalaxy) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) Test(org.junit.Test)

Example 4 with IridaWorkflowParameter

use of ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowParameter in project irida by phac-nml.

the class AnalysisParameterServiceGalaxyTest method testPrepareParametersOverrideSuccessTwoTools.

/**
 * Tests preparing workflow parameters and overriding with custom value
 * successfully in two tools.
 *
 * @throws IridaWorkflowParameterException
 */
@Test
public void testPrepareParametersOverrideSuccessTwoTools() throws IridaWorkflowParameterException {
    Map<String, String> parameters = Maps.newHashMap();
    parameters.put("parameter1", "1");
    IridaToolParameter iridaToolParameter = new IridaToolParameter("galaxy-tool1", "parameter1");
    IridaToolParameter iridaToolParameter2 = new IridaToolParameter("galaxy-tool1", "parameter2");
    IridaWorkflowParameter parameter1 = new IridaWorkflowParameter("parameter1", "0", Lists.newArrayList(iridaToolParameter, iridaToolParameter2));
    List<IridaWorkflowParameter> iridaWorkflowParameters = Lists.newArrayList(parameter1);
    when(iridaWorkflowDescription.getParameters()).thenReturn(iridaWorkflowParameters);
    WorkflowInputsGalaxy workflowInputsGalaxy = analysisParameterService.prepareAnalysisParameters(parameters, iridaWorkflow);
    assertNotNull("workflowInputsGalaxy is null", workflowInputsGalaxy);
    WorkflowInputs workflowInputs = workflowInputsGalaxy.getInputsObject();
    Map<Object, Map<String, Object>> workflowParameters = workflowInputs.getParameters();
    Map<String, Object> tool1Parameters = workflowParameters.get("galaxy-tool1");
    assertNotNull("parameters for galaxy-tool1 should not be null", tool1Parameters);
    assertEquals("galaxy-tool1,parameter1 is not valid", "1", tool1Parameters.get("parameter1"));
    assertEquals("galaxy-tool1,parameter2 is not valid", "1", tool1Parameters.get("parameter2"));
}
Also used : IridaWorkflowParameter(ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowParameter) IridaToolParameter(ca.corefacility.bioinformatics.irida.model.workflow.description.IridaToolParameter) WorkflowInputs(com.github.jmchilton.blend4j.galaxy.beans.WorkflowInputs) WorkflowInputsGalaxy(ca.corefacility.bioinformatics.irida.model.workflow.execution.galaxy.WorkflowInputsGalaxy) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) Test(org.junit.Test)

Example 5 with IridaWorkflowParameter

use of ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowParameter in project irida by phac-nml.

the class AnalysisParameterServiceGalaxy method prepareAnalysisParameters.

/**
 * {@inheritDoc}
 */
@Override
public WorkflowInputsGalaxy prepareAnalysisParameters(Map<String, String> parameters, IridaWorkflow iridaWorkflow) throws IridaWorkflowParameterException {
    checkNotNull(parameters, "parameters is null");
    checkNotNull(iridaWorkflow, "iridaWorkflow is null");
    WorkflowInputs inputs = new WorkflowInputs();
    Set<String> parameterNamesUsed = Sets.newHashSet();
    if (!iridaWorkflow.getWorkflowDescription().acceptsParameters()) {
        if (parameters.isEmpty()) {
            logger.debug("workflow " + iridaWorkflow + " does not accept parameters and no parameters passed.");
        } else {
            throw new IridaWorkflowNoParameterException("The workflow " + iridaWorkflow + " does not accept parameters but parameters " + parameters + " were passed.");
        }
    } else {
        List<IridaWorkflowParameter> iridaParameters = iridaWorkflow.getWorkflowDescription().getParameters();
        ParameterBuilderGalaxy parameterBuilder = new ParameterBuilderGalaxy();
        for (IridaWorkflowParameter iridaParameter : iridaParameters) {
            String parameterName = iridaParameter.getName();
            String value = parameters.get(parameterName);
            parameterNamesUsed.add(parameterName);
            if (ignoreDefaultValue(parameters, parameterName)) {
                logger.debug("Parameter with name=" + parameterName + " will ignore the default value=" + iridaParameter.getDefaultValue());
            } else {
                if (useDefaultValue(parameters, parameterName)) {
                    value = iridaParameter.getDefaultValue();
                    logger.debug("Parameter with name=" + parameterName + ", for workflow=" + iridaWorkflow + ", has no value set, using defaultValue=" + value);
                }
                for (IridaToolParameter iridaToolParameter : iridaParameter.getToolParameters()) {
                    String toolId = iridaToolParameter.getToolId();
                    String galaxyParameterName = iridaToolParameter.getParameterName();
                    parameterBuilder.addParameter(toolId, galaxyParameterName, value);
                    logger.debug("Setting parameter iridaName=" + parameterName + ", galaxyToolId=" + toolId + ", galaxyParameterName=" + galaxyParameterName + ", value=" + value);
                }
            }
        }
        for (ParameterBuilderGalaxy.ParameterId parameterId : parameterBuilder.getParameterIds()) {
            inputs.setToolParameter(parameterId.getToolId(), parameterId.getStartName(), parameterBuilder.getMappingForParameterId(parameterId));
        }
    }
    Set<String> parameterNamesUnused = Sets.difference(parameters.keySet(), parameterNamesUsed);
    if (!parameterNamesUnused.isEmpty()) {
        throw new IridaWorkflowParameterException("The set of parameters " + parameterNamesUnused + " are not defined in " + iridaWorkflow);
    } else {
        return new WorkflowInputsGalaxy(inputs);
    }
}
Also used : IridaWorkflowParameter(ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowParameter) WorkflowInputs(com.github.jmchilton.blend4j.galaxy.beans.WorkflowInputs) IridaToolParameter(ca.corefacility.bioinformatics.irida.model.workflow.description.IridaToolParameter) IridaWorkflowNoParameterException(ca.corefacility.bioinformatics.irida.exceptions.IridaWorkflowNoParameterException) WorkflowInputsGalaxy(ca.corefacility.bioinformatics.irida.model.workflow.execution.galaxy.WorkflowInputsGalaxy) IridaWorkflowParameterException(ca.corefacility.bioinformatics.irida.exceptions.IridaWorkflowParameterException)

Aggregations

IridaWorkflowParameter (ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowParameter)13 IridaToolParameter (ca.corefacility.bioinformatics.irida.model.workflow.description.IridaToolParameter)8 Test (org.junit.Test)6 IridaWorkflowDescription (ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowDescription)5 WorkflowInputsGalaxy (ca.corefacility.bioinformatics.irida.model.workflow.execution.galaxy.WorkflowInputsGalaxy)5 WorkflowInputs (com.github.jmchilton.blend4j.galaxy.beans.WorkflowInputs)5 ImmutableMap (com.google.common.collect.ImmutableMap)5 Map (java.util.Map)5 IridaWorkflow (ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow)4 IridaWorkflowParameterException (ca.corefacility.bioinformatics.irida.exceptions.IridaWorkflowParameterException)3 IridaWorkflowInput (ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowInput)3 IridaWorkflowOutput (ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowOutput)3 IridaWorkflowToolRepository (ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowToolRepository)3 URL (java.net.URL)2 LinkedList (java.util.LinkedList)2 DuplicateSampleException (ca.corefacility.bioinformatics.irida.exceptions.DuplicateSampleException)1 IridaWorkflowLoadException (ca.corefacility.bioinformatics.irida.exceptions.IridaWorkflowLoadException)1 IridaWorkflowNoParameterException (ca.corefacility.bioinformatics.irida.exceptions.IridaWorkflowNoParameterException)1 IridaWorkflowNotFoundException (ca.corefacility.bioinformatics.irida.exceptions.IridaWorkflowNotFoundException)1 Join (ca.corefacility.bioinformatics.irida.model.joins.Join)1