Search in sources :

Example 26 with SequencingObject

use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject in project irida by phac-nml.

the class CoverageFileProcessor method process.

@Override
public void process(SequencingObject sequencingObject) {
    logger.trace("Counting coverage for file " + sequencingObject);
    if (sequencingObject.getQcEntries() != null) {
        // remove any existing coverage entries
        sequencingObject.getQcEntries().stream().filter(q -> q instanceof CoverageQCEntry).forEach(q -> qcEntryRepository.delete(q));
    }
    // count the total bases
    long totalBases = sequencingObject.getFiles().stream().mapToLong(f -> {
        AnalysisFastQC fastqc = analysisRepository.findFastqcAnalysisForSequenceFile(f);
        return fastqc.getTotalBases();
    }).sum();
    // save the entry
    CoverageQCEntry coverageQCEntry = new CoverageQCEntry(sequencingObject, totalBases);
    qcEntryRepository.save(coverageQCEntry);
}
Also used : Component(org.springframework.stereotype.Component) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) AnalysisFastQC(ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisFastQC) Autowired(org.springframework.beans.factory.annotation.Autowired) AnalysisRepository(ca.corefacility.bioinformatics.irida.repositories.analysis.AnalysisRepository) CoverageQCEntry(ca.corefacility.bioinformatics.irida.model.sample.CoverageQCEntry) SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) Project(ca.corefacility.bioinformatics.irida.model.project.Project) QCEntryRepository(ca.corefacility.bioinformatics.irida.repositories.sample.QCEntryRepository) FileProcessor(ca.corefacility.bioinformatics.irida.processing.FileProcessor) CoverageQCEntry(ca.corefacility.bioinformatics.irida.model.sample.CoverageQCEntry) AnalysisFastQC(ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisFastQC)

Example 27 with SequencingObject

use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject in project irida by phac-nml.

the class DefaultFileProcessingChain method getSettledSequencingObject.

/**
 * Checks the {@link SequenceFile}s for the given {@link SequencingObject}
 * to see if it's files are in the place they should be. Since there's lots
 * of saves going on during the {@link FileProcessingChain} the transaction
 * might not be complete in the time the file is first read.
 *
 * @param sequencingObjectId
 *            the id of the {@link SequencingObject} to check
 * @return the settled {@link SequencingObject}
 * @throws FileProcessorTimeoutException
 *             if the files don't settle in the configured timeout
 */
private SequencingObject getSettledSequencingObject(Long sequencingObjectId) throws FileProcessorTimeoutException {
    boolean filesNotSettled = true;
    Integer waiting = 0;
    SequencingObject sequencingObject;
    do {
        if (waiting > timeout) {
            throw new FileProcessorTimeoutException("Waiting for longer than " + sleepDuration * timeout + "ms, bailing out.  File id " + sequencingObjectId);
        }
        waiting++;
        try {
            Thread.sleep(sleepDuration);
        } catch (InterruptedException e) {
        }
        sequencingObject = sequencingObjectRepository.findOne(sequencingObjectId);
        Set<SequenceFile> files = sequencingObject.getFiles();
        filesNotSettled = files.stream().anyMatch(f -> {
            return !Files.exists(f.getFile());
        });
    } while (filesNotSettled);
    return sequencingObject;
}
Also used : Arrays(java.util.Arrays) Logger(org.slf4j.Logger) Files(java.nio.file.Files) FileProcessorException(ca.corefacility.bioinformatics.irida.processing.FileProcessorException) SequencingObjectRepository(ca.corefacility.bioinformatics.irida.repositories.sequencefile.SequencingObjectRepository) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) QCEntryRepository(ca.corefacility.bioinformatics.irida.repositories.sample.QCEntryRepository) ArrayList(java.util.ArrayList) FileProcessor(ca.corefacility.bioinformatics.irida.processing.FileProcessor) FileProcessorErrorQCEntry(ca.corefacility.bioinformatics.irida.model.sample.FileProcessorErrorQCEntry) List(java.util.List) FileProcessorTimeoutException(ca.corefacility.bioinformatics.irida.exceptions.FileProcessorTimeoutException) FileProcessingChain(ca.corefacility.bioinformatics.irida.processing.FileProcessingChain) FileProcessorTimeoutException(ca.corefacility.bioinformatics.irida.exceptions.FileProcessorTimeoutException) SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile)

