@Override public String toString() { return "BCF2FieldEncoder for " + getField() + " with count " + getCountType() + " encoded with " + getClass().getSimpleName(); }
/** * Get the BCF2 type for this field, either from the static type of the * field itself or by inspecting the value itself. * * @return the BCF2 type for this field */ public final BCF2Type getType(final Object value) { return isDynamicallyTyped() ? getDynamicType(value) : getStaticType(); }
/** * A convenience access for the number of elements. * @param vc * @param value * @return the number of encoded elements, either from the fixed number * it has, from the VC, or from the value itself. */ public final int numElements(final VariantContext vc, final Object value) { if ( hasConstantNumElements() ) return numElements(); else if ( hasContextDeterminedNumElements() ) return numElements(vc); else return numElements(value); }
/** * @return True if this field has a non-fixed number of elements that depends only on the properties * of the current VariantContext, such as one value per Allele or per genotype configuration. */ public boolean hasContextDeterminedNumElements() { return ! hasConstantNumElements() && ! hasValueDeterminedNumElements(); }
@Override public void site(final BCF2Encoder encoder, final VariantContext vc) throws IOException { final Object rawValue = vc.getAttribute(getField(), null); final BCF2Type type = getFieldEncoder().getType(rawValue); if ( rawValue == null ) { // the value is missing, just write in null encoder.encodeType(0, type); } else { final int valueCount = getFieldEncoder().numElements(vc, rawValue); encoder.encodeType(valueCount, type); getFieldEncoder().encodeValue(encoder, rawValue, type, valueCount); } } }
protected GenotypesWriter(final VCFHeader header, final BCF2FieldEncoder fieldEncoder) { super(header, fieldEncoder); if ( fieldEncoder.hasConstantNumElements() ) { nValuesPerGenotype = getFieldEncoder().numElements(); } }
public BCF2Type getDynamicType(final Object value) { throw new IllegalStateException("BUG: cannot get dynamic type for statically typed BCF2 field " + getField()); }
@Override public void addGenotype(final BCF2Encoder encoder, final VariantContext vc, final Genotype g) throws IOException { final String fieldValue = g.getFilters(); getFieldEncoder().encodeValue(encoder, fieldValue, encodingType, nValuesPerGenotype); }
/** * @return True if the only way to determine how many elements this field contains is by * inspecting the actual value directly, such as when the number of elements * is a variable length list per site or per genotype. */ public boolean hasValueDeterminedNumElements() { return getCountType() == VCFHeaderLineCount.UNBOUNDED; }
/** * Is the BCF2 type of this field static, or does it have to be determine from * the actual field value itself? * @return true if the field is static */ public final boolean isStaticallyTyped() { return ! isDynamicallyTyped(); }
public StaticallyTypeGenotypesWriter(final VCFHeader header, final BCF2FieldEncoder fieldEncoder) { super(header, fieldEncoder); encodingType = getFieldEncoder().getStaticType(); } }
@Override public void start(final BCF2Encoder encoder, final VariantContext vc) throws IOException { // TODO // TODO this piece of code consumes like 10% of the runtime alone because fo the vc.getGenotypes() iteration // TODO encodingType = BCF2Type.INT8; for ( final Genotype g : vc.getGenotypes() ) { final int[] pls = ige.getValues(g); final BCF2Type plsType = getFieldEncoder().getType(pls); encodingType = BCF2Utils.maxIntegerType(encodingType, plsType); if ( encodingType == BCF2Type.INT32 ) break; // stop early } super.start(encoder, vc); }
@Override public void site(final BCF2Encoder encoder, final VariantContext vc) throws IOException { final Object rawValue = vc.getAttribute(getField(), null); final BCF2Type type = getFieldEncoder().getType(rawValue); if ( rawValue == null ) { // the value is missing, just write in null encoder.encodeType(0, type); } else { final int valueCount = getFieldEncoder().numElements(vc, rawValue); encoder.encodeType(valueCount, type); getFieldEncoder().encodeValue(encoder, rawValue, type, valueCount); } } }
/** * @return True if this field has a non-fixed number of elements that depends only on the properties * of the current VariantContext, such as one value per Allele or per genotype configuration. */ public boolean hasContextDeterminedNumElements() { return ! hasConstantNumElements() && ! hasValueDeterminedNumElements(); }
protected GenotypesWriter(final VCFHeader header, final BCF2FieldEncoder fieldEncoder) { super(header, fieldEncoder); if ( fieldEncoder.hasConstantNumElements() ) { nValuesPerGenotype = getFieldEncoder().numElements(); } }
public BCF2Type getDynamicType(final Object value) { throw new IllegalStateException("BUG: cannot get dynamic type for statically typed BCF2 field " + getField()); }
@Override public void addGenotype(final BCF2Encoder encoder, final VariantContext vc, final Genotype g) throws IOException { final String fieldValue = g.getFilters(); getFieldEncoder().encodeValue(encoder, fieldValue, encodingType, nValuesPerGenotype); }
/** * @return True if this field has a constant, fixed number of elements (such as 1 for an atomic integer) */ public boolean hasConstantNumElements() { return getCountType() == VCFHeaderLineCount.INTEGER; }
/** * Is the BCF2 type of this field static, or does it have to be determine from * the actual field value itself? * @return true if the field is static */ public final boolean isStaticallyTyped() { return ! isDynamicallyTyped(); }
public StaticallyTypeGenotypesWriter(final VCFHeader header, final BCF2FieldEncoder fieldEncoder) { super(header, fieldEncoder); encodingType = getFieldEncoder().getStaticType(); } }