use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile in project irida by phac-nml.
the class SequencingObjectServiceImplIT method testCreateSequenceFileInSample.
@Test
@WithMockUser(username = "fbristow", roles = "SEQUENCER")
public void testCreateSequenceFileInSample() throws IOException, InterruptedException {
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);
// Sleeping for a bit to let file processing run
Thread.sleep(10000);
Sample readSample = sampleService.read(s.getId());
List<QCEntry> qcEntries = sampleService.getQCEntriesForSample(readSample);
assertEquals("should be one qc entries", 1, qcEntries.size());
QCEntry qcEntry = qcEntries.iterator().next();
assertTrue("should be coverage entry", qcEntry instanceof CoverageQCEntry);
CoverageQCEntry coverage = (CoverageQCEntry) qcEntry;
assertEquals("should be 18 bases", 18, coverage.getTotalBases());
}
use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile in project irida by phac-nml.
the class SequencingObjectServiceImplIT method testCreateCompressedSequenceFile.
@Test
@WithMockUser(username = "fbristow", roles = "SEQUENCER")
public void testCreateCompressedSequenceFile() throws IOException, InterruptedException {
final Long expectedRevisionNumber = 2L;
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 singleEndSequenceFile = new SingleEndSequenceFile(sf);
logger.trace("About to save the file.");
SequencingObject sequencingObject = 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
// 2; the file was gzipped)
// get the MOST RECENT version of the sequence file from the database
// (it will have been modified outside of the create method.)
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());
assertFalse("File name is still gzipped.", sf.getFile().getFileName().toString().endsWith(".gz"));
AnalysisFastQC analysis = asRole(Role.ROLE_ADMIN, "admin").analysisService.getFastQCAnalysisForSequenceFile(readObject, sf.getId());
// verify the file checksum was taken properly
assertEquals("checksum should be equal", ZIPPED_CHECKSUM, sf.getUploadSha256());
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
String filename = sequenceFile.getFileName().toString();
filename = filename.substring(0, filename.lastIndexOf('.'));
Path idDirectory = baseDirectory.resolve(Paths.get(sf.getId().toString()));
assertTrue("Revision directory doesn't exist.", Files.exists(idDirectory.resolve(Paths.get(sf.getFileRevisionNumber().toString(), filename))));
// 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", 2, fileCount);
}
use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile in project irida by phac-nml.
the class SequencingRunServiceImplIT method testAddSequenceFileToMiseqRun.
private void testAddSequenceFileToMiseqRun() throws IOException, InterruptedException {
SequencingRun miseqRun = miseqRunService.read(1L);
// we can't actually know a file name in the XML file that we use to
// populate the database for these tests, so the files don't exist
// anywhere. Create a new temp file and update that in the database
// prior to adding a file to a miseq run so that we have something there
// that we can link to.
Path sequenceFile = Files.createTempFile(null, null);
Files.write(sequenceFile, FASTQ_FILE_CONTENTS);
SequenceFile sf = new SequenceFile(sequenceFile);
SequencingObject so = new SingleEndSequenceFile(sf);
so = objectService.create(so);
miseqRunService.addSequencingObjectToSequencingRun(miseqRun, so);
SequencingRun saved = miseqRunService.read(1L);
SequencingObject readObject = objectService.read(so.getId());
Set<SequencingObject> sequencingObjectsForSequencingRun = objectService.getSequencingObjectsForSequencingRun(saved);
assertTrue("Saved miseq run should have seqence file", sequencingObjectsForSequencingRun.contains(so));
if (SecurityContextHolder.getContext().getAuthentication().getAuthorities().stream().anyMatch(auth -> auth.getAuthority().equals("ROLE_ADMIN"))) {
AnalysisFastQC analysis = null;
do {
try {
readObject = objectService.read(so.getId());
SequenceFile readFile = readObject.getFiles().iterator().next();
analysis = analysisService.getFastQCAnalysisForSequenceFile(readObject, readFile.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 uploaded file.", analysis);
}
}
use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile in project irida by phac-nml.
the class SequencingObjectServiceTest method testCreateSequenceFileInSampleWrongType.
@Test(expected = IllegalArgumentException.class)
public void testCreateSequenceFileInSampleWrongType() throws IOException {
Sample s = new Sample();
SingleEndSequenceFile so = TestDataFactory.constructSingleEndSequenceFile();
SequencingRun run = new MiseqRun(LayoutType.PAIRED_END, "workflow");
so.setSequencingRun(run);
when(repository.save(so)).thenReturn(so);
service.createSequencingObjectInSample(so, s);
}
use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile in project irida by phac-nml.
the class SequencingObjectServiceTest method testCreateSequenceFileInSample.
@Test
public void testCreateSequenceFileInSample() throws IOException {
Sample s = new Sample();
SingleEndSequenceFile sf = TestDataFactory.constructSingleEndSequenceFile();
when(repository.save(sf)).thenReturn(sf);
service.createSequencingObjectInSample(sf, s);
verify(sequenceFileRepository, times(1)).save(any(SequenceFile.class));
// verify that we're only actually running one file processor on the new
// sequence file.
verify(executor, times(1)).execute(any(Runnable.class));
}
Aggregations