Search in sources :

Example 6 with SequenceFile

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);
}
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 7 with SequenceFile

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);
}
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 8 with SequenceFile

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);
}
Also used : SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) ArrayList(java.util.ArrayList) Join(ca.corefacility.bioinformatics.irida.model.joins.Join) ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) Project(ca.corefacility.bioinformatics.irida.model.project.Project) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) Test(org.junit.Test)

Example 9 with SequenceFile

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;
}
Also used : SequenceFilePair(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)

Example 10 with SequenceFile

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());
}
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)

Aggregations

SequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile)111 SingleEndSequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)84 Test (org.junit.Test)61 Path (java.nio.file.Path)50 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)39 SampleSequencingObjectJoin (ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin)31 SequencingObject (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject)25 SequenceFilePair (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair)20 Project (ca.corefacility.bioinformatics.irida.model.project.Project)15 AnalysisFastQC (ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisFastQC)15 WithMockUser (org.springframework.security.test.context.support.WithMockUser)13 IOException (java.io.IOException)11 SequencingRun (ca.corefacility.bioinformatics.irida.model.run.SequencingRun)9 ArrayList (java.util.ArrayList)9 ProjectSampleJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin)8 GZIPOutputStream (java.util.zip.GZIPOutputStream)8 Link (org.springframework.hateoas.Link)8 AnalysisSubmission (ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)7 OutputStream (java.io.OutputStream)7 Before (org.junit.Before)7