Search in sources :

Example 1 with SpecimenWithSamples

use of org.icgc.dcc.song.server.model.entity.composites.SpecimenWithSamples in project SONG by overture-stack.

the class EntityTest method testDonorWithSpecimens.

@Test
public void testDonorWithSpecimens() {
    val specimen1 = Specimen.create("mySpecimen1", "mySpecimenSubmitter1", "myDonor1", SPECIMEN_CLASSES.get(2), SPECIMEN_TYPES.get(2));
    val specimen2 = Specimen.create("mySpecimen2", "mySpecimenSubmitter2", "myDonor2", SPECIMEN_CLASSES.get(1), SPECIMEN_TYPES.get(1));
    val sample11 = Sample.create("mySample11", "mySubmitterSample11", "mySpecimen11", SAMPLE_TYPES.get(2));
    val sample12 = Sample.create("mySample12", "mySubmitterSample12", "mySpecimen12", SAMPLE_TYPES.get(2));
    val sampleGroup1 = newArrayList(sample11, sample12);
    val sample21 = Sample.create("mySample21", "mySubmitterSample21", "mySpecimen21", SAMPLE_TYPES.get(3));
    val sample22 = Sample.create("mySample22", "mySubmitterSample22", "mySpecimen22", SAMPLE_TYPES.get(3));
    val sampleGroup2 = newArrayList(sample21, sample22);
    val specimenWithSample1 = new SpecimenWithSamples();
    specimenWithSample1.setSpecimen(specimen1);
    specimenWithSample1.setSamples(sampleGroup1);
    val specimenWithSample2 = new SpecimenWithSamples();
    specimenWithSample2.setSpecimen(specimen2);
    specimenWithSample2.setSamples(sampleGroup2);
    val specimenWSampleGroup1 = newArrayList(specimenWithSample1, specimenWithSample2);
    val specimenWSampleGroup2 = newArrayList(specimenWithSample1);
    val donor1 = Donor.create("myDonor1", "myDonorSubmitter1", DEFAULT_STUDY_ID, "male");
    val donor2 = Donor.create("myDonor2", "myDonorSubmitter2", DEFAULT_STUDY_ID, "female");
    val d1 = new DonorWithSpecimens();
    d1.setDonorGender(donor1.getDonorGender());
    d1.setDonorId(donor1.getDonorId());
    d1.setDonorSubmitterId(donor1.getDonorSubmitterId());
    d1.setStudyId(donor1.getStudyId());
    val d2 = new DonorWithSpecimens();
    d2.setDonor(donor1);
    assertEntitiesEqual(d1, d2, true);
    // 00 - matchingDonors=0   matchingSpecimenGroups=0
    d1.setDonor(donor1);
    d1.setSpecimens(specimenWSampleGroup1);
    d2.setDonor(donor2);
    d2.setSpecimens(specimenWSampleGroup2);
    assertEntitiesNotEqual(d1, d2);
    // 01 - matchingDonors=0   matchingSpecimenGroups=1
    d1.setDonor(donor1);
    d1.setSpecimens(specimenWSampleGroup1);
    d2.setDonor(donor2);
    d2.setSpecimens(specimenWSampleGroup1);
    assertEntitiesNotEqual(d1, d2);
    // 10 - matchingDonors=1   matchingSpecimenGroups=0
    d1.setDonor(donor1);
    d1.setSpecimens(specimenWSampleGroup1);
    d2.setDonor(donor1);
    d2.setSpecimens(specimenWSampleGroup2);
    assertEntitiesNotEqual(d1, d2);
    // 11 - matchingDonors=1   matchingSpecimenGroups=1
    d1.setDonor(donor1);
    d1.setSpecimens(specimenWSampleGroup1);
    d2.setDonor(donor1);
    d2.setSpecimens(specimenWSampleGroup1);
    assertEntitiesEqual(d1, d2, true);
    d1.setInfo("key1", "f5c9381090a53c54358feb2ba5b7a3d7");
    d2.setInfo("key2", "6329334b-dcd5-53c8-98fd-9812ac386d30");
    assertEntitiesNotEqual(d1, d2);
    // Test getters
    assertThat(d1.getDonorGender()).isEqualTo(donor1.getDonorGender());
    assertThat(d1.getDonorSubmitterId()).isEqualTo(donor1.getDonorSubmitterId());
    assertThat(d1.getDonorId()).isEqualTo(donor1.getDonorId());
    assertThat(d1.getStudyId()).isEqualTo(donor1.getStudyId());
    assertThat(d1.getSpecimens()).containsExactlyInAnyOrder(specimenWithSample1, specimenWithSample2);
    assertThat(d1.createDonor()).isNotEqualTo(donor1);
    assertInfoKVPair(d1, "key1", "f5c9381090a53c54358feb2ba5b7a3d7");
}
Also used : lombok.val(lombok.val) DonorWithSpecimens(org.icgc.dcc.song.server.model.entity.composites.DonorWithSpecimens) SpecimenWithSamples(org.icgc.dcc.song.server.model.entity.composites.SpecimenWithSamples) Test(org.junit.Test)

