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() { List<String> samples = studyConfiguration1.getSamplesInFiles() .get(file1) .stream() .map(s -> studyConfiguration1.getSampleIds().inverse().get(s)) .limit(5) .collect(Collectors.toList()); query = new Query(STUDY.key(), studyConfiguration1.getStudyId()) .append(SAMPLE.key(), String.join(AND, samples)); queryResult = dbAdaptor.get(query, options); assertThat(queryResult, everyResult(withStudy(studyConfiguration1.getStudyName(), allOf( withSampleData(samples.get(0), "GT", containsString("1")), withSampleData(samples.get(1), "GT", containsString("1")), withSampleData(samples.get(2), "GT", containsString("1")), withSampleData(samples.get(3), "GT", containsString("1")), withSampleData(samples.get(4), "GT", containsString("1")), withSamples(samples), withFileId(is(Collections.singletonList(fileName1))) )))); }
queryResult = query(query, new QueryOptions()); System.out.println("queryResult.getNumResults() = " + queryResult.getNumResults()); assertThat(queryResult, everyResult(allVariants, withStudy("S_1", allOf( anyOf( withFileId(file12877, withAttribute("HaplotypeScore", asNumber(lt(10))) ), withFileId(file12878, withAttribute("DP", asNumber(gt(100))) queryResult = query(query, new QueryOptions()); System.out.println("queryResult.getNumResults() = " + queryResult.getNumResults()); assertThat(queryResult, everyResult(allVariants, withStudy("S_1", allOf( anyOf( withFileId(file12877, withAttribute("HaplotypeScore", asNumber(lt(10))) ), withFileId(file12878, withAttribute("DP", asNumber(gt(100)))
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 testGetAllVariants_xref() { Query query = new Query(ANNOT_XREF.key(), "3:108634973:C:A,rs2032582,HP:0001250,VAR_048225,Q9BY64,ENSG00000250026,TMPRSS11B,COSM1421316"); queryResult = query(query, null); assertThat(queryResult, everyResult(allVariants, anyOf( hasAnnotation(at("3:108634973:C:A")), with("id", Variant::getId, is("rs2032582")), hasAnnotation(with("GeneTraitAssociation", VariantAnnotation::getGeneTraitAssociation, hasItem(with("HPO", GeneTraitAssociation::getHpo, is("HP:0001250"))))), hasAnnotation(with("ConsequenceType", VariantAnnotation::getConsequenceTypes, hasItem(with("ProteinVariantAnnotation", ConsequenceType::getProteinVariantAnnotation, with("UniprotVariantId", ProteinVariantAnnotation::getUniprotVariantId, is("VAR_048225")))))), hasAnnotation(with("ConsequenceType", VariantAnnotation::getConsequenceTypes, hasItem(with("ProteinVariantAnnotation", ConsequenceType::getProteinVariantAnnotation, with("UniprotName", ProteinVariantAnnotation::getUniprotAccession, is("Q9BY64")))))), hasAnnotation(with("ConsequenceType", VariantAnnotation::getConsequenceTypes, hasItem(with("EnsemblGene", ConsequenceType::getEnsemblGeneId, is("ENSG00000250026"))))), hasAnnotation(with("ConsequenceType", VariantAnnotation::getConsequenceTypes, hasItem(with("GeneName", ConsequenceType::getGeneName, is("TMPRSS11B"))))), hasAnnotation(with("VariantTraitAssociation", VariantAnnotation::getVariantTraitAssociation, with("Cosmic", VariantTraitAssociation::getCosmic, hasItem(with("MutationId", Cosmic::getMutationId, is("COSM1421316")))))) ))); }
@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 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 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)))))); }
queries.put("<0.101", lt(0.101)); queries.put("<0.201", lt(0.201)); queries.put("<0.501", lt(0.501)); queries.put("<0.901", lt(0.901)); queries.put(">0.101", gt(0.101)); queries.put(">0.201", gt(0.201)); queries.put(">0.501", gt(0.501)); queries.put(">0.901", gt(0.901)); assertThat(queryResult, everyResult(allVariants, hasAnnotation(hasAnySift(m)))); assertThat(queryResult, everyResult(allVariants, hasAnnotation(hasAnyPolyphen(m)))); assertThat(queryResult, everyResult(allVariants, hasAnnotation(hasAnyPolyphen(m)))); assertThat(queryResult, everyResult(allVariants, hasAnnotation(hasAnySift(m)))); assertThat(queryResult, everyResult(allVariants, hasAnnotation(hasPolyphen(anyOf(hasItem(m), isEmpty()))))); assertThat(queryResult, everyResult(allVariants, hasAnnotation(hasSift(anyOf(hasItem(m), isEmpty())))));
assertThat(queryResult, everyResult(allVariants, withStudy(STUDY_NAME, withStats(StudyEntry.DEFAULT_COHORT, withMaf(gt(0.2)))))); int expectedCount = (int) VariantMatchers.count(allVariants.getResult(), withStudy(STUDY_NAME, withStats("cohort1", withMaf(gt(0.2))))); numResults = count(new Query(STATS_MAF.key(), STUDY_NAME + ":cohort1>0.2")); assertEquals(expectedCount, numResults); queryResult = query(new Query(STUDY.key(), 1).append(STATS_MAF.key(), "10>0.2"), null); assertEquals(expectedCount, queryResult.getNumResults()); assertThat(queryResult, everyResult(allVariants, withStudy(STUDY_NAME, withStats("cohort1", withMaf(gt(0.2)))))); assertThat(queryResult, everyResult(allVariants, withStudy(STUDY_NAME, withStats("cohort2", withMaf(gt(0.2)))))); assertThat(queryResult, numResults(is(allVariants.getNumResults()))); assertThat(queryResult, numResults(is(0))); assertThat(queryResult, everyResult(allVariants, withStudy(STUDY_NAME, allOf( withStats("cohort2", withMaf(gt(0.2))), withStats("cohort1", withMaf(lt(0.2))))))); assertThat(queryResult, everyResult(allVariants, withStudy(STUDY_NAME, anyOf( withStats("cohort2", withMaf(gt(0.2))), withStats("cohort1", withMaf(lt(0.2)))))));
queryResult = query(query, new QueryOptions()); System.out.println("queryResult.getNumResults() = " + queryResult.getNumResults()); assertThat(queryResult, everyResult(allVariants, withStudy("S_1", allOf( withSamples("NA12877", "NA12878"), anyOf( withSampleData("NA12877", "GT", containsString("1")), withSampleData("NA12878", "GT", containsString("1")) ), withSampleData("NA12877", "DP", asNumber(lt(100))) queryResult = query(query, new QueryOptions()); System.out.println("queryResult.getNumResults() = " + queryResult.getNumResults()); assertThat(queryResult, everyResult(allVariants, withStudy("S_1", allOf( withSamples("NA12877", "NA12878"), withSampleData("NA12877", "GT", is("1/1")), withSampleData("NA12877", "DP", asNumber(lt(100))) queryResult = query(query, new QueryOptions()); System.out.println("queryResult.getNumResults() = " + queryResult.getNumResults()); assertThat(queryResult, everyResult(allVariants, withStudy("S_1", allOf( withSamples("NA12877", "NA12878"), withSampleData("NA12877", "GT", anyOf(is("1/1"), is("0/1"))), withSampleData("NA12877", "DP", asNumber(lt(100))) queryResult = query(query, new QueryOptions()); System.out.println("queryResult.getNumResults() = " + queryResult.getNumResults()); assertThat(queryResult, everyResult(allVariants, withStudy("S_1", allOf( withSamples("NA12877", "NA12878"), anyOf(
System.out.println("queryResult.getNumResults() = " + queryResult.getNumResults()); System.out.println(allVariants.first().toJson()); assertThat(queryResult, everyResult(allVariants, withStudy("S_1", withFileId(file12877, with(QUAL, fileEntry -> fileEntry.getAttributes().get(QUAL), allOf(notNullValue(), with("", Double::valueOf, gt(50)))))))); queryResult = query(query, options); System.out.println("queryResult.getNumResults() = " + queryResult.getNumResults()); assertThat(queryResult, everyResult(allVariants, withStudy("S_1", withFileId(file12877, with(QUAL, fileEntry -> fileEntry.getAttributes().get(QUAL), allOf(notNullValue(), with("", Double::valueOf, lt(50)))))))); queryResult = query(query, options); System.out.println("queryResult.getNumResults() = " + queryResult.getNumResults()); assertThat(queryResult, everyResult(allVariants, withStudy("S_1", withFileId(file12877, with(QUAL, fileEntry -> fileEntry.getAttributes().get(QUAL), anyOf(with("", Double::valueOf, lt(5)), nullValue())))))); queryResult = query(query, options); System.out.println("queryResult.getNumResults() = " + queryResult.getNumResults()); assertThat(queryResult, everyResult(allVariants, withStudy("S_1", withFileId(file12877, allOf( with(QUAL, fileEntry -> fileEntry.getAttributes().get(QUAL), allOf(notNullValue(), with("", Double::valueOf, lt(50)))), with(FILTER, fileEntry -> fileEntry.getAttributes().get(FILTER), anyOf( containsString("LowGQX"), containsString("LowMQ")
@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())))); }
private void queryGeneCT(String gene, String so, Query query, Matcher<VariantAnnotation> regionMatcher) { logger.info(query.toJson()); queryResult = query(query, null); logger.info(" -> numResults " + queryResult.getNumResults()); Matcher<String> geneMatcher; List<String> genes = Arrays.asList(gene.split(",")); if (gene.contains(",")) { geneMatcher = anyOf(genes.stream().map(CoreMatchers::is).collect(Collectors.toList())); } else { geneMatcher = is(gene); } assertThat(queryResult, everyResult(allVariants, hasAnnotation( anyOf( allOf( hasAnyGeneOf(genes), withAny("consequence type", VariantAnnotation::getConsequenceTypes, allOf( with("gene", ConsequenceType::getGeneName, geneMatcher), withAny("SO", ConsequenceType::getSequenceOntologyTerms, with("accession", SequenceOntologyTerm::getAccession, is(so)))))) , allOf( regionMatcher, // not(hasAnyGeneOf(genes)), hasSO(hasItem(so)) ))))); }
assertThat(queryResult, everyResult(allVariants, hasAnnotation(hasPopMaf(GENOMES_PHASE_3, "AFR", lte(0.05001))))); assertThat(queryResult, everyResult(allVariants, hasAnnotation(hasPopMaf(ESP_6500, "AA", gt(0.05001))))); assertThat(queryResult, everyResult(allVariants, hasAnnotation(hasPopMaf(GENOMES_PHASE_3, "ALL", lt(0.05001))))); assertThat(queryResult, everyResult(allVariants, hasAnnotation(allOf( hasPopMaf(ESP_6500, "AA", gt(0.0501)), hasPopMaf(GENOMES_PHASE_3, "AFR", lte(0.0501)))))); assertThat(queryResult, everyResult(allVariants, hasAnnotation(anyOf( hasPopMaf(ESP_6500, "AA", gt(0.0501)), hasPopMaf(GENOMES_PHASE_3, "AFR", lte(0.0501))))));
.append(ANNOT_POPULATION_ALTERNATE_FREQUENCY.key(), ESP_6500 + ":AA>0.05001"); queryResult = query(query, options); assertThat(queryResult, everyResult(allVariants, hasAnnotation(hasPopAltFreq(ESP_6500, "AA", gt(0.05001))))); .append(ANNOT_POPULATION_ALTERNATE_FREQUENCY.key(), GENOMES_PHASE_3 + ":AFR<=0.05001"); queryResult = query(query, options); assertThat(queryResult, everyResult(allVariants, hasAnnotation(hasPopAltFreq(GENOMES_PHASE_3, "AFR", lte(0.05001))))); .append(ANNOT_POPULATION_ALTERNATE_FREQUENCY.key(), ESP_6500 + ":AA>0.05001;" + GENOMES_PHASE_3 + ":AFR<=0.05001"); queryResult = query(query, options); assertThat(queryResult, everyResult(allVariants, hasAnnotation(allOf( hasPopAltFreq(ESP_6500, "AA", gt(0.05001)), hasPopAltFreq(GENOMES_PHASE_3, "AFR", lte(0.05001)))))); queryResult = query(query, options); assertThat(queryResult, everyResult(allVariants, hasAnnotation(anyOf( hasPopAltFreq(ESP_6500, "AA", gt(0.05001)), hasPopAltFreq(GENOMES_PHASE_3, "AFR", lte(0.05001))))));
assertThat(queryResult, everyResult(allVariants, hasAnnotation(hasSO(hasItem("SO:0001566"))))); assertThat(queryResult, numResults(gt(0))); assertThat(queryResult, everyResult(allVariants, hasAnnotation(hasSO(hasItem("SO:0001566"))))); assertThat(queryResult, numResults(gt(0))); assertThat(queryResult, everyResult(allVariants, hasAnnotation(hasSO(anyOf(hasItem("SO:0001566"), hasItem("SO:0001583")))))); assertThat(queryResult, numResults(gt(0))); assertThat(queryResult, everyResult(allVariants, hasAnnotation(hasSO(anyOf(hasItem("SO:0001566"), hasItem("SO:0001583")))))); assertThat(queryResult, numResults(gt(0))); assertThat(queryResult, everyResult(allVariants, hasAnnotation(hasSO(anyOf(hasItem("SO:0001566"), hasItem("SO:0001583")))))); assertThat(queryResult, numResults(gt(0))); assertThat(queryResult, everyResult(allVariants, hasAnnotation(hasSO(allOf(hasItem("SO:0001566"), hasItem("SO:0001583")))))); assertThat(queryResult, numResults(gt(0)));
public static Matcher<Variant> overlaps(Region region) { return overlaps(region, true); }
@Test public void testGetAlVariants_polyphenSiftDescription() { for (String p : Arrays.asList("benign", "possibly damaging", "probably damaging", "unknown")) { queryResult = query(new Query(ANNOT_POLYPHEN.key(), p), null); assertThat(queryResult, everyResult(allVariants, hasAnnotation(hasAnyPolyphenDesc(equalTo(p))))); queryResult = query(new Query(ANNOT_PROTEIN_SUBSTITUTION.key(), "polyphen=" + p), null); assertThat(queryResult, everyResult(allVariants, hasAnnotation(hasAnyPolyphenDesc(equalTo(p))))); } for (String s : Arrays.asList("deleterious", "tolerated")) { queryResult = query(new Query(ANNOT_SIFT.key(), s), null); assertThat(queryResult, everyResult(allVariants, hasAnnotation(hasAnySiftDesc(equalTo(s))))); queryResult = query(new Query(ANNOT_PROTEIN_SUBSTITUTION.key(), "sift=" + s), null); assertThat(queryResult, everyResult(allVariants, hasAnnotation(hasAnySiftDesc(equalTo(s))))); } }
@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)))))); }