Search in sources :

Example 6 with AnalysisType

use of ca.corefacility.bioinformatics.irida.model.enums.AnalysisType 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 7 with AnalysisType

use of ca.corefacility.bioinformatics.irida.model.enums.AnalysisType 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 8 with AnalysisType

use of ca.corefacility.bioinformatics.irida.model.enums.AnalysisType 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 9 with AnalysisType

use of ca.corefacility.bioinformatics.irida.model.enums.AnalysisType in project irida by phac-nml.

the class RESTProjectAnalysisController method getProjectAnalysesByType.

/**
 * Get the list of {@link AnalysisSubmission}s for this {@link Project} by
 * type of analysis.
 *
 * @param projectId
 *            The {@link Project} to search.
 * @param type
 *            The analysis type to search for.
 * @return A list of {@link AnalysisSubmission}s for the given
 *         {@link Project} by the given type.
 * @throws IridaWorkflowNotFoundException
 *             If the {@link AnalysisSubmission} is linked to a workflow not
 *             found in IRIDA.
 */
@RequestMapping(value = "/api/projects/{projectId}/analyses/{type}", method = RequestMethod.GET)
public ModelMap getProjectAnalysesByType(@PathVariable Long projectId, @PathVariable String type) throws IridaWorkflowNotFoundException {
    logger.debug("Loading analyses for project [" + projectId + "] by type [" + type + "]");
    if (!RESTAnalysisSubmissionController.ANALYSIS_TYPES.containsKey(type)) {
        throw new EntityNotFoundException("Analysis type [" + type + "] not found");
    }
    AnalysisType analysisType = RESTAnalysisSubmissionController.ANALYSIS_TYPES.get(type);
    ModelMap modelMap = new ModelMap();
    Project p = projectService.read(projectId);
    Collection<AnalysisSubmission> analysisSubmissions = analysisSubmissionService.getAnalysisSubmissionsSharedToProject(p);
    ResourceCollection<AnalysisSubmission> analysisResources = new ResourceCollection<>(analysisSubmissions.size());
    for (AnalysisSubmission submission : analysisSubmissions) {
        IridaWorkflow iridaWorkflow = iridaWorkflowsService.getIridaWorkflow(submission.getWorkflowId());
        AnalysisType submissionAnalysisType = iridaWorkflow.getWorkflowDescription().getAnalysisType();
        if (analysisType.equals(submissionAnalysisType)) {
            submission.add(linkTo(methodOn(RESTAnalysisSubmissionController.class, Long.class).getResource(submission.getId())).withSelfRel());
            analysisResources.add(submission);
        }
    }
    analysisResources.add(linkTo(methodOn(RESTProjectsController.class, Long.class).getResource(projectId)).withRel(PROJECT_REL));
    analysisResources.add(linkTo(methodOn(RESTProjectAnalysisController.class, Long.class).getProjectAnalysesByType(projectId, type)).withSelfRel());
    modelMap.addAttribute(ANALYSIS_RESOURCES, analysisResources);
    return modelMap;
}
Also used : AnalysisType(ca.corefacility.bioinformatics.irida.model.enums.AnalysisType) Project(ca.corefacility.bioinformatics.irida.model.project.Project) IridaWorkflow(ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow) ModelMap(org.springframework.ui.ModelMap) AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) ResourceCollection(ca.corefacility.bioinformatics.irida.web.assembler.resource.ResourceCollection) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with AnalysisType

use of ca.corefacility.bioinformatics.irida.model.enums.AnalysisType 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)

Aggregations

AnalysisType (ca.corefacility.bioinformatics.irida.model.enums.AnalysisType)12 IridaWorkflow (ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow)10 AnalysisSubmission (ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)5 EntityNotFoundException (ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException)4 IridaWorkflowNotFoundException (ca.corefacility.bioinformatics.irida.exceptions.IridaWorkflowNotFoundException)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 Path (java.nio.file.Path)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 Analysis (ca.corefacility.bioinformatics.irida.model.workflow.analysis.Analysis)2 IridaWorkflowDescription (ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowDescription)2 ResourceCollection (ca.corefacility.bioinformatics.irida.web.assembler.resource.ResourceCollection)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Map (java.util.Map)2 UUID (java.util.UUID)2 ModelMap (org.springframework.ui.ModelMap)2 IridaWorkflowDefaultException (ca.corefacility.bioinformatics.irida.exceptions.IridaWorkflowDefaultException)1 AnalysisState (ca.corefacility.bioinformatics.irida.model.enums.AnalysisState)1 Project (ca.corefacility.bioinformatics.irida.model.project.Project)1 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)1 SequenceFilePair (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair)1