Search in sources :

Example 96 with Sample

use of ca.corefacility.bioinformatics.irida.model.sample.Sample in project irida by phac-nml.

the class SampleServiceImplIT method testGetSampleByExternalIdDuplicates.

@Test
@WithMockUser(username = "fbristow", roles = "ADMIN")
@DatabaseSetup("/ca/corefacility/bioinformatics/irida/service/impl/SampleServiceImplIT_duplicateSampleIds.xml")
public void testGetSampleByExternalIdDuplicates() {
    Project p = projectService.read(7L);
    Sample s = sampleService.getSampleBySampleName(p, "sample");
    assertEquals("Should have retrieved sample with ID 1L.", Long.valueOf(7L), s.getId());
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test) DatabaseSetup(com.github.springtestdbunit.annotation.DatabaseSetup)

Example 97 with Sample

use of ca.corefacility.bioinformatics.irida.model.sample.Sample in project irida by phac-nml.

the class SampleServiceImplIT method testMergeSamplesIntoSample1.

/**
 * Straightforward merging of samples all belonging to the same project.
 */
@Test
@WithMockUser(username = "fbristow", roles = "ADMIN")
public void testMergeSamplesIntoSample1() {
    Sample mergeInto = sampleService.read(1L);
    Sample sample2 = sampleService.read(2L);
    Sample sample3 = sampleService.read(3L);
    Project p = projectService.read(1L);
    assertEquals("Sample 1 should only have genome assembly 1", Lists.newArrayList(1L), sampleGenomeAssemblyJoinRepository.findBySample(mergeInto).stream().map(t -> t.getObject().getId()).collect(Collectors.toList()));
    assertEquals("Sample 2 should only have genome assembly 2", Lists.newArrayList(2L), sampleGenomeAssemblyJoinRepository.findBySample(sample2).stream().map(t -> t.getObject().getId()).collect(Collectors.toList()));
    assertTrue("Sample 3 should have no genome assemblies before", sampleGenomeAssemblyJoinRepository.findBySample(sample3).isEmpty());
    assertNotNull("Join between sample 2 and genome assembly 2 should exist", sampleGenomeAssemblyJoinRepository.findBySampleAndAssemblyId(2L, 2L));
    Sample merged = sampleService.mergeSamples(p, mergeInto, Lists.newArrayList(sample2, sample3));
    assertEquals("Merged sample should be same as mergeInto.", mergeInto, merged);
    // merged samples should be deleted
    assertSampleNotFound(2L);
    assertSampleNotFound(3L);
    assertNull("Join between sample 2 and genome assembly 2 should not exist", sampleGenomeAssemblyJoinRepository.findBySampleAndAssemblyId(2L, 2L));
    // the merged sample should have 3 sequence files
    assertEquals("Merged sample should have 3 sequence files", 3, objectService.getSequencingObjectsForSample(merged).size());
    assertEquals("Sample 1 should only have genome assemblies 1 and 2", Lists.newArrayList(1L, 2L), sampleGenomeAssemblyJoinRepository.findBySample(mergeInto).stream().map(t -> t.getObject().getId()).collect(Collectors.toList()));
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Example 98 with Sample

use of ca.corefacility.bioinformatics.irida.model.sample.Sample in project irida by phac-nml.

the class SampleServiceImplIT method testMergeSampleReject.

/**
 * Sample merging should be rejected when samples are attempted to be joined
 * where they do not share the same project.
 */
@Test(expected = IllegalArgumentException.class)
@WithMockUser(username = "fbristow", roles = "ADMIN")
public void testMergeSampleReject() {
    Sample mergeInto = sampleService.read(1L);
    Project p = projectService.read(1L);
    sampleService.mergeSamples(p, mergeInto, Lists.newArrayList(sampleService.read(4L)));
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Example 99 with Sample

use of ca.corefacility.bioinformatics.irida.model.sample.Sample in project irida by phac-nml.

the class SampleServiceImplIT method testEstimateCoverageForSampleAsUser.

/**
 * Tests getting the coverage as a regular user.
 *
 * @throws SequenceFileAnalysisException
 */
@Test
@WithMockUser(username = "fbristow", roles = "USER")
public void testEstimateCoverageForSampleAsUser() throws SequenceFileAnalysisException {
    Long sampleID = 1L;
    Sample s = sampleService.read(sampleID);
    double coverage = sampleService.estimateCoverageForSample(s, 500);
    assertEquals(2.0, coverage, deltaFloatEquality);
}
Also used : Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Example 100 with Sample

use of ca.corefacility.bioinformatics.irida.model.sample.Sample in project irida by phac-nml.

the class SampleServiceImplIT method testGetGenomeAssemblyForSampleSuccess.

@Test
@WithMockUser(username = "fbristow", roles = "USER")
public void testGetGenomeAssemblyForSampleSuccess() throws AnalysisAlreadySetException {
    Path expectedAssemblyPath = outputFileBaseDirectory.resolve("testfile.fasta");
    Sample s = sampleService.read(1L);
    GenomeAssembly genomeAssembly = sampleService.getGenomeAssemblyForSample(s, 1L);
    assertEquals("should have same path for assembly", expectedAssemblyPath, genomeAssembly.getFile());
}
Also used : Path(java.nio.file.Path) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) GenomeAssembly(ca.corefacility.bioinformatics.irida.model.assembly.GenomeAssembly) WithMockUser(org.springframework.security.test.context.support.WithMockUser) 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