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;
}
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;
}
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());
}
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;
}
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;
}
Aggregations