@Override public BCF2Type getDynamicType(final Object value) { return value == null ? BCF2Type.INT8 : BCF2Utils.determineIntegerType(BCF2Utils.toList(Integer.class, value)); }
@Override public BCF2Type getDynamicType(final Object value) { return value == null ? BCF2Type.INT8 : BCF2Utils.determineIntegerType(BCF2Utils.toList(Integer.class, value)); }
@Override public void encodeValue(final BCF2Encoder encoder, final Object value, final BCF2Type type, final int minValues) throws IOException { int count = 0; for ( final Integer i : BCF2Utils.toList(Integer.class, value) ) { if ( i != null ) { // necessary because .,. => [null, null] in VC encoder.encodeRawInt(i, type); count++; } } for ( ; count < minValues; count++ ) encoder.encodeRawMissingValue(type); } }
@Override public void encodeValue(final BCF2Encoder encoder, final Object value, final BCF2Type type, final int minValues) throws IOException { int count = 0; for ( final Integer i : BCF2Utils.toList(Integer.class, value) ) { if ( i != null ) { // necessary because .,. => [null, null] in VC encoder.encodeRawInt(i, type); count++; } } for ( ; count < minValues; count++ ) encoder.encodeRawMissingValue(type); } }
@Test(dataProvider = "toListTestProvider") public void testToList(final Class<?> cls, final Object input, final List<Object> expectedOutput) { assertListsAreEquivalent(BCF2Utils.toList(cls, input), expectedOutput); }
@Override public void start(final BCF2Encoder encoder, final VariantContext vc) throws IOException { // the only value that is dynamic are integers final List<Integer> values = new ArrayList<Integer>(vc.getNSamples()); for ( final Genotype g : vc.getGenotypes() ) { for ( final Object i : BCF2Utils.toList(g.getExtendedAttribute(getField(), null)) ) { if ( i != null ) values.add((Integer)i); // we know they are all integers } } encodingType = BCF2Utils.determineIntegerType(values); super.start(encoder, vc); } }
@Override public void start(final BCF2Encoder encoder, final VariantContext vc) throws IOException { // the only value that is dynamic are integers final List<Integer> values = new ArrayList<Integer>(vc.getNSamples()); for ( final Genotype g : vc.getGenotypes() ) { for ( final Integer i : BCF2Utils.toList(Integer.class, g.getExtendedAttribute(getField(), null)) ) { if ( i != null ) values.add(i); } } encodingType = BCF2Utils.determineIntegerType(values); super.start(encoder, vc); } }
@Override public void start(final BCF2Encoder encoder, final VariantContext vc) throws IOException { // the only value that is dynamic are integers final List<Integer> values = new ArrayList<Integer>(vc.getNSamples()); for ( final Genotype g : vc.getGenotypes() ) { for ( final Integer i : BCF2Utils.toList(Integer.class, g.getExtendedAttribute(getField(), null)) ) { if ( i != null ) values.add(i); } } encodingType = BCF2Utils.determineIntegerType(values); super.start(encoder, vc); } }
@Override public void encodeValue(final BCF2Encoder encoder, final Object value, final BCF2Type type, final int minValues) throws IOException { int count = 0; // TODO -- can be restructured to avoid toList operation if ( isAtomic ) { // fast path for fields with 1 fixed float value if ( value != null ) { encoder.encodeRawFloat((Double)value); count++; } } else { // handle generic case final List<Double> doubles = BCF2Utils.toList(Double.class, value); for ( final Double d : doubles ) { if ( d != null ) { // necessary because .,. => [null, null] in VC encoder.encodeRawFloat(d); count++; } } } for ( ; count < minValues; count++ ) encoder.encodeRawMissingValue(type); } }
@Override public void encodeValue(final BCF2Encoder encoder, final Object value, final BCF2Type type, final int minValues) throws IOException { int count = 0; // TODO -- can be restructured to avoid toList operation if ( isAtomic ) { // fast path for fields with 1 fixed float value if ( value != null ) { encoder.encodeRawFloat((Double)value); count++; } } else { // handle generic case final List<Double> doubles = BCF2Utils.toList(Double.class, value); for ( final Double d : doubles ) { if ( d != null ) { // necessary because .,. => [null, null] in VC encoder.encodeRawFloat(d); count++; } } } for ( ; count < minValues; count++ ) encoder.encodeRawMissingValue(type); } }