public static Map<String, List<String>> getSamplesMetadataIfRequested(Query query, QueryOptions options, StudyConfigurationManager studyConfigurationManager) { if (query.getBoolean(SAMPLE_METADATA.key(), false)) { return getSamplesMetadata(query, options, studyConfigurationManager); } else { return null; } }
private List<Region> getRegions(Query query) { List<Region> regions = new ArrayList<>(); if (isValidParam(query, REGION)) { regions.addAll(Region.parseRegions(query.getString(REGION.key()))); } if (isValidParam(query, ANNOT_GENE_REGIONS)) { regions.addAll(Region.parseRegions(query.getString(ANNOT_GENE_REGIONS.key()))); } regions = mergeRegions(regions); return regions; }
@Test public void queryByPanel() throws Exception { Query query = queryUtils.parseQuery(new Query(STUDY.key(), "s1").append(PANEL.key(), "MyPanel"), sessionId); assertEquals(Arrays.asList("BRCA2","CADM1","CTBP2P1","ADSL"), query.getAsList(GENE.key())); query = queryUtils.parseQuery(new Query(STUDY.key(), "s1").append(PANEL.key(), "MyPanel").append(GENE.key(), "ASDF"), sessionId); assertEquals(Arrays.asList("BRCA2","CADM1","CTBP2P1","ADSL", "ASDF"), query.getAsList(GENE.key())); }
@Test public void fileNotIndexed() throws Exception { thrown.expectMessage("not indexed"); thrown.expect(VariantQueryException.class); queryUtils.parseQuery(new Query(VariantQueryParam.FILE.key(), "file5.vcf") .append(VariantQueryParam.STUDY.key(), "s1") .append(VariantQueryParam.RELEASE.key(), 1), sessionId).toJson(); }
@Test public void cohortStatsWrongRelease() throws Exception { VariantQueryException e = VariantCatalogQueryUtils.wrongReleaseException(VariantQueryParam.STATS_MAF, "c2", 1); thrown.expectMessage(e.getMessage()); thrown.expect(e.getClass()); queryUtils.parseQuery(new Query(VariantQueryParam.STATS_MAF.key(), "c2>0.2") .append(VariantQueryParam.STUDY.key(), "s1") .append(VariantQueryParam.RELEASE.key(), 1), sessionId).toJson(); }
@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 parseAnnotCT1() { QueryOptions queryOptions = new QueryOptions(); Query query = new Query(); // consequence types and genes // no xrefs or regions: genes AND cts query.put(ANNOT_CONSEQUENCE_TYPE.key(), "missense_variant,coding_sequence_variant"); query.put(ANNOT_XREF.key(), "RIPK2,NCF4"); SolrQuery solrQuery = solrQueryParser.parse(query, queryOptions); display(query, queryOptions, solrQuery); assertEquals(flDefault1 + "&q=*:*&fq=geneToSoAcc:\"RIPK2_1583\"+OR+geneToSoAcc:\"RIPK2_1580\"+OR+geneToSoAcc:\"NCF4_1583\"+OR+geneToSoAcc:\"NCF4_1580\"", solrQuery.toString()); }
@Test public void parseAnnotCT4() { QueryOptions queryOptions = new QueryOptions(); Query query = new Query(); // no consequence types: (xrefs OR regions) but we must add "OR genes", i.e.: xrefs OR regions OR genes // we must make an OR with xrefs, genes and regions and add it to the "AND" filter list query.put(REGION.key(), "1,2"); query.put(ANNOT_XREF.key(), "RIPK2,NCF4"); SolrQuery solrQuery = solrQueryParser.parse(query, queryOptions); display(query, queryOptions, solrQuery); assertEquals(flDefault1 + "&q=*:*&fq=xrefs:\"RIPK2\"+OR+xrefs:\"NCF4\"+OR+(chromosome:\"1\")+OR+(chromosome:\"2\")", solrQuery.toString()); }
@Test public void testGetAllVariants_polyphenSiftMalformed() { Query query = new Query(ANNOT_POLYPHEN.key(), "sift>0.5"); thrown.expect(VariantQueryException.class); query(query, null); }
@Test public void testQueryExcludeSamples() throws Exception { QueryOptions queryOptions = new QueryOptions(QueryOptions.EXCLUDE, VariantField.STUDIES_SAMPLES_DATA); Query query = new Query(); // Without studies Map<String, List<Sample>> longListMap = variantManager.checkSamplesPermissions(query, queryOptions, mockVariantDBAdaptor().getStudyConfigurationManager(), sessionId); Assert.assertEquals(Collections.singletonMap(studyFqn, Collections.emptyList()), longListMap); // With studies query.append(VariantQueryParam.STUDY.key(), studyFqn); longListMap = variantManager.checkSamplesPermissions(query, queryOptions, mockVariantDBAdaptor().getStudyConfigurationManager(), sessionId); Assert.assertEquals(Collections.singletonMap(studyFqn, Collections.emptyList()), longListMap); }
@Test public void parseConsequenceTypeSOAcc() { QueryOptions queryOptions = new QueryOptions(); Query query = new Query(); query.put(ANNOT_CONSEQUENCE_TYPE.key(), "SO:0001792,SO:0001619"); SolrQuery solrQuery = solrQueryParser.parse(query, queryOptions); display(query, queryOptions, solrQuery); assertEquals(flDefault1 + "&q=*:*&fq=soAcc:\"1792\"+OR+soAcc:\"1619\"", solrQuery.toString()); }
@Test public void parsePopMafScoreMissing() { QueryOptions queryOptions = new QueryOptions(); Query query = new Query(); // (* -popFreq__1kG_phase3__YRI:*) OR popFreq_1kG_phase3__YRI:[0.01 TO *] query.put(ANNOT_POPULATION_MINOR_ALLELE_FREQUENCY.key(), "1kG_phase3:YRI<<0.01"); SolrQuery solrQuery = solrQueryParser.parse(query, queryOptions); display(query, queryOptions, solrQuery); assertEquals(flDefault1 + "&q=*:*&fq=(popFreq__1kG_phase3__YRI:[0+TO+0.01}+OR+(*+-popFreq__1kG_phase3__YRI:*))", solrQuery.toString()); }
@Test public void parseNoPopMaf() { QueryOptions queryOptions = new QueryOptions(); Query query = new Query(); query.put(ANNOT_POPULATION_MINOR_ALLELE_FREQUENCY.key(), "1kG_phase3:GWD!=0.061946902"); SolrQuery solrQuery = solrQueryParser.parse(query, queryOptions); display(query, queryOptions, solrQuery); assertEquals(flDefault1 + "&q=*:*&fq=-popFreq__1kG_phase3__GWD:0.061946902", solrQuery.toString()); }
@Test public void parseNoExactSift() { QueryOptions queryOptions = new QueryOptions(); Query query = new Query(); query.put(ANNOT_PROTEIN_SUBSTITUTION.key(), "sift!=-0.3"); SolrQuery solrQuery = solrQueryParser.parse(query, queryOptions); display(query, queryOptions, solrQuery); assertEquals(flDefault1 + "&q=*:*&fq=-sift:\\-0.3", solrQuery.toString()); }
@Test public void parseHPOs() { QueryOptions queryOptions = new QueryOptions(); Query query = new Query(); query.put(ANNOT_HPO.key(), "HP%3A000365,HP%3A0000007"); SolrQuery solrQuery = solrQueryParser.parse(query, queryOptions); display(query, queryOptions, solrQuery); assertEquals(flDefault1 + "&q=*:*&fq=(traits:\"HP%253A000365\"+OR+traits:\"HP%253A0000007\")", solrQuery.toString()); }
@Test public void testQueryExcludeStudies() throws Exception { Query query = new Query(VariantQueryParam.STUDY.key(), studyId); QueryOptions queryOptions = new QueryOptions(QueryOptions.EXCLUDE, VariantField.STUDIES); Map<String, List<Sample>> longListMap = variantManager.checkSamplesPermissions(query, queryOptions, mockVariantDBAdaptor().getStudyConfigurationManager(), sessionId); Assert.assertEquals(Collections.emptyMap(), longListMap); }
@Test public void testGetAllVariants_functionalScore_wrongSource() { String value = "cad<=0.5"; VariantQueryException expected = VariantQueryException.malformedParam(ANNOT_FUNCTIONAL_SCORE, value); thrown.expect(expected.getClass()); thrown.expectMessage(expected.getMessage()); query(new Query(ANNOT_FUNCTIONAL_SCORE.key(), value), null); }
@Test public void testGetAllVariants_conservationScoreWrongSource() { VariantQueryException e = VariantQueryException.malformedParam(ANNOT_CONSERVATION, "phast<0.5"); thrown.expect(e.getClass()); thrown.expectMessage(e.getMessage()); query(new Query(ANNOT_CONSERVATION.key(), "phast<0.5"), null); }
@Test public void testFailSearchNotAvailable() throws StorageEngineException { VariantQueryException exception = new VariantQueryException("Unable to use search index. SearchEngine is not available"); thrown.expect(exception.getClass()); thrown.expectMessage(exception.getMessage()); variantStorageEngine.getConfiguration().getSearch().setActive(false); variantStorageEngine.doIntersectWithSearch(new Query(ANNOT_TRAIT.key(), "myTrait"), new QueryOptions(USE_SEARCH_INDEX, VariantStorageEngine.UseSearchIndex.YES)); }
@Test public void testUseSearchIndex() throws StorageEngineException { assertFalse(variantStorageEngine.doIntersectWithSearch(new Query(), new QueryOptions())); assertTrue(variantStorageEngine.doIntersectWithSearch(new Query(), new QueryOptions(USE_SEARCH_INDEX, VariantStorageEngine.UseSearchIndex.YES))); assertTrue(variantStorageEngine.doIntersectWithSearch(new Query(ANNOT_TRAIT.key(), "myTrait"), new QueryOptions())); }