Search in sources :

Example 6 with SequencingReadAnalysis

use of org.icgc.dcc.song.server.model.analysis.SequencingReadAnalysis in project SONG by overture-stack.

the class AnalysisService method read.

public Analysis read(String id) {
    val analysis = checkAnalysis(id);
    analysis.setInfo(analysisInfoService.readNullableInfo(id));
    analysis.setFile(readFiles(id));
    analysis.setSample(readSamples(id));
    if (analysis instanceof SequencingReadAnalysis) {
        val experiment = readSequencingRead(id);
        ((SequencingReadAnalysis) analysis).setExperiment(experiment);
    } else if (analysis instanceof VariantCallAnalysis) {
        val experiment = readVariantCall(id);
        ((VariantCallAnalysis) analysis).setExperiment(experiment);
    }
    return analysis;
}
Also used : lombok.val(lombok.val) SequencingReadAnalysis(org.icgc.dcc.song.server.model.analysis.SequencingReadAnalysis) VariantCallAnalysis(org.icgc.dcc.song.server.model.analysis.VariantCallAnalysis)

Example 7 with SequencingReadAnalysis

use of org.icgc.dcc.song.server.model.analysis.SequencingReadAnalysis in project SONG by overture-stack.

the class ExportService method convertToPayload.

@SneakyThrows
private static JsonNode convertToPayload(@NonNull Analysis a, boolean includeAnalysisId, boolean includeOtherIds) {
    JsonNode output;
    val analysisType = resolveAnalysisType(a.getAnalysisType());
    if (analysisType == SEQUENCING_READ) {
        val seqRead = (SequencingReadAnalysis) a;
        output = readTree(toPrettyJson(seqRead));
    } else if (analysisType == VARIANT_CALL) {
        val varCall = (VariantCallAnalysis) a;
        output = readTree(toPrettyJson(varCall));
    } else {
        throw new IllegalStateException(format("Should not be here, unsupported analysisType '%s'", a.getAnalysisType()));
    }
    val payloadConverter = createPayloadConverter(includeAnalysisId, includeOtherIds);
    val payloadParser = createPayloadParser(output);
    return payloadConverter.convert(payloadParser);
}
Also used : lombok.val(lombok.val) SequencingReadAnalysis(org.icgc.dcc.song.server.model.analysis.SequencingReadAnalysis) JsonNode(com.fasterxml.jackson.databind.JsonNode) SneakyThrows(lombok.SneakyThrows)

Example 8 with SequencingReadAnalysis

use of org.icgc.dcc.song.server.model.analysis.SequencingReadAnalysis in project SONG by overture-stack.

the class AnalysisServiceTest method testGetAnalysisAndIdSearch.

