Search in sources :

Example 6 with IridaWorkflowDescription

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

the class AnalysisSubmissionServiceImpl method createMultipleSampleSubmission.

/**
 * {@inheritDoc}
 */
@Transactional
@PreAuthorize("hasRole('ROLE_USER')")
public AnalysisSubmission createMultipleSampleSubmission(IridaWorkflow workflow, Long ref, List<SingleEndSequenceFile> sequenceFiles, List<SequenceFilePair> sequenceFilePairs, Map<String, String> params, IridaWorkflowNamedParameters namedParameters, String name, String newAnalysisDescription, List<Project> projectsToShare, boolean writeResultsToSamples) {
    AnalysisSubmission.Builder builder = AnalysisSubmission.builder(workflow.getWorkflowIdentifier());
    builder.name(name);
    builder.priority(AnalysisSubmission.Priority.MEDIUM);
    builder.updateSamples(writeResultsToSamples);
    IridaWorkflowDescription description = workflow.getWorkflowDescription();
    // Add reference file
    if (ref != null && description.requiresReference()) {
        ReferenceFile referenceFile = referenceFileRepository.findOne(ref);
        builder.referenceFile(referenceFile);
    }
    // Add any single end sequencing files.
    if (description.acceptsSingleSequenceFiles()) {
        if (!sequenceFiles.isEmpty()) {
            builder.inputFiles(Sets.newHashSet(sequenceFiles));
        }
    }
    // Add any paired end sequencing files.
    if (description.acceptsPairedSequenceFiles()) {
        if (!sequenceFilePairs.isEmpty()) {
            builder.inputFiles(Sets.newHashSet(sequenceFilePairs));
        }
    }
    if (description.acceptsParameters()) {
        if (namedParameters != null) {
            builder.withNamedParameters(namedParameters);
        } else {
            if (!params.isEmpty()) {
                // Note: This cannot be empty if through the UI if
                // the pipeline required params.
                builder.inputParameters(params);
            }
        }
    }
    // Add description to submission, can be null
    builder.analysisDescription(newAnalysisDescription);
    // Create the submission
    AnalysisSubmission submission = create(builder.build());
    // Share with the required projects
    for (Project project : projectsToShare) {
        pasRepository.save(new ProjectAnalysisSubmissionJoin(project, submission));
    }
    return submission;
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) ReferenceFile(ca.corefacility.bioinformatics.irida.model.project.ReferenceFile) AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) IridaWorkflowDescription(ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowDescription) ProjectAnalysisSubmissionJoin(ca.corefacility.bioinformatics.irida.model.workflow.submission.ProjectAnalysisSubmissionJoin) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Transactional(javax.transaction.Transactional)

Example 7 with IridaWorkflowDescription

use of ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowDescription 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 8 with IridaWorkflowDescription

use of ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowDescription 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 9 with IridaWorkflowDescription

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

the class RESTAnalysisSubmissionController method listOfType.

/**
 * Get all analyses of a given type
 *
 * @param type
 *            The type to request
 * @return ModelMap containing the requested type of resource
 */
@RequestMapping("/analysisType/{type}")
public ModelMap listOfType(@PathVariable String type) {
    ModelMap model = new ModelMap();
    if (!ANALYSIS_TYPES.containsKey(type)) {
        throw new EntityNotFoundException("Analysis type not found");
    }
    AnalysisType analysisType = ANALYSIS_TYPES.get(type);
    Set<UUID> workflowIds;
    try {
        workflowIds = iridaWorkflowsService.getAllWorkflowsByType(analysisType).stream().map(IridaWorkflow::getWorkflowDescription).map(IridaWorkflowDescription::getId).collect(Collectors.toSet());
    } catch (IridaWorkflowNotFoundException e) {
        throw new EntityNotFoundException("Analysis type not found", e);
    }
    List<AnalysisSubmission> analysesOfType = analysisSubmissionService.getAnalysisSubmissionsAccessibleByCurrentUserByWorkflowIds(workflowIds);
    ResourceCollection<AnalysisSubmission> resourceCollection = new ResourceCollection<>(analysesOfType.size());
    for (AnalysisSubmission s : analysesOfType) {
        s.add(constructCustomResourceLinks(s));
        s.add(linkTo(methodOn(RESTAnalysisSubmissionController.class).getResource(s.getId())).withSelfRel());
        resourceCollection.add(s);
    }
    resourceCollection.add(linkTo(methodOn(RESTAnalysisSubmissionController.class).listOfType(type)).withSelfRel());
    resourceCollection.add(linkTo(RESTAnalysisSubmissionController.class).withRel(SUBMISSIONS_REL));
    model.addAttribute(RESOURCE_NAME, resourceCollection);
    return model;
}
Also used : AnalysisType(ca.corefacility.bioinformatics.irida.model.enums.AnalysisType) IridaWorkflowNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.IridaWorkflowNotFoundException) ModelMap(org.springframework.ui.ModelMap) AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) IridaWorkflowDescription(ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowDescription) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) UUID(java.util.UUID) ResourceCollection(ca.corefacility.bioinformatics.irida.web.assembler.resource.ResourceCollection) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with IridaWorkflowDescription

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

the class AnalysisControllerTest method testGetAnalysisDetailsNotCompleted.

@Test
public void testGetAnalysisDetailsNotCompleted() throws IOException, IridaWorkflowNotFoundException {
    Long submissionId = 1L;
    ExtendedModelMap model = new ExtendedModelMap();
    Locale locale = Locale.ENGLISH;
    final IridaWorkflowInput input = new IridaWorkflowInput("single", "paired", "reference", true);
    AnalysisSubmission submission = TestDataFactory.constructAnalysisSubmission();
    IridaWorkflowDescription description = new IridaWorkflowDescription(submission.getWorkflowId(), "My Workflow", "V1", AnalysisType.PHYLOGENOMICS, input, Lists.newArrayList(), Lists.newArrayList(), Lists.newArrayList());
    IridaWorkflow iridaWorkflow = new IridaWorkflow(description, null);
    submission.setAnalysisState(AnalysisState.RUNNING);
    when(analysisSubmissionServiceMock.read(submissionId)).thenReturn(submission);
    when(iridaWorkflowsServiceMock.getIridaWorkflow(submission.getWorkflowId())).thenReturn(iridaWorkflow);
    String detailsPage = analysisController.getDetailsPage(submissionId, model, locale);
    assertEquals("should be details page", AnalysisController.PAGE_DETAILS_DIRECTORY + "tree", detailsPage);
    assertFalse("No preview should be available", model.containsAttribute("preview"));
    assertEquals("submission should be in model", submission, model.get("analysisSubmission"));
}
Also used : Locale(java.util.Locale) ExtendedModelMap(org.springframework.ui.ExtendedModelMap) IridaWorkflowInput(ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowInput) IridaWorkflow(ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow) AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) IridaWorkflowDescription(ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowDescription) Test(org.junit.Test)

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