Permalink
Browse files

support genotype filters in Genotype.getAnyAttribute() and hasAnyAttr…

…ibute

add unit test

correct preexisting java doc issue
  • Loading branch information...
1 parent e7c7bf6 commit 6141de3e8885cb3491fef598db19bdf342a94060 @bbimber bbimber committed Jul 13, 2016
@@ -528,7 +528,7 @@ public double getAttributeAsDouble(String key, double defaultValue) {
}
/**
- * A totally generic getter, that allows you to specific keys that correspond
+ * A totally generic getter, that allows you to get specific keys that correspond
* to even inline values (GQ, for example). Can be very expensive. Additionally,
* all <code>int[]</code> are converted inline into <code>List&lt;Integer&gt;</code> for convenience.
*
@@ -556,6 +556,8 @@ public Object getAnyAttribute(final String key) {
return Collections.EMPTY_LIST;
} else if (key.equals(VCFConstants.DEPTH_KEY)) {
return getDP();
+ } else if (key.equals(VCFConstants.GENOTYPE_FILTER_KEY)) {
+ return getFilters();
} else {
return getExtendedAttribute(key);
}
@@ -572,6 +574,8 @@ public boolean hasAnyAttribute(final String key) {
return hasPL();
} else if (key.equals(VCFConstants.DEPTH_KEY)) {
return hasDP();
+ } else if (key.equals(VCFConstants.GENOTYPE_FILTER_KEY)) {
+ return true; //always available
} else {
return hasExtendedAttribute(key);
}
@@ -30,6 +30,7 @@
import htsjdk.variant.VariantBaseTest;
+import htsjdk.variant.vcf.VCFConstants;
import org.testng.Assert;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;
@@ -63,6 +64,9 @@ public void testFilters() {
Assert.assertEquals(makeGB().filters("x", "y", "z").make().getFilters(), "x;y;z", "Multiple filter field values should be joined with ;");
Assert.assertTrue(makeGB().filters("x", "y", "z").make().isFiltered(), "Multiple filter values should be filtered");
Assert.assertEquals(makeGB().filter("x;y;z").make().getFilters(), "x;y;z", "Multiple filter field values should be joined with ;");
+ Assert.assertEquals(makeGB().filter("x;y;z").make().getAnyAttribute(VCFConstants.GENOTYPE_FILTER_KEY), "x;y;z", "getAnyAttribute(GENOTYPE_FILTER_KEY) should return the filter");
+ Assert.assertTrue(makeGB().filter("x;y;z").make().hasAnyAttribute(VCFConstants.GENOTYPE_FILTER_KEY), "hasAnyAttribute(GENOTYPE_FILTER_KEY) should return true");
+ Assert.assertTrue(makeGB().make().hasAnyAttribute(VCFConstants.GENOTYPE_FILTER_KEY), "hasAnyAttribute(GENOTYPE_FILTER_KEY) should return true");
Assert.assertFalse(makeGB().filter("").make().isFiltered(), "empty filters should count as unfiltered");
Assert.assertEquals(makeGB().filter("").make().getFilters(), null, "empty filter string should result in null filters");
}

0 comments on commit 6141de3

Please sign in to comment.