Package htsjdk.variant.vcf

# Class VCFEncoder

java.lang.Object
htsjdk.variant.vcf.VCFEncoder

public class VCFEncoder extends Object
Functions specific to encoding VCF records.

## Field Summary

Fields
Modifier and Type
Field
Description
`static final Charset`
`VCF_CHARSET`
The encoding used for VCF files: ISO-8859-1.

## Constructor Summary

Constructors
Constructor
Description
`VCFEncoder(VCFHeader header, boolean allowMissingFieldsInHeader, boolean outputTrailingFormatFields)`
Prepare a VCFEncoder that will encode records appropriate to the given VCF header, optionally allowing missing fields in the header.

## Method Summary

Modifier and Type
Method
Description
`void`
`addGenotypeData(VariantContext vc, Map<Allele,String> alleleMap, List<String> genotypeFormatKeys, StringBuilder builder)`
`static Map<Allele,String>`
`buildAlleleStrings(VariantContext vc)`
return a Map containing Allele -> String(allele position) for all Alleles in VC (as well as NO_CALL) ex: A,T,TC -> { A:0, T:1, TC:2, NO_CALL:EMPTY_ALLELE} This may be efficient when looking up values for many genotypes per VC
`String`
`encode(VariantContext context)`
encodes a `VariantContext` as a VCF line Depending on the use case it may be more efficient to `write(Appendable, VariantContext)` directly instead of creating an intermediate string.
`static String`
`encodeGtField(VariantContext vc, Genotype g)`
Easy way to generate the GT field for a Genotype.
`static String`
`formatVCFDouble(double d)`
Takes a double value and pretty prints it to a String for display
`void`
`setAllowMissingFieldsInHeader(boolean allow)`
Deprecated.
since 10/24/13 use the constructor
`void`
`setVCFHeader(VCFHeader header)`
Deprecated.
since 10/24/13 use the constructor
`void`
`write(Appendable vcfOutput, VariantContext context)`
encodes a `VariantContext` context as VCF, and writes it directly to an `Appendable` This may be more efficient than calling `encode(VariantContext)` and then writing the result since it avoids creating an intermediate string.
`static void`
`writeGtField(Map<Allele,String> alleleMap, Appendable vcfoutput, Genotype g)`
write the encoded GT field for a Genotype

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### VCF_CHARSET

public static final Charset VCF_CHARSET
The encoding used for VCF files: ISO-8859-1. When writing VCF4.3 is implemented, this should change to UTF-8.

## Constructor Details

### VCFEncoder

public VCFEncoder(VCFHeader header, boolean allowMissingFieldsInHeader, boolean outputTrailingFormatFields)
Prepare a VCFEncoder that will encode records appropriate to the given VCF header, optionally allowing missing fields in the header.

## Method Details

### setVCFHeader

@Deprecated public void setVCFHeader(VCFHeader header)
Deprecated.
since 10/24/13 use the constructor

### setAllowMissingFieldsInHeader

@Deprecated public void setAllowMissingFieldsInHeader(boolean allow)
Deprecated.
since 10/24/13 use the constructor

### encode

public String encode(VariantContext context)
encodes a `VariantContext` as a VCF line Depending on the use case it may be more efficient to `write(Appendable, VariantContext)` directly instead of creating an intermediate string.

Returns:
  the VCF line

### write

public void write(Appendable vcfOutput, VariantContext context) throws IOException
encodes a `VariantContext` context as VCF, and writes it directly to an `Appendable` This may be more efficient than calling `encode(VariantContext)` and then writing the result since it avoids creating an intermediate string.

Parameters:
  `vcfOutput` - the `Appendable` to write to
  `context` - the variant
Throws:
  `IOException`

### formatVCFDouble

public static String formatVCFDouble(double d)
Takes a double value and pretty prints it to a String for display

Large doubles => gets %.2f style formatting Doubles < 1 / 10 but > 1/100 => get %.3f style formatting Double < 1/100 => %.3e formatting

Parameters:
  `d` -
Returns:

### addGenotypeData

public void addGenotypeData(VariantContext vc, Map<Allele,String> alleleMap, List<String> genotypeFormatKeys, StringBuilder builder)

### writeGtField

public static void writeGtField(Map<Allele,String> alleleMap, Appendable vcfoutput, Genotype g) throws IOException
write the encoded GT field for a Genotype

Parameters:
  `alleleMap` - a mapping of Allele -> GT allele value (from
  invalid @link

      {@link this#buildAlleleStrings(VariantContext)

  }
  `vcfoutput` - the appendable to write to, to avoid inefficiency due to string copying
  `g` - the genotoype to encode
Throws:
  `IOException` - if appending fails with an IOException

### encodeGtField

public static String encodeGtField(VariantContext vc, Genotype g)
Easy way to generate the GT field for a Genotype. This will be less efficient than using
invalid @link

    {@link this#writeGtField(Map, Appendable, Genotype)

} because of redundant Map initializations

Parameters:
  `vc` - a VariantContext which must contain g or the results are likely to be incorrect
  `g` - a Genotype in vc
Returns:
  a String containing the encoding of the GT field of g

### buildAlleleStrings

public static Map<Allele,String> buildAlleleStrings(VariantContext vc)
return a Map containing Allele -> String(allele position) for all Alleles in VC (as well as NO_CALL) ex: A,T,TC -> { A:0, T:1, TC:2, NO_CALL:EMPTY_ALLELE} This may be efficient when looking up values for many genotypes per VC