use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile 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.sequenceFile.SingleEndSequenceFile 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.sequenceFile.SingleEndSequenceFile 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);
}
use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile in project irida by phac-nml.
the class SISTRSampleUpdaterTest method testUpdaterPassed.
@SuppressWarnings("unchecked")
@Test
public void testUpdaterPassed() throws PostProcessingException, AnalysisAlreadySetException {
ImmutableMap<String, String> expectedResults = ImmutableMap.of("SISTR serovar", "Enteritidis", "SISTR cgMLST Subspecies", "enterica", "SISTR QC Status", "PASS");
Path outputPath = Paths.get("src/test/resources/files/sistr-predictions-pass.json");
AnalysisOutputFile outputFile = new AnalysisOutputFile(outputPath, null, null, null);
Analysis analysis = new Analysis(null, ImmutableMap.of("sistr-predictions", outputFile), null, null);
AnalysisSubmission submission = AnalysisSubmission.builder(UUID.randomUUID()).inputFiles(ImmutableSet.of(new SingleEndSequenceFile(null))).build();
submission.setAnalysis(analysis);
Sample sample = new Sample();
sample.setId(1L);
ImmutableMap<MetadataTemplateField, MetadataEntry> metadataMap = ImmutableMap.of(new MetadataTemplateField("SISTR Field", "text"), new MetadataEntry("Value1", "text"));
when(metadataTemplateService.getMetadataMap(any(Map.class))).thenReturn(metadataMap);
updater.update(Lists.newArrayList(sample), submission);
ArgumentCaptor<Map> mapCaptor = ArgumentCaptor.forClass(Map.class);
// this is the important bit. Ensures the correct values got pulled from the file
verify(metadataTemplateService).getMetadataMap(mapCaptor.capture());
Map<String, MetadataEntry> metadata = mapCaptor.getValue();
int found = 0;
for (Map.Entry<String, MetadataEntry> e : metadata.entrySet()) {
if (expectedResults.containsKey(e.getKey())) {
String expected = expectedResults.get(e.getKey());
MetadataEntry value = e.getValue();
assertEquals("metadata values should match", expected, value.getValue());
found++;
}
}
assertEquals("should have found the same number of results", expectedResults.keySet().size(), found);
// this bit just ensures the merged data got saved
verify(sampleService).updateFields(eq(sample.getId()), mapCaptor.capture());
Map<MetadataTemplateField, MetadataEntry> value = (Map<MetadataTemplateField, MetadataEntry>) mapCaptor.getValue().get("metadata");
assertEquals(metadataMap.keySet().iterator().next(), value.keySet().iterator().next());
}
use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile in project irida by phac-nml.
the class SISTRSampleUpdaterTest method testUpdaterBadFile.
@Test(expected = PostProcessingException.class)
public void testUpdaterBadFile() throws PostProcessingException, AnalysisAlreadySetException {
ImmutableMap<String, String> expectedResults = ImmutableMap.of("SISTR serovar", "Enteritidis", "SISTR cgMLST Subspecies", "enterica", "SISTR QC Status", "PASS");
Path outputPath = Paths.get("src/test/resources/files/snp_tree.tree");
AnalysisOutputFile outputFile = new AnalysisOutputFile(outputPath, null, null, null);
Analysis analysis = new Analysis(null, ImmutableMap.of("sistr-predictions", outputFile), null, null);
AnalysisSubmission submission = AnalysisSubmission.builder(UUID.randomUUID()).inputFiles(ImmutableSet.of(new SingleEndSequenceFile(null))).build();
submission.setAnalysis(analysis);
Sample sample = new Sample();
sample.setId(1L);
updater.update(Lists.newArrayList(sample), submission);
}
Aggregations