Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
More getters for VariantContext #712
Conversation
coveralls
commented
Sep 17, 2016
coveralls
commented
Sep 21, 2016
|
@yfarjoun and @ldgauthier, because you are the ones interested in that issue, could you have a look here? |
| @@ -26,6 +26,7 @@ | ||
| package htsjdk.variant.variantcontext; | ||
| + |
yfarjoun
requested changes
Sep 24, 2016
This is great! thanks!
Please add some tests to cover this and make sure that many different ways of creating lists and things that can be added to attributes are tested...
| + if (x == null || x == VCFConstants.MISSING_VALUE_v4) { | ||
| + return defaultValue; | ||
| + } else if (x instanceof Integer) { | ||
| + return (Integer) x; |
yfarjoun
Sep 24, 2016
Contributor
what if someone writes an array of ints? int[5] to the attribute? will it work?
magicDGS
Sep 26, 2016
Contributor
int[5] generates an empty array with each element initialized to 0, so it will work. The same for the double.
| + } else if (x instanceof Double) { | ||
| + return (Double) x; | ||
| + } else { | ||
| + return Double.valueOf((String)x); // throws an exception if this isn't a string |
|
@yfarjoun, before adding the tests. Do you think that it is better to have as a default value a |
coveralls
commented
Sep 27, 2016
|
@yfarjoun I added the tests and I realized that I based my implementation on ( |
yfarjoun
self-assigned this
Oct 27, 2016
| @@ -251,10 +254,51 @@ public Object getAttribute(String key, Object defaultValue) { | ||
| Object o = getAttribute(key); | ||
| if ( o == null ) return Collections.emptyList(); | ||
| if ( o instanceof List ) return (List<Object>)o; | ||
| - if ( o.getClass().isArray() ) return Arrays.asList((Object[])o); | ||
| + if ( o.getClass().isArray() ) { | ||
| + if (o instanceof int[]) { |
yfarjoun
Nov 7, 2016
Contributor
please add a note about special handling of int[] and double[] to the javadoc so that the behavior will be clear.
| + | ||
| + public List<Integer> getAttributeAsIntList(String key, Integer defaultValue) { | ||
| + return getAttributeAsList(key, x -> { | ||
| + if (x == null || x == VCFConstants.MISSING_VALUE_v4) { |
|
looks good. thanks @magicDGS. minor comments (and looks like you need to rebase) and we should be ready to go! |
magicDGS
added some commits
Sep 17, 2016
|
Rebased and addressed comments. Back to you @yfarjoun! |
coveralls
commented
Nov 7, 2016
coveralls
commented
Nov 7, 2016
coveralls
commented
Nov 7, 2016
| + Assert.assertEquals(context.getAttributeAsDoubleList("StringList", 5), Arrays.asList(1d, 2d)); | ||
| + try { | ||
| + context.getAttributeAsIntList("NotNumeric", 5); | ||
| + Assert.fail(); |
magicDGS
Nov 20, 2016
Contributor
This assers that an exception is thrown if a numeric list is requested for a key that is not a number. I change it here and the rest of tests for Assert.assertThrows, which is clear.
| + 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
Nov 19, 2016
Contributor
please test an empty list and a missing list (here and in the other tests too!)
| + | ||
| + public List<Double> getAttributeAsDoubleList(String key, Double defaultValue) { | ||
| + return getAttributeAsList(key, x -> { | ||
| + if (x == null || x == VCFConstants.MISSING_VALUE_v4) { |
|
Addressed the comments. Back to you @yfarjoun! |
coveralls
commented
Nov 20, 2016
| + Assert.assertEquals(context.getAttributeAsStringList("StringList", "empty"), Arrays.asList("1", "2")); | ||
| + Assert.assertEquals(context.getAttributeAsStringList("NotNumeric", "empty"), Arrays.asList("A", "B")); | ||
| + // test the case of a missing key | ||
| + Assert.assertTrue(context.getAttributeAsStringList("MissingList", "empy").isEmpty()); |
|
tiny typo and |
|
Fixed the typo! Thanks for the review! |
coveralls
commented
Nov 20, 2016
yfarjoun
merged commit 5ddddde
into
samtools:master
Nov 20, 2016
|
thank-you for this! |
magicDGS commentedSep 17, 2016
•
edited
Description
Checklist