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