Search in sources :

Example 1 with SingleEndSequenceFile

use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile 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);
}
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) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) Test(org.junit.Test)

Example 2 with SingleEndSequenceFile

use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile 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);
}
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) Test(org.junit.Test)

Example 3 with SingleEndSequenceFile

use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile 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());
}
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) Link(org.springframework.hateoas.Link) Test(org.junit.Test)

Example 4 with SingleEndSequenceFile

use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile 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);
}
Also used : Path(java.nio.file.Path) MockMultipartFile(org.springframework.mock.web.MockMultipartFile) 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) SequenceFileResource(ca.corefacility.bioinformatics.irida.web.assembler.resource.sequencefile.SequenceFileResource) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Link(org.springframework.hateoas.Link) Test(org.junit.Test)

Example 5 with SingleEndSequenceFile

use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile 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)

Aggregations

SingleEndSequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)99 Test (org.junit.Test)72 SequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile)61 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)44 Path (java.nio.file.Path)33 SampleSequencingObjectJoin (ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin)24 SequencingObject (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject)22 SequenceFilePair (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair)20 WithMockUser (org.springframework.security.test.context.support.WithMockUser)18 Project (ca.corefacility.bioinformatics.irida.model.project.Project)17 AnalysisSubmission (ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)17 AnalysisFastQC (ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisFastQC)12 Analysis (ca.corefacility.bioinformatics.irida.model.workflow.analysis.Analysis)11 IridaWorkflow (ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow)10 ArrayList (java.util.ArrayList)10 SequencingRun (ca.corefacility.bioinformatics.irida.model.run.SequencingRun)8 HistoriesClient (com.github.jmchilton.blend4j.galaxy.HistoriesClient)8 History (com.github.jmchilton.blend4j.galaxy.beans.History)8 GZIPOutputStream (java.util.zip.GZIPOutputStream)8 ModelMap (org.springframework.ui.ModelMap)8