Example 28 with SequencingObject

use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject in project irida by phac-nml.

the class SistrTypingFileProcessor method shouldTypeWithSISTR.

/**
 * Check whether any {@link Project} associated with the
 * {@link SequencingObject} is set to type with SISTR.
 *
 * @param object {@link SequencingObject} to check to type with SISTR.
 * @return true if it should type with SISTR, false otherwise
 */
private Project.AutomatedSISTRSetting shouldTypeWithSISTR(SequencingObject object) {
    Project.AutomatedSISTRSetting type = Project.AutomatedSISTRSetting.OFF;
    SampleSequencingObjectJoin sampleForSequencingObject = ssoRepository.getSampleForSequencingObject(object);
    /*
		 * This is something that should only ever happen in tests, but added
		 * check with a warning
		 */
    if (sampleForSequencingObject != null) {
        List<Join<Project, Sample>> projectForSample = psjRepository.getProjectForSample(sampleForSequencingObject.getSubject());
        Set<Project.AutomatedSISTRSetting> sistrOptions = projectForSample.stream().map(j -> j.getSubject().getSistrTypingUploads()).collect(Collectors.toSet());
        if (sistrOptions.contains(Project.AutomatedSISTRSetting.AUTO_METADATA)) {
            return Project.AutomatedSISTRSetting.AUTO_METADATA;
        } else if (sistrOptions.contains(Project.AutomatedSISTRSetting.AUTO))
            return Project.AutomatedSISTRSetting.AUTO;
    } else {
        logger.warn("Cannot find sample for sequencing object.  Not typing with SISTR");
    }
    return type;
}
Also used : ProjectSampleJoinRepository(ca.corefacility.bioinformatics.irida.repositories.joins.project.ProjectSampleJoinRepository) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) Join(ca.corefacility.bioinformatics.irida.model.joins.Join) SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) AnalysisType(ca.corefacility.bioinformatics.irida.model.enums.AnalysisType) FileProcessor(ca.corefacility.bioinformatics.irida.processing.FileProcessor) UserRepository(ca.corefacility.bioinformatics.irida.repositories.user.UserRepository) Logger(org.slf4j.Logger) IridaWorkflowNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.IridaWorkflowNotFoundException) AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) FileProcessorException(ca.corefacility.bioinformatics.irida.processing.FileProcessorException) SequencingObjectRepository(ca.corefacility.bioinformatics.irida.repositories.sequencefile.SequencingObjectRepository) IridaWorkflowsService(ca.corefacility.bioinformatics.irida.service.workflow.IridaWorkflowsService) SequenceFilePair(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair) Set(java.util.Set) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) SampleSequencingObjectJoinRepository(ca.corefacility.bioinformatics.irida.repositories.joins.sample.SampleSequencingObjectJoinRepository) Project(ca.corefacility.bioinformatics.irida.model.project.Project) Sets(com.google.common.collect.Sets) List(java.util.List) Component(org.springframework.stereotype.Component) User(ca.corefacility.bioinformatics.irida.model.user.User) Builder(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission.Builder) AnalysisSubmissionRepository(ca.corefacility.bioinformatics.irida.repositories.analysis.submission.AnalysisSubmissionRepository) Transactional(org.springframework.transaction.annotation.Transactional) IridaWorkflow(ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow) Project(ca.corefacility.bioinformatics.irida.model.project.Project) Join(ca.corefacility.bioinformatics.irida.model.joins.Join) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin)

Example 29 with SequencingObject

use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject in project irida by phac-nml.

the class SequenceFilePairConcatenator method concatenateFiles.

/**
 * {@inheritDoc}
 */
