Search in sources :

Example 6 with File

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

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

the class EntityTest method testFile.

@Test
public void testFile() {
    val file1 = new File();
    file1.setAnalysisId("a1");
    file1.setFileAccess(CONTROLLED);
    file1.setFileMd5sum("b1");
    file1.setFileName("c1");
    file1.setFileSize(13L);
    file1.setFileType(FILE_TYPES.get(0));
    file1.setObjectId("d1");
    file1.setStudyId("e1");
    val file1_same = File.create("d1", "a1", "c1", "e1", 13L, FILE_TYPES.get(0), "b1", CONTROLLED);
    assertEntitiesEqual(file1, file1_same, true);
    val file2 = File.create("d2", "a2", "c2", "e2", 14L, FILE_TYPES.get(1), "b2", CONTROLLED);
    assertEntitiesNotEqual(file1, file2);
    file1.setInfo("key1", "f5c9381090a53c54358feb2ba5b7a3d7");
    file1_same.setInfo("key2", "6329334b-dcd5-53c8-98fd-9812ac386d30");
    assertEntitiesNotEqual(file1, file1_same);
    // Test getters
    assertThat(file1.getAnalysisId()).isEqualTo("a1");
    assertThat(file1.getFileAccess()).isEqualTo(CONTROLLED.toString());
    assertThat(file1.getFileMd5sum()).isEqualTo("b1");
    assertThat(file1.getFileName()).isEqualTo("c1");
    assertThat(file1.getFileType()).isEqualTo(FILE_TYPES.get(0));
    assertThat(file1.getObjectId()).isEqualTo("d1");
    assertThat(file1.getStudyId()).isEqualTo("e1");
    assertInfoKVPair(file1, "key1", "f5c9381090a53c54358feb2ba5b7a3d7");
}
Also used : lombok.val(lombok.val) File(org.icgc.dcc.song.server.model.entity.File) Test(org.junit.Test)

Example 8 with File

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

the class FileServiceTest method testFileExists.

@Test
public void testFileExists() {
    val existingFileId = DEFAULT_FILE_ID;
    assertThat(fileService.isFileExist(existingFileId)).isTrue();
    fileService.checkFileExists(existingFileId);
    val file = new File();
    file.setObjectId(existingFileId);
    fileService.checkFileExists(file);
    val randomFile = createRandomFile(DEFAULT_STUDY_ID, DEFAULT_ANALYSIS_ID);
    assertThat(fileService.isFileExist(randomFile.getObjectId())).isFalse();
    assertSongError(() -> fileService.checkFileExists(randomFile.getObjectId()), FILE_NOT_FOUND);
    assertSongError(() -> fileService.checkFileExists(randomFile), FILE_NOT_FOUND);
}
Also used : lombok.val(lombok.val) File(org.icgc.dcc.song.server.model.entity.File) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 9 with File

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

the class AnalysisService method publish.

