Search in sources :

Example 1 with CompositeEntity

use of org.icgc.dcc.song.server.model.entity.composites.CompositeEntity 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 2 with CompositeEntity

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

the class AnalysisServiceTest method testReadSequencingRead.

@Test
public void testReadSequencingRead() {
    val json = getJsonStringFromClasspath("documents/sequencingread-read-test.json");
    val analysisRaw = fromJson(json, SequencingReadAnalysis.class);
    val analysisId = service.create(DEFAULT_STUDY_ID, analysisRaw, false);
    val a = (SequencingReadAnalysis) service.read(analysisId);
    // Asserting Analysis
    assertThat(a.getAnalysisState()).isEqualTo("UNPUBLISHED");
    assertThat(a.getAnalysisType()).isEqualTo("sequencingRead");
    assertThat(a.getStudy()).isEqualTo(DEFAULT_STUDY_ID);
    assertInfoKVPair(a, "description1", "description1 for this sequencingRead analysis an01");
    assertInfoKVPair(a, "description2", "description2 for this sequencingRead analysis an01");
    val experiment = a.getExperiment();
    assertThat(experiment.getAnalysisId()).isEqualTo(analysisId);
    assertThat(experiment.getLibraryStrategy()).isEqualTo("WXS");
    assertThat(experiment.getPairedEnd()).isFalse();
    assertThat(experiment.getInsertSize()).isEqualTo(92736);
    assertThat(experiment.getAligned()).isTrue();
    assertThat(experiment.getAlignmentTool()).isEqualTo("myCool Sequence ReadingTool");
    assertThat(experiment.getReferenceGenome()).isEqualTo("someSeq Genome");
    assertInfoKVPair(experiment, "extraExperimentInfo", "some more data for a sequencingRead experiment ex02");
    val sampleMap = Maps.<String, CompositeEntity>newHashMap();
    // Asserting Sample
    assertThat(a.getSample()).hasSize(2);
    val sample0 = a.getSample().get(0);
    sampleMap.put(sample0.getSampleId(), sample0);
    assertThat(sample0.getSampleSubmitterId()).isEqualTo("internal_sample_98024759826836_fr01");
    assertThat(sample0.getSampleType()).isEqualTo("Total RNA");
    assertInfoKVPair(sample0, "extraSampleInfo", "some more data for a sequencingRead sample_fr01");
    val donor00 = sample0.getDonor();
    assertThat(donor00.getStudyId()).isEqualTo(DEFAULT_STUDY_ID);
    assertThat(donor00.getDonorGender()).isEqualTo("male");
    assertThat(donor00.getDonorSubmitterId()).isEqualTo("internal_donor_123456789-00_fr01");
    assertInfoKVPair(donor00, "extraDonorInfo", "some more data for a sequencingRead donor_fr01");
    val specimen00 = sample0.getSpecimen();
    assertThat(specimen00.getDonorId()).isEqualTo(donor00.getDonorId());
    assertThat(specimen00.getSpecimenClass()).isEqualTo("Tumour");
    assertThat(specimen00.getSpecimenType()).isEqualTo("Primary tumour - other");
    assertThat(sample0.getSpecimenId()).isEqualTo(specimen00.getSpecimenId());
    assertInfoKVPair(specimen00, "extraSpecimenInfo_0", "first for a sequencingRead specimen_fr01");
    assertInfoKVPair(specimen00, "extraSpecimenInfo_1", "second data for a sequencingRead specimen_fr01");
    val sample1 = a.getSample().get(1);
    sampleMap.put(sample1.getSampleId(), sample1);
    assertThat(sample1.getSampleSubmitterId()).isEqualTo("internal_sample_98024759826836_fr02");
    assertThat(sample1.getSampleType()).isEqualTo("Total RNA");
    assertInfoKVPair(sample1, "extraSampleInfo", "some more data for a sequencingRead sample_fr02");
    val donor01 = sample1.getDonor();
    assertThat(donor01.getStudyId()).isEqualTo(DEFAULT_STUDY_ID);
    assertThat(donor01.getDonorGender()).isEqualTo("female");
    assertThat(donor01.getDonorSubmitterId()).isEqualTo("internal_donor_123456789-00_fr02");
    assertInfoKVPair(donor01, "extraDonorInfo_0", "first data for a sequencingRead donor_fr02");
    assertInfoKVPair(donor01, "extraDonorInfo_1", "second data for a sequencingRead donor_fr02");
    val specimen01 = sample1.getSpecimen();
    assertThat(specimen01.getDonorId()).isEqualTo(donor01.getDonorId());
    assertThat(specimen01.getSpecimenClass()).isEqualTo("Tumour");
    assertThat(specimen01.getSpecimenType()).isEqualTo("Primary tumour - other");
    assertThat(sample1.getSpecimenId()).isEqualTo(specimen01.getSpecimenId());
    assertInfoKVPair(specimen01, "extraSpecimenInfo", "some more data for a sequencingRead specimen_fr02");
    assertThat(a.getFile()).hasSize(3);
    val file0 = a.getFile().get(0);
    val file1 = a.getFile().get(1);
    val file2 = a.getFile().get(2);
    assertThat(file0.getAnalysisId()).isEqualTo(analysisId);
    assertThat(file1.getAnalysisId()).isEqualTo(analysisId);
    assertThat(file2.getAnalysisId()).isEqualTo(analysisId);
    assertThat(file0.getStudyId()).isEqualTo(DEFAULT_STUDY_ID);
    assertThat(file1.getStudyId()).isEqualTo(DEFAULT_STUDY_ID);
    assertThat(file2.getStudyId()).isEqualTo(DEFAULT_STUDY_ID);
    val fileName0 = "a3bc0998a-3521-43fd-fa10-a834f3874e46-fn1.MUSE_1-0rc-vcf.20170711.bam";
    val fileName1 = "a3bc0998a-3521-43fd-fa10-a834f3874e46-fn2.MUSE_1-0rc-vcf.20170711.bam";
    val fileName2 = "a3bc0998a-3521-43fd-fa10-a834f3874e46-fn3.MUSE_1-0rc-vcf.20170711.bam.bai";
    val fileMap = Maps.<String, File>newHashMap();
    for (val file : a.getFile()) {
        fileMap.put(file.getFileName(), file);
        if (file.getFileName().equals(fileName0)) {
            assertThat(file.getFileName()).isEqualTo(fileName0);
            assertThat(file.getFileSize()).isEqualTo(1212121);
            assertThat(file.getFileMd5sum()).isEqualTo("e2324667df8085eddfe95742047e153f");
            assertThat(file.getFileAccess()).isEqualTo("controlled");
            assertThat(file.getFileType()).isEqualTo("BAM");
            assertInfoKVPair(file, "extraFileInfo_0", "first data for sequencingRead file_fn1");
            assertInfoKVPair(file, "extraFileInfo_1", "second data for sequencingRead file_fn1");
        } else if (file.getFileName().equals(fileName1)) {
            assertThat(file.getFileName()).isEqualTo(fileName1);
            assertThat(file.getFileSize()).isEqualTo(34343);
            assertThat(file.getFileMd5sum()).isEqualTo("8b5379a29aac642d6fe1808826bd9e49");
            assertThat(file.getFileAccess()).isEqualTo("open");
            assertThat(file.getFileType()).isEqualTo("BAM");
            assertInfoKVPair(file, "extraFileInfo", "some more data for sequencingRead file_fn2");
        } else if (file.getFileName().equals(fileName2)) {
            assertThat(file.getFileName()).isEqualTo(fileName2);
            assertThat(file.getFileSize()).isEqualTo(4840);
            assertThat(file.getFileMd5sum()).isEqualTo("61da923f32863a9c5fa3d2a0e19bdee3");
            assertThat(file.getFileAccess()).isEqualTo("open");
            assertThat(file.getFileType()).isEqualTo("BAI");
            assertInfoKVPair(file, "extraFileInfo", "some more data for sequencingRead file_fn3");
        } else {
            fail(format("the fileName %s is not recognized", file.getFileName()));
        }
    }
    // Test the readFiles method
    for (val file : service.readFiles(analysisId)) {
        assertThat(fileMap).containsKeys(file.getFileName());
        assertThat(file).isEqualTo(fileMap.get(file.getFileName()));
    }
    // Test readSample method
    for (val compositeEntity : service.readSamples(analysisId)) {
        assertThat(sampleMap).containsKeys(compositeEntity.getSampleId());
        assertThat(compositeEntity).isEqualTo(sampleMap.get(compositeEntity.getSampleId()));
    }
    assertThat(service.readSequencingRead(analysisId)).isEqualTo(experiment);
}
Also used : lombok.val(lombok.val) SequencingReadAnalysis(org.icgc.dcc.song.server.model.analysis.SequencingReadAnalysis) CompositeEntity(org.icgc.dcc.song.server.model.entity.composites.CompositeEntity) File(org.icgc.dcc.song.server.model.entity.File) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 3 with CompositeEntity

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