@Test
public void testGetAnalysisAndIdSearch() {
    val studyGenerator = createStudyGenerator(studyService, randomGenerator);
    val studyId = studyGenerator.createRandomStudy();
    val analysisGenerator = createAnalysisGenerator(studyId, service, payloadGenerator);
    val numAnalysis = 10;
    val sraMap = Maps.<String, SequencingReadAnalysis>newHashMap();
    val vcaMap = Maps.<String, VariantCallAnalysis>newHashMap();
    val expectedAnalyses = Sets.<Analysis>newHashSet();
    for (int i = 1; i <= numAnalysis; i++) {
        if (i % 2 == 0) {
            val sra = analysisGenerator.createDefaultRandomSequencingReadAnalysis();
            assertThat(sraMap.containsKey(sra.getAnalysisId())).isFalse();
            sraMap.put(sra.getAnalysisId(), sra);
            expectedAnalyses.add(sra);
        } else {
            val vca = analysisGenerator.createDefaultRandomVariantCallAnalysis();
            assertThat(sraMap.containsKey(vca.getAnalysisId())).isFalse();
            vcaMap.put(vca.getAnalysisId(), vca);
            expectedAnalyses.add(vca);
        }
    }
    assertThat(expectedAnalyses).hasSize(numAnalysis);
    assertThat(sraMap.keySet().size() + vcaMap.keySet().size()).isEqualTo(numAnalysis);
    val expectedVCAs = newHashSet(vcaMap.values());
    val expectedSRAs = newHashSet(sraMap.values());
    assertThat(expectedSRAs).hasSize(sraMap.keySet().size());
    assertThat(expectedVCAs).hasSize(vcaMap.keySet().size());
    val actualAnalyses = service.getAnalysis(studyId);
    val actualSRAs = actualAnalyses.stream().filter(x -> resolveAnalysisType(x.getAnalysisType()) == SEQUENCING_READ).collect(toSet());
    val actualVCAs = actualAnalyses.stream().filter(x -> resolveAnalysisType(x.getAnalysisType()) == VARIANT_CALL).collect(toSet());
    assertThat(actualSRAs).hasSize(sraMap.keySet().size());
    assertThat(actualVCAs).hasSize(vcaMap.keySet().size());
    assertThat(actualSRAs).containsAll(expectedSRAs);
    assertThat(actualVCAs).containsAll(expectedVCAs);
    // Do a study-wide idSearch and verify the response effectively has the same
    // number of results as the getAnalysis method
    val searchedAnalyses = service.idSearch(studyId, createIdSearchRequest(null, null, null, null));
    assertThat(searchedAnalyses).hasSameSizeAs(expectedAnalyses);
    assertThat(searchedAnalyses).containsOnlyElementsOf(expectedAnalyses);
}
Also used : lombok.val(lombok.val) ANALYSIS_ID_NOT_FOUND(org.icgc.dcc.song.core.exceptions.ServerErrors.ANALYSIS_ID_NOT_FOUND) ExistenceService.createExistenceService(org.icgc.dcc.song.server.service.ExistenceService.createExistenceService) File(org.icgc.dcc.song.server.model.entity.File) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Autowired(org.springframework.beans.factory.annotation.Autowired) SequencingReadAnalysis(org.icgc.dcc.song.server.model.analysis.SequencingReadAnalysis) ActiveProfiles(org.springframework.test.context.ActiveProfiles) DUPLICATE_ANALYSIS_ATTEMPT(org.icgc.dcc.song.core.exceptions.ServerErrors.DUPLICATE_ANALYSIS_ATTEMPT) AnalysisTypes.resolveAnalysisType(org.icgc.dcc.song.server.model.enums.AnalysisTypes.resolveAnalysisType) TestExecutionListeners(org.springframework.test.context.TestExecutionListeners) Study(org.icgc.dcc.song.server.model.entity.Study) PayloadGenerator.createPayloadGenerator(org.icgc.dcc.song.server.utils.PayloadGenerator.createPayloadGenerator) VariantCallAnalysis(org.icgc.dcc.song.server.model.analysis.VariantCallAnalysis) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) SpringRunner(org.springframework.test.context.junit4.SpringRunner) SongErrorAssertions.assertSongError(org.icgc.dcc.song.core.testing.SongErrorAssertions.assertSongError) Collectors.toSet(java.util.stream.Collectors.toSet) STUDY_ID_DOES_NOT_EXIST(org.icgc.dcc.song.core.exceptions.ServerErrors.STUDY_ID_DOES_NOT_EXIST) ANALYSIS_MISSING_FILES(org.icgc.dcc.song.core.exceptions.ServerErrors.ANALYSIS_MISSING_FILES) RandomGenerator.createRandomGenerator(org.icgc.dcc.song.core.utils.RandomGenerator.createRandomGenerator) WireMock.aResponse(com.github.tomakehurst.wiremock.client.WireMock.aResponse) TestFiles.assertInfoKVPair(org.icgc.dcc.song.server.utils.TestFiles.assertInfoKVPair) Sets(com.google.common.collect.Sets) String.format(java.lang.String.format) JsonUtils(org.icgc.dcc.song.core.utils.JsonUtils) Slf4j(lombok.extern.slf4j.Slf4j) Assertions.fail(org.assertj.core.api.Assertions.fail) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) ANALYSIS_MISSING_SAMPLES(org.icgc.dcc.song.core.exceptions.ServerErrors.ANALYSIS_MISSING_SAMPLES) JsonUtils.fromJson(org.icgc.dcc.song.core.utils.JsonUtils.fromJson) RandomGenerator(org.icgc.dcc.song.core.utils.RandomGenerator) IdSearchRequest.createIdSearchRequest(org.icgc.dcc.song.server.repository.search.IdSearchRequest.createIdSearchRequest) RunWith(org.junit.runner.RunWith) SEQUENCING_READ(org.icgc.dcc.song.server.model.enums.AnalysisTypes.SEQUENCING_READ) Analysis(org.icgc.dcc.song.server.model.analysis.Analysis) ArrayList(java.util.ArrayList) WireMockRule(com.github.tomakehurst.wiremock.junit.WireMockRule) AnalysisGenerator.createAnalysisGenerator(org.icgc.dcc.song.server.utils.AnalysisGenerator.createAnalysisGenerator) AnalysisGenerator(org.icgc.dcc.song.server.utils.AnalysisGenerator) DependencyInjectionTestExecutionListener(org.springframework.test.context.support.DependencyInjectionTestExecutionListener) UNPUBLISHED_FILE_IDS(org.icgc.dcc.song.core.exceptions.ServerErrors.UNPUBLISHED_FILE_IDS) Before(org.junit.Before) WireMock.get(com.github.tomakehurst.wiremock.client.WireMock.get) VARIANT_CALL(org.icgc.dcc.song.server.model.enums.AnalysisTypes.VARIANT_CALL) JsonUtils.toJson(org.icgc.dcc.song.core.utils.JsonUtils.toJson) lombok.val(lombok.val) WireMockConfiguration.options(com.github.tomakehurst.wiremock.core.WireMockConfiguration.options) ReflectionTestUtils(org.springframework.test.util.ReflectionTestUtils) Test(org.junit.Test) Maps(com.google.common.collect.Maps) CompositeEntity(org.icgc.dcc.song.server.model.entity.composites.CompositeEntity) WireMock.urlMatching(com.github.tomakehurst.wiremock.client.WireMock.urlMatching) UNPUBLISHED(org.icgc.dcc.song.server.model.enums.AnalysisStates.UNPUBLISHED) TestFiles.getJsonStringFromClasspath(org.icgc.dcc.song.server.utils.TestFiles.getJsonStringFromClasspath) AnalysisRepository(org.icgc.dcc.song.server.repository.AnalysisRepository) SEQUENCING_READ_NOT_FOUND(org.icgc.dcc.song.core.exceptions.ServerErrors.SEQUENCING_READ_NOT_FOUND) PayloadGenerator(org.icgc.dcc.song.server.utils.PayloadGenerator) Rule(org.junit.Rule) Metadata(org.icgc.dcc.song.server.model.Metadata) SampleRepository(org.icgc.dcc.song.server.repository.SampleRepository) VARIANT_CALL_NOT_FOUND(org.icgc.dcc.song.core.exceptions.ServerErrors.VARIANT_CALL_NOT_FOUND) StudyGenerator.createStudyGenerator(org.icgc.dcc.song.server.utils.StudyGenerator.createStudyGenerator) RetryTemplate(org.springframework.retry.support.RetryTemplate) OK(org.springframework.http.HttpStatus.OK) Sample(org.icgc.dcc.song.server.model.entity.Sample) SequencingReadAnalysis(org.icgc.dcc.song.server.model.analysis.SequencingReadAnalysis) SequencingReadAnalysis(org.icgc.dcc.song.server.model.analysis.SequencingReadAnalysis) VariantCallAnalysis(org.icgc.dcc.song.server.model.analysis.VariantCallAnalysis) Analysis(org.icgc.dcc.song.server.model.analysis.Analysis) VariantCallAnalysis(org.icgc.dcc.song.server.model.analysis.VariantCallAnalysis) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 9 with SequencingReadAnalysis

