Search in sources :

Example 1 with FileProcessorException

use of ca.corefacility.bioinformatics.irida.processing.FileProcessorException 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 2 with FileProcessorException

use of ca.corefacility.bioinformatics.irida.processing.FileProcessorException 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 3 with FileProcessorException

use of ca.corefacility.bioinformatics.irida.processing.FileProcessorException in project irida by phac-nml.

the class ChecksumFileProcessor method process.

/**
 * Create an sha256sum for the files in a {@link SequencingObject} and save
 * it with the file.
 *
 * @param sequencingObject
 *            the {@link SequencingObject} to modify
 * @throws FileProcessorException
 *             a {@link FileProcessorException} if the file could not be
 *             processed
 */
@Override
public void process(SequencingObject sequencingObject) {
    Set<SequenceFile> files = sequencingObject.getFiles();
    for (SequenceFile file : files) {
        try (InputStream is = Files.newInputStream(file.getFile())) {
            String shaDigest = DigestUtils.sha256Hex(is);
            logger.trace("Checksum generated for file " + file.getId() + ": " + shaDigest);
            file.setUploadSha256(shaDigest);
            fileRepository.saveMetadata(file);
        } catch (IOException e) {
            throw new FileProcessorException("could not calculate checksum", e);
        }
    }
}
Also used : FileProcessorException(ca.corefacility.bioinformatics.irida.processing.FileProcessorException) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) InputStream(java.io.InputStream) IOException(java.io.IOException)

Example 4 with FileProcessorException

use of ca.corefacility.bioinformatics.irida.processing.FileProcessorException in project irida by phac-nml.

the class DefaultFileProcessingChain method launchChain.

/**
 * {@inheritDoc}
 */
@Override
public List<Exception> launchChain(Long sequencingObjectId) throws FileProcessorTimeoutException {
    List<Exception> ignoredExceptions = new ArrayList<>();
    Integer waiting = 0;
    // file has been persisted in the database.
    while (!sequencingObjectRepository.exists(sequencingObjectId)) {
        if (waiting > timeout) {
            throw new FileProcessorTimeoutException("Waiting for longer than " + sleepDuration * timeout + "ms, bailing out.");
        }
        waiting++;
        try {
            Thread.sleep(sleepDuration);
        } catch (InterruptedException e) {
        }
    }
    for (FileProcessor fileProcessor : fileProcessors) {
        try {
            if (fileProcessor.shouldProcessFile(sequencingObjectId)) {
                SequencingObject settledSequencingObject = getSettledSequencingObject(sequencingObjectId);
                fileProcessor.process(settledSequencingObject);
            }
        } catch (FileProcessorException e) {
            SequencingObject sequencingObject = sequencingObjectRepository.findOne(sequencingObjectId);
            qcRepository.save(new FileProcessorErrorQCEntry(sequencingObject));
            // execution (show the error, but proceed).
            if (fileProcessor.modifiesFile() || fastFail) {
                throw e;
            } else {
                ignoredExceptions.add(e);
                logger.error("File processor [" + fileProcessor.getClass() + "] failed to process [" + sequencingObjectId + "], but proceeding with the remaining processors because the " + "file would not be modified by the processor. Stack trace follows.", e);
            }
        }
    }
    return ignoredExceptions;
}
Also used : FileProcessorTimeoutException(ca.corefacility.bioinformatics.irida.exceptions.FileProcessorTimeoutException) FileProcessor(ca.corefacility.bioinformatics.irida.processing.FileProcessor) SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) FileProcessorException(ca.corefacility.bioinformatics.irida.processing.FileProcessorException) FileProcessorErrorQCEntry(ca.corefacility.bioinformatics.irida.model.sample.FileProcessorErrorQCEntry) ArrayList(java.util.ArrayList) FileProcessorException(ca.corefacility.bioinformatics.irida.processing.FileProcessorException) FileProcessorTimeoutException(ca.corefacility.bioinformatics.irida.exceptions.FileProcessorTimeoutException)

Example 5 with FileProcessorException

use of ca.corefacility.bioinformatics.irida.processing.FileProcessorException in project irida by phac-nml.

the class FastqcFileProcessor method processSingleFile.

/**
 * Process a single {@link SequenceFile}
 *
 * @param sequenceFile
 *            file to process
 * @throws FileProcessorException
 *             if an error occurs while processing
 */
