Search in sources :

Example 21 with IridaWorkflow

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

the class IridaWorkflowsService method setDefaultWorkflow.

/**
 * Sets the given workflow as a default workflow for it's analysis type.
 *
 * @param workflowId
 *            The workflow id to set as default.
 * @throws IridaWorkflowNotFoundException
 *             If the given workflow cannot be found.
 * @throws IridaWorkflowDefaultException
 *             If the corresponding workflow type already has a default
 *             workflow set.
 */
public void setDefaultWorkflow(UUID workflowId) throws IridaWorkflowNotFoundException, IridaWorkflowDefaultException {
    checkNotNull(workflowId, "workflowId is null");
    IridaWorkflow iridaWorkflow = getIridaWorkflow(workflowId);
    AnalysisType analysisType = iridaWorkflow.getWorkflowDescription().getAnalysisType();
    if (defaultWorkflowForAnalysis.containsKey(analysisType)) {
        throw new IridaWorkflowDefaultException("Cannot set workflow " + workflowId + " as default, already exists default workflow for \"" + analysisType + "\"");
    } else {
        defaultWorkflowForAnalysis.put(analysisType, workflowId);
    }
}
Also used : AnalysisType(ca.corefacility.bioinformatics.irida.model.enums.AnalysisType) IridaWorkflow(ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow) IridaWorkflowDefaultException(ca.corefacility.bioinformatics.irida.exceptions.IridaWorkflowDefaultException)

Example 22 with IridaWorkflow

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

the class IridaWorkflowsService method getAllDefaultWorkflowsByType.

/**
 * Gets all of the default workflows for a given {@link Set} of
 * {@link AnalysisType}s.
 *
 * @param analysisTypes
 *            A {@link Set} of {@link AnalysisType}s.
 * @return A {@link Map} of {@link AnalysisType} to {@link IridaWorkflow}
 *         all the passed analysis types.
 * @throws IridaWorkflowNotFoundException
 *             If one of the analysis types does not have any associated
 *             workflows.
 */
public Map<AnalysisType, IridaWorkflow> getAllDefaultWorkflowsByType(Set<AnalysisType> analysisTypes) throws IridaWorkflowNotFoundException {
    checkNotNull(analysisTypes, "analysisTypes is null");
    Map<AnalysisType, IridaWorkflow> analysisTypeWorkflowsMap = Maps.newHashMap();
    for (AnalysisType analysisType : analysisTypes) {
        analysisTypeWorkflowsMap.put(analysisType, getDefaultWorkflowByType(analysisType));
    }
    return analysisTypeWorkflowsMap;
}
Also used : AnalysisType(ca.corefacility.bioinformatics.irida.model.enums.AnalysisType) IridaWorkflow(ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow)

Example 23 with IridaWorkflow

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

the class ToolsListExporter method getDefaultWorkflows.

private static Map<AnalysisType, IridaWorkflow> getDefaultWorkflows() throws IridaWorkflowNotFoundException {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    context.getEnvironment().setActiveProfiles("dev");
    context.register(new Class[] { IridaApiPropertyPlaceholderConfig.class, IridaWorkflowsConfig.class });
    context.refresh();
    IridaWorkflowsService iridaWorkflowsService = context.getBean(IridaWorkflowsService.class);
    Map<AnalysisType, IridaWorkflow> workflows = iridaWorkflowsService.getAllDefaultWorkflowsByType(Sets.newHashSet(AnalysisType.executableAnalysisTypes()));
    context.close();
    return workflows;
}
Also used : AnalysisType(ca.corefacility.bioinformatics.irida.model.enums.AnalysisType) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) IridaWorkflow(ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow) IridaWorkflowsService(ca.corefacility.bioinformatics.irida.service.workflow.IridaWorkflowsService)

Example 24 with IridaWorkflow

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

the class ToolsListExporter method main.