@Override
public SequenceFilePair concatenateFiles(List<? extends SequencingObject> toConcatenate, String filename) throws ConcatenateException {
    // create the filenames with F/R for the forward and reverse files
    String forwardName = filename + "_R1.fastq";
    String reverseName = filename + "_R2.fastq";
    Path forwardFile;
    Path reverseFile;
    try {
        // create a temp directory for the new files
        Path tempDirectory = Files.createTempDirectory(null);
        forwardFile = tempDirectory.resolve(forwardName);
        reverseFile = tempDirectory.resolve(reverseName);
        // create temp files
        forwardFile = Files.createFile(forwardFile);
        reverseFile = Files.createFile(reverseFile);
    } catch (IOException e) {
        throw new ConcatenateException("Could not create temporary files", e);
    }
    // for each file concatenate the forward and reverse files
    for (SequencingObject f : toConcatenate) {
        SequenceFilePair pair = (SequenceFilePair) f;
        SequenceFile forwardSequenceFile = pair.getForwardSequenceFile();
        SequenceFile reverseSequenceFile = pair.getReverseSequenceFile();
        appendToFile(forwardFile, forwardSequenceFile);
        appendToFile(reverseFile, reverseSequenceFile);
    }
    // create new SequenceFiles
    SequenceFile forward = new SequenceFile(forwardFile);
    SequenceFile reverse = new SequenceFile(reverseFile);
    // create the new pair
    SequenceFilePair sequenceFilePair = new SequenceFilePair(forward, reverse);
    return sequenceFilePair;
}
Also used : Path(java.nio.file.Path) SequenceFilePair(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair) SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) IOException(java.io.IOException) ConcatenateException(ca.corefacility.bioinformatics.irida.exceptions.ConcatenateException)

Example 30 with SequencingObject

use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject in project irida by phac-nml.

the class SingleEndSequenceFileConcatenator method concatenateFiles.

/**
 * {@inheritDoc}
 */
@Override
public SingleEndSequenceFile concatenateFiles(List<? extends SequencingObject> toConcatenate, String filename) throws ConcatenateException {
    Path tempFile;
    // create the filename with extension
    filename = filename + ".fastq";
    try {
        // create a temp directory and temp file
        Path tempDirectory = Files.createTempDirectory(null);
        tempFile = tempDirectory.resolve(filename);
        tempFile = Files.createFile(tempFile);
    } catch (IOException e) {
        throw new ConcatenateException("Could not create temporary files", e);
    }
    // for each file concatenate the file
    for (SequencingObject f : toConcatenate) {
        SingleEndSequenceFile single = (SingleEndSequenceFile) f;
        SequenceFile forwardSequenceFile = single.getSequenceFile();
        appendToFile(tempFile, forwardSequenceFile);
    }
    // create the new sequencefile and object
    SequenceFile forward = new SequenceFile(tempFile);
    SingleEndSequenceFile seqObject = new SingleEndSequenceFile(forward);
    return seqObject;
}
Also used : Path(java.nio.file.Path) SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) IOException(java.io.IOException) ConcatenateException(ca.corefacility.bioinformatics.irida.exceptions.ConcatenateException) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)

Aggregations

SequencingObject (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject)61 SingleEndSequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)29 SequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile)25 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)24 Test (org.junit.Test)24 SampleSequencingObjectJoin (ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin)16 SequenceFilePair (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair)14 WithMockUser (org.springframework.security.test.context.support.WithMockUser)14 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)12 Project (ca.corefacility.bioinformatics.irida.model.project.Project)11 AnalysisFastQC (ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisFastQC)11 AnalysisSubmission (ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)10 SequencingRun (ca.corefacility.bioinformatics.irida.model.run.SequencingRun)8 Path (java.nio.file.Path)8 ModelMap (org.springframework.ui.ModelMap)8 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)6 Transactional (org.springframework.transaction.annotation.Transactional)6 IOException (java.io.IOException)5 List (java.util.List)5 Logger (org.slf4j.Logger)5