@Test public void testRelease() throws Exception { List<Variant> variants = query(new Query(), new QueryOptions()).getResult(); for (Variant variant : variants) { Integer minFileId = variant.getStudies().stream() .flatMap(s -> s.getFiles().stream()) .map(FileEntry::getFileId) .map(s -> s.substring(30, 35)) .map(Integer::valueOf) .min(Integer::compareTo) .orElse(0); assertTrue(minFileId > 0); int expectedRelease = (minFileId - 12877/*first file loaded*/) / 2/*each release contains 2 files*/ + 1/*base-1*/; int release = Integer.valueOf(variant.getAnnotation().getAdditionalAttributes().get("opencga").getAttribute().get("release")); assertEquals(expectedRelease, release); } }
@Test public void testIncludeStudiesAll() throws Exception { query = new Query(VariantQueryParam.INCLUDE_STUDY.key(), ALL); queryResult = query(query, options); VariantQueryResult<Variant> allVariants = dbAdaptor.get(new Query(), options); assertThat(queryResult, everyResult(allVariants, notNullValue(Variant.class))); }
@Test public void testIncludeStudies() throws Exception { query = new Query() .append(VariantQueryParam.INCLUDE_STUDY.key(), "S_1"); this.queryResult = query(query, options); assertEquals(dbAdaptor.count(null).first().intValue(), this.queryResult.getNumResults()); assertThat(this.queryResult, everyResult(allOf(withStudy("S_2", nullValue()), withStudy("S_3", nullValue()), withStudy("S_4", nullValue())))); }
@Test public void testIncludeStudiesNone() throws Exception { query = new Query(VariantQueryParam.INCLUDE_STUDY.key(), NONE); queryResult = query(query, options); assertEquals(dbAdaptor.count(null).first().intValue(), queryResult.getNumResults()); assertThat(queryResult, everyResult(firstStudy(nullValue()))); }
@Test public void testGetAllVariants_infoFail() { thrown.expect(VariantQueryException.class); thrown.expectMessage("INFO field \"JJ\" not found."); Query query = new Query(STUDY.key(), "S_1").append(INFO.key(), "1K.end.platinum-genomes-vcf-NA12877_S1.genome.vcf.gz:JJ<100"); queryResult = query(query, new QueryOptions()); }
@Test public void testGetAllVariants_formatFail() { thrown.expect(VariantQueryException.class); thrown.expectMessage("FORMAT field \"JJ\" not found."); Query query = new Query(STUDY.key(), "S_1").append(FORMAT.key(), "NA12877:JJ<100"); queryResult = query(query, new QueryOptions()); }
@Test public void testGetByStudiesNegated() throws Exception { query = new Query() .append(VariantQueryParam.STUDY.key(), "S_1" + AND + NOT + "S_2"); queryResult = query(query, options); VariantQueryResult<Variant> allVariants = dbAdaptor.get(new Query() .append(VariantQueryParam.INCLUDE_STUDY.key(), "S_1,S_2"), options); assertThat(queryResult, everyResult(allVariants, allOf(withStudy("S_1"), not(withStudy("S_2"))))); }
@Test public void testGetByFilterByIncludeSample() { VariantQueryResult<Variant> allVariants = dbAdaptor.get(new Query() .append(VariantQueryParam.INCLUDE_STUDY.key(), "S_1") .append(VariantQueryParam.INCLUDE_SAMPLE.key(), sampleNA12877) .append(VariantQueryParam.INCLUDE_FILE.key(), asList(file12877)), options); query = new Query() .append(VariantQueryParam.STUDY.key(), "S_1") .append(VariantQueryParam.FILTER.key(), "LowGQX;LowMQ") .append(VariantQueryParam.INCLUDE_SAMPLE.key(), sampleNA12877); queryResult = query(query, options); assertThat(queryResult, everyResult(allVariants, withStudy("S_1", withFileId(file12877, withAttribute(FILTER, allOf(containsString("LowGQX"), containsString("LowMQ"))))))); }
@Test public void testGetByFilterBySample() { VariantQueryResult<Variant> allVariants = dbAdaptor.get(new Query() .append(VariantQueryParam.INCLUDE_STUDY.key(), "S_1") .append(VariantQueryParam.INCLUDE_SAMPLE.key(), sampleNA12877) .append(VariantQueryParam.INCLUDE_FILE.key(), asList(file12877)), options); query = new Query() .append(VariantQueryParam.STUDY.key(), "S_1") .append(VariantQueryParam.FILTER.key(), "LowGQX;LowMQ") .append(VariantQueryParam.SAMPLE.key(), sampleNA12877); queryResult = query(query, options); assertThat(queryResult, everyResult(allVariants, withStudy("S_1", allOf( withFileId(file12877, withAttribute(FILTER, allOf(containsString("LowGQX"), containsString("LowMQ")))), withSampleData(sampleNA12877, "GT", containsString("1")) )))); }
@Test public void testGetByStudies() throws Exception { query = new Query() .append(VariantQueryParam.STUDY.key(), "S_1"); queryResult = query(query, options); VariantQueryResult<Variant> allVariants = dbAdaptor.get(new Query() .append(VariantQueryParam.INCLUDE_STUDY.key(), "S_1"), options); assertThat(queryResult, everyResult(allVariants, withStudy("S_1"))); }
@Test public void testGetByFileNamesMultiStudiesImplicitAnd() { query = new Query() .append(VariantQueryParam.FILE.key(), file12877 + AND + file12882); queryResult = query(query, options); VariantQueryResult<Variant> allVariants = dbAdaptor.get(new Query() .append(VariantQueryParam.INCLUDE_SAMPLE.key(), "NA12877,NA12882") .append(VariantQueryParam.INCLUDE_FILE.key(), asList(file12877 , file12882)), options); assertThat(queryResult, everyResult(allVariants, allOf(withStudy("S_1", withFileId(file12877)), withStudy("S_2", withFileId(file12882))))); }
@Test public void testGetByFileNamesMultiStudiesImplicitOr() { query = new Query() .append(VariantQueryParam.FILE.key(), file12877 + OR + file12882); queryResult = query(query, options); VariantQueryResult<Variant> allVariants = dbAdaptor.get(new Query() .append(VariantQueryParam.INCLUDE_SAMPLE.key(), "NA12877,NA12882") .append(VariantQueryParam.INCLUDE_FILE.key(), asList(file12877 , file12882)), options); assertThat(queryResult, everyResult(allVariants, anyOf(withStudy("S_1", withFileId(file12877)), withStudy("S_2", withFileId(file12882))))); }
@Test public void testGetBySampleNamesAND() throws Exception { query = new Query() .append(VariantQueryParam.STUDY.key(), "S_1") .append(VariantQueryParam.SAMPLE.key(), "NA12877;NA12878"); queryResult = query(query, options); VariantQueryResult<Variant> allVariants = dbAdaptor.get(new Query() .append(VariantQueryParam.INCLUDE_STUDY.key(), "S_1") .append(VariantQueryParam.INCLUDE_SAMPLE.key(), "NA12877,NA12878") .append(VariantQueryParam.INCLUDE_FILE.key(), file12877 + "," + file12878), options); assertThat(queryResult, everyResult(allVariants, withStudy("S_1", allOf( withFileId(file12877), withSampleData("NA12877", "GT", containsString("1")), withFileId(file12878), withSampleData("NA12878", "GT", containsString("1")) )))); }
@Test public void testGetBySampleName() throws Exception { query = new Query() .append(VariantQueryParam.STUDY.key(), "S_1") .append(VariantQueryParam.SAMPLE.key(), "NA12877"); queryResult = query(query, options); VariantQueryResult<Variant> allVariants = dbAdaptor.get(new Query() .append(VariantQueryParam.INCLUDE_STUDY.key(), "S_1") .append(VariantQueryParam.INCLUDE_SAMPLE.key(), "NA12877") .append(VariantQueryParam.INCLUDE_FILE.key(), file12877), options); assertThat(queryResult, everyResult(allVariants, withStudy("S_1", allOf(withFileId(file12877), withSampleData("NA12877", "GT", containsString("1")))))); }
@Test public void testGetBySampleNamesOR() throws Exception { query = new Query() .append(VariantQueryParam.STUDY.key(), "S_1") .append(VariantQueryParam.SAMPLE.key(), "NA12877,NA12878"); queryResult = query(query, options); VariantQueryResult<Variant> allVariants = dbAdaptor.get(new Query() .append(VariantQueryParam.INCLUDE_STUDY.key(), "S_1") .append(VariantQueryParam.INCLUDE_SAMPLE.key(), "NA12877,NA12878") .append(VariantQueryParam.INCLUDE_FILE.key(), file12877 + "," + file12878), options); assertThat(queryResult, everyResult(allVariants, withStudy("S_1", anyOf( allOf(withFileId(file12877), withSampleData("NA12877", "GT", containsString("1"))), allOf(withFileId(file12878), withSampleData("NA12878", "GT", containsString("1"))) )))); }
@Test public void testGetByFileNamesAnd() { query = new Query() .append(VariantQueryParam.STUDY.key(), "S_1") .append(VariantQueryParam.FILE.key(), file12877 + AND + file12878); queryResult = query(query, options); VariantQueryResult<Variant> allVariants = dbAdaptor.get(new Query() .append(VariantQueryParam.INCLUDE_STUDY.key(), "S_1") .append(VariantQueryParam.INCLUDE_SAMPLE.key(), "NA12877,NA12878") .append(VariantQueryParam.INCLUDE_FILE.key(), asList(file12877 , file12878)), options); assertThat(queryResult, everyResult(allVariants, withStudy("S_1", allOf(withFileId(file12877), withFileId(file12878))))); }
@Test public void testGetByFileNamesMultiStudiesAnd() { query = new Query() .append(VariantQueryParam.STUDY.key(), "S_1,S_2") .append(VariantQueryParam.FILE.key(), file12877 + AND + file12882); queryResult = query(query, options); VariantQueryResult<Variant> allVariants = dbAdaptor.get(new Query() .append(VariantQueryParam.INCLUDE_STUDY.key(), "S_1,S_2") .append(VariantQueryParam.INCLUDE_SAMPLE.key(), "NA12877,NA12882") .append(VariantQueryParam.INCLUDE_FILE.key(), asList(file12877 , file12882)), options); assertThat(queryResult, everyResult(allVariants, allOf(withStudy("S_1", withFileId(file12877)), withStudy("S_2", withFileId(file12882))))); }
@Test public void testGetByFileNamesMultiStudiesOr() { query = new Query() .append(VariantQueryParam.STUDY.key(), "S_1,S_2") .append(VariantQueryParam.FILE.key(), file12877 + VariantQueryUtils.OR + file12882); queryResult = query(query, options); VariantQueryResult<Variant> allVariants = dbAdaptor.get(new Query() .append(VariantQueryParam.INCLUDE_STUDY.key(), "S_1,S_2") .append(VariantQueryParam.INCLUDE_SAMPLE.key(), "NA12877,NA12882") .append(VariantQueryParam.INCLUDE_FILE.key(), asList(file12877 , file12882)), options); assertThat(queryResult, everyResult(allVariants, anyOf(withStudy("S_1", withFileId(file12877)), withStudy("S_2", withFileId(file12882))))); }
@Test public void testGetByFileName() throws Exception { query = new Query() .append(VariantQueryParam.STUDY.key(), "S_1") .append(VariantQueryParam.FILE.key(), file12877); queryResult = query(query, options); VariantQueryResult<Variant> allVariants = dbAdaptor.get(new Query() .append(VariantQueryParam.INCLUDE_STUDY.key(), "all") .append(VariantQueryParam.INCLUDE_SAMPLE.key(), "NA12877") .append(VariantQueryParam.INCLUDE_FILE.key(), file12877), options); assertThat(queryResult, everyResult(allVariants, withStudy("S_1", withFileId(file12877)))); }
@Test public void testGetByFileNamesOr() { query = new Query() .append(VariantQueryParam.STUDY.key(), "S_1") // .append(VariantQueryParam.SAMPLE.key(), sampleNA12877) .append(VariantQueryParam.FILE.key(), file12877 + VariantQueryUtils.OR + file12878); queryResult = query(query, options); VariantQueryResult<Variant> allVariants = dbAdaptor.get(new Query() .append(VariantQueryParam.INCLUDE_STUDY.key(), "S_1") .append(VariantQueryParam.INCLUDE_SAMPLE.key(), "NA12877,NA12878") .append(VariantQueryParam.INCLUDE_FILE.key(), file12877+","+file12878), options); assertThat(queryResult, everyResult(allVariants, withStudy("S_1", anyOf(withFileId(file12877), withFileId(file12878))))); }