public static void main(String[] args) throws IridaWorkflowNotFoundException, JsonGenerationException, JsonMappingException, IOException {
    if (args.length != 1) {
        throw new RuntimeException("Error: invalid number of arguments \n" + usage);
    }
    Path toolsListOutput = Paths.get(args[0]);
    ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
    Map<AnalysisType, IridaWorkflow> workflows = getDefaultWorkflows();
    Set<IridaWorkflowToolRepository> uniqueToolRepositories = new HashSet<>();
    Map<String, Object> yamlMap = Maps.newHashMap();
    yamlMap.put("api_key", "<Galaxy Admin user API key>");
    yamlMap.put("galaxy_instance", "<IP address for target Galaxy instance>");
    List<Map<String, String>> tools = Lists.newArrayList();
    yamlMap.put("tools", tools);
    List<IridaWorkflow> workflowsSorted = workflows.values().stream().sorted(new Comparator<IridaWorkflow>() {

        @Override
        public int compare(IridaWorkflow o1, IridaWorkflow o2) {
            return o1.getWorkflowDescription().getName().compareTo(o2.getWorkflowDescription().getName());
        }
    }).collect(Collectors.toList());
    for (IridaWorkflow workflow : workflowsSorted) {
        logger.info("Adding tools for workflow " + workflow);
        String workflowName = workflow.getWorkflowDescription().getName();
        String workflowVersion = workflow.getWorkflowDescription().getVersion();
        tools.add(ImmutableMap.of(toolsSectionName, "### Tools for " + workflowName + " v" + workflowVersion + " ###"));
        for (IridaWorkflowToolRepository toolRepository : workflow.getWorkflowDescription().getToolRepositories()) {
            // Append trailing '/' to URL, so it becomes for example
            // http://example.com/galaxy-shed/
            // This is because other software (e.g. bioblend) assume a
            // Galaxy toolshed URL ends with a '/'
            // Otherwise, the end component of the path is stripped (e.g.,
            // becomes http://example.com)
            String toolRepositoryURLString = toolRepository.getUrl().toString();
            if (!toolRepositoryURLString.endsWith("/")) {
                toolRepositoryURLString += "/";
            }
            if (uniqueToolRepositories.contains(toolRepository)) {
                logger.info("Tool defined by " + toolRepository + " already exists, skipping ...");
            } else {
                uniqueToolRepositories.add(toolRepository);
                // @formatter:off
                tools.add(ImmutableMap.<String, String>builder().put("name", toolRepository.getName()).put("owner", toolRepository.getOwner()).put("tool_shed_url", toolRepositoryURLString).put("revision", toolRepository.getRevision()).put("tool_panel_section_id", defaultToolPanelId).build());
            // @formatter:on
            }
        }
    }
    // Bit of a hack, but does the job. Wanted to add a comment in the YAML
    // file for each tool section for readability but no YAML library
    // supports this. Instead, I do some pattern substitute/replace on a
    // special String variable "toolsSectionName" to generate the comments.
    String yaml = replaceAllWithCaptureGroup1(mapper.writeValueAsString(yamlMap), regexPattern, "\n  ", "\n");
    if (yaml.matches(toolsSectionName)) {
        throw new RuntimeException("Error: not all instances of \"" + toolsSectionName + "\" were replaced");
    }
    PrintWriter outputFileWriter = new PrintWriter(toolsListOutput.toFile());
    outputFileWriter.print(yaml);
    outputFileWriter.close();
    logger.info("Wrote tools list to: " + toolsListOutput.toAbsolutePath());
}
Also used : Path(java.nio.file.Path) AnalysisType(ca.corefacility.bioinformatics.irida.model.enums.AnalysisType) IridaWorkflow(ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow) Comparator(java.util.Comparator) YAMLFactory(com.fasterxml.jackson.dataformat.yaml.YAMLFactory) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IridaWorkflowToolRepository(ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowToolRepository) HashSet(java.util.HashSet) PrintWriter(java.io.PrintWriter)

Example 25 with IridaWorkflow

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

the class AnalysisExecutionServiceGalaxyAsync method prepareSubmission.

