public static <T> Matcher<QueryResult<T>> everyResult(List<T> allValues, Matcher<T> subMatcher) { long count = count(allValues, subMatcher); Set<T> expectValues = filter(allValues, subMatcher); return allOf(numResults(expectValues), everyResult(subMatcher)); }
@Test public void testGetNotFromSearch() throws Exception { Query query = new Query(ANNOT_PROTEIN_SUBSTITUTION.key(), "sift>0.1"); VariantQueryResult<Variant> result = variantStorageEngine.get(query, new QueryOptions()); verify(solrClient, never()).query(anyString(), any()); assertThat(result, everyResult(allVariants, hasAnnotation(hasSift(hasItem(gt(0.1)))))); }
@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))); }
public void checkRegion(Region queryRegion, Region overlappingRegion) { queryResult = query(new Query(REGION.key(), queryRegion), null); assertThat(queryResult, everyResult(allVariants, overlaps(overlappingRegion))); }
@Test public void testGetAllVariants_samples_gt() { Query query = new Query(SAMPLE.key(), "NA19600").append(GENOTYPE.key(), "NA19685" + IS + homRef).append(INCLUDE_SAMPLE.key(), ALL); thrown.expect(VariantQueryException.class); thrown.expectMessage("Can not be used along with filter \"genotype\""); queryResult = query(query, new QueryOptions()); assertThat(queryResult, everyResult(allVariants, withStudy(STUDY_NAME, allOf( withSampleData("NA19600", "GT", containsString("1")), withSampleData("NA19685", "GT", is(homRef)))))); }
@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_mgf() throws Exception { queryResult = query(new Query(STATS_MGF.key(), STUDY_NAME + ":ALL>0.2"), null); System.out.println(queryResult.getNumResults()); assertThat(queryResult, everyResult(allVariants, withStudy(STUDY_NAME, withStats("ALL", withMgf(gt(0.2)))))); queryResult = query(new Query(STATS_MGF.key(), STUDY_NAME + ":ALL<0.2"), null); System.out.println(queryResult.getNumResults()); assertThat(queryResult, everyResult(allVariants, withStudy(STUDY_NAME, withStats("ALL", withMgf(lt(0.2)))))); }
@Test public void testGetAllVariants_genes() { Query query = new Query(GENE.key(), "FLG-AS1"); QueryResult<Variant> result = query(query, new QueryOptions()); assertThat(result, everyResult(allVariants, hasAnnotation(hasGenes(Collections.singletonList("FLG-AS1"))))); for (Variant variant : result.getResult()) { System.out.println("variant = " + variant); } query = new Query(GENE.key(), "WRONG_GENE"); VariantQueryException exception = VariantQueryException.geneNotFound("WRONG_GENE"); thrown.expect(exception.getClass()); thrown.expectMessage(exception.getMessage()); result = 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 testGetAllVariants_populationFrequencyRef() { final PopulationFrequency defaultPopulation = new PopulationFrequency(null, null, null, null, 0F, 0F, 0F, 0F, 0F); Query query; query = new Query() .append(ANNOT_POPULATION_REFERENCE_FREQUENCY.key(), GENOMES_PHASE_3 + ":AFR<=0.05001"); queryResult = query(query, options); assertThat(queryResult, everyResult(allVariants, hasAnnotation(hasPopRefFreq(GENOMES_PHASE_3, "AFR", lte(0.05001))))); }
@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 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))))); }
private void checkQueryGenotypes(VariantHadoopDBAdaptor dbAdaptor) { StudyConfiguration sc = dbAdaptor.getStudyConfigurationManager().getStudyConfiguration(STUDY_ID, null).first(); List<Variant> allVariants = dbAdaptor.get(new Query(), new QueryOptions()).getResult(); for (String sample : StudyConfiguration.getIndexedSamples(sc).keySet()) { VariantQueryResult<Variant> queryResult = dbAdaptor.get(new Query(VariantQueryParam.SAMPLE.key(), sample) .append(VariantQueryParam.INCLUDE_SAMPLE.key(), VariantQueryUtils.ALL) .append(VariantQueryParam.INCLUDE_FILE.key(), VariantQueryUtils.ALL), new QueryOptions("explain", true)); assertThat(queryResult, everyResult(allVariants, withStudy(STUDY_NAME, withSampleData(sample, "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")))))); }
public void testGetBySampleName(String expectedSource, QueryOptions options) throws Exception { query = new Query() .append(VariantQueryParam.STUDY.key(), "S_1") .append(VariantQueryParam.SAMPLE.key(), "NA12877"); // queryResult = dbAdaptor.get(query, options); queryResult = variantStorageEngine.get(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(), "1K.end.platinum-genomes-vcf-NA12877_S1.genome.vcf.gz"), options); assertEquals(expectedSource, queryResult.getSource()); assertThat(queryResult, everyResult(allVariants, withStudy("S_1", allOf(withFileId("1K.end.platinum-genomes-vcf-NA12877_S1.genome.vcf.gz"), withSampleData("NA12877", "GT", containsString("1")))))); }
public void testGetByFileName(String expectedSource, QueryOptions options) throws Exception { query = new Query() // .append(VariantQueryParam.STUDY.key(), "S_1") .append(VariantQueryParam.FILE.key(), "1K.end.platinum-genomes-vcf-NA12877_S1.genome.vcf.gz"); // queryResult = dbAdaptor.get(query, options); queryResult = variantStorageEngine.get(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(), "1K.end.platinum-genomes-vcf-NA12877_S1.genome.vcf.gz"), options); assertEquals(expectedSource, queryResult.getSource()); assertThat(queryResult, everyResult(allVariants, withStudy("S_1", withFileId("1K.end.platinum-genomes-vcf-NA12877_S1.genome.vcf.gz")))); }
@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)))); }