use of org.icgc.dcc.song.server.model.analysis.SequencingReadAnalysis in project SONG by overture-stack.
the class AnalysisServiceTest method testCreateAndUpdate.
@Test
public void testCreateAndUpdate() {
val created = analysisGenerator.createDefaultRandomSequencingReadAnalysis();
val analysisId = created.getAnalysisId();
assertThat(created.getAnalysisId()).isEqualTo(analysisId);
assertThat(created.getAnalysisState()).isEqualTo("UNPUBLISHED");
assertThat(created.getAnalysisType()).isEqualTo("sequencingRead");
assertThat(created.getSample().size()).isEqualTo(1);
val sample = created.getSample().get(0);
val experiment = ((SequencingReadAnalysis) created).getExperiment();
assertThat(experiment).isNotNull();
assertThat(experiment.getAlignmentTool().equals("BigWrench"));
val expectedMetadata = new Metadata();
expectedMetadata.setInfo("marginOfError", "0.01%");
assertThat(experiment.getInfo()).isEqualTo(expectedMetadata.getInfo());
// test update
;
val change = "ModifiedToolName";
experiment.setAlignmentTool(change);
service.updateAnalysis(DEFAULT_STUDY_ID, created);
val gotBack = service.read(analysisId);
val experiment2 = ((SequencingReadAnalysis) gotBack).getExperiment();
assertThat(experiment2.getAlignmentTool()).isEqualTo(change);
log.info(format("Created '%s'", toJson(created)));
}
use of org.icgc.dcc.song.server.model.analysis.SequencingReadAnalysis in project SONG by overture-stack.
the class DeserializationTest method testSequencingReadDeserialization.
@Test
public void testSequencingReadDeserialization() {
val a1 = fromJson(TestFiles.getJsonNodeFromClasspath("documents/deserialization/sequencingread-deserialize1.json"), Analysis.class);
val sa1 = ((SequencingReadAnalysis) a1).getExperiment();
assertThat(sa1.getAnalysisId()).isEmpty();
assertThat(sa1.getAligned()).isNull();
assertThat(sa1.getAlignmentTool()).isNull();
assertThat(sa1.getInsertSize()).isNull();
assertThat(sa1.getLibraryStrategy()).isEqualTo("WXS");
assertThat(sa1.getPairedEnd()).isNull();
assertThat(sa1.getReferenceGenome()).isNull();
assertThat(sa1.getInfo().path("random").isNull()).isTrue();
val a2 = fromJson(TestFiles.getJsonNodeFromClasspath("documents/deserialization/sequencingread-deserialize2.json"), Analysis.class);
val sa2 = ((SequencingReadAnalysis) a2).getExperiment();
assertThat(sa2.getAnalysisId()).isEmpty();
assertThat(sa2.getAligned()).isNull();
assertThat(sa2.getAlignmentTool()).isNull();
assertThat(sa2.getInsertSize()).isNull();
assertThat(sa2.getLibraryStrategy()).isEqualTo("WXS");
assertThat(sa2.getPairedEnd()).isTrue();
assertThat(sa2.getReferenceGenome()).isNull();
}
use of org.icgc.dcc.song.server.model.analysis.SequencingReadAnalysis in project SONG by overture-stack.
the class EntityTest method testSequencingReadAnalysis.
@Test
public void testSequencingReadAnalysis() {
val seq1 = SequencingRead.create("a1", true, "b1", 99999L, LIBRARY_STRATEGIES.get(0), false, "c1");
val seq2 = SequencingRead.create("a2", false, "b2", 55555L, LIBRARY_STRATEGIES.get(1), false, "c2");
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 compositeEntity11 = CompositeEntity.create(sample1);
compositeEntity11.setDonor(donor1);
compositeEntity11.setSpecimen(specimen2);
val compositeEntity12 = CompositeEntity.create(sample1);
compositeEntity12.setDonor(donor2);
compositeEntity12.setSpecimen(specimen1);
val compositeGroup1 = newArrayList(compositeEntity11, compositeEntity12);
val compositeEntity21 = CompositeEntity.create(sample2);
compositeEntity21.setDonor(donor1);
compositeEntity21.setSpecimen(specimen2);
val compositeEntity22 = CompositeEntity.create(sample2);
compositeEntity22.setDonor(donor2);
compositeEntity22.setSpecimen(specimen1);
val compositeGroup2 = newArrayList(compositeEntity21, compositeEntity22);
val file11 = File.create("d11", "a11", "c11", "e11", 113L, FILE_TYPES.get(0), "b11", CONTROLLED);
val file12 = File.create("d12", "a12", "c12", "e12", 114L, FILE_TYPES.get(0), "b12", CONTROLLED);
val fileGroup1 = newArrayList(file11, file12);
val file21 = File.create("d21", "a21", "c21", "e21", 213L, FILE_TYPES.get(1), "b21", CONTROLLED);
val file22 = File.create("d22", "a22", "c22", "e22", 224L, FILE_TYPES.get(1), "b22", CONTROLLED);
val fileGroup2 = newArrayList(file21, file22);
val a1 = new SequencingReadAnalysis();
a1.setAnalysisId("a1");
a1.setAnalysisState(PUBLISHED.toString());
a1.setStudy("b1");
val a1_same = new SequencingReadAnalysis();
a1_same.setAnalysisId("a1");
a1_same.setAnalysisState(PUBLISHED.toString());
a1_same.setStudy("b1");
assertEntitiesEqual(a1, a1_same, true);
val a2 = new SequencingReadAnalysis();
a2.setAnalysisId("a2");
a2.setAnalysisState(UNPUBLISHED.toString());
a2.setStudy("b2");
val a2_same = new SequencingReadAnalysis();
a2_same.setAnalysisId("a2");
a2_same.setAnalysisState(UNPUBLISHED.toString());
a2_same.setStudy("b2");
assertEntitiesEqual(a2, a2_same, true);
// 0000 - matchingSamples=0, matchingFile=0, matchingExperiment=0, matchingSelf=0
a1.setExperiment(seq1);
a1.setFile(fileGroup1);
a1.setSample(compositeGroup1);
a2.setExperiment(seq2);
a2.setFile(fileGroup2);
a2.setSample(compositeGroup2);
assertEntitiesNotEqual(a1, a2);
// 0001 - matchingSamples=0, matchingFile=0, matchingExperiment=0, matchingSelf=1
a1.setExperiment(seq1);
a1.setFile(fileGroup1);
a1.setSample(compositeGroup1);
a1_same.setExperiment(seq2);
a1_same.setFile(fileGroup2);
a1_same.setSample(compositeGroup2);
assertEntitiesNotEqual(a1, a2);
// 0010 - matchingSamples=0, matchingFile=0, matchingExperiment=1, matchingSelf=0
a1.setExperiment(seq1);
a1.setFile(fileGroup1);
a1.setSample(compositeGroup1);
a2.setExperiment(seq1);
a2.setFile(fileGroup2);
a2.setSample(compositeGroup2);
assertEntitiesNotEqual(a1, a2);
// 0011 - matchingSamples=0, matchingFile=0, matchingExperiment=1, matchingSelf=1
a1.setExperiment(seq1);
a1.setFile(fileGroup1);
a1.setSample(compositeGroup1);
a1_same.setExperiment(seq1);
a1_same.setFile(fileGroup2);
a1_same.setSample(compositeGroup2);
assertEntitiesNotEqual(a1, a2);
// 0100 - matchingSamples=0, matchingFile=1, matchingExperiment=0, matchingSelf=0
a1.setExperiment(seq1);
a1.setFile(fileGroup1);
a1.setSample(compositeGroup1);
a2.setExperiment(seq2);
a2.setFile(fileGroup1);
a2.setSample(compositeGroup2);
assertEntitiesNotEqual(a1, a2);
// 0101 - matchingSamples=0, matchingFile=1, matchingExperiment=0, matchingSelf=1
a1.setExperiment(seq1);
a1.setFile(fileGroup1);
a1.setSample(compositeGroup1);
a1_same.setExperiment(seq2);
a1_same.setFile(fileGroup1);
a1_same.setSample(compositeGroup2);
assertEntitiesNotEqual(a1, a2);
// 0110 - matchingSamples=0, matchingFile=1, matchingExperiment=1, matchingSelf=0
a1.setExperiment(seq1);
a1.setFile(fileGroup1);
a1.setSample(compositeGroup1);
a2.setExperiment(seq1);
a2.setFile(fileGroup1);
a2.setSample(compositeGroup2);
assertEntitiesNotEqual(a1, a2);
// 0111 - matchingSamples=0, matchingFile=1, matchingExperiment=1, matchingSelf=1
a1.setExperiment(seq1);
a1.setFile(fileGroup1);
a1.setSample(compositeGroup1);
a1_same.setExperiment(seq1);
a1_same.setFile(fileGroup1);
a1_same.setSample(compositeGroup2);
assertEntitiesNotEqual(a1, a2);
// 1000 - matchingSamples=1, matchingFile=0, matchingExperiment=0, matchingSelf=0
a1.setExperiment(seq1);
a1.setFile(fileGroup1);
a1.setSample(compositeGroup1);
a2.setExperiment(seq2);
a2.setFile(fileGroup2);
a2.setSample(compositeGroup1);
assertEntitiesNotEqual(a1, a2);
// 1001 - matchingSamples=1, matchingFile=0, matchingExperiment=0, matchingSelf=1
a1.setExperiment(seq1);
a1.setFile(fileGroup1);
a1.setSample(compositeGroup1);
a1_same.setExperiment(seq2);
a1_same.setFile(fileGroup2);
a1_same.setSample(compositeGroup1);
assertEntitiesNotEqual(a1, a2);
// 1010 - matchingSamples=1, matchingFile=0, matchingExperiment=1, matchingSelf=0
a1.setExperiment(seq1);
a1.setFile(fileGroup1);
a1.setSample(compositeGroup1);
a2.setExperiment(seq1);
a2.setFile(fileGroup2);
a2.setSample(compositeGroup1);
assertEntitiesNotEqual(a1, a2);
// 1011 - matchingSamples=1, matchingFile=0, matchingExperiment=1, matchingSelf=1
a1.setExperiment(seq1);
a1.setFile(fileGroup1);
a1.setSample(compositeGroup1);
a1_same.setExperiment(seq1);
a1_same.setFile(fileGroup2);
a1_same.setSample(compositeGroup1);
assertEntitiesNotEqual(a1, a2);
// 1100 - matchingSamples=1, matchingFile=1, matchingExperiment=0, matchingSelf=0
a1.setExperiment(seq1);
a1.setFile(fileGroup1);
a1.setSample(compositeGroup1);
a2.setExperiment(seq2);
a2.setFile(fileGroup1);
a2.setSample(compositeGroup1);
assertEntitiesNotEqual(a1, a2);
// 1101 - matchingSamples=1, matchingFile=1, matchingExperiment=0, matchingSelf=1
a1.setExperiment(seq1);
a1.setFile(fileGroup1);
a1.setSample(compositeGroup1);
a1_same.setExperiment(seq2);
a1_same.setFile(fileGroup1);
a1_same.setSample(compositeGroup1);
assertEntitiesNotEqual(a1, a2);
// 1110 - matchingSamples=1, matchingFile=1, matchingExperiment=1, matchingSelf=0
a1.setExperiment(seq1);
a1.setFile(fileGroup1);
a1.setSample(compositeGroup1);
a2.setExperiment(seq1);
a2.setFile(fileGroup1);
a2.setSample(compositeGroup1);
assertEntitiesNotEqual(a1, a2);
// 1111 - matchingSamples=1, matchingFile=1, matchingExperiment=1, matchingSelf=1
a1.setExperiment(seq1);
a1.setFile(fileGroup1);
a1.setSample(compositeGroup1);
a1_same.setExperiment(seq1);
a1_same.setFile(fileGroup1);
a1_same.setSample(compositeGroup1);
assertEntitiesEqual(a1, a1_same, true);
a1.setInfo("key1", "f5c9381090a53c54358feb2ba5b7a3d7");
a1_same.setInfo("key2", "6329334b-dcd5-53c8-98fd-9812ac386d30");
assertEntitiesNotEqual(a1, a1_same);
}
use of org.icgc.dcc.song.server.model.analysis.SequencingReadAnalysis 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);
}
use of org.icgc.dcc.song.server.model.analysis.SequencingReadAnalysis in project SONG by overture-stack.
the class AnalysisService method create.
public String create(String studyId, Analysis a, boolean ignoreAnalysisIdCollisions) {
studyService.checkStudyExist(studyId);
val candidateAnalysisId = a.getAnalysisId();
val id = idService.resolveAnalysisId(candidateAnalysisId, ignoreAnalysisIdCollisions);
/**
* [Summary]: Guard from misleading response
* [Details]: If user attempts to save an uploadId a second time, an error is thrown.
* This restricts the user from doing updates to the uploadId after saving, and then
* re-saving. The following edge case explains why an error is thrown instead of returning
* the existing analysisId:
* - user does upload1 which defines the analysisId field as AN123
* - user does save for upload1 and gets analysisId AN123
* - user realizes a mistake, and corrects upload1 which has the analysisId AN123 as explicitly stated
* - user re-uploads upload1, returning the same uploadId since the analysisId has not changed
* - user re-saves upload1 and gets the existing analysisId AN123 back.
* - user thinks they updated the analysis with the re-upload.
*/
checkServer(!doesAnalysisIdExist(id), this.getClass(), DUPLICATE_ANALYSIS_ATTEMPT, "Attempted to create a duplicate analysis. Please " + "delete the analysis for analysisId '%s' and re-save", id);
a.setAnalysisId(id);
a.setStudy(studyId);
val status = repository.createAnalysis(a);
checkServer(status == 1, getClass(), ANALYSIS_REPOSITORY_CREATE_RECORD, "Unable to create analysis with analysisId '%s' to repository: %s", a.getAnalysisId(), a);
analysisInfoService.create(id, a.getInfoAsString());
saveCompositeEntities(studyId, id, a.getSample());
saveFiles(id, studyId, a.getFile());
if (a instanceof SequencingReadAnalysis) {
val experiment = ((SequencingReadAnalysis) a).getExperiment();
createSequencingRead(id, experiment);
} else if (a instanceof VariantCallAnalysis) {
val experiment = ((VariantCallAnalysis) a).getExperiment();
createVariantCall(id, experiment);
} else {
// shouldn't be possible if we validated our JSON first...
throw new IllegalArgumentException("Invalid analysis type");
}
sender.send(String.format("{\"analysis_id\": %s, \"state\": \"UNPUBLISHED\"}", id));
return id;
}
Aggregations