use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile in project irida by phac-nml.
the class SampleSequenceFilesControllerTest method testAddNewSequenceFilePairToSample.
@Test
public void testAddNewSequenceFilePairToSample() throws IOException {
Sample s = TestDataFactory.constructSample();
String file1Name = "file1_R1_01.fastq.gz";
String file2Name = "file2_R2_01.fastq.gz";
SequenceFilePair pair = TestDataFactory.constructSequenceFilePair();
Iterator<SequenceFile> iterator = pair.getFiles().iterator();
SequenceFile sf1 = iterator.next();
SequenceFile sf2 = iterator.next();
sf1.setFile(Paths.get(file1Name));
sf2.setFile(Paths.get(file2Name));
sf1.setId(3245L);
SampleSequencingObjectJoin sso = new SampleSequencingObjectJoin(s, pair);
SequenceFileResource resource1 = new SequenceFileResource();
SequenceFileResource resource2 = new SequenceFileResource();
Path f1 = Files.createTempFile(null, null);
Path f2 = Files.createTempFile(null, null);
MockMultipartFile mmf1 = new MockMultipartFile(file1Name, file1Name, "blurgh1", FileCopyUtils.copyToByteArray(f1.toFile()));
MockMultipartFile mmf2 = new MockMultipartFile(file2Name, file2Name, "blurgh2", FileCopyUtils.copyToByteArray(f2.toFile()));
MockHttpServletResponse response = new MockHttpServletResponse();
// mock out the service calls
when(sampleService.read(s.getId())).thenReturn(s);
when(sequencingObjectService.createSequencingObjectInSample(any(SequenceFilePair.class), Matchers.eq(s))).thenReturn(sso);
ModelMap modelMap = controller.addNewSequenceFilePairToSample(s.getId(), mmf1, resource1, mmf2, resource2, response);
verify(sampleService).read(s.getId());
verify(sequencingObjectService).createSequencingObjectInSample(any(SequenceFilePair.class), Matchers.eq(s));
Object o = modelMap.get(RESTGenericController.RESOURCE_NAME);
assertNotNull("Object should not be null", o);
assertTrue("Object should be an instance of SequenceFilePair", o instanceof SequenceFilePair);
SequenceFilePair returnVal = (SequenceFilePair) o;
Link selfCollection = returnVal.getLink(Link.REL_SELF);
Link sampleRC = returnVal.getLink(RESTSampleSequenceFilesController.REL_SAMPLE);
Link sampleSequenceFiles = returnVal.getLink(RESTSampleSequenceFilesController.REL_SAMPLE_SEQUENCE_FILES);
String sampleLocation = "http://localhost/api/samples/" + s.getId();
String pairLocation = sampleLocation + "/pairs/" + pair.getId();
assertEquals("Pair location should be correct", pairLocation, selfCollection.getHref());
assertEquals("Sample location should be correct", sampleLocation, sampleRC.getHref());
assertEquals("Sequence file location should be correct", sampleLocation + "/sequenceFiles", sampleSequenceFiles.getHref());
String sequenceFileLocation1 = pairLocation + "/files/" + sf1.getId();
String sequenceFileLocation2 = pairLocation + "/files/" + sf2.getId();
String[] sequenceFileLocs = new String[] { sequenceFileLocation1, sequenceFileLocation2 };
String locationHeader = response.getHeader(HttpHeaders.LOCATION);
assertEquals("The location header should have the self rel", pairLocation, locationHeader);
Iterator<SequenceFile> filesIterator = returnVal.getFiles().iterator();
for (int i = 0; i < 2; i++) {
SequenceFile returnedFile = filesIterator.next();
Link self = returnedFile.getLink(Link.REL_SELF);
assertNotNull("Self link should not be null", self);
assertEquals("Self reference should be correct", sequenceFileLocs[i], self.getHref());
}
assertEquals("HTTP status must be CREATED", HttpStatus.CREATED.value(), response.getStatus());
Files.delete(f1);
Files.delete(f2);
}
use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile in project irida by phac-nml.
the class SampleSequenceFilesControllerTest method testAddNewSequenceFileToSample.
@Test
public void testAddNewSequenceFileToSample() throws IOException {
Sample s = TestDataFactory.constructSample();
SingleEndSequenceFile so = TestDataFactory.constructSingleEndSequenceFile();
SequenceFile sf = so.getSequenceFile();
SampleSequencingObjectJoin sso = new SampleSequencingObjectJoin(s, so);
SequenceFileResource resource = new SequenceFileResource();
Path f = Files.createTempFile(null, null);
MockMultipartFile mmf = new MockMultipartFile("filename", "filename", "blurgh", FileCopyUtils.copyToByteArray(f.toFile()));
MockHttpServletResponse response = new MockHttpServletResponse();
when(sampleService.read(s.getId())).thenReturn(s);
when(sequencingObjectService.createSequencingObjectInSample(any(SingleEndSequenceFile.class), Matchers.eq(s))).thenReturn(sso);
when(sequencingObjectService.read(so.getId())).thenReturn(so);
ModelMap modelMap = controller.addNewSequenceFileToSample(s.getId(), mmf, resource, response);
verify(sampleService).read(s.getId());
verify(sampleService, times(1)).read(s.getId());
verify(sequencingObjectService).createSequencingObjectInSample(any(SingleEndSequenceFile.class), Matchers.eq(s));
Object o = modelMap.get(RESTGenericController.RESOURCE_NAME);
assertNotNull("object must not be null", o);
assertTrue("object must be a SequenceFile", o instanceof SequenceFile);
SequenceFile sfr = (SequenceFile) o;
assertEquals("response must have CREATED status", HttpStatus.CREATED.value(), response.getStatus());
Link self = sfr.getLink(Link.REL_SELF);
Link sampleSequenceFiles = sfr.getLink(RESTSampleSequenceFilesController.REL_SAMPLE_SEQUENCE_FILES);
Link sample = sfr.getLink(RESTSampleSequenceFilesController.REL_SAMPLE);
String sampleLocation = "http://localhost/api/samples/" + s.getId();
String sequenceFileLocation = sampleLocation + "/unpaired/" + so.getIdentifier() + "/files/" + sf.getId();
assertNotNull("self reference must exist", self);
assertEquals("self reference must be correct", sequenceFileLocation, self.getHref());
assertNotNull("sequence files link must exist", sampleSequenceFiles);
assertEquals("sequence files location must be correct", sampleLocation + "/sequenceFiles", sampleSequenceFiles.getHref());
assertNotNull("sample link must exist", sample);
assertEquals("sample location must be correct", sampleLocation, sample.getHref());
Files.delete(f);
}
use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile in project irida by phac-nml.
the class SampleSequenceFilesControllerTest method testGetSampleSequenceFiles.
@Test
public void testGetSampleSequenceFiles() throws IOException {
Sample s = TestDataFactory.constructSample();
SingleEndSequenceFile so = TestDataFactory.constructSingleEndSequenceFile();
SampleSequencingObjectJoin r = new SampleSequencingObjectJoin(s, so);
List<SampleSequencingObjectJoin> relationships = Lists.newArrayList(r);
// mock out the service calls
when(sampleService.read(s.getId())).thenReturn(s);
when(sequencingObjectService.getSequencingObjectsForSample(s)).thenReturn(relationships);
ModelMap modelMap = controller.getSampleSequenceFiles(s.getId());
// verify that the service calls were used.
verify(sampleService).read(s.getId());
verify(sequencingObjectService).getSequencingObjectsForSample(s);
Object o = modelMap.get(RESTGenericController.RESOURCE_NAME);
assertTrue(o instanceof ResourceCollection);
@SuppressWarnings("unchecked") ResourceCollection<SequenceFile> resources = (ResourceCollection<SequenceFile>) o;
assertNotNull(resources);
assertEquals(1, resources.size());
Link selfCollection = resources.getLink(Link.REL_SELF);
Link sample = resources.getLink(RESTSampleSequenceFilesController.REL_SAMPLE);
String sampleLocation = "http://localhost/api/samples/" + s.getId();
String sequenceFileLocation = sampleLocation + "/unpaired/" + so.getIdentifier() + "/files/" + so.getSequenceFile().getId();
assertEquals(sampleLocation + "/sequenceFiles", selfCollection.getHref());
assertEquals(sampleLocation, sample.getHref());
// confirm that the self rel for an individual sequence file exists
SequenceFile sfr = resources.iterator().next();
Link self = sfr.getLink(Link.REL_SELF);
assertEquals(sequenceFileLocation, self.getHref());
assertEquals(so.getSequenceFile().getFile(), sfr.getFile());
}
use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile in project irida by phac-nml.
the class SampleServiceImplTest method sf.
private SequenceFile sf(Long id) {
SequenceFile sf = new SequenceFile();
sf.setId(id);
try {
sf.setFile(Files.createTempFile(null, null));
} catch (IOException e) {
}
return sf;
}
use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile in project irida by phac-nml.
the class SampleServiceImplTest method testGetCoverageForSampleSuccess.
/**
* Tests out successfully getting the coverage from a sample with a sequence
* file.
*
* @throws SequenceFileAnalysisException
* @throws AnalysisAlreadySetException
*/
@Test
public void testGetCoverageForSampleSuccess() throws SequenceFileAnalysisException, AnalysisAlreadySetException {
Sample s1 = new Sample();
s1.setId(1L);
SequenceFile sf1 = new SequenceFile();
sf1.setId(2222L);
SampleSequencingObjectJoin join = new SampleSequencingObjectJoin(s1, new SingleEndSequenceFile(sf1));
AnalysisFastQC analysisFastQC1 = AnalysisFastQC.sloppyBuilder().executionManagerAnalysisId("id").totalBases(1000L).build();
sf1.setFastQCAnalysis(analysisFastQC1);
when(ssoRepository.getSequencesForSample(s1)).thenReturn(Arrays.asList(join));
when(analysisRepository.findFastqcAnalysisForSequenceFile(sf1)).thenReturn(analysisFastQC1);
double coverage = sampleService.estimateCoverageForSample(s1, 500L);
assertEquals(2.0, coverage, deltaFloatEquality);
}
Aggregations