Search in sources :

Example 1 with CoverageQCEntry

use of ca.corefacility.bioinformatics.irida.model.sample.CoverageQCEntry in project irida by phac-nml.

the class CoverageFileProcessorTest method testBadCoverage.

@Test
public void testBadCoverage() {
    Project p = new Project();
    p.setGenomeSize(100L);
    p.setMinimumCoverage(5);
    SequenceFile file = new SequenceFile();
    SequencingObject o = new SingleEndSequenceFile(file);
    AnalysisFastQC fqc = mock(AnalysisFastQC.class);
    Long baseCount = 300L;
    when(analysisRepository.findFastqcAnalysisForSequenceFile(file)).thenReturn(fqc);
    when(fqc.getTotalBases()).thenReturn(baseCount);
    processor.process(o);
    ArgumentCaptor<CoverageQCEntry> qcCaptor = ArgumentCaptor.forClass(CoverageQCEntry.class);
    verify(qcEntryRepository, times(0)).delete(any(QCEntry.class));
    verify(qcEntryRepository).save(qcCaptor.capture());
    CoverageQCEntry qc = qcCaptor.getValue();
    qc.addProjectSettings(p);
    assertEquals("should show 3 times coverage", 3, qc.getCoverage());
    assertEquals("should be bad coverage", QCEntryStatus.NEGATIVE, qc.getStatus());
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) CoverageQCEntry(ca.corefacility.bioinformatics.irida.model.sample.CoverageQCEntry) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) CoverageQCEntry(ca.corefacility.bioinformatics.irida.model.sample.CoverageQCEntry) QCEntry(ca.corefacility.bioinformatics.irida.model.sample.QCEntry) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) AnalysisFastQC(ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisFastQC) Test(org.junit.Test)

Example 2 with CoverageQCEntry

use of ca.corefacility.bioinformatics.irida.model.sample.CoverageQCEntry in project irida by phac-nml.

the class CoverageFileProcessorTest method testRemoveExistingEntry.

@Test
public void testRemoveExistingEntry() {
    Project p = new Project();
    p.setGenomeSize(100L);
    p.setMinimumCoverage(2);
    SequenceFile file = new SequenceFile();
    SequencingObject o = new SingleEndSequenceFile(file);
    AnalysisFastQC fqc = mock(AnalysisFastQC.class);
    Long baseCount = 300L;
    QCEntry existingQc = new CoverageQCEntry();
    o.setQcEntries(Sets.newHashSet(existingQc));
    when(analysisRepository.findFastqcAnalysisForSequenceFile(file)).thenReturn(fqc);
    when(fqc.getTotalBases()).thenReturn(baseCount);
    processor.process(o);
    ArgumentCaptor<CoverageQCEntry> qcCaptor = ArgumentCaptor.forClass(CoverageQCEntry.class);
    verify(qcEntryRepository).delete(existingQc);
    verify(qcEntryRepository).save(qcCaptor.capture());
    CoverageQCEntry qc = qcCaptor.getValue();
    qc.addProjectSettings(p);
    assertEquals("should show 3 times coverage", 3, qc.getCoverage());
    assertEquals("should be positive coverage", QCEntryStatus.POSITIVE, qc.getStatus());
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) CoverageQCEntry(ca.corefacility.bioinformatics.irida.model.sample.CoverageQCEntry) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) CoverageQCEntry(ca.corefacility.bioinformatics.irida.model.sample.CoverageQCEntry) QCEntry(ca.corefacility.bioinformatics.irida.model.sample.QCEntry) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) AnalysisFastQC(ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisFastQC) Test(org.junit.Test)

Example 3 with CoverageQCEntry

use of ca.corefacility.bioinformatics.irida.model.sample.CoverageQCEntry in project irida by phac-nml.

the class CoverageFileProcessorTest method testGoodCoverage.

@Test
public void testGoodCoverage() {
    Project p = new Project();
    p.setGenomeSize(100L);
    p.setMinimumCoverage(2);
    SequenceFile file = new SequenceFile();
    SequencingObject o = new SingleEndSequenceFile(file);
    AnalysisFastQC fqc = mock(AnalysisFastQC.class);
    Long baseCount = 300L;
    when(analysisRepository.findFastqcAnalysisForSequenceFile(file)).thenReturn(fqc);
    when(fqc.getTotalBases()).thenReturn(baseCount);
    processor.process(o);
    ArgumentCaptor<CoverageQCEntry> qcCaptor = ArgumentCaptor.forClass(CoverageQCEntry.class);
    verify(qcEntryRepository, times(0)).delete(any(QCEntry.class));
    verify(qcEntryRepository).save(qcCaptor.capture());
    CoverageQCEntry qc = qcCaptor.getValue();
    qc.addProjectSettings(p);
    assertEquals("should show 3 times coverage", 3, qc.getCoverage());
    assertEquals("should be positive coverage", QCEntryStatus.POSITIVE, qc.getStatus());
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) CoverageQCEntry(ca.corefacility.bioinformatics.irida.model.sample.CoverageQCEntry) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) CoverageQCEntry(ca.corefacility.bioinformatics.irida.model.sample.CoverageQCEntry) QCEntry(ca.corefacility.bioinformatics.irida.model.sample.QCEntry) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) AnalysisFastQC(ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisFastQC) Test(org.junit.Test)