use of org.icgc.dcc.song.server.model.analysis.SequencingReadAnalysis 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 10 with SequencingReadAnalysis

use of org.icgc.dcc.song.server.model.analysis.SequencingReadAnalysis in project SONG by overture-stack.

the class SerializationTest method testSequencingReadAnalysisFromJson.

@Test
public void testSequencingReadAnalysisFromJson() throws IOException {
    val json = readFile(FILEPATH + "sequencingRead.json");
    val analysis = JsonUtils.fromJson(json, Analysis.class);
    System.out.printf("*** Analysis object='%s'\n", analysis);
    assertThat(analysis.getAnalysisType()).isEqualTo("sequencingRead");
    assertThat(analysis.getFile().size()).isEqualTo(2);
    assertThat(analysis.getSample().get(0).getDonor().getDonorSubmitterId()).isEqualTo("internal_donor_123456789-00");
    assertThat(analysis).isInstanceOf(SequencingReadAnalysis.class);
    val r = ((SequencingReadAnalysis) analysis).getExperiment();
    assertThat(r.getLibraryStrategy()).isEqualTo("WXS");
    assertThat(r.getInsertSize()).isEqualTo(900);
    assertThat(r.getAlignmentTool()).isEqualTo("MUSE variant call pipeline");
}
Also used : lombok.val(lombok.val) SequencingReadAnalysis(org.icgc.dcc.song.server.model.analysis.SequencingReadAnalysis) Test(org.junit.Test)

Aggregations

lombok.val (lombok.val)13 SequencingReadAnalysis (org.icgc.dcc.song.server.model.analysis.SequencingReadAnalysis)13 Test (org.junit.Test)8 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)5 VariantCallAnalysis (org.icgc.dcc.song.server.model.analysis.VariantCallAnalysis)4 CompositeEntity (org.icgc.dcc.song.server.model.entity.composites.CompositeEntity)3 Maps (com.google.common.collect.Maps)2 Collectors.toSet (java.util.stream.Collectors.toSet)2 Slf4j (lombok.extern.slf4j.Slf4j)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 RandomGenerator (org.icgc.dcc.song.core.utils.RandomGenerator)2 RandomGenerator.createRandomGenerator (org.icgc.dcc.song.core.utils.RandomGenerator.createRandomGenerator)2 Metadata (org.icgc.dcc.song.server.model.Metadata)2 File (org.icgc.dcc.song.server.model.entity.File)2 Sample (org.icgc.dcc.song.server.model.entity.Sample)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 WireMock.aResponse (com.github.tomakehurst.wiremock.client.WireMock.aResponse)1 WireMock.get (com.github.tomakehurst.wiremock.client.WireMock.get)1 WireMock.urlMatching (com.github.tomakehurst.wiremock.client.WireMock.urlMatching)1 WireMockConfiguration.options (com.github.tomakehurst.wiremock.core.WireMockConfiguration.options)1