@Override public void before() throws Exception { boolean wasLoaded = loaded; super.before(); if (loaded && !wasLoaded) { VariantHbaseTestUtils.printVariants(((VariantHadoopDBAdaptor) variantStorageEngine.getDBAdaptor()), newOutputUri(getClass().getSimpleName())); // for (String study : variantStorageEngine.getDBAdaptor().getStudyConfigurationManager().getStudies(null).keySet()) { // variantStorageEngine.fillMissing(study, new ObjectMap(), false); // } // VariantHbaseTestUtils.printVariants(((VariantHadoopDBAdaptor) variantStorageEngine.getDBAdaptor()), newOutputUri(getClass().getSimpleName())); } }
protected void load() throws Exception { VariantStorageEngine storageEngine = getVariantStorageEngine(); ObjectMap options = getOptions(); for (int fileId = 12877; fileId <= 12893; fileId++) { String fileName = "1K.end.platinum-genomes-vcf-NA" + fileId + "_S1.genome.vcf.gz"; URI inputFile = getResourceUri("platinum/" + fileName); inputFiles.add(inputFile); studyConfiguration.getFileIds().put(fileName, fileId);
@Override protected void load() throws Exception { super.load(); StudyConfigurationManager scm = dbAdaptor.getStudyConfigurationManager(); for (String studyName : scm.getStudyNames(null)) { StudyConfiguration sc = scm.getStudyConfiguration(studyName, null).first(); ArrayList<String> samples = new ArrayList<>(sc.getSampleIds().keySet()); samples.sort(String::compareTo); variantStorageEngine.searchIndexSamples(sc.getStudyName(), samples.subList(0, samples.size() / 2)); variantStorageEngine.searchIndexSamples(sc.getStudyName(), samples.subList(samples.size() / 2, samples.size())); } }
@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); } }
@Override public void testGetAllVariants_format() { Assume.assumeTrue(false); super.testGetAllVariants_format(); } }
protected VariantQueryResult<Variant> query(Query query, QueryOptions options) { query = preProcessQuery(query, options); return dbAdaptor.get(query, options); }
@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())))); }
@Before public void before() throws Exception { solr.configure(variantStorageEngine); super.before(); options.append(QueryOptions.EXCLUDE, VariantField.ANNOTATION); }
@Before public void before() throws Exception { dbAdaptor = variantStorageEngine.getDBAdaptor(); if (!loaded) { super.before(); load(); loaded = true; } }
@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 testGetByNegatedFilter() { VariantQueryResult<Variant> allVariants = dbAdaptor.get(new Query() .append(VariantQueryParam.INCLUDE_SAMPLE.key(), "NA12877") .append(VariantQueryParam.INCLUDE_FILE.key(), file12877), options); query = new Query() .append(VariantQueryParam.FILTER.key(), "LowGQX" + AND + "LowMQ" + AND + NOT + "SiteConflict") .append(VariantQueryParam.FILE.key(), file12877); queryResult = query(query, options); System.out.println("queryResult.getNumResults() = " + queryResult.getNumResults()); assertThat(queryResult, everyResult(allVariants, withStudy("S_1", withFileId(file12877, with(FILTER, fileEntry -> fileEntry.getAttributes().get(FILTER), allOf( containsString("LowGQX"), containsString("LowMQ"), not(containsString("SiteConflict")) )))))); query = new Query() .append(VariantQueryParam.FILTER.key(), "LowGQX" + AND + "LowQD" + AND + NOT + "\"LowGQX;LowQD;SiteConflict\"") .append(VariantQueryParam.FILE.key(), file12877); queryResult = query(query, options); System.out.println("queryResult.getNumResults() = " + queryResult.getNumResults()); assertThat(queryResult, everyResult(allVariants, withStudy("S_1", withFileId(file12877, with(FILTER, fileEntry -> fileEntry.getAttributes().get(FILTER), allOf( containsString("LowGQX"), containsString("LowQD"), not(is("LowGQX;LowQD;SiteConflict")) )))))); }
@Test public void testGetByFilterMultiStudy() { query = new Query() .append(VariantQueryParam.FILTER.key(), "LowGQX;LowMQ") .append(VariantQueryParam.FILE.key(), file12877 + VariantQueryUtils.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, with(FILTER, fileEntry -> fileEntry.getAttributes().get(FILTER), allOf(containsString("LowGQX"), containsString("LowMQ"))))), withStudy("S_2", withFileId(file12882, with(FILTER, fileEntry -> fileEntry.getAttributes().get(FILTER), allOf(containsString("LowGQX"), containsString("LowMQ"))))) ))); }
@Test public void testIncludeFiles() throws Exception { query = new Query() .append(VariantQueryParam.INCLUDE_STUDY.key(), "S_1") .append(VariantQueryParam.INCLUDE_FILE.key(), file12877); queryResult = query(query, options); assertEquals(dbAdaptor.count(null).first().intValue(), queryResult.getNumResults()); for (Variant variant : queryResult.getResult()) { assertTrue(variant.getStudies().size() <= 1); StudyEntry s_1 = variant.getStudy("S_1"); if (s_1 != null) { assertTrue(s_1.getFiles().size() <= 1); if (s_1.getFiles().size() == 1) { assertNotNull(s_1.getFile(file12877)); } } assertTrue(variant.getStudies().size() <= 1); } assertThat(queryResult, everyResult(allOf(not(withStudy("S_2")), not(withStudy("S_3")), not(withStudy("S_4"))))); }
@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 testGetByGenotype() throws Exception { 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); query = new Query() .append(VariantQueryParam.STUDY.key(), "S_1") .append(VariantQueryParam.GENOTYPE.key(), "NA12877:" + GenotypeClass.HOM_ALT); queryResult = query(query, options); assertThat(queryResult, everyResult(allVariants, withStudy("S_1", allOf(withFileId(file12877), withSampleData("NA12877", "GT", anyOf(is("1/1"), is("2/2"))))))); query = new Query() .append(VariantQueryParam.STUDY.key(), "S_1") .append(VariantQueryParam.GENOTYPE.key(), "NA12877:" + GenotypeClass.HET_REF); queryResult = query(query, options); assertThat(queryResult, everyResult(allVariants, withStudy("S_1", allOf(withFileId(file12877), withSampleData("NA12877", "GT", anyOf(is("0/1"), is("0/2"))))))); query = new Query() .append(VariantQueryParam.STUDY.key(), "S_1") .append(VariantQueryParam.GENOTYPE.key(), "NA12877:" + GenotypeClass.HET_ALT); queryResult = query(query, options); assertThat(queryResult, everyResult(allVariants, withStudy("S_1", allOf(withFileId(file12877), withSampleData("NA12877", "GT", anyOf(is("1/2"), is("2/3"))))))); }
@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 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")) )))); }