public ResponseEntity<String> publish(@NonNull String accessToken, @NonNull String id) {
    val files = readFiles(id);
    val missingFileIds = files.stream().filter(f -> !confirmUploaded(accessToken, f.getObjectId())).collect(toImmutableList());
    val isMissingFiles = missingFileIds.size() > 0;
    checkServer(!isMissingFiles, getClass(), UNPUBLISHED_FILE_IDS, "The following file ids must be published before analysisId %s can be published: %s", id, COMMA.join(missingFileIds));
    checkedUpdateState(id, PUBLISHED);
    sender.send(String.format("{\"analysis_id\": %s, \"state\": \"PUBLISHED\"}", id));
    return ok("AnalysisId %s successfully published", id);
}
Also used : lombok.val(lombok.val) ANALYSIS_ID_NOT_FOUND(org.icgc.dcc.song.core.exceptions.ServerErrors.ANALYSIS_ID_NOT_FOUND) File(org.icgc.dcc.song.server.model.entity.File) RequiredArgsConstructor(lombok.RequiredArgsConstructor) Autowired(org.springframework.beans.factory.annotation.Autowired) SequencingReadAnalysis(org.icgc.dcc.song.server.model.analysis.SequencingReadAnalysis) DUPLICATE_ANALYSIS_ATTEMPT(org.icgc.dcc.song.core.exceptions.ServerErrors.DUPLICATE_ANALYSIS_ATTEMPT) COMMA(org.icgc.dcc.common.core.util.Joiners.COMMA) Analysis(org.icgc.dcc.song.server.model.analysis.Analysis) SequencingRead(org.icgc.dcc.song.server.model.experiment.SequencingRead) InfoSearchResponse(org.icgc.dcc.song.server.repository.search.InfoSearchResponse) SearchRepository(org.icgc.dcc.song.server.repository.search.SearchRepository) VARIANT_CALL_REPOSITORY_CREATE_RECORD(org.icgc.dcc.song.core.exceptions.ServerErrors.VARIANT_CALL_REPOSITORY_CREATE_RECORD) Service(org.springframework.stereotype.Service) VariantCallAnalysis(org.icgc.dcc.song.server.model.analysis.VariantCallAnalysis) ANALYSIS_STATE_UPDATE_FAILED(org.icgc.dcc.song.core.exceptions.ServerErrors.ANALYSIS_STATE_UPDATE_FAILED) PUBLISHED(org.icgc.dcc.song.server.model.enums.AnalysisStates.PUBLISHED) Objects.isNull(java.util.Objects.isNull) ServerException.checkServer(org.icgc.dcc.song.core.exceptions.ServerException.checkServer) Sender(org.icgc.dcc.song.server.kafka.Sender) UNPUBLISHED_FILE_IDS(org.icgc.dcc.song.core.exceptions.ServerErrors.UNPUBLISHED_FILE_IDS) ANALYSIS_MISSING_FILES(org.icgc.dcc.song.core.exceptions.ServerErrors.ANALYSIS_MISSING_FILES) SUPPRESSED(org.icgc.dcc.song.server.model.enums.AnalysisStates.SUPPRESSED) AnalysisStates(org.icgc.dcc.song.server.model.enums.AnalysisStates) InfoSearchRequest(org.icgc.dcc.song.server.repository.search.InfoSearchRequest) NonNull(lombok.NonNull) Collection(java.util.Collection) lombok.val(lombok.val) SearchTerm.createMultiSearchTerms(org.icgc.dcc.song.server.repository.search.SearchTerm.createMultiSearchTerms) MultiValueMap(org.springframework.util.MultiValueMap) SEQUENCING_READ_REPOSITORY_CREATE_RECORD(org.icgc.dcc.song.core.exceptions.ServerErrors.SEQUENCING_READ_REPOSITORY_CREATE_RECORD) Responses.ok(org.icgc.dcc.song.core.utils.Responses.ok) VariantCall(org.icgc.dcc.song.server.model.experiment.VariantCall) CompositeEntity(org.icgc.dcc.song.server.model.entity.composites.CompositeEntity) AnalysisRepository(org.icgc.dcc.song.server.repository.AnalysisRepository) SEQUENCING_READ_NOT_FOUND(org.icgc.dcc.song.core.exceptions.ServerErrors.SEQUENCING_READ_NOT_FOUND) Objects(java.util.Objects) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Collectors.toImmutableList(org.icgc.dcc.common.core.util.stream.Collectors.toImmutableList) ANALYSIS_MISSING_SAMPLES(org.icgc.dcc.song.core.exceptions.ServerErrors.ANALYSIS_MISSING_SAMPLES) VARIANT_CALL_NOT_FOUND(org.icgc.dcc.song.core.exceptions.ServerErrors.VARIANT_CALL_NOT_FOUND) ResponseEntity(org.springframework.http.ResponseEntity) ANALYSIS_REPOSITORY_CREATE_RECORD(org.icgc.dcc.song.core.exceptions.ServerErrors.ANALYSIS_REPOSITORY_CREATE_RECORD) IdSearchRequest(org.icgc.dcc.song.server.repository.search.IdSearchRequest) ServerException.buildServerException(org.icgc.dcc.song.core.exceptions.ServerException.buildServerException)

Aggregations

lombok.val (lombok.val)9 File (org.icgc.dcc.song.server.model.entity.File)9 Test (org.junit.Test)5 Collection (java.util.Collection)3 List (java.util.List)3 NonNull (lombok.NonNull)3 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)3 Files (java.nio.file.Files)2 Map (java.util.Map)2 Set (java.util.Set)2 Collectors.groupingBy (java.util.stream.Collectors.groupingBy)2 SneakyThrows (lombok.SneakyThrows)2 Collectors.toImmutableSet (org.icgc.dcc.common.core.util.stream.Collectors.toImmutableSet)2 DccMetadataConverter (org.icgc.dcc.song.importer.convert.DccMetadataConverter)2 FileConverter.convertToFile (org.icgc.dcc.song.importer.convert.FileConverter.convertToFile)2 DccMetadataDao (org.icgc.dcc.song.importer.dao.dcc.DccMetadataDao)2 CounterMonitor.newMonitor (org.icgc.dcc.song.importer.measurement.CounterMonitor.newMonitor)2 DccMetadata (org.icgc.dcc.song.importer.model.DccMetadata)2 SequencingReadAnalysis (org.icgc.dcc.song.server.model.analysis.SequencingReadAnalysis)2 CompositeEntity (org.icgc.dcc.song.server.model.entity.composites.CompositeEntity)2