Example 2 with SpecimenWithSamples

use of org.icgc.dcc.song.server.model.entity.composites.SpecimenWithSamples in project SONG by overture-stack.

the class StudyWithDonorsServiceTest method testReadWithChildren.

@Test
public void testReadWithChildren() {
    // Create random isolated study
    val studyId = studyGenerator.createRandomStudy();
    // Generate Random SequencingRead analyses
    val analysisGenerator = createAnalysisGenerator(studyId, analysisService, randomGenerator);
    val numAnalysis = 11;
    val analysisMap = Maps.<String, SequencingReadAnalysis>newHashMap();
    for (int i = 0; i < numAnalysis; i++) {
        val sequencingReadAnalysis = analysisGenerator.createDefaultRandomSequencingReadAnalysis();
        analysisMap.put(sequencingReadAnalysis.getAnalysisId(), sequencingReadAnalysis);
    }
    // Extract expected donors and verify
    val expectedDonors = analysisMap.values().stream().flatMap(x -> x.getSample().stream()).map(CompositeEntity::getDonor).collect(toSet());
    assertThat(expectedDonors).hasSize(numAnalysis);
    assertThat(expectedDonors.stream().map(Donor::getDonorSubmitterId).distinct().count()).isEqualTo(numAnalysis);
    assertThat(expectedDonors.stream().filter(x -> x.getStudyId().equals(studyId)).count()).isEqualTo(numAnalysis);
    // Extract expected specimens and verify
    val expectedSpecimens = analysisMap.values().stream().flatMap(x -> x.getSample().stream()).map(CompositeEntity::getSpecimen).collect(toSet());
    assertThat(expectedSpecimens).hasSize(numAnalysis);
    assertThat(expectedSpecimens.stream().map(Specimen::getSpecimenSubmitterId).distinct().count()).isEqualTo(numAnalysis);
    // Extract expected samples and verify
    val expectedSamples = analysisMap.values().stream().flatMap(x -> x.getSample().stream()).collect(toSet());
    val expectedSampleSubmitterIds = expectedSamples.stream().map(Sample::getSampleSubmitterId).collect(toSet());
    assertThat(expectedSamples).hasSize(numAnalysis);
    assertThat(expectedSampleSubmitterIds).hasSize(numAnalysis);
    // Run the target method to test, readWithChildren
    val studyWithDonors = studyWithDonorsService.readWithChildren(studyId);
    // Extract actual donors
    val actualDonors = studyWithDonors.getDonors().stream().map(DonorWithSpecimens::createDonor).collect(toSet());
    // Extract actual specimens
    val actualSpecimens = studyWithDonors.getDonors().stream().map(DonorWithSpecimens::getSpecimens).flatMap(Collection::stream).map(SpecimenWithSamples::getSpecimen).collect(toSet());
    // Extract actual samples
    val actualSamples = studyWithDonors.getDonors().stream().map(DonorWithSpecimens::getSpecimens).flatMap(Collection::stream).map(SpecimenWithSamples::getSamples).flatMap(Collection::stream).collect(toSet());
    val actualSampleSubmitterIds = actualSamples.stream().map(Sample::getSampleSubmitterId).collect(toSet());
    // Verify expected donors and actual donors match
    assertSetsMatch(expectedDonors, actualDonors);
    // Verify expected specimens and actual specimens match
    assertSetsMatch(expectedSpecimens, actualSpecimens);
    // Verify expected sampleSubmitterIds and actual sampleSubmitterIds match
    assertSetsMatch(expectedSampleSubmitterIds, actualSampleSubmitterIds);
}
Also used : lombok.val(lombok.val) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) Autowired(org.springframework.beans.factory.annotation.Autowired) SequencingReadAnalysis(org.icgc.dcc.song.server.model.analysis.SequencingReadAnalysis) ActiveProfiles(org.springframework.test.context.ActiveProfiles) TestFiles.assertSetsMatch(org.icgc.dcc.song.server.utils.TestFiles.assertSetsMatch) StudyGenerator(org.icgc.dcc.song.server.utils.StudyGenerator) TestExecutionListeners(org.springframework.test.context.TestExecutionListeners) AnalysisGenerator.createAnalysisGenerator(org.icgc.dcc.song.server.utils.AnalysisGenerator.createAnalysisGenerator) SpringRunner(org.springframework.test.context.junit4.SpringRunner) DonorWithSpecimens(org.icgc.dcc.song.server.model.entity.composites.DonorWithSpecimens) DependencyInjectionTestExecutionListener(org.springframework.test.context.support.DependencyInjectionTestExecutionListener) Collectors.toSet(java.util.stream.Collectors.toSet) Before(org.junit.Before) RandomGenerator.createRandomGenerator(org.icgc.dcc.song.core.utils.RandomGenerator.createRandomGenerator) Donor(org.icgc.dcc.song.server.model.entity.Donor) Specimen(org.icgc.dcc.song.server.model.entity.Specimen) Collection(java.util.Collection) lombok.val(lombok.val) Test(org.junit.Test) Maps(com.google.common.collect.Maps) CompositeEntity(org.icgc.dcc.song.server.model.entity.composites.CompositeEntity) Slf4j(lombok.extern.slf4j.Slf4j) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) SpecimenWithSamples(org.icgc.dcc.song.server.model.entity.composites.SpecimenWithSamples) RandomGenerator(org.icgc.dcc.song.core.utils.RandomGenerator) StudyGenerator.createStudyGenerator(org.icgc.dcc.song.server.utils.StudyGenerator.createStudyGenerator) Sample(org.icgc.dcc.song.server.model.entity.Sample) Specimen(org.icgc.dcc.song.server.model.entity.Specimen) Donor(org.icgc.dcc.song.server.model.entity.Donor) SequencingReadAnalysis(org.icgc.dcc.song.server.model.analysis.SequencingReadAnalysis) DonorWithSpecimens(org.icgc.dcc.song.server.model.entity.composites.DonorWithSpecimens) Collection(java.util.Collection) SpecimenWithSamples(org.icgc.dcc.song.server.model.entity.composites.SpecimenWithSamples) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with SpecimenWithSamples

