use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile in project irida by phac-nml.
the class SampleServiceImplTest method testRemoveSequenceFileFromSample.
@Test
public void testRemoveSequenceFileFromSample() {
Sample s = new Sample();
s.setId(1111L);
SequenceFile sf = new SequenceFile();
sf.setId(2222L);
SingleEndSequenceFile obj = new SingleEndSequenceFile(sf);
obj.setId(2L);
SampleSequencingObjectJoin join = new SampleSequencingObjectJoin(s, obj);
when(ssoRepository.readObjectForSample(s, obj.getId())).thenReturn(join);
sampleService.removeSequencingObjectFromSample(s, obj);
verify(ssoRepository).delete(join);
}
use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile in project irida by phac-nml.
the class SampleServiceImplTest method testGetTotalBasesForSampleFailMultipleFastQC.
/**
* Tests out failing to get the total bases from a sample with one sequence
* file due to too many FastQC
*
* @throws SequenceFileAnalysisException
*/
@Test(expected = SequenceFileAnalysisException.class)
public void testGetTotalBasesForSampleFailMultipleFastQC() throws SequenceFileAnalysisException {
Sample s1 = new Sample();
s1.setId(1L);
SequenceFile sf1 = new SequenceFile();
sf1.setId(2222L);
SampleSequencingObjectJoin join = new SampleSequencingObjectJoin(s1, new SingleEndSequenceFile(sf1));
when(ssoRepository.getSequencesForSample(s1)).thenReturn(Arrays.asList(join));
sampleService.getTotalBasesForSample(s1);
}
use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile in project irida by phac-nml.
the class SampleServiceImplTest method testMergeSamples.
@Test
public void testMergeSamples() {
// For every sample in toMerge, the service should:
// 1. call SequenceFileRepository to get the sequence files in that
// sample,
// 2. call SequenceFileRepository to add the sequence files to
// mergeInto,
// 3. call SampleRepository to persist the sample as deleted.
final int SIZE = 3;
Sample s = s(1L);
Project project = p(1L);
Sample[] toMerge = new Sample[SIZE];
SequenceFile[] toMerge_sf = new SequenceFile[SIZE];
SequencingObject[] toMerge_so = new SequencingObject[SIZE];
SampleSequencingObjectJoin[] s_so_joins = new SampleSequencingObjectJoin[SIZE];
SampleSequencingObjectJoin[] s_so_original = new SampleSequencingObjectJoin[SIZE];
ProjectSampleJoin[] p_s_joins = new ProjectSampleJoin[SIZE];
List<Sample> mergeSamples = new ArrayList<>();
for (long i = 0; i < SIZE; i++) {
int p = (int) i;
toMerge[p] = s(i + 2);
mergeSamples.add(toMerge[p]);
toMerge_sf[p] = sf(i + 2);
toMerge_so[p] = so(i + 2);
s_so_joins[p] = new SampleSequencingObjectJoin(s, toMerge_so[p]);
p_s_joins[p] = new ProjectSampleJoin(project, toMerge[p], true);
List<Join<Project, Sample>> projectSampleJoins = new ArrayList<>();
projectSampleJoins.add(p_s_joins[p]);
List<SampleSequencingObjectJoin> sampleSeqObjectJoins = new ArrayList<>();
SampleSequencingObjectJoin join = new SampleSequencingObjectJoin(toMerge[p], toMerge_so[p]);
sampleSeqObjectJoins.add(join);
s_so_original[p] = join;
when(ssoRepository.getSequencesForSample(toMerge[p])).thenReturn(null);
when(ssoRepository.getSequencesForSample(toMerge[p])).thenReturn(sampleSeqObjectJoins);
when(ssoRepository.save(s_so_joins[p])).thenReturn(s_so_joins[p]);
when(ssoRepository.readObjectForSample(toMerge[p], toMerge_so[p].getId())).thenReturn(join);
when(psjRepository.getProjectForSample(toMerge[p])).thenReturn(projectSampleJoins);
// for deletion
when(psjRepository.readSampleForProject(project, toMerge[p])).thenReturn(p_s_joins[p]);
}
List<Join<Project, Sample>> joins = new ArrayList<>();
joins.add(new ProjectSampleJoin(project, s, true));
when(psjRepository.getProjectForSample(s)).thenReturn(joins);
Sample saved = sampleService.mergeSamples(project, s, mergeSamples);
verify(psjRepository).getProjectForSample(s);
for (int i = 0; i < SIZE; i++) {
verify(ssoRepository).getSequencesForSample(toMerge[i]);
verify(ssoRepository).save(s_so_joins[i]);
verify(ssoRepository).delete(s_so_original[i]);
verify(sampleRepository).delete(toMerge[i].getId());
verify(psjRepository).getProjectForSample(toMerge[i]);
verify(psjRepository).delete(p_s_joins[i]);
}
assertEquals("The saved sample should be the same as the sample to merge into.", s, saved);
}
use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile in project irida by phac-nml.
the class TestDataFactory method constructSequenceFilePair.
/**
* Construct a simple {@link SequenceFilePair} object
*
* @return a {@link SequenceFilePair}
* @throws IOException
* if the temp files couldn't be created
*/
public static SequenceFilePair constructSequenceFilePair() throws IOException {
SequenceFile sf1 = constructSequenceFile();
SequenceFile sf2 = constructSequenceFile();
SequenceFilePair pair = new SequenceFilePair(sf1, sf2);
pair.setId(1L);
return pair;
}
use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile in project irida by phac-nml.
the class SampleSequenceFilesControllerTest method testGetSequenceFileForSample.
@Test
public void testGetSequenceFileForSample() throws IOException {
Sample s = TestDataFactory.constructSample();
SingleEndSequenceFile so = TestDataFactory.constructSingleEndSequenceFile();
when(sampleService.read(s.getId())).thenReturn(s);
when(sequencingObjectService.readSequencingObjectForSample(s, so.getId())).thenReturn(so);
ModelMap modelMap = controller.readSequenceFileForSequencingObject(s.getId(), RESTSampleSequenceFilesController.objectLabels.get(so.getClass()), so.getId(), so.getSequenceFile().getId());
verify(sampleService).read(s.getId());
verify(sequencingObjectService).readSequencingObjectForSample(s, so.getId());
Object o = modelMap.get(RESTGenericController.RESOURCE_NAME);
assertNotNull(o);
assertTrue(o instanceof SequenceFile);
SequenceFile sfr = (SequenceFile) o;
assertEquals(so.getSequenceFile().getFile(), sfr.getFile());
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/" + so.getSequenceFile().getId();
assertNotNull(self);
assertEquals(sequenceFileLocation, self.getHref());
assertNotNull(sampleSequenceFiles);
assertEquals(sampleLocation + "/sequenceFiles", sampleSequenceFiles.getHref());
assertNotNull(sample);
assertEquals(sampleLocation, sample.getHref());
}
Aggregations