Search in sources :

Example 6 with IridaWorkflowParameter

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

the class IridaWorkflowLoaderService method loadWorkflowDescription.

/**
 * Loads up the workflow description from the given file.
 *
 * @param descriptionFile
 *            The file to load up a workflow description.
 * @return An IridaWorkflowDescription object.
 * @throws IOException
 *             If there was an issue reading the passed file.
 * @throws IridaWorkflowLoadException
 *             If there was an issue loading up the workflow description.
 */
public IridaWorkflowDescription loadWorkflowDescription(Path descriptionFile) throws IOException, IridaWorkflowLoadException {
    checkNotNull(descriptionFile, "descriptionFile is null");
    if (!Files.exists(descriptionFile)) {
        throw new FileNotFoundException(descriptionFile.toAbsolutePath().toString());
    }
    Source source = new StreamSource(Files.newInputStream(descriptionFile));
    IridaWorkflowDescription workflowDescription = (IridaWorkflowDescription) workflowDescriptionUnmarshaller.unmarshal(source);
    if (workflowDescription.getId() == null) {
        throw new IridaWorkflowLoadException("No id for workflow description from file " + descriptionFile);
    } else if (workflowDescription.getAnalysisType() == null) {
        throw new IridaWorkflowLoadException("Invalid analysisType for workflow description from file " + descriptionFile);
    } else {
        if (workflowDescription.acceptsParameters()) {
            for (IridaWorkflowParameter workflowParameter : workflowDescription.getParameters()) {
                if (workflowParameter.getDefaultValue() == null && !workflowParameter.isRequired()) {
                    throw new IridaWorkflowLoadException("Parameters with no default value must set the \"required\" attribute to \"true\"." + descriptionFile);
                }
                if (workflowParameter.hasDynamicSource() && !workflowParameter.isRequired()) {
                    throw new IridaWorkflowLoadException("Parameters loaded from Dynamic Sources must set the \"required\" attribute to \"true\"." + descriptionFile);
                }
                if (workflowParameter.isRequired() && workflowParameter.getDefaultValue() != null) {
                    throw new IridaWorkflowLoadException("Required parameters should not have a default value." + descriptionFile);
                }
                try {
                    workflowParameter.getDynamicSource();
                } catch (IridaWorkflowParameterException e) {
                    throw new IridaWorkflowLoadException("Parameters may have no more than one Dynamic Source." + descriptionFile);
                }
            }
        }
        return workflowDescription;
    }
}
Also used : IridaWorkflowParameter(ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowParameter) StreamSource(javax.xml.transform.stream.StreamSource) FileNotFoundException(java.io.FileNotFoundException) IridaWorkflowDescription(ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowDescription) IridaWorkflowLoadException(ca.corefacility.bioinformatics.irida.exceptions.IridaWorkflowLoadException) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) IridaWorkflowParameterException(ca.corefacility.bioinformatics.irida.exceptions.IridaWorkflowParameterException)

Example 7 with IridaWorkflowParameter

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

the class IridaWorkflowTestBuilder method buildTestDescription.

/**
 * Builds a {@link IridaWorkflowDescription} with the following information.
 *
 * @param id
 *            The id of the workflow.
 * @param name
 *            The name of the workflow.
 * @param version
 *            The version of the workflow.
 * @param analysisType
 *            The {@link AnalysisType} of the workflow.
 * @param reference
 *            The reference label for the workflow.
 * @param requiresSingleSample
 *            Whether or not this workflow requires a single sample.
 * @return An {@link IridaWorkflowDescription} with the given information.
 * @throws MalformedURLException
 */
public static IridaWorkflowDescription buildTestDescription(UUID id, String name, String version, AnalysisType analysisType, Input input, String reference, boolean requiresSingleSample) throws MalformedURLException {
    List<IridaWorkflowOutput> outputs = new LinkedList<>();
    outputs.add(new IridaWorkflowOutput("output1", "output1.txt"));
    outputs.add(new IridaWorkflowOutput("output2", "output2.txt"));
    List<IridaWorkflowToolRepository> tools = new LinkedList<>();
    IridaWorkflowToolRepository workflowTool = new IridaWorkflowToolRepository("sam_to_bam", "devteam", new URL("http://toolshed.g2.bx.psu.edu/"), "8176b2575aa1");
    tools.add(workflowTool);
    IridaWorkflowInput workflowInput = null;
    switch(input) {
        case SINGLE:
            workflowInput = new IridaWorkflowInput("sequence_reads", null, reference, requiresSingleSample);
            break;
        case PAIRED:
            workflowInput = new IridaWorkflowInput(null, "sequence_reads_paired", reference, requiresSingleSample);
            break;
        case SINGLE_PAIRED:
            workflowInput = new IridaWorkflowInput("sequence_reads", "sequence_reads_paired", reference, requiresSingleSample);
            break;
    }
    List<IridaWorkflowParameter> parameters = new LinkedList<>();
    IridaToolParameter tool1 = new IridaToolParameter("irida.corefacility.ca/galaxy-shed/repos/irida/test-tool/0.1", "a");
    IridaToolParameter tool2 = new IridaToolParameter("irida.corefacility.ca/galaxy-shed/repos/irida/test-tool/0.1", "b");
    IridaWorkflowParameter parameter1 = new IridaWorkflowParameter("test-parameter", "1", Lists.newArrayList(tool1, tool2));
    parameters.add(parameter1);
    IridaWorkflowDescription iridaWorkflow = new IridaWorkflowDescription(id, name, version, analysisType, workflowInput, outputs, tools, parameters);
    return iridaWorkflow;
}
Also used : IridaWorkflowOutput(ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowOutput) IridaWorkflowInput(ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowInput) IridaWorkflowParameter(ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowParameter) IridaToolParameter(ca.corefacility.bioinformatics.irida.model.workflow.description.IridaToolParameter) IridaWorkflowDescription(ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowDescription) LinkedList(java.util.LinkedList) IridaWorkflowToolRepository(ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowToolRepository) URL(java.net.URL)

Example 8 with IridaWorkflowParameter

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

the class AnalysisParameterServiceGalaxyTest method testPrepareParametersOverrideThreeLevelMultipleParameterSuccess.

/**
 * Tests preparing workflow parameters with three levels, multiple
 * parameters and overriding with custom value successfully.
 *
 * @throws IridaWorkflowParameterException
 */
@Test
public void testPrepareParametersOverrideThreeLevelMultipleParameterSuccess() throws IridaWorkflowParameterException {
    IridaToolParameter iridaToolParameter = new IridaToolParameter("galaxy-tool1", "level1.level2.parameter1");
    IridaToolParameter iridaToolParameter2 = new IridaToolParameter("galaxy-tool1", "level1.level2.parameter2");
    IridaToolParameter iridaToolParameter3 = new IridaToolParameter("galaxy-tool1", "level1.parameter3");
    IridaWorkflowParameter parameter1 = new IridaWorkflowParameter("parameter1", "0", Lists.newArrayList(iridaToolParameter, iridaToolParameter2, iridaToolParameter3));
    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("parameter3", "1", "level2", ImmutableMap.of("parameter1", "1", "parameter2", "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 9 with IridaWorkflowParameter

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

the class AnalysisParameterServiceGalaxyTest method testPrepareParametersOverrideMultipleLevelMultipleParameterSuccess.

/**
 * Tests preparing workflow parameters with multiple levels, multiple
 * parameters and overriding with custom value successfully.
 *
 * @throws IridaWorkflowParameterException
 */
@Test
public void testPrepareParametersOverrideMultipleLevelMultipleParameterSuccess() throws IridaWorkflowParameterException {
    IridaToolParameter iridaToolParameter = new IridaToolParameter("galaxy-tool1", "level1.parameter1");
    IridaToolParameter iridaToolParameter2 = new IridaToolParameter("galaxy-tool1", "level1.parameter2");
    IridaWorkflowParameter parameter1 = new IridaWorkflowParameter("parameter1", "0", Lists.newArrayList(iridaToolParameter, iridaToolParameter2));
    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", "parameter2", "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 10 with IridaWorkflowParameter

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

the class AnalysisParameterServiceGalaxyTest method setup.

@Before
public void setup() {
    MockitoAnnotations.initMocks(this);
    analysisParameterService = new AnalysisParameterServiceGalaxy();
    when(iridaWorkflow.getWorkflowDescription()).thenReturn(iridaWorkflowDescription);
    IridaToolParameter iridaToolParameter = new IridaToolParameter("galaxy-tool1", "parameter1");
    IridaWorkflowParameter parameter1 = new IridaWorkflowParameter("parameter1", "0", Lists.newArrayList(iridaToolParameter));
    List<IridaWorkflowParameter> iridaWorkflowParameters = Lists.newArrayList(parameter1);
    when(iridaWorkflowDescription.getParameters()).thenReturn(iridaWorkflowParameters);
    when(iridaWorkflowDescription.acceptsParameters()).thenReturn(true);
}
Also used : IridaWorkflowParameter(ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowParameter) IridaToolParameter(ca.corefacility.bioinformatics.irida.model.workflow.description.IridaToolParameter) AnalysisParameterServiceGalaxy(ca.corefacility.bioinformatics.irida.service.analysis.workspace.galaxy.AnalysisParameterServiceGalaxy) Before(org.junit.Before)

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