use of org.icgc.dcc.song.server.model.entity.composites.SpecimenWithSamples in project SONG by overture-stack.

the class SpecimenService method readWithSamples.

SpecimenWithSamples readWithSamples(String id) {
    val specimen = read(id);
    val s = new SpecimenWithSamples();
    s.setSpecimen(specimen);
    s.setSamples(sampleService.readByParentId(id));
    return s;
}
Also used : lombok.val(lombok.val) SpecimenWithSamples(org.icgc.dcc.song.server.model.entity.composites.SpecimenWithSamples)

Example 4 with SpecimenWithSamples

use of org.icgc.dcc.song.server.model.entity.composites.SpecimenWithSamples in project SONG by overture-stack.

the class EntityTest method testStudyWithDonors.

@Test
public void testStudyWithDonors() {
    val study1 = Study.create("d1", "b1", "c1", "a1");
    val study2 = Study.create("d2", "b2", "c2", "a2");
    val s1 = new StudyWithDonors();
    s1.setStudy(study1);
    val s1_same = new StudyWithDonors();
    s1_same.setName(study1.getName());
    s1_same.setOrganization(study1.getOrganization());
    s1_same.setStudyId(study1.getStudyId());
    s1_same.setDescription(study1.getDescription());
    assertEntitiesEqual(s1, s1_same, true);
    val s2 = new StudyWithDonors();
    s2.setStudy(study2);
    assertEntitiesNotEqual(s1, s2);
    // ---------------
    val specimen1 = Specimen.create("mySpecimen1", "mySpecimenSubmitter1", "myDonor1", SPECIMEN_CLASSES.get(2), SPECIMEN_TYPES.get(2));
    val specimen2 = Specimen.create("mySpecimen2", "mySpecimenSubmitter2", "myDonor2", SPECIMEN_CLASSES.get(1), SPECIMEN_TYPES.get(1));
    val sample11 = Sample.create("mySample11", "mySubmitterSample11", "mySpecimen11", SAMPLE_TYPES.get(2));
    val sample12 = Sample.create("mySample12", "mySubmitterSample12", "mySpecimen12", SAMPLE_TYPES.get(2));
    val sampleGroup1 = newArrayList(sample11, sample12);
    val sample21 = Sample.create("mySample21", "mySubmitterSample21", "mySpecimen21", SAMPLE_TYPES.get(3));
    val sample22 = Sample.create("mySample22", "mySubmitterSample22", "mySpecimen22", SAMPLE_TYPES.get(3));
    val sampleGroup2 = newArrayList(sample21, sample22);
    val specimenWithSample1 = new SpecimenWithSamples();
    specimenWithSample1.setSpecimen(specimen1);
    specimenWithSample1.setSamples(sampleGroup1);
    val specimenWithSample2 = new SpecimenWithSamples();
    specimenWithSample2.setSpecimen(specimen2);
    specimenWithSample2.setSamples(sampleGroup2);
    val specimenWSampleGroup1 = newArrayList(specimenWithSample1, specimenWithSample2);
    val specimenWSampleGroup2 = newArrayList(specimenWithSample1);
    val donor1 = Donor.create("myDonor1", "myDonorSubmitter1", DEFAULT_STUDY_ID, "male");
    val donor2 = Donor.create("myDonor2", "myDonorSubmitter2", DEFAULT_STUDY_ID, "female");
    val d1 = new DonorWithSpecimens();
    d1.setDonor(donor1);
    d1.setSpecimens(specimenWSampleGroup1);
    val d2 = new DonorWithSpecimens();
    d2.setDonor(donor2);
    d2.setSpecimens(specimenWSampleGroup2);
    // 00 -- matchingDonorGroup=0    matchingStudy=0
    s1.setStudy(study1);
    s1.setDonors(newArrayList(d1));
    s2.setStudy(study2);
    s2.setDonors(newArrayList(d2));
    assertEntitiesNotEqual(s1, s2);
    // 01 -- matchingDonorGroup=0    matchingStudy=1
    s1.setStudy(study1);
    s1.setDonors(newArrayList(d1));
    s2.setStudy(study1);
    s2.setDonors(newArrayList(d2));
    assertEntitiesNotEqual(s1, s2);
    // 10 -- matchingDonorGroup=1    matchingStudy=0
    s1.setStudy(study1);
    s1.setDonors(newArrayList(d1));
    s2.setStudy(study2);
    s2.setDonors(newArrayList(d1));
    assertEntitiesNotEqual(s1, s2);
    // 11 -- matchingDonorGroup=1    matchingStudy=1
    s1.setStudy(study1);
    s1.setDonors(newArrayList(d1));
    s2.setStudy(study1);
    s2.setDonors(newArrayList(d1));
    assertEntitiesEqual(s1, s2, true);
    s1.setInfo("key1", "f5c9381090a53c54358feb2ba5b7a3d7");
    s2.setInfo("key2", "6329334b-dcd5-53c8-98fd-9812ac386d30");
    assertInfoKVPair(s1, "key1", "f5c9381090a53c54358feb2ba5b7a3d7");
    assertEntitiesNotEqual(s1, s2);
    s1.setInfo("key1", "f5c9381090a53c54358feb2ba5b7a3d7");
    s2.setInfo("key1", "6329334b-dcd5-53c8-98fd-9812ac386d30");
    assertEntitiesNotEqual(s1, s2);
    // Test getters
    assertThat(s1.getDescription()).isEqualTo(study1.getDescription());
    assertThat(s1.getName()).isEqualTo(study1.getName());
    assertThat(s1.getOrganization()).isEqualTo(study1.getOrganization());
    assertThat(s1.getStudyId()).isEqualTo(study1.getStudyId());
    assertThat(s1.getStudy()).isNotSameAs(study1);
    assertThat(s1.getDonors()).containsExactlyInAnyOrder(d1);
    assertInfoKVPair(s1, "key1", "f5c9381090a53c54358feb2ba5b7a3d7");
    // Assert addDonor
    val sLeft = new StudyWithDonors();
    sLeft.setStudy(study1);
    sLeft.setDonors(newArrayList(d1, d2));
    val sRight = new StudyWithDonors();
    sRight.setStudy(study1);
    sRight.addDonor(d1);
    sRight.addDonor(d2);
    assertThat(sLeft).isEqualTo(sRight);
}
Also used : lombok.val(lombok.val) DonorWithSpecimens(org.icgc.dcc.song.server.model.entity.composites.DonorWithSpecimens) SpecimenWithSamples(org.icgc.dcc.song.server.model.entity.composites.SpecimenWithSamples) StudyWithDonors(org.icgc.dcc.song.server.model.entity.composites.StudyWithDonors) Test(org.junit.Test)