/**
 * Prepares the given {@link AnalysisSubmission} to be executed within an
 * execution manager. This will persist the submission within the database.
 *
 * @param analysisSubmission
 *            The {@link AnalysisSubmission} to prepare.
 * @return A {@link Future} with an {@link AnalysisSubmission} for the
 *         analysis submitted.
 * @throws IridaWorkflowNotFoundException
 *             If there was an issue getting a workflow.
 * @throws IOException
 *             If there was an issue reading the workflow.
 * @throws ExecutionManagerException
 *             If there was an issue preparing a workspace for the workflow.
 */
@Transactional
public Future<AnalysisSubmission> prepareSubmission(final AnalysisSubmission analysisSubmission) throws IridaWorkflowNotFoundException, IOException, ExecutionManagerException {
    checkNotNull(analysisSubmission, "analysisSubmission is null");
    checkNotNull(analysisSubmission.getId(), "analysisSubmission id is null");
    checkArgument(null == analysisSubmission.getRemoteAnalysisId(), "remote analyis id should be null");
    checkArgument(null == analysisSubmission.getRemoteWorkflowId(), "remoteWorkflowId should be null");
    IridaWorkflow iridaWorkflow = iridaWorkflowsService.getIridaWorkflow(analysisSubmission.getWorkflowId());
    IridaWorkflowStructure workflowStructure = iridaWorkflow.getWorkflowStructure();
    logger.debug("Preparing submission for " + analysisSubmission);
    String workflowId = galaxyWorkflowService.uploadGalaxyWorkflow(workflowStructure.getWorkflowFile());
    analysisSubmission.setRemoteWorkflowId(workflowId);
    logger.trace("Uploaded workflow for " + analysisSubmission + " to workflow with id=" + workflowId);
    String analysisId = workspaceService.prepareAnalysisWorkspace(analysisSubmission);
    logger.trace("Created Galaxy history for analysis " + " id=" + analysisId + ", " + analysisSubmission);
    analysisSubmission.setAnalysisState(AnalysisState.PREPARED);
    analysisSubmission.setRemoteWorkflowId(workflowId);
    analysisSubmission.setRemoteAnalysisId(analysisId);
    AnalysisSubmission analysisPrepared = analysisSubmissionService.update(analysisSubmission);
    return new AsyncResult<>(analysisPrepared);
}
Also used : IridaWorkflow(ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow) AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) IridaWorkflowStructure(ca.corefacility.bioinformatics.irida.model.workflow.structure.IridaWorkflowStructure) AsyncResult(org.springframework.scheduling.annotation.AsyncResult) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

IridaWorkflow (ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow)50 AnalysisSubmission (ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)27 Test (org.junit.Test)27 Path (java.nio.file.Path)25 History (com.github.jmchilton.blend4j.galaxy.beans.History)19 HistoriesClient (com.github.jmchilton.blend4j.galaxy.HistoriesClient)18 WorkflowsClient (com.github.jmchilton.blend4j.galaxy.WorkflowsClient)18 Workflow (com.github.jmchilton.blend4j.galaxy.beans.Workflow)18 WithMockUser (org.springframework.security.test.context.support.WithMockUser)18 AnalysisType (ca.corefacility.bioinformatics.irida.model.enums.AnalysisType)10 SequenceFilePair (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair)10 Analysis (ca.corefacility.bioinformatics.irida.model.workflow.analysis.Analysis)9 ArrayList (java.util.ArrayList)9 SingleEndSequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)8 IridaWorkflowDescription (ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowDescription)8 ToolsClient (com.github.jmchilton.blend4j.galaxy.ToolsClient)8 IridaWorkflowNotFoundException (ca.corefacility.bioinformatics.irida.exceptions.IridaWorkflowNotFoundException)7 PreparedWorkflowGalaxy (ca.corefacility.bioinformatics.irida.model.workflow.execution.galaxy.PreparedWorkflowGalaxy)7 WorkflowInputsGalaxy (ca.corefacility.bioinformatics.irida.model.workflow.execution.galaxy.WorkflowInputsGalaxy)6 HistoryContents (com.github.jmchilton.blend4j.galaxy.beans.HistoryContents)6