Search in sources :

Example 6 with AnalysisSubmission

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);
}
Also used : Analysis(ca.corefacility.bioinformatics.irida.model.workflow.analysis.Analysis) AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) AnalysisOutputFile(ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisOutputFile)

Example 7 with AnalysisSubmission

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;
}
Also used : AnalysisType(ca.corefacility.bioinformatics.irida.model.enums.AnalysisType) IridaWorkflow(ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow) AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) JsonParseException(com.fasterxml.jackson.core.JsonParseException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Path(java.nio.file.Path) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) IridaWorkflowNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.IridaWorkflowNotFoundException) Analysis(ca.corefacility.bioinformatics.irida.model.workflow.analysis.Analysis) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 8 with AnalysisSubmission

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));
}
Also used : AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)

Example 9 with AnalysisSubmission

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;
}
Also used : AnalysisState(ca.corefacility.bioinformatics.irida.model.enums.AnalysisState) AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) ExecutionManagerException(ca.corefacility.bioinformatics.irida.exceptions.ExecutionManagerException)

Example 10 with AnalysisSubmission

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));
}
Also used : Analysis(ca.corefacility.bioinformatics.irida.model.workflow.analysis.Analysis) AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) AnalysisOutputFile(ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisOutputFile)

Aggregations

AnalysisSubmission (ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)183 Test (org.junit.Test)121 WithMockUser (org.springframework.security.test.context.support.WithMockUser)95 IridaWorkflow (ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow)30 Analysis (ca.corefacility.bioinformatics.irida.model.workflow.analysis.Analysis)30 Path (java.nio.file.Path)25 SequenceFilePair (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair)23 HistoriesClient (com.github.jmchilton.blend4j.galaxy.HistoriesClient)20 Project (ca.corefacility.bioinformatics.irida.model.project.Project)19 History (com.github.jmchilton.blend4j.galaxy.beans.History)19 SingleEndSequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)18 AnalysisOutputFile (ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisOutputFile)18 WorkflowsClient (com.github.jmchilton.blend4j.galaxy.WorkflowsClient)18 Workflow (com.github.jmchilton.blend4j.galaxy.beans.Workflow)18 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)15 User (ca.corefacility.bioinformatics.irida.model.user.User)15 EntityNotFoundException (ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException)12 ExecutionManagerException (ca.corefacility.bioinformatics.irida.exceptions.ExecutionManagerException)12 ProjectAnalysisSubmissionJoin (ca.corefacility.bioinformatics.irida.model.workflow.submission.ProjectAnalysisSubmissionJoin)12 ToolExecution (ca.corefacility.bioinformatics.irida.model.workflow.analysis.ToolExecution)11