Search in sources :

Example 11 with IridaWorkflowParameter

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

the class TestDataFactory method getIridaWorkflow.

public static IridaWorkflow getIridaWorkflow(UUID id) {
    IridaWorkflowInput input = new IridaWorkflowInput();
    List<IridaWorkflowOutput> outputs = ImmutableList.of(new IridaWorkflowOutput());
    List<IridaWorkflowToolRepository> tools = ImmutableList.of();
    List<IridaWorkflowParameter> parameters = ImmutableList.of();
    IridaWorkflowDescription description = new IridaWorkflowDescription(id, "My Workflow", "V1", AnalysisType.DEFAULT, input, outputs, tools, parameters);
    IridaWorkflowStructure structure = new IridaWorkflowStructure(null);
    return new IridaWorkflow(description, structure);
}
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) 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) IridaWorkflowToolRepository(ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowToolRepository)

Example 12 with IridaWorkflowParameter

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

the class IridaWorkflowLoaderServiceIT method buildTestDescription.

private IridaWorkflowDescription buildTestDescription(UUID id, String name, String version, String sequenceReadsSingle, String sequenceReadsPaired, 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);
    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.DEFAULT, new IridaWorkflowInput(sequenceReadsSingle, sequenceReadsPaired, "reference", requiresSingleSample), outputs, tools, parameters);
    return iridaWorkflow;
}
Also used : IridaWorkflowOutput(ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowOutput) IridaWorkflowParameter(ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowParameter) IridaWorkflowInput(ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowInput) 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 13 with IridaWorkflowParameter

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

the class PipelineController method getSpecifiedPipelinePage.

/**
 * Get a generic pipeline page.
 *
 * @param model
 *            the the model for the current request
 * @param principal
 *            the user in the current request
 * @param locale
 *            the locale that the user is using
 * @param pipelineId
 *            the pipeline to load
 * @return a page reference or redirect to load.
 */