the class EntityTest method testCompositeEntity.

@Test
public void testCompositeEntity() {
    val donor1 = Donor.create("myDonor1", "myDonorSubmitter1", DEFAULT_STUDY_ID, "male");
    val donor2 = Donor.create("myDonor2", "myDonorSubmitter2", DEFAULT_STUDY_ID, "female");
    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 sample1 = Sample.create("mySample1", "mySubmitterSample1", "mySpecimen1", SAMPLE_TYPES.get(2));
    val sample2 = Sample.create("mySample2", "mySubmitterSample2", "mySpecimen2", SAMPLE_TYPES.get(3));
    val compositeEntity1 = CompositeEntity.create(sample1);
    compositeEntity1.setDonor(donor1);
    compositeEntity1.setSpecimen(specimen1);
    val compositeEntity1_same = new CompositeEntity();
    compositeEntity1_same.setSampleType(SAMPLE_TYPES.get(2));
    compositeEntity1_same.setSampleSubmitterId("mySubmitterSample1");
    compositeEntity1_same.setSampleId("mySample1");
    compositeEntity1_same.setSpecimenId("mySpecimen1");
    compositeEntity1_same.setSpecimen(specimen1);
    compositeEntity1_same.setDonor(donor1);
    assertEntitiesEqual(compositeEntity1, compositeEntity1_same, true);
    val compositeEntity2 = CompositeEntity.create(sample1);
    compositeEntity2.setDonor(donor1);
    compositeEntity2.setSpecimen(specimen2);
    assertEntitiesNotEqual(compositeEntity1, compositeEntity2);
    compositeEntity2.setDonor(donor2);
    compositeEntity2.setSpecimen(specimen1);
    assertEntitiesNotEqual(compositeEntity1, compositeEntity2);
    compositeEntity2.setDonor(donor2);
    compositeEntity2.setSpecimen(specimen2);
    assertEntitiesNotEqual(compositeEntity1, compositeEntity2);
    val compositeEntity3 = CompositeEntity.create(sample2);
    compositeEntity3.setDonor(donor1);
    compositeEntity3.setSpecimen(specimen2);
    assertEntitiesNotEqual(compositeEntity1, compositeEntity3);
    compositeEntity3.setDonor(donor2);
    compositeEntity3.setSpecimen(specimen1);
    assertEntitiesNotEqual(compositeEntity1, compositeEntity3);
    compositeEntity3.setDonor(donor2);
    compositeEntity3.setSpecimen(specimen2);
    assertEntitiesNotEqual(compositeEntity1, compositeEntity3);
    compositeEntity3.setDonor(donor1);
    compositeEntity3.setSpecimen(specimen1);
    assertEntitiesNotEqual(compositeEntity1, compositeEntity3);
    compositeEntity1.setInfo("key1", "f5c9381090a53c54358feb2ba5b7a3d7");
    compositeEntity1_same.setInfo("key2", "6329334b-dcd5-53c8-98fd-9812ac386d30");
    assertEntitiesNotEqual(compositeEntity1, compositeEntity1_same);
    // Test getters
    assertThat(compositeEntity1.getSampleId()).isEqualTo("mySample1");
    assertThat(compositeEntity1.getSampleType()).isEqualTo(SAMPLE_TYPES.get(2));
    assertThat(compositeEntity1.getSampleSubmitterId()).isEqualTo("mySubmitterSample1");
    assertThat(compositeEntity1.getSpecimenId()).isEqualTo("mySpecimen1");
    assertThat(compositeEntity1.getSpecimen()).isEqualTo(specimen1);
    assertThat(compositeEntity1.getDonor()).isEqualTo(donor1);
    assertInfoKVPair(compositeEntity1, "key1", "f5c9381090a53c54358feb2ba5b7a3d7");
}
Also used : lombok.val(lombok.val) CompositeEntity(org.icgc.dcc.song.server.model.entity.composites.CompositeEntity) Test(org.junit.Test)

Aggregations

lombok.val (lombok.val)3 CompositeEntity (org.icgc.dcc.song.server.model.entity.composites.CompositeEntity)3 Test (org.junit.Test)3 SequencingReadAnalysis (org.icgc.dcc.song.server.model.analysis.SequencingReadAnalysis)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 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 Donor (org.icgc.dcc.song.server.model.entity.Donor)1 File (org.icgc.dcc.song.server.model.entity.File)1 Sample (org.icgc.dcc.song.server.model.entity.Sample)1 Specimen (org.icgc.dcc.song.server.model.entity.Specimen)1 DonorWithSpecimens (org.icgc.dcc.song.server.model.entity.composites.DonorWithSpecimens)1 SpecimenWithSamples (org.icgc.dcc.song.server.model.entity.composites.SpecimenWithSamples)1 AnalysisGenerator.createAnalysisGenerator (org.icgc.dcc.song.server.utils.AnalysisGenerator.createAnalysisGenerator)1 StudyGenerator (org.icgc.dcc.song.server.utils.StudyGenerator)1