use of ca.corefacility.bioinformatics.irida.model.sample.Sample 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.sample.Sample 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);
}
use of ca.corefacility.bioinformatics.irida.model.sample.Sample in project irida by phac-nml.
the class SampleServiceImplTest method testGetTotalBasesForSampleSuccessOne.
/**
* Tests out successfully getting the total bases from a sample with one
* sequence file.
*
* @throws SequenceFileAnalysisException
* @throws AnalysisAlreadySetException
*/
@Test
public void testGetTotalBasesForSampleSuccessOne() 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);
long actualBases = sampleService.getTotalBasesForSample(s1);
assertEquals(1000, actualBases);
}
use of ca.corefacility.bioinformatics.irida.model.sample.Sample in project irida by phac-nml.
the class SampleRemoteServiceImplTest method testGetSamplesForProject.
@Test
public void testGetSamplesForProject() {
String samplesHref = "http://somewhere/projects/5/samples";
Project project = new Project();
project.add(new Link(samplesHref, SampleRemoteServiceImpl.PROJECT_SAMPLES_REL));
RemoteAPI api = new RemoteAPI();
project.setRemoteStatus(new RemoteStatus("http://nowhere", api));
Sample remoteSample = new Sample();
remoteSample.setRemoteStatus(new RemoteStatus("http://nowhere", api));
List<Sample> samples = Lists.newArrayList(remoteSample);
when(sampleRemoteRepository.list(samplesHref, api)).thenReturn(samples);
List<Sample> samplesForProject = sampleRemoteService.getSamplesForProject(project);
verify(sampleRemoteRepository).list(samplesHref, api);
assertEquals(samples, samplesForProject);
}
use of ca.corefacility.bioinformatics.irida.model.sample.Sample in project irida by phac-nml.
the class SingleEndSequenceFileRemoteServiceImplTest method testGetSequenceFilesForSample.
@Test
public void testGetSequenceFilesForSample() {
String seqFilesHref = "http://somewhere/projects/1/samples/2/sequencefiles";
RemoteAPI api = new RemoteAPI();
Sample sample = new Sample();
sample.add(new Link(seqFilesHref, SingleEndSequenceFileRemoteServiceImpl.SAMPLE_SEQENCE_FILE_UNPAIRED_REL));
sample.setRemoteStatus(new RemoteStatus("http://nowhere", api));
List<SingleEndSequenceFile> filesList = Lists.newArrayList(new SingleEndSequenceFile(new SequenceFile()));
when(apiRepo.getRemoteAPIForUrl(seqFilesHref)).thenReturn(api);
when(repository.list(seqFilesHref, api)).thenReturn(filesList);
List<SingleEndSequenceFile> sequenceFilesForSample = service.getUnpairedFilesForSample(sample);
assertEquals(filesList, sequenceFilesForSample);
verify(repository).list(seqFilesHref, api);
}
Aggregations