use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject in project irida by phac-nml.
the class SequencingObjectServiceImplIT method testGetSequenceFilePairForSample.
@Test
@WithMockUser(username = "admin", roles = "ADMIN")
public void testGetSequenceFilePairForSample() {
Sample s = sampleService.read(2L);
Set<Long> fileIds = Sets.newHashSet(3L, 4L);
Collection<SampleSequencingObjectJoin> sequenceFilePairsForSample = objectService.getSequencesForSampleOfType(s, SequenceFilePair.class);
assertEquals(1, sequenceFilePairsForSample.size());
SequencingObject pair = sequenceFilePairsForSample.iterator().next().getObject();
for (SequenceFile file : pair.getFiles()) {
assertTrue("file id should be in set", fileIds.contains(file.getId()));
fileIds.remove(file.getId());
}
assertTrue("all file ids should have been found", fileIds.isEmpty());
}
use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject in project irida by phac-nml.
the class SequencingObjectServiceImplIT method testGetUniqueSamplesForSequencingObjectsSuccess.
/**
* Tests to make sure we get a properly constructed map of samples to sequencing objects.
*/
@Test
@WithMockUser(username = "admin", roles = "ADMIN")
public void testGetUniqueSamplesForSequencingObjectsSuccess() {
SequencingObject s1 = objectService.read(1L);
SequencingObject s2 = objectService.read(2L);
Sample sa1 = sampleService.read(1L);
Sample sa2 = sampleService.read(2L);
Map<Sample, SequencingObject> sampleMap = objectService.getUniqueSamplesForSequencingObjects(Sets.newHashSet(s1, s2));
assertEquals("Incorrect number of results returned in sample map", 2, sampleMap.size());
assertEquals("Incorrect sequencing object mapped to sample", s2.getId(), sampleMap.get(sa1).getId());
assertEquals("Incorrect sequencing object mapped to sample", s1.getId(), sampleMap.get(sa2).getId());
}
use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject in project irida by phac-nml.
the class SequencingObjectServiceImplIT method testGetUniqueSamplesForSequencingObjectsFailDuplicateSample.
/**
* Tests failure for duplicate samples in sequencing objects.
*/
@Test(expected = DuplicateSampleException.class)
@WithMockUser(username = "admin", roles = "ADMIN")
public void testGetUniqueSamplesForSequencingObjectsFailDuplicateSample() {
SequencingObject s1 = objectService.read(1L);
SequencingObject s4 = objectService.read(4L);
objectService.getUniqueSamplesForSequencingObjects(Sets.newHashSet(s1, s4));
}
use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject 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.sequenceFile.SequencingObject in project irida by phac-nml.
the class SamplesControllerTest method testRemoveFileFromSample.
@Test
public void testRemoveFileFromSample() {
Long sampleId = 1L;
Long fileId = 2L;
Sample sample = new Sample();
SequencingObject file = new SingleEndSequenceFile(new SequenceFile(Paths.get("/tmp")));
when(sampleService.read(sampleId)).thenReturn(sample);
when(sequencingObjectService.readSequencingObjectForSample(sample, fileId)).thenReturn(file);
RedirectAttributesModelMap attributes = new RedirectAttributesModelMap();
HttpServletRequest request = new MockHttpServletRequest();
controller.removeSequencingObjectFromSample(attributes, sampleId, fileId, request, Locale.US);
verify(sampleService).removeSequencingObjectFromSample(sample, file);
}
Aggregations