use of ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisFastQC 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.workflow.analysis.AnalysisFastQC in project irida by phac-nml.
the class SequencingObjectServiceImplIT method testCreateNotCompressedSequenceFile.
@Test
@WithMockUser(username = "fbristow", roles = "SEQUENCER")
public void testCreateNotCompressedSequenceFile() throws IOException, InterruptedException {
final Long expectedRevisionNumber = 1L;
SequenceFile sf = createSequenceFile("file1");
Path sequenceFile = sf.getFile();
SingleEndSequenceFile singleEndSequenceFile = new SingleEndSequenceFile(sf);
logger.trace("About to save the file.");
SequencingObject sequencingObject = asRole(Role.ROLE_SEQUENCER, "fbristow").objectService.create(singleEndSequenceFile);
logger.trace("Finished saving the file.");
assertNotNull("ID wasn't assigned.", sequencingObject.getId());
// Sleeping for a bit to let file processing run
Thread.sleep(10000);
// figure out what the version number of the sequence file is (should be
// 1; the file wasn't gzipped, but fastqc will have modified it.)
SequencingObject readObject = null;
do {
readObject = asRole(Role.ROLE_ADMIN, "admin").objectService.read(sequencingObject.getId());
sf = readObject.getFiles().iterator().next();
if (sf.getFileRevisionNumber() < expectedRevisionNumber) {
logger.info("Still waiting on thread to finish, having a bit of a sleep.");
Thread.sleep(1000);
}
} while (sf.getFileRevisionNumber() < expectedRevisionNumber);
assertEquals("Wrong version number after processing.", expectedRevisionNumber, sf.getFileRevisionNumber());
// verify the file checksum was taken properly
assertEquals("checksum should be equal", CHECKSUM, sf.getUploadSha256());
AnalysisFastQC analysis = asRole(Role.ROLE_ADMIN, "admin").analysisService.getFastQCAnalysisForSequenceFile(readObject, sf.getId());
assertNotNull("FastQCAnalysis should have been created for the file.", analysis);
Set<OverrepresentedSequence> overrepresentedSequences = analysis.getOverrepresentedSequences();
assertNotNull("No overrepresented sequences were found.", overrepresentedSequences);
assertEquals("Wrong number of overrepresented sequences were found.", 1, overrepresentedSequences.size());
OverrepresentedSequence overrepresentedSequence = overrepresentedSequences.iterator().next();
assertEquals("Sequence was not the correct sequence.", SEQUENCE, overrepresentedSequence.getSequence());
assertEquals("The count was not correct.", 2, overrepresentedSequence.getOverrepresentedSequenceCount());
assertEquals("The percent was not correct.", new BigDecimal("100.00"), overrepresentedSequence.getPercentage());
// confirm that the file structure is correct
Path idDirectory = baseDirectory.resolve(Paths.get(sf.getId().toString()));
assertTrue("Revision directory doesn't exist.", Files.exists(idDirectory.resolve(Paths.get(sf.getFileRevisionNumber().toString(), sequenceFile.getFileName().toString()))));
// no other files or directories should be beneath the ID directory
int fileCount = 0;
Iterator<Path> dir = Files.newDirectoryStream(idDirectory).iterator();
while (dir.hasNext()) {
dir.next();
fileCount++;
}
assertEquals("Wrong number of directories beneath the id directory", 1, fileCount);
}
use of ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisFastQC in project irida by phac-nml.
the class SequencingRunServiceImplIT method testAddDetachedRunToSequenceFile.
/**
* This test simulates a bug that happens from the REST API when uploading
* sequence files to samples, where a new sequence file is created, then
* detached from a transaction.
*
* @throws IOException
* @throws InterruptedException
*/
@Test
@WithMockUser(username = "fbristow", password = "password1", roles = "ADMIN")
public void testAddDetachedRunToSequenceFile() throws IOException, InterruptedException {
final String SEQUENCE = "ACGTACGTN";
final byte[] FASTQ_FILE_CONTENTS = ("@testread\n" + SEQUENCE + "\n+\n?????????\n@testread2\n" + SEQUENCE + "\n+\n?????????").getBytes();
Path p = Files.createTempFile(null, null);
Files.write(p, FASTQ_FILE_CONTENTS);
SequenceFile sf = new SequenceFile();
sf.setFile(p);
SingleEndSequenceFile so = new SingleEndSequenceFile(sf);
Sample sample = sampleService.read(1L);
SequencingRun run = miseqRunService.read(2L);
objectService.createSequencingObjectInSample(so, sample);
miseqRunService.addSequencingObjectToSequencingRun(run, so);
AnalysisFastQC analysis = null;
do {
try {
analysis = analysisService.getFastQCAnalysisForSequenceFile(so, sf.getId());
} catch (final EntityNotFoundException e) {
logger.info("Fastqc still isn't finished, sleeping a bit.");
Thread.sleep(1000);
}
} while (analysis == null);
assertNotNull("FastQC analysis should have been created for sequence file.", analysis);
}
use of ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisFastQC in project irida by phac-nml.
the class SampleServiceImpl method getTotalBasesForSample.
/**
* {@inheritDoc}
*/
@Override
@Transactional(readOnly = true)
@PreAuthorize("hasRole('ROLE_ADMIN') or hasPermission(#sample, 'canReadSample')")
public Long getTotalBasesForSample(Sample sample) throws SequenceFileAnalysisException {
checkNotNull(sample, "sample is null");
long totalBases = 0;
List<SampleSequencingObjectJoin> sequencesForSample = ssoRepository.getSequencesForSample(sample);
for (SampleSequencingObjectJoin join : sequencesForSample) {
for (SequenceFile sequenceFile : join.getObject().getFiles()) {
final AnalysisFastQC sequenceFileFastQC = analysisRepository.findFastqcAnalysisForSequenceFile(sequenceFile);
if (sequenceFileFastQC == null || sequenceFileFastQC.getTotalBases() == null) {
throw new SequenceFileAnalysisException("Missing FastQC analysis for SequenceFile [" + sequenceFile.getId() + "]");
}
totalBases += sequenceFileFastQC.getTotalBases();
}
}
return totalBases;
}
use of ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisFastQC 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