More getters for VariantContext #712
Merged
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
60c64cd
fixes #371
magicDGS aa71943
removed unused imports
magicDGS c370944
unit tests + solved bug in getAttributesAsList with primitive arrays
magicDGS 243031c
added documentation about primitive arrays
magicDGS 4db74d7
removing extra indents
magicDGS 8b79661
removed extra indent
magicDGS f0b15d1
more tests
magicDGS 9cfe0cd
fixed typo
magicDGS
Jump to file or symbol
Failed to load files and symbols.
| @@ -38,7 +38,6 @@ | ||
| import htsjdk.variant.bcf2.BCF2Codec; | ||
| import htsjdk.variant.vcf.VCFCodec; | ||
| import htsjdk.tribble.TribbleException; | ||
| -import htsjdk.variant.VariantBaseTest; | ||
| import htsjdk.variant.vcf.VCFConstants; | ||
| import htsjdk.variant.vcf.VCFFileReader; | ||
| @@ -1478,4 +1477,76 @@ public void testExtractStructuralVariationsData(final File vcfFile) { | ||
| CloserUtil.close(reader); | ||
| } | ||
| } | ||
| + | ||
| + @Test | ||
| + public void testGetAttributeAsIntList() { | ||
| + final VariantContext context = basicBuilder | ||
| + .attribute("Empty", new int[0]) | ||
| + .attribute("DefaultIntegerList", new int[5]) | ||
| + .attribute("ListWithMissing", new Object[]{1, null, null}) | ||
| + .attribute("IntegerList", new int[]{0, 1, 2, 3}) | ||
| + .attribute("DoubleList", new double[]{1.8, 1.6, 2.1}) | ||
| + .attribute("StringList", new String[]{"1", "2"}) | ||
| + .attribute("NotNumeric", new String[]{"A", "B"}) | ||
| + .make(); | ||
| + // test an empty value | ||
| + Assert.assertTrue(context.getAttributeAsIntList("Empty", 5).isEmpty()); | ||
| + // test as integer | ||
| + Assert.assertEquals(context.getAttributeAsIntList("DefaultIntegerList", 5), Arrays.asList(0, 0, 0, 0, 0)); | ||
| + Assert.assertEquals(context.getAttributeAsIntList("ListWithMissing", 5), Arrays.asList(1, 5, 5)); | ||
| + Assert.assertEquals(context.getAttributeAsIntList("IntegerList", 5), Arrays.asList(0, 1, 2, 3)); | ||
| + Assert.assertEquals(context.getAttributeAsIntList("DoubleList", 5), Arrays.asList(1, 1, 2)); | ||
| + Assert.assertEquals(context.getAttributeAsIntList("StringList", 5), Arrays.asList(1, 2)); | ||
| + Assert.assertThrows(() -> context.getAttributeAsIntList("NotNumeric", 5)); | ||
| + // test the case of a missing key | ||
| + Assert.assertTrue(context.getAttributeAsIntList("MissingList", 5).isEmpty()); | ||
| + } | ||
| + | ||
| + @Test | ||
| + public void testGetAttributeAsDoubleList() { | ||
| + final VariantContext context = basicBuilder | ||
| + .attribute("Empty", new int[0]) | ||
| + .attribute("DefaultIntegerList", new int[5]) | ||
| + .attribute("ListWithMissing", new Object[]{1, null, null}) | ||
| + .attribute("IntegerList", new int[]{0, 1, 2, 3}) | ||
| + .attribute("DoubleList", new double[]{1.8, 1.6, 2.1}) | ||
| + .attribute("StringList", new String[]{"1", "2"}) | ||
| + .attribute("NotNumeric", new String[]{"A", "B"}) | ||
| + .make(); | ||
| + // test an empty value | ||
| + Assert.assertTrue(context.getAttributeAsDoubleList("Empty", 5).isEmpty()); | ||
| + // test as double | ||
| + Assert.assertEquals(context.getAttributeAsDoubleList("DefaultIntegerList", 5), Arrays.asList(0d, 0d, 0d, 0d, 0d)); | ||
| + Assert.assertEquals(context.getAttributeAsDoubleList("ListWithMissing", 5), Arrays.asList(1d, 5d, 5d)); | ||
| + Assert.assertEquals(context.getAttributeAsDoubleList("IntegerList", 5), Arrays.asList(0d, 1d, 2d, 3d)); | ||
| + Assert.assertEquals(context.getAttributeAsDoubleList("DoubleList", 5), Arrays.asList(1.8, 1.6, 2.1)); | ||
| + Assert.assertEquals(context.getAttributeAsDoubleList("StringList", 5), Arrays.asList(1d, 2d)); | ||
| + Assert.assertThrows(() -> context.getAttributeAsDoubleList("NotNumeric", 5)); | ||
| + // test the case of a missing key | ||
| + Assert.assertTrue(context.getAttributeAsDoubleList("MissingList", 5).isEmpty()); | ||
| + } | ||
| + | ||
| + @Test | ||
| + public void testGetAttributeAsStringList() { | ||
| + final VariantContext context = basicBuilder | ||
| + .attribute("Empty", new int[0]) | ||
| + .attribute("DefaultIntegerList", new int[5]) | ||
| + .attribute("ListWithMissing", new Object[]{1, null, null}) | ||
| + .attribute("IntegerList", new int[]{0, 1, 2, 3}) | ||
| + .attribute("DoubleList", new double[]{1.8, 1.6, 2.1}) | ||
| + .attribute("StringList", new String[]{"1", "2"}) | ||
| + .attribute("NotNumeric", new String[]{"A", "B"}) | ||
| + .make(); | ||
| + // test an empty value | ||
| + Assert.assertTrue(context.getAttributeAsStringList("Empty", "empty").isEmpty()); | ||
| + // test as string | ||
| + Assert.assertEquals(context.getAttributeAsStringList("DefaultIntegerList", "empty"), Arrays.asList("0", "0", "0", "0", "0")); | ||
| + Assert.assertEquals(context.getAttributeAsStringList("ListWithMissing", "empty"), Arrays.asList("1", "empty", "empty")); | ||
| + Assert.assertEquals(context.getAttributeAsStringList("IntegerList", "empty"), Arrays.asList("0", "1", "2", "3")); | ||
| + Assert.assertEquals(context.getAttributeAsStringList("DoubleList", "empty"), Arrays.asList("1.8", "1.6", "2.1")); | ||
| + Assert.assertEquals(context.getAttributeAsStringList("StringList", "empty"), Arrays.asList("1", "2")); | ||
| + Assert.assertEquals(context.getAttributeAsStringList("NotNumeric", "empty"), Arrays.asList("A", "B")); | ||
yfarjoun
Contributor
|
||
| + // test the case of a missing key | ||
| + Assert.assertTrue(context.getAttributeAsStringList("MissingList", "empty").isEmpty()); | ||
| + } | ||
| } | ||
please add a note about special handling of int[] and double[] to the javadoc so that the behavior will be clear.