private void processSingleFile(SequenceFile sequenceFile) throws FileProcessorException {
    Path fileToProcess = sequenceFile.getFile();
    AnalysisFastQC.AnalysisFastQCBuilder analysis = AnalysisFastQC.builder().executionManagerAnalysisId(EXECUTION_MANAGER_ANALYSIS_ID).description(messageSource.getMessage("fastqc.file.processor.analysis.description", null, LocaleContextHolder.getLocale()));
    try {
        uk.ac.babraham.FastQC.Sequence.SequenceFile fastQCSequenceFile = SequenceFactory.getSequenceFile(fileToProcess.toFile());
        BasicStats basicStats = new BasicStats();
        PerBaseQualityScores pbqs = new PerBaseQualityScores();
        PerSequenceQualityScores psqs = new PerSequenceQualityScores();
        OverRepresentedSeqs overRep = new OverRepresentedSeqs();
        QCModule[] moduleList = new QCModule[] { basicStats, pbqs, psqs, overRep };
        logger.debug("Launching FastQC analysis modules on all sequences.");
        while (fastQCSequenceFile.hasNext()) {
            Sequence sequence = fastQCSequenceFile.next();
            for (QCModule module : moduleList) {
                module.processSequence(sequence);
            }
        }
        logger.debug("Finished FastQC analysis modules.");
        handleBasicStats(basicStats, analysis);
        handlePerBaseQualityScores(pbqs, analysis);
        handlePerSequenceQualityScores(psqs, analysis);
        handleDuplicationLevel(overRep.duplicationLevelModule(), analysis);
        Set<OverrepresentedSequence> overrepresentedSequences = handleOverRepresentedSequences(overRep);
        logger.trace("Saving FastQC analysis.");
        analysis.overrepresentedSequences(overrepresentedSequences);
        sequenceFile.setFastQCAnalysis(analysis.build());
        sequenceFileRepository.saveMetadata(sequenceFile);
    } catch (Exception e) {
        logger.error("FastQC failed to process the sequence file. Stack trace follows.", e);
        throw new FileProcessorException("FastQC failed to parse the sequence file.", e);
    }
}
Also used : Path(java.nio.file.Path) Sequence(uk.ac.babraham.FastQC.Sequence.Sequence) OverrepresentedSequence(ca.corefacility.bioinformatics.irida.model.sequenceFile.OverrepresentedSequence) AnalysisFastQC(ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisFastQC) FileProcessorException(ca.corefacility.bioinformatics.irida.processing.FileProcessorException) IOException(java.io.IOException) QCModule(uk.ac.babraham.FastQC.Modules.QCModule) PerBaseQualityScores(uk.ac.babraham.FastQC.Modules.PerBaseQualityScores) FileProcessorException(ca.corefacility.bioinformatics.irida.processing.FileProcessorException) OverRepresentedSeqs(uk.ac.babraham.FastQC.Modules.OverRepresentedSeqs) AnalysisFastQCBuilder(ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisFastQC.AnalysisFastQCBuilder) PerSequenceQualityScores(uk.ac.babraham.FastQC.Modules.PerSequenceQualityScores) BasicStats(uk.ac.babraham.FastQC.Modules.BasicStats) OverrepresentedSequence(ca.corefacility.bioinformatics.irida.model.sequenceFile.OverrepresentedSequence)

Aggregations

FileProcessorException (ca.corefacility.bioinformatics.irida.processing.FileProcessorException)8 IOException (java.io.IOException)3 FileProcessorTimeoutException (ca.corefacility.bioinformatics.irida.exceptions.FileProcessorTimeoutException)2 IridaWorkflowNotFoundException (ca.corefacility.bioinformatics.irida.exceptions.IridaWorkflowNotFoundException)2 SequenceFilePair (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair)2 User (ca.corefacility.bioinformatics.irida.model.user.User)2 IridaWorkflow (ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow)2 AnalysisSubmission (ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)2 Builder (ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission.Builder)2 FileProcessingChain (ca.corefacility.bioinformatics.irida.processing.FileProcessingChain)2 DefaultFileProcessingChain (ca.corefacility.bioinformatics.irida.processing.impl.DefaultFileProcessingChain)2 Path (java.nio.file.Path)2 UUID (java.util.UUID)2 Test (org.junit.Test)2 Project (ca.corefacility.bioinformatics.irida.model.project.Project)1 FileProcessorErrorQCEntry (ca.corefacility.bioinformatics.irida.model.sample.FileProcessorErrorQCEntry)1 QCEntry (ca.corefacility.bioinformatics.irida.model.sample.QCEntry)1 OverrepresentedSequence (ca.corefacility.bioinformatics.irida.model.sequenceFile.OverrepresentedSequence)1 SequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile)1 SequencingObject (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject)1