use of ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission in project irida by phac-nml.
the class AnalysisController method getAjaxDownloadAnalysisSubmission.
/**
* Download all output files from an {@link AnalysisSubmission}
*
* @param analysisSubmissionId Id for a {@link AnalysisSubmission}
* @param response {@link HttpServletResponse}
*/
@RequestMapping(value = "/ajax/download/{analysisSubmissionId}", produces = MediaType.APPLICATION_JSON_VALUE)
public void getAjaxDownloadAnalysisSubmission(@PathVariable Long analysisSubmissionId, HttpServletResponse response) {
AnalysisSubmission analysisSubmission = analysisSubmissionService.read(analysisSubmissionId);
Analysis analysis = analysisSubmission.getAnalysis();
Set<AnalysisOutputFile> files = analysis.getAnalysisOutputFiles();
FileUtilities.createAnalysisOutputFileZippedResponse(response, analysisSubmission.getName(), files);
}
use of ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission in project irida by phac-nml.
the class AnalysisController method getSistrAnalysis.
/**
* Get the sistr analysis information to display
*
* @param id ID of the analysis submission
* @return Json results for the SISTR analysis
*/
@SuppressWarnings("resource")
@RequestMapping("/ajax/sistr/{id}")
@ResponseBody
public Map<String, Object> getSistrAnalysis(@PathVariable Long id) {
AnalysisSubmission submission = analysisSubmissionService.read(id);
Collection<Sample> samples = sampleService.getSamplesForAnalysisSubmission(submission);
Map<String, Object> result = ImmutableMap.of("parse_results_error", true);
final String sistrFileKey = "sistr-predictions";
// Get details about the workflow
UUID workflowUUID = submission.getWorkflowId();
IridaWorkflow iridaWorkflow;
try {
iridaWorkflow = workflowsService.getIridaWorkflow(workflowUUID);
} catch (IridaWorkflowNotFoundException e) {
logger.error("Error finding workflow, ", e);
throw new EntityNotFoundException("Couldn't find workflow for submission " + submission.getId(), e);
}
AnalysisType analysisType = iridaWorkflow.getWorkflowDescription().getAnalysisType();
if (analysisType.equals(AnalysisType.SISTR_TYPING)) {
Analysis analysis = submission.getAnalysis();
Path path = analysis.getAnalysisOutputFile(sistrFileKey).getFile();
try {
String json = new Scanner(new BufferedReader(new FileReader(path.toFile()))).useDelimiter("\\Z").next();
// verify file is proper json file
ObjectMapper mapper = new ObjectMapper();
List<Map<String, Object>> sistrResults = mapper.readValue(json, new TypeReference<List<Map<String, Object>>>() {
});
if (sistrResults.size() > 0) {
// should only ever be one sample for these results
if (samples.size() == 1) {
Sample sample = samples.iterator().next();
result = sistrResults.get(0);
result.put("parse_results_error", false);
result.put("sample_name", sample.getSampleName());
} else {
logger.error("Invalid number of associated samles for submission " + submission);
}
} else {
logger.error("SISTR results for file [" + path + "] are not correctly formatted");
}
} catch (FileNotFoundException e) {
logger.error("File [" + path + "] not found", e);
} catch (JsonParseException | JsonMappingException e) {
logger.error("Error attempting to parse file [" + path + "] as JSON", e);
} catch (IOException e) {
logger.error("Error reading file [" + path + "]", e);
}
}
return result;
}
use of ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission in project irida by phac-nml.
the class AnalysisController method deleteAjaxAnalysisSubmission.
// ************************************************************************************************
// AJAX
// ************************************************************************************************
/**
* Delete an {@link AnalysisSubmission} by id.
*
* @param analysisSubmissionId the submission ID to delete.
* @param locale Locale of the logged in user
* @return A message stating the submission was deleted
*/
@RequestMapping("/ajax/delete/{analysisSubmissionId}")
@ResponseBody
public Map<String, String> deleteAjaxAnalysisSubmission(@PathVariable Long analysisSubmissionId, final Locale locale) {
final AnalysisSubmission deletedSubmission = analysisSubmissionService.read(analysisSubmissionId);
analysisSubmissionService.delete(analysisSubmissionId);
return ImmutableMap.of("result", messageSource.getMessage("analysis.delete.message", new Object[] { deletedSubmission.getLabel() }, locale));
}
use of ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission in project irida by phac-nml.
the class AnalysisController method getAjaxStatusUpdateForAnalysisSubmission.
/**
* Get the current status for a given {@link AnalysisSubmission}
*
* @param submissionId The {@link UUID} id for a given {@link AnalysisSubmission}
* @param locale The users current {@link Locale}
* @return {@link HashMap} containing the status and the percent complete for the {@link AnalysisSubmission}
*/
@RequestMapping(value = "/ajax/status/{submissionId}", produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public Map<String, String> getAjaxStatusUpdateForAnalysisSubmission(@PathVariable Long submissionId, Locale locale) {
Map<String, String> result = new HashMap<>();
AnalysisSubmission analysisSubmission = analysisSubmissionService.read(submissionId);
AnalysisState state = analysisSubmission.getAnalysisState();
result.put("state", state.toString());
result.put("stateLang", messageSource.getMessage("analysis.state." + state.toString(), null, locale));
if (!state.equals(AnalysisState.ERROR)) {
float percentComplete = 0;
try {
percentComplete = analysisSubmissionService.getPercentCompleteForAnalysisSubmission(analysisSubmission.getId());
result.put("percentComplete", Float.toString(percentComplete));
} catch (ExecutionManagerException e) {
logger.error("Error getting the percentage complete", e);
result.put("percentageComplete", "");
}
}
return result;
}
use of ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission in project irida by phac-nml.
the class AnalysisController method getNewickForAnalysis.
/**
* Get a newick file associated with a specific {@link AnalysisSubmission}.
*
* @param submissionId {@link Long} id for an {@link AnalysisSubmission}
* @return {@link Map} containing the newick file contents.
* @throws IOException {@link IOException} if the newick file is not found
*/
@RequestMapping("/ajax/{submissionId}/newick")
@ResponseBody
public Map<String, Object> getNewickForAnalysis(@PathVariable Long submissionId) throws IOException {
final String treeFileKey = "tree";
AnalysisSubmission submission = analysisSubmissionService.read(submissionId);
Analysis analysis = submission.getAnalysis();
AnalysisOutputFile file = analysis.getAnalysisOutputFile(treeFileKey);
List<String> lines = Files.readAllLines(file.getFile());
return ImmutableMap.of("newick", lines.get(0));
}
Aggregations