Search in sources :

Example 36 with Sample

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());
}
Also used : SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) ModelMap(org.springframework.ui.ModelMap) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) Link(org.springframework.hateoas.Link) ResourceCollection(ca.corefacility.bioinformatics.irida.web.assembler.resource.ResourceCollection) Test(org.junit.Test)

Example 37 with Sample

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);
}
Also used : SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) AnalysisFastQC(ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisFastQC) Test(org.junit.Test)

Example 38 with Sample

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);
}
Also used : SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) AnalysisFastQC(ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisFastQC) Test(org.junit.Test)

Example 39 with Sample

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);
}
Also used : RemoteAPI(ca.corefacility.bioinformatics.irida.model.RemoteAPI) Project(ca.corefacility.bioinformatics.irida.model.project.Project) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) RemoteStatus(ca.corefacility.bioinformatics.irida.model.remote.RemoteStatus) Link(org.springframework.hateoas.Link) Test(org.junit.Test)

Example 40 with Sample

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);
}
Also used : RemoteAPI(ca.corefacility.bioinformatics.irida.model.RemoteAPI) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) RemoteStatus(ca.corefacility.bioinformatics.irida.model.remote.RemoteStatus) Link(org.springframework.hateoas.Link) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) Test(org.junit.Test)

Aggregations

Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)243 Test (org.junit.Test)162 Project (ca.corefacility.bioinformatics.irida.model.project.Project)114 WithMockUser (org.springframework.security.test.context.support.WithMockUser)71 ProjectSampleJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin)62 SampleSequencingObjectJoin (ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin)53 SingleEndSequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)53 SequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile)41 Join (ca.corefacility.bioinformatics.irida.model.joins.Join)33 SequencingObject (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject)33 Path (java.nio.file.Path)28 ModelMap (org.springframework.ui.ModelMap)28 SequenceFilePair (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair)24 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)24 AnalysisSubmission (ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)23 ArrayList (java.util.ArrayList)22 EntityNotFoundException (ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException)17 User (ca.corefacility.bioinformatics.irida.model.user.User)14 HashMap (java.util.HashMap)14 RelatedProjectJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin)13