Example 4 with CoverageQCEntry

use of ca.corefacility.bioinformatics.irida.model.sample.CoverageQCEntry in project irida by phac-nml.

the class SequencingObjectServiceImplIT method testCoverage.

@Test
@WithMockUser(username = "admin", roles = "ADMIN")
public void testCoverage() throws IOException, InterruptedException {
    Project project = projectService.read(1L);
    project.setGenomeSize(3L);
    project.setMinimumCoverage(2);
    project = projectService.update(project);
    Sample s = sampleService.read(1L);
    SequenceFile sf = new SequenceFile();
    Path sequenceFile = Files.createTempFile("TEMPORARY-SEQUENCE-FILE", ".gz");
    OutputStream gzOut = new GZIPOutputStream(Files.newOutputStream(sequenceFile));
    gzOut.write(FASTQ_FILE_CONTENTS);
    gzOut.close();
    sf.setFile(sequenceFile);
    SingleEndSequenceFile so = new SingleEndSequenceFile(sf);
    objectService.createSequencingObjectInSample(so, s);
    SequencingRun mr = sequencingRunService.read(1L);
    sequencingRunService.addSequencingObjectToSequencingRun(mr, so);
    // Wait 10 seconds. file processing should have run by then.
    Thread.sleep(10000);
    Sample readSample = sampleService.read(s.getId());
    List<QCEntry> qcEntries = sampleService.getQCEntriesForSample(readSample);
    assertEquals("should be one qc entry", 1, qcEntries.size());
    QCEntry qcEntry = qcEntries.iterator().next();
    qcEntry.addProjectSettings(project);
    assertTrue("should be coverage entry", qcEntry instanceof CoverageQCEntry);
    assertEquals("qc should have passed", QCEntryStatus.POSITIVE, qcEntry.getStatus());
    assertEquals("should be 6x coverage", "6x", qcEntry.getMessage());
    project.setMinimumCoverage(10);
    project = projectService.update(project);
    // Wait 10 seconds. file processing should have run by then.
    Thread.sleep(10000);
    qcEntries = sampleService.getQCEntriesForSample(readSample);
    assertEquals("should be one qc entry", 1, qcEntries.size());
    qcEntry = qcEntries.iterator().next();
    qcEntry.addProjectSettings(project);
    assertTrue("should be coverage entry", qcEntry instanceof CoverageQCEntry);
    assertEquals("qc should have failed", QCEntryStatus.NEGATIVE, qcEntry.getStatus());
}
Also used : Path(java.nio.file.Path) Project(ca.corefacility.bioinformatics.irida.model.project.Project) CoverageQCEntry(ca.corefacility.bioinformatics.irida.model.sample.CoverageQCEntry) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) SequencingRun(ca.corefacility.bioinformatics.irida.model.run.SequencingRun) GZIPOutputStream(java.util.zip.GZIPOutputStream) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) GZIPOutputStream(java.util.zip.GZIPOutputStream) OutputStream(java.io.OutputStream) CoverageQCEntry(ca.corefacility.bioinformatics.irida.model.sample.CoverageQCEntry) FileProcessorErrorQCEntry(ca.corefacility.bioinformatics.irida.model.sample.FileProcessorErrorQCEntry) QCEntry(ca.corefacility.bioinformatics.irida.model.sample.QCEntry) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Example 5 with CoverageQCEntry

use of ca.corefacility.bioinformatics.irida.model.sample.CoverageQCEntry 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)

Aggregations

CoverageQCEntry (ca.corefacility.bioinformatics.irida.model.sample.CoverageQCEntry)6 Project (ca.corefacility.bioinformatics.irida.model.project.Project)5 QCEntry (ca.corefacility.bioinformatics.irida.model.sample.QCEntry)5 SequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile)5 SingleEndSequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)5 Test (org.junit.Test)5 SequencingObject (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject)4 AnalysisFastQC (ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisFastQC)4 SequencingRun (ca.corefacility.bioinformatics.irida.model.run.SequencingRun)2 FileProcessorErrorQCEntry (ca.corefacility.bioinformatics.irida.model.sample.FileProcessorErrorQCEntry)2 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)2 OutputStream (java.io.OutputStream)2 Path (java.nio.file.Path)2 GZIPOutputStream (java.util.zip.GZIPOutputStream)2 WithMockUser (org.springframework.security.test.context.support.WithMockUser)2 FileProcessor (ca.corefacility.bioinformatics.irida.processing.FileProcessor)1 AnalysisRepository (ca.corefacility.bioinformatics.irida.repositories.analysis.AnalysisRepository)1 QCEntryRepository (ca.corefacility.bioinformatics.irida.repositories.sample.QCEntryRepository)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1