@RequestMapping(value = "/{pipelineId}")
public String getSpecifiedPipelinePage(final Model model, Principal principal, Locale locale, @PathVariable UUID pipelineId) {
    String response = URL_EMPTY_CART_REDIRECT;
    boolean canUpdateAllSamples;
    Map<Project, Set<Sample>> cartMap = cartController.getSelected();
    // Cannot run a pipeline on an empty cart!
    if (!cartMap.isEmpty()) {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        IridaWorkflow flow = null;
        try {
            flow = workflowsService.getIridaWorkflow(pipelineId);
        } catch (IridaWorkflowNotFoundException e) {
            logger.error("Workflow not found - See stack:", e);
            return "redirect:errors/not_found";
        }
        // Check if there even is functionality to update samples from results for this pipeline
        canUpdateAllSamples = analysisSubmissionSampleProcessor.hasRegisteredAnalysisSampleUpdater(flow.getWorkflowDescription().getAnalysisType());
        User user = userService.getUserByUsername(principal.getName());
        // Get all the reference files that could be used for this pipeline.
        List<Map<String, Object>> referenceFileList = new ArrayList<>();
        List<Map<String, Object>> projectList = new ArrayList<>();
        List<Map<String, Object>> addRefList = new ArrayList<>();
        IridaWorkflowDescription description = flow.getWorkflowDescription();
        final String workflowName = description.getName().toLowerCase();
        for (Project project : cartMap.keySet()) {
            // Check to see if it requires a reference file.
            if (description.requiresReference()) {
                List<Join<Project, ReferenceFile>> joinList = referenceFileService.getReferenceFilesForProject(project);
                for (Join<Project, ReferenceFile> join : joinList) {
                    referenceFileList.add(ImmutableMap.of("project", project, "file", join.getObject()));
                }
                if (referenceFileList.size() == 0) {
                    if (user.getSystemRole().equals(Role.ROLE_ADMIN) || projectService.userHasProjectRole(user, project, ProjectRole.PROJECT_OWNER)) {
                        addRefList.add(ImmutableMap.of("name", project.getLabel(), "id", project.getId()));
                    }
                }
            }
            Set<Sample> samples = cartMap.get(project);
            Map<String, Object> projectMap = new HashMap<>();
            List<Map<String, Object>> sampleList = new ArrayList<>();
            for (Sample sample : samples) {
                Map<String, Object> sampleMap = new HashMap<>();
                sampleMap.put("name", sample.getLabel());
                sampleMap.put("id", sample.getId().toString());
                Map<String, List<? extends Object>> files = new HashMap<>();
                // Paired end reads
                if (description.acceptsPairedSequenceFiles()) {
                    Collection<SampleSequencingObjectJoin> pairs = sequencingObjectService.getSequencesForSampleOfType(sample, SequenceFilePair.class);
                    files.put("paired_end", pairs.stream().map(SampleSequencingObjectJoin::getObject).collect(Collectors.toList()));
                }
                // Singe end reads
                if (description.acceptsSingleSequenceFiles()) {
                    Collection<SampleSequencingObjectJoin> singles = sequencingObjectService.getSequencesForSampleOfType(sample, SingleEndSequenceFile.class);
                    files.put("single_end", singles.stream().map(SampleSequencingObjectJoin::getObject).collect(Collectors.toList()));
                }
                sampleMap.put("files", files);
                sampleList.add(sampleMap);
            }
            projectMap.put("id", project.getId().toString());
            projectMap.put("name", project.getLabel());
            projectMap.put("samples", sampleList);
            projectList.add(projectMap);
            canUpdateAllSamples &= updateSamplePermission.isAllowed(authentication, samples);
        }
        // Need to add the pipeline parameters
        final List<IridaWorkflowParameter> defaultWorkflowParameters = flow.getWorkflowDescription().getParameters();
        final List<Map<String, Object>> parameters = new ArrayList<>();
        if (defaultWorkflowParameters != null) {
            final List<Map<String, String>> defaultParameters = new ArrayList<>();
            for (IridaWorkflowParameter p : defaultWorkflowParameters) {
                if (p.isRequired()) {
                    continue;
                }
                defaultParameters.add(ImmutableMap.of("label", messageSource.getMessage("pipeline.parameters." + workflowName + "." + p.getName(), null, locale), "value", p.getDefaultValue(), "name", p.getName()));
            }
            parameters.add(ImmutableMap.of("id", DEFAULT_WORKFLOW_PARAMETERS_ID, "label", messageSource.getMessage("workflow.parameters.named.default", null, locale), "parameters", defaultParameters));
            final List<IridaWorkflowNamedParameters> namedParameters = namedParameterService.findNamedParametersForWorkflow(pipelineId);
            for (final IridaWorkflowNamedParameters p : namedParameters) {
                final List<Map<String, String>> namedParametersList = new ArrayList<>();
                for (final Map.Entry<String, String> parameter : p.getInputParameters().entrySet()) {
                    namedParametersList.add(ImmutableMap.of("label", messageSource.getMessage("pipeline.parameters." + workflowName + "." + parameter.getKey(), null, locale), "value", parameter.getValue(), "name", parameter.getKey()));
                }
                parameters.add(ImmutableMap.of("id", p.getId(), "label", p.getLabel(), "parameters", namedParametersList));
            }
            model.addAttribute("parameterModalTitle", messageSource.getMessage("pipeline.parameters.modal-title." + workflowName, null, locale));
        } else {
            model.addAttribute("noParameters", messageSource.getMessage("pipeline.no-parameters", null, locale));
        }
        // Parameters should be added not matter what, even if they are empty.
        model.addAttribute("parameters", parameters);
        model.addAttribute("title", messageSource.getMessage("pipeline.title." + description.getName(), null, locale));
        model.addAttribute("mainTitle", messageSource.getMessage("pipeline.h1." + description.getName(), null, locale));
        model.addAttribute("name", description.getName());
        model.addAttribute("pipelineId", pipelineId.toString());
        model.addAttribute("referenceFiles", referenceFileList);
        model.addAttribute("referenceRequired", description.requiresReference());
        model.addAttribute("addRefProjects", addRefList);
        model.addAttribute("projects", projectList);
        model.addAttribute("canUpdateSamples", canUpdateAllSamples);
        model.addAttribute("workflowName", workflowName);
        model.addAttribute("dynamicSourceRequired", description.requiresDynamicSource());
        final List<Map<String, Object>> dynamicSources = new ArrayList<>();
        if (description.requiresDynamicSource()) {
            TabularToolDataTable galaxyToolDataTable = new TabularToolDataTable();
            IridaWorkflowDynamicSourceGalaxy dynamicSource = new IridaWorkflowDynamicSourceGalaxy();
            for (IridaWorkflowParameter parameter : description.getParameters()) {
                if (parameter.isRequired() && parameter.hasDynamicSource()) {
                    try {
                        dynamicSource = parameter.getDynamicSource();
                    } catch (IridaWorkflowParameterException e) {
                        logger.debug("Dynamic Source error: ", e);
                    }
                    List<Object> parametersList = new ArrayList<>();
                    String dynamicSourceName;
                    Map<String, Object> toolDataTable = new HashMap<>();
                    try {
                        dynamicSourceName = dynamicSource.getName();
                        toolDataTable.put("id", dynamicSourceName);
                        toolDataTable.put("label", messageSource.getMessage("dynamicsource.label." + dynamicSourceName, null, locale));
                        toolDataTable.put("parameters", parametersList);
                        galaxyToolDataTable = galaxyToolDataService.getToolDataTable(dynamicSourceName);
                        List<String> labels = galaxyToolDataTable.getFieldsForColumn(dynamicSource.getDisplayColumn());
                        Iterator<String> labelsIterator = labels.iterator();
                        List<String> values = galaxyToolDataTable.getFieldsForColumn(dynamicSource.getParameterColumn());
                        Iterator<String> valuesIterator = values.iterator();
                        while (labelsIterator.hasNext() && valuesIterator.hasNext()) {
                            String label = labelsIterator.next();
                            String value = valuesIterator.next();
                            HashMap<String, String> toolDataTableFieldsMap = new HashMap<>();
                            toolDataTableFieldsMap.put("label", label);
                            toolDataTableFieldsMap.put("value", value);
                            toolDataTableFieldsMap.put("name", parameter.getName());
                            parametersList.add(toolDataTableFieldsMap);
                        }
                        dynamicSources.add(toolDataTable);
                    } catch (Exception e) {
                        logger.debug("Tool Data Table not found: ", e);
                    }
                }
            }
            model.addAttribute("dynamicSources", dynamicSources);
        }
        response = URL_GENERIC_PIPELINE;
    }
    return response;
}
Also used : ReferenceFile(ca.corefacility.bioinformatics.irida.model.project.ReferenceFile) Set(java.util.Set) User(ca.corefacility.bioinformatics.irida.model.user.User) 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) IridaWorkflowParameterException(ca.corefacility.bioinformatics.irida.exceptions.IridaWorkflowParameterException) IridaWorkflowParameter(ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowParameter) List(java.util.List) ArrayList(java.util.ArrayList) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) Join(ca.corefacility.bioinformatics.irida.model.joins.Join) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) TabularToolDataTable(com.github.jmchilton.blend4j.galaxy.beans.TabularToolDataTable) 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) Authentication(org.springframework.security.core.Authentication) 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) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

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