Search in sources :

Example 1 with IridaWorkflowNotFoundException

use of ca.corefacility.bioinformatics.irida.exceptions.IridaWorkflowNotFoundException 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 IridaWorkflowNotFoundException

use of ca.corefacility.bioinformatics.irida.exceptions.IridaWorkflowNotFoundException 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 IridaWorkflowNotFoundException

use of ca.corefacility.bioinformatics.irida.exceptions.IridaWorkflowNotFoundException in project irida by phac-nml.

the class AssemblyFileProcessor method process.

/**
 * {@inheritDoc}
 */
@Override
@Transactional
public void process(SequencingObject sequencingObject) {
    logger.debug("Setting up automated assembly for sequence " + sequencingObject.getId());
    // assembly run by admin
    User admin = userRepository.loadUserByUsername("admin");
    // assembled
    if (sequencingObject instanceof SequenceFilePair) {
        IridaWorkflow defaultWorkflowByType;
        // get the workflow
        try {
            defaultWorkflowByType = workflowsService.getDefaultWorkflowByType(AnalysisType.ASSEMBLY_ANNOTATION);
        } catch (IridaWorkflowNotFoundException e) {
            throw new FileProcessorException("Cannot find assembly workflow", e);
        }
        UUID pipelineUUID = defaultWorkflowByType.getWorkflowIdentifier();
        // build an AnalysisSubmission
        Builder builder = new AnalysisSubmission.Builder(pipelineUUID);
        AnalysisSubmission submission = builder.inputFiles(Sets.newHashSet((SequenceFilePair) sequencingObject)).priority(AnalysisSubmission.Priority.LOW).name("Automated Assembly " + sequencingObject.toString()).updateSamples(true).build();
        submission.setSubmitter(admin);
        submission = submissionRepository.save(submission);
        // Associate the submission with the seqobject
        sequencingObject.setAutomatedAssembly(submission);
        objectRepository.save(sequencingObject);
        logger.debug("Automated assembly submission created for sequencing object " + sequencingObject.getId());
    } else {
        logger.warn("Could not assemble sequencing object " + sequencingObject.getId() + " because it's not paired end");
    }
}
Also used : IridaWorkflowNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.IridaWorkflowNotFoundException) SequenceFilePair(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair) FileProcessorException(ca.corefacility.bioinformatics.irida.processing.FileProcessorException) User(ca.corefacility.bioinformatics.irida.model.user.User) IridaWorkflow(ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow) Builder(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission.Builder) AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) UUID(java.util.UUID) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with IridaWorkflowNotFoundException

use of ca.corefacility.bioinformatics.irida.exceptions.IridaWorkflowNotFoundException in project irida by phac-nml.

the class SistrTypingFileProcessor method process.

/**
 * {@inheritDoc}
 */
@Override
public void process(SequencingObject sequencingObject) {
    logger.debug("Setting up SISTR typing for sequence " + sequencingObject.getId());
    User admin = userRepository.loadUserByUsername("admin");
    Project.AutomatedSISTRSetting automatedSISTRSetting = shouldTypeWithSISTR(sequencingObject);
    // assembled/typed.
    if (sequencingObject instanceof SequenceFilePair) {
        IridaWorkflow defaultWorkflowByType;
        // get the workflow
        try {
            defaultWorkflowByType = workflowsService.getDefaultWorkflowByType(AnalysisType.SISTR_TYPING);
        } catch (IridaWorkflowNotFoundException e) {
            throw new FileProcessorException("Cannot find assembly workflow", e);
        }
        UUID pipelineUUID = defaultWorkflowByType.getWorkflowIdentifier();
        // build an AnalysisSubmission
        Builder builder = new AnalysisSubmission.Builder(pipelineUUID);
        if (automatedSISTRSetting.equals(Project.AutomatedSISTRSetting.AUTO_METADATA)) {
            builder.updateSamples(true);
        } else if (automatedSISTRSetting.equals(Project.AutomatedSISTRSetting.AUTO)) {
            builder.updateSamples(false);
        }
        AnalysisSubmission submission = builder.inputFiles(Sets.newHashSet((SequenceFilePair) sequencingObject)).priority(AnalysisSubmission.Priority.LOW).name("Automated SISTR Typing " + sequencingObject.toString()).build();
        submission.setSubmitter(admin);
        submission = submissionRepository.save(submission);
        // Associate the submission with the seqobject
        sequencingObject.setSistrTyping(submission);
        objectRepository.save(sequencingObject);
        logger.debug("Automated SISTR typing submission created for sequencing object " + sequencingObject.getId());
    } else {
        logger.warn("Could not run SISTR typing for sequencing object " + sequencingObject.getId() + " because it's not paired end");
    }
}
Also used : IridaWorkflowNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.IridaWorkflowNotFoundException) Project(ca.corefacility.bioinformatics.irida.model.project.Project) SequenceFilePair(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair) FileProcessorException(ca.corefacility.bioinformatics.irida.processing.FileProcessorException) User(ca.corefacility.bioinformatics.irida.model.user.User) IridaWorkflow(ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow) Builder(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission.Builder) AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) UUID(java.util.UUID)

Example 5 with IridaWorkflowNotFoundException

use of ca.corefacility.bioinformatics.irida.exceptions.IridaWorkflowNotFoundException 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;
}
Also used : AnalysisType(ca.corefacility.bioinformatics.irida.model.enums.AnalysisType) IridaWorkflowNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.IridaWorkflowNotFoundException) ModelMap(org.springframework.ui.ModelMap) AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) IridaWorkflowDescription(ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowDescription) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) UUID(java.util.UUID) ResourceCollection(ca.corefacility.bioinformatics.irida.web.assembler.resource.ResourceCollection) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

IridaWorkflowNotFoundException (ca.corefacility.bioinformatics.irida.exceptions.IridaWorkflowNotFoundException)9 IridaWorkflow (ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow)7 AnalysisSubmission (ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)6 AnalysisType (ca.corefacility.bioinformatics.irida.model.enums.AnalysisType)4 SequenceFilePair (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair)4 IridaWorkflowDescription (ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowDescription)4 ImmutableMap (com.google.common.collect.ImmutableMap)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 EntityNotFoundException (ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException)3 Project (ca.corefacility.bioinformatics.irida.model.project.Project)3 User (ca.corefacility.bioinformatics.irida.model.user.User)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 UUID (java.util.UUID)3 DuplicateSampleException (ca.corefacility.bioinformatics.irida.exceptions.DuplicateSampleException)2 IridaWorkflowParameterException (ca.corefacility.bioinformatics.irida.exceptions.IridaWorkflowParameterException)2 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)2 SequencingObject (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject)2