Search in sources :

Example 1 with AnalysisType

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

the class AnalysisController method getDetailsPage.

/**
 * View details about an individual analysis submission
 *
 * @param submissionId the ID of the submission
 * @param model        Model for the view
 * @param locale       User's locale
 * @return name of the details page view
 */
@RequestMapping(value = "/{submissionId}", produces = MediaType.TEXT_HTML_VALUE)
public String getDetailsPage(@PathVariable Long submissionId, Model model, Locale locale) {
    logger.trace("reading analysis submission " + submissionId);
    AnalysisSubmission submission = analysisSubmissionService.read(submissionId);
    model.addAttribute("analysisSubmission", submission);
    UUID workflowUUID = submission.getWorkflowId();
    logger.trace("Workflow ID is " + workflowUUID);
    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);
    }
    // Get the name of the workflow
    AnalysisType analysisType = iridaWorkflow.getWorkflowDescription().getAnalysisType();
    model.addAttribute("analysisType", analysisType);
    String viewName = getViewForAnalysisType(analysisType);
    String workflowName = messageSource.getMessage("workflow." + analysisType.toString() + ".title", null, locale);
    model.addAttribute("workflowName", workflowName);
    model.addAttribute("version", iridaWorkflow.getWorkflowDescription().getVersion());
    // Input files
    // - Paired
    Set<SequenceFilePair> inputFilePairs = sequencingObjectService.getSequencingObjectsOfTypeForAnalysisSubmission(submission, SequenceFilePair.class);
    model.addAttribute("paired_end", inputFilePairs);
    // Check if user can update analysis
    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    model.addAttribute("updatePermission", updateAnalysisPermission.isAllowed(authentication, submission));
    if (iridaWorkflow.getWorkflowDescription().requiresReference() && submission.getReferenceFile().isPresent()) {
        logger.debug("Adding reference file to page for submission with id [" + submission.getId() + "].");
        model.addAttribute("referenceFile", submission.getReferenceFile().get());
    } else {
        logger.debug("No reference file required for workflow.");
    }
    /*
		 * Preview information
		 */
    try {
        if (submission.getAnalysisState().equals(AnalysisState.COMPLETED)) {
            if (analysisType.equals(AnalysisType.PHYLOGENOMICS)) {
                tree(submission, model);
            } else if (analysisType.equals(AnalysisType.SISTR_TYPING)) {
                model.addAttribute("sistr", true);
            }
        }
    } catch (IOException e) {
        logger.error("Couldn't get preview for analysis", e);
    }
    return viewName;
}
Also used : IridaWorkflowNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.IridaWorkflowNotFoundException) AnalysisType(ca.corefacility.bioinformatics.irida.model.enums.AnalysisType) SequenceFilePair(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair) IridaWorkflow(ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow) Authentication(org.springframework.security.core.Authentication) AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException)

Example 2 with AnalysisType

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

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

the class IridaWorkflowsConfig method defaultIridaWorkflows.

/**
 * A set of workflow ids to use as defaults.
 *
 * @return A set of workflow ids to use as defaults.
 */
@Bean
public IridaWorkflowIdSet defaultIridaWorkflows() {
    Set<UUID> defaultWorkflowIds = Sets.newHashSet();
    for (AnalysisType analysisType : AnalysisType.values()) {
        String analysisDefaultProperyName = IRIDA_DEFAULT_WORKFLOW_PREFIX + "." + analysisType;
        logger.trace("Getting default workflow id from property '" + analysisDefaultProperyName + "'");
        String analysisDefaultId = environment.getProperty(analysisDefaultProperyName);
        if (analysisDefaultId == null) {
            logger.warn("No default workflow id associated with property '" + analysisDefaultProperyName + "'");
        } else {
            try {
                UUID id = UUID.fromString(analysisDefaultId);
                logger.debug("Adding default workflow " + analysisDefaultProperyName + "=" + analysisDefaultId);
                defaultWorkflowIds.add(id);
            } catch (IllegalArgumentException e) {
                logger.error("Default workflow id for " + analysisDefaultProperyName + "=" + analysisDefaultId + " is not a valid workflow id");
            }
        }
    }
    return new IridaWorkflowIdSet(defaultWorkflowIds);
}
Also used : AnalysisType(ca.corefacility.bioinformatics.irida.model.enums.AnalysisType) UUID(java.util.UUID) IridaWorkflowIdSet(ca.corefacility.bioinformatics.irida.model.workflow.config.IridaWorkflowIdSet) Bean(org.springframework.context.annotation.Bean)

Example 4 with AnalysisType

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

the class AnalysisWorkspaceServiceGalaxy method getAnalysisResults.

/**
 * {@inheritDoc}
 */
@Override
public Analysis getAnalysisResults(AnalysisSubmission analysisSubmission) throws ExecutionManagerException, IridaWorkflowNotFoundException, IOException, IridaWorkflowAnalysisTypeException {
    checkNotNull(analysisSubmission, "analysisSubmission is null");
    checkNotNull(analysisSubmission.getWorkflowId(), "workflowId is null");
    checkNotNull(analysisSubmission.getRemoteWorkflowId(), "remoteWorkflowId is null");
    Path outputDirectory = Files.createTempDirectory("analysis-output");
    logger.trace("Created temporary directory " + outputDirectory + " for analysis output files");
    IridaWorkflow iridaWorkflow = iridaWorkflowsService.getIridaWorkflow(analysisSubmission.getWorkflowId());
    String analysisId = analysisSubmission.getRemoteAnalysisId();
    Map<String, IridaWorkflowOutput> outputsMap = iridaWorkflow.getWorkflowDescription().getOutputsMap();
    String labelPrefix = getLabelPrefix(analysisSubmission, iridaWorkflow);
    Map<String, AnalysisOutputFile> analysisOutputFiles = Maps.newHashMap();
    for (String analysisOutputName : outputsMap.keySet()) {
        String outputFileName = outputsMap.get(analysisOutputName).getFileName();
        Dataset outputDataset = galaxyHistoriesService.getDatasetForFileInHistory(outputFileName, analysisId);
        AnalysisOutputFile analysisOutput = buildOutputFile(analysisId, labelPrefix, outputDataset, outputDirectory);
        analysisOutputFiles.put(analysisOutputName, analysisOutput);
    }
    AnalysisType analysisType = iridaWorkflow.getWorkflowDescription().getAnalysisType();
    return new Analysis(analysisId, analysisOutputFiles, analysisType);
}
Also used : Path(java.nio.file.Path) AnalysisType(ca.corefacility.bioinformatics.irida.model.enums.AnalysisType) IridaWorkflowOutput(ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowOutput) IridaWorkflow(ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow) Dataset(com.github.jmchilton.blend4j.galaxy.beans.Dataset) Analysis(ca.corefacility.bioinformatics.irida.model.workflow.analysis.Analysis) AnalysisOutputFile(ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisOutputFile)

Example 5 with AnalysisType

use of ca.corefacility.bioinformatics.irida.model.enums.AnalysisType 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);
    }
}
Also used : AnalysisType(ca.corefacility.bioinformatics.irida.model.enums.AnalysisType) IridaWorkflow(ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow) IridaWorkflowDefaultException(ca.corefacility.bioinformatics.irida.exceptions.IridaWorkflowDefaultException)

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