Example 5 with SpecimenWithSamples

use of org.icgc.dcc.song.server.model.entity.composites.SpecimenWithSamples in project SONG by overture-stack.

the class EntityTest method testSpecimenWithSamples.

@Test
public void testSpecimenWithSamples() {
    val specimen1 = Specimen.create("mySpecimen1", "mySpecimenSubmitter1", "myDonor1", SPECIMEN_CLASSES.get(2), SPECIMEN_TYPES.get(2));
    val specimen2 = Specimen.create("mySpecimen2", "mySpecimenSubmitter2", "myDonor2", SPECIMEN_CLASSES.get(1), SPECIMEN_TYPES.get(1));
    val sample11 = Sample.create("mySample11", "mySubmitterSample11", "mySpecimen11", SAMPLE_TYPES.get(2));
    val sample12 = Sample.create("mySample12", "mySubmitterSample12", "mySpecimen12", SAMPLE_TYPES.get(2));
    val sampleGroup1 = newArrayList(sample11, sample12);
    val sample21 = Sample.create("mySample21", "mySubmitterSample21", "mySpecimen21", SAMPLE_TYPES.get(3));
    val sample22 = Sample.create("mySample22", "mySubmitterSample22", "mySpecimen22", SAMPLE_TYPES.get(3));
    val sampleGroup2 = newArrayList(sample21, sample22);
    val s1 = new SpecimenWithSamples();
    s1.setDonorId(specimen1.getDonorId());
    s1.setSpecimenClass(specimen1.getSpecimenClass());
    s1.setSpecimenSubmitterId(specimen1.getSpecimenSubmitterId());
    s1.setSpecimenId(specimen1.getSpecimenId());
    s1.setSpecimenType(specimen1.getSpecimenType());
    val s2 = new SpecimenWithSamples();
    s2.setSpecimen(specimen1);
    assertEntitiesEqual(s1, s2, true);
    // 00 - matchingSampleGroup=0   matchingSpecimen=0
    s1.setSpecimen(specimen1);
    s1.setSamples(sampleGroup1);
    s2.setSpecimen(specimen2);
    s2.setSamples(sampleGroup2);
    assertEntitiesNotEqual(s1, s2);
    // 01 - matchingSampleGroup=0   matchingSpecimen=1
    s1.setSpecimen(specimen1);
    s1.setSamples(sampleGroup1);
    s2.setSpecimen(specimen1);
    s2.setSamples(sampleGroup2);
    assertEntitiesNotEqual(s1, s2);
    // 10 - matchingSampleGroup=1   matchingSpecimen=0
    s1.setSpecimen(specimen1);
    s1.setSamples(sampleGroup1);
    s2.setSpecimen(specimen2);
    s2.setSamples(sampleGroup1);
    assertEntitiesNotEqual(s1, s2);
    // 11 - matchingSampleGroup=1   matchingSpecimen=1
    s1.setSpecimen(specimen1);
    s1.setSamples(sampleGroup1);
    s2.setSpecimen(specimen1);
    s2.setSamples(sampleGroup1);
    assertEntitiesEqual(s1, s2, true);
    s1.setInfo("key1", "f5c9381090a53c54358feb2ba5b7a3d7");
    s2.setInfo("key2", "6329334b-dcd5-53c8-98fd-9812ac386d30");
    assertEntitiesNotEqual(s1, s2);
    // Test getters
    assertThat(s1.getDonorId()).isEqualTo(specimen1.getDonorId());
    assertThat(s1.getSpecimenClass()).isEqualTo(specimen1.getSpecimenClass());
    assertThat(s1.getSpecimenSubmitterId()).isEqualTo(specimen1.getSpecimenSubmitterId());
    assertThat(s1.getSpecimenType()).isEqualTo(specimen1.getSpecimenType());
    assertThat(s1.getSpecimenId()).isEqualTo(specimen1.getSpecimenId());
    assertThat(s1.getSamples()).containsExactlyInAnyOrder(sample11, sample12);
    assertInfoKVPair(s1, "key1", "f5c9381090a53c54358feb2ba5b7a3d7");
    // Test addSample
    val sLeft = new SpecimenWithSamples();
    sLeft.setDonorId(specimen1.getDonorId());
    sLeft.setSpecimenClass(specimen1.getSpecimenClass());
    sLeft.setSpecimenSubmitterId(specimen1.getSpecimenSubmitterId());
    sLeft.setSpecimenId(specimen1.getSpecimenId());
    sLeft.setSpecimenType(specimen1.getSpecimenType());
    sLeft.setSamples(sampleGroup2);
    val sRight = new SpecimenWithSamples();
    sRight.setDonorId(specimen1.getDonorId());
    sRight.setSpecimenClass(specimen1.getSpecimenClass());
    sRight.setSpecimenSubmitterId(specimen1.getSpecimenSubmitterId());
    sRight.setSpecimenId(specimen1.getSpecimenId());
    sRight.setSpecimenType(specimen1.getSpecimenType());
    sampleGroup2.forEach(sRight::addSample);
    assertThat(sLeft).isEqualTo(sRight);
}
Also used : lombok.val(lombok.val) SpecimenWithSamples(org.icgc.dcc.song.server.model.entity.composites.SpecimenWithSamples) Test(org.junit.Test)

Aggregations

lombok.val (lombok.val)5 SpecimenWithSamples (org.icgc.dcc.song.server.model.entity.composites.SpecimenWithSamples)5 Test (org.junit.Test)4 DonorWithSpecimens (org.icgc.dcc.song.server.model.entity.composites.DonorWithSpecimens)3 Maps (com.google.common.collect.Maps)1 Collection (java.util.Collection)1 Collectors.toSet (java.util.stream.Collectors.toSet)1 Slf4j (lombok.extern.slf4j.Slf4j)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 RandomGenerator (org.icgc.dcc.song.core.utils.RandomGenerator)1 RandomGenerator.createRandomGenerator (org.icgc.dcc.song.core.utils.RandomGenerator.createRandomGenerator)1 SequencingReadAnalysis (org.icgc.dcc.song.server.model.analysis.SequencingReadAnalysis)1 Donor (org.icgc.dcc.song.server.model.entity.Donor)1 Sample (org.icgc.dcc.song.server.model.entity.Sample)1 Specimen (org.icgc.dcc.song.server.model.entity.Specimen)1 CompositeEntity (org.icgc.dcc.song.server.model.entity.composites.CompositeEntity)1 StudyWithDonors (org.icgc.dcc.song.server.model.entity.composites.StudyWithDonors)1 AnalysisGenerator.createAnalysisGenerator (org.icgc.dcc.song.server.utils.AnalysisGenerator.createAnalysisGenerator)1 StudyGenerator (org.icgc.dcc.song.server.utils.StudyGenerator)1 StudyGenerator.createStudyGenerator (org.icgc.dcc.song.server.utils.StudyGenerator.createStudyGenerator)1