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());
}
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());
}
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());
}
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());
}
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);
}
Aggregations