Search in sources :

Example 16 with IridaWorkflowDescription

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

the class IridaWorkflowLoaderServiceIT method testLoadWorkflowDescriptionRequiresSingleSample.

/**
 * Tests loading up the workflow description file that requires a single sample.
 *
 * @throws IOException
 * @throws IridaWorkflowLoadException
 */
@Test
public void testLoadWorkflowDescriptionRequiresSingleSample() throws IOException, IridaWorkflowLoadException {
    IridaWorkflowDescription iridaWorkflowDescription = buildTestDescriptionRequiresSingleSample();
    IridaWorkflowDescription iridaWorkflowFromFile = workflowLoaderService.loadWorkflowDescription(workflowRequiresSingleSampleXmlPath);
    assertEquals("irida workflow description is invalid", iridaWorkflowFromFile, iridaWorkflowDescription);
}
Also used : IridaWorkflowDescription(ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowDescription) Test(org.junit.Test)

Example 17 with IridaWorkflowDescription

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

the class IridaWorkflowLoaderServiceIT method testLoadWorkflowDescriptionRequiresSingleSampleInvalid.

/**
 * Tests loading up the workflow description file with an invalid string for requires single sample and setting to default.
 *
 * @throws IOException
 * @throws IridaWorkflowLoadException
 */
@Test
public void testLoadWorkflowDescriptionRequiresSingleSampleInvalid() throws IOException, IridaWorkflowLoadException {
    IridaWorkflowDescription iridaWorkflowDescription = buildTestDescriptionRequiresSingleSampleInvalid();
    IridaWorkflowDescription iridaWorkflowFromFile = workflowLoaderService.loadWorkflowDescription(workflowInvalidRequiresSingleSampleXmlPath);
    assertEquals("irida workflow description is invalid", iridaWorkflowFromFile, iridaWorkflowDescription);
}
Also used : IridaWorkflowDescription(ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowDescription) Test(org.junit.Test)

Example 18 with IridaWorkflowDescription

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

the class IridaWorkflowLoaderServiceTest method testLoadWorkflowDescriptionFail.

/**
 * Tests failing to loading a workflow description.
 *
 * @throws IOException
 * @throws XmlMappingException
 * @throws IridaWorkflowLoadException
 */
@Test(expected = IridaWorkflowLoadException.class)
public void testLoadWorkflowDescriptionFail() throws XmlMappingException, IOException, IridaWorkflowLoadException {
    IridaWorkflowDescription description = IridaWorkflowTestBuilder.buildTestDescription(iridaWorkflowId, "name", "version", null, IridaWorkflowTestBuilder.Input.SINGLE, "reference", true);
    when(workflowDescriptionUnmarshellar.unmarshal(any(Source.class))).thenReturn(description);
    iridaWorkflowLoaderService.loadWorkflowDescription(workflowDescriptionPath);
}
Also used : IridaWorkflowDescription(ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowDescription) Source(javax.xml.transform.Source) Test(org.junit.Test)

Example 19 with IridaWorkflowDescription

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

the class IridaWorkflowLoaderService method loadIridaWorkflow.

/**
 * Loads up an {@link IridaWorkflow} from the given information files.
 *
 * @param descriptionFile
 *            The description file for the workflow.
 * @param structureFile
 *            The file describing the structure of a workflow.
 * @return An IridaWorkflow object for this workflow.
 * @throws IOException
 *             If there was an issue reading the passed file.
 * @throws IridaWorkflowLoadException
 *             If there was an issue loading up the workflow.
 */
public IridaWorkflow loadIridaWorkflow(Path descriptionFile, Path structureFile) throws IOException, IridaWorkflowLoadException {
    checkNotNull(descriptionFile, "descriptionFile is null");
    checkNotNull(structureFile, "structureFile is null");
    IridaWorkflowDescription worklowDescription = loadWorkflowDescription(descriptionFile);
    IridaWorkflowStructure workflowStructure = loadWorkflowStructure(structureFile);
    return new IridaWorkflow(worklowDescription, workflowStructure);
}
Also used : IridaWorkflow(ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow) IridaWorkflowDescription(ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowDescription) IridaWorkflowStructure(ca.corefacility.bioinformatics.irida.model.workflow.structure.IridaWorkflowStructure)

Example 20 with IridaWorkflowDescription

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

the class PipelineController method ajaxStartPipeline.

// ************************************************************************************************
// AJAX
// ************************************************************************************************
/**
 * Launch a pipeline
 *
 * @param locale     the locale that the browser is using for the current request.
 * @param parameters DTO of pipeline start parameters
 * @return a JSON response with the status and any messages.
 */
@RequestMapping(value = "/ajax/start", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> ajaxStartPipeline(Locale locale, @RequestBody final PipelineStartParameters parameters) {
    try {
        IridaWorkflow flow = workflowsService.getIridaWorkflow(parameters.getWorkflowId());
        IridaWorkflowDescription description = flow.getWorkflowDescription();
        // The pipeline needs to have a name.
        String name = parameters.getName();
        if (Strings.isNullOrEmpty(name)) {
            return ImmutableMap.of("error", messageSource.getMessage("workflow.no-name-provided", null, locale));
        }
        // Check to see if a reference file is required.
        Long ref = parameters.getRef();
        if (description.requiresReference() && ref == null) {
            return ImmutableMap.of("error", messageSource.getMessage("pipeline.error.no-reference.pipeline-start", null, locale));
        }
        // Get a list of the files to submit
        List<SingleEndSequenceFile> singleEndFiles = new ArrayList<>();
        List<SequenceFilePair> sequenceFilePairs = new ArrayList<>();
        List<Long> single = parameters.getSingle();
        if (single != null) {
            Iterable<SequencingObject> readMultiple = sequencingObjectService.readMultiple(single);
            readMultiple.forEach(f -> {
                if (!(f instanceof SingleEndSequenceFile)) {
                    throw new IllegalArgumentException("file " + f.getId() + " not a SingleEndSequenceFile");
                }
                singleEndFiles.add((SingleEndSequenceFile) f);
            });
            // Check the single files for duplicates in a sample, throws SampleAnalysisDuplicateException
            sequencingObjectService.getUniqueSamplesForSequencingObjects(Sets.newHashSet(singleEndFiles));
        }
        List<Long> paired = parameters.getPaired();
        if (paired != null) {
            Iterable<SequencingObject> readMultiple = sequencingObjectService.readMultiple(paired);
            readMultiple.forEach(f -> {
                if (!(f instanceof SequenceFilePair)) {
                    throw new IllegalArgumentException("file " + f.getId() + " not a SequenceFilePair");
                }
                sequenceFilePairs.add((SequenceFilePair) f);
            });
            // Check the pair files for duplicates in a sample, throws SampleAnalysisDuplicateException
            sequencingObjectService.getUniqueSamplesForSequencingObjects(Sets.newHashSet(sequenceFilePairs));
        }
        // Get the pipeline parameters
        Map<String, String> params = new HashMap<>();
        IridaWorkflowNamedParameters namedParameters = null;
        Map<String, Object> selectedParameters = parameters.getSelectedParameters();
        if (selectedParameters != null) {
            try {
                final String selectedParametersId = selectedParameters.get("id").toString();
                if (!DEFAULT_WORKFLOW_PARAMETERS_ID.equals(selectedParametersId) && !CUSTOM_UNSAVED_WORKFLOW_PARAMETERS_ID.equals(selectedParametersId)) {
                    // this means that a named parameter set was selected
                    // and unmodified, so load up that named parameter set
                    // to pass along.
                    namedParameters = namedParameterService.read(Long.valueOf(selectedParametersId));
                } else {
                    @SuppressWarnings("unchecked") final List<Map<String, String>> unnamedParameters = (List<Map<String, String>>) selectedParameters.get("parameters");
                    for (final Map<String, String> parameter : unnamedParameters) {
                        params.put(parameter.get("name"), parameter.get("value"));
                    }
                }
            } catch (Exception e) {
                return ImmutableMap.of("parameterError", messageSource.getMessage("pipeline.parameters.error", null, locale));
            }
        }
        List<Project> projectsToShare = new ArrayList<>();
        List<Long> sharedProjects = parameters.getSharedProjects();
        if (sharedProjects != null && !sharedProjects.isEmpty()) {
            projectsToShare = Lists.newArrayList(projectService.readMultiple(sharedProjects));
        }
        String analysisDescription = parameters.getDescription();
        Boolean writeResultsToSamples = parameters.getWriteResultsToSamples();
        if (description.getInputs().requiresSingleSample()) {
            analysisSubmissionService.createSingleSampleSubmission(flow, ref, singleEndFiles, sequenceFilePairs, params, namedParameters, name, analysisDescription, projectsToShare, writeResultsToSamples);
        } else {
            analysisSubmissionService.createMultipleSampleSubmission(flow, ref, singleEndFiles, sequenceFilePairs, params, namedParameters, name, analysisDescription, projectsToShare, writeResultsToSamples);
        }
    } catch (IridaWorkflowNotFoundException e) {
        logger.error("Cannot find IridaWorkflow [" + parameters.getWorkflowId() + "]", e);
        return ImmutableMap.of("pipelineError", messageSource.getMessage("pipeline.error.invalid-pipeline", null, locale));
    } catch (DuplicateSampleException e) {
        logger.error("Multiple files for Sample found", e);
        return ImmutableMap.of("pipelineError", messageSource.getMessage("pipeline.error.duplicate-samples", null, locale));
    }
    return ImmutableMap.of("success", true);
}
Also used : SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) HashMap(java.util.HashMap) IridaWorkflow(ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow) ArrayList(java.util.ArrayList) IridaWorkflowNamedParameters(ca.corefacility.bioinformatics.irida.model.workflow.submission.IridaWorkflowNamedParameters) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) DuplicateSampleException(ca.corefacility.bioinformatics.irida.exceptions.DuplicateSampleException) SequenceFilePair(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair) List(java.util.List) ArrayList(java.util.ArrayList) IridaWorkflowNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.IridaWorkflowNotFoundException) IridaWorkflowParameterException(ca.corefacility.bioinformatics.irida.exceptions.IridaWorkflowParameterException) IOException(java.io.IOException) DuplicateSampleException(ca.corefacility.bioinformatics.irida.exceptions.DuplicateSampleException) IridaWorkflowNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.IridaWorkflowNotFoundException) Project(ca.corefacility.bioinformatics.irida.model.project.Project) IridaWorkflowDescription(ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowDescription) SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

IridaWorkflowDescription (ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowDescription)22 Test (org.junit.Test)10 IridaWorkflow (ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow)8 IridaWorkflowInput (ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowInput)5 IridaWorkflowParameter (ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowParameter)5 AnalysisSubmission (ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)5 IridaWorkflowNotFoundException (ca.corefacility.bioinformatics.irida.exceptions.IridaWorkflowNotFoundException)4 Project (ca.corefacility.bioinformatics.irida.model.project.Project)4 ImmutableMap (com.google.common.collect.ImmutableMap)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 IridaWorkflowParameterException (ca.corefacility.bioinformatics.irida.exceptions.IridaWorkflowParameterException)3 ReferenceFile (ca.corefacility.bioinformatics.irida.model.project.ReferenceFile)3 IridaWorkflowOutput (ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowOutput)3 IridaWorkflowToolRepository (ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowToolRepository)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 DuplicateSampleException (ca.corefacility.bioinformatics.irida.exceptions.DuplicateSampleException)2 AnalysisType (ca.corefacility.bioinformatics.irida.model.enums.AnalysisType)2 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)2