Package vcf
Class VcfRecBuilder
- java.lang.Object
-
- vcf.VcfRecBuilder
-
public final class VcfRecBuilder extends java.lang.ObjectClass
VcfRecBuildercontains methods for constructing and printing a VCF record in VCF 4.2 format. The FORMAT field data for each sample is added sequentially to the record via theaddSampleData()method.Instances of class
VcfRecBuilderare not thread-safe.
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_INIT_SIZEThe default initial size for the string buffer, which is 50 characters.
-
Constructor Summary
Constructors Constructor Description VcfRecBuilder()Constructs a newVcfRecBuilderinstance with initial buffer size equal toVcfRecBuilder.DEFAULT_INIT_SIZE.VcfRecBuilder(int initSize)Constructs a newVcfRecBuilderinstance with the specified initial buffer size.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddSampleData(double[] gtypeProbs)Adds the FORMAT field for a sample to the VCF record for the current marker.voidaddSampleData(double[] alProbs1, double[] alProbs2)Adds the FORMAT field for a sample to the VCF record for the current marker.Markermarker()Returns the current marker.booleanprintDS()Returnstrueif the FORMAT field in the VCF record for this marker includes a DS subfield, andfalseotherwisebooleanprintGP()Returnstrueif the FORMAT field in the VCF record for this marker includes a GP subfield, andfalseotherwisevoidreset(Marker marker, boolean printDS, boolean printGP)Clears existing data, and sets the current marker to the specified marker.voidwriteRec(java.io.PrintWriter out, boolean isImputed)Prints the current VCF record for the current marker to the specifiedPrintWriter.
-
-
-
Field Detail
-
DEFAULT_INIT_SIZE
public static final int DEFAULT_INIT_SIZE
The default initial size for the string buffer, which is 50 characters.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
VcfRecBuilder
public VcfRecBuilder()
Constructs a newVcfRecBuilderinstance with initial buffer size equal toVcfRecBuilder.DEFAULT_INIT_SIZE.
-
VcfRecBuilder
public VcfRecBuilder(int initSize)
Constructs a newVcfRecBuilderinstance with the specified initial buffer size.- Parameters:
initSize- the initial buffer size- Throws:
java.lang.NegativeArraySizeException- ifinitCapacity < 0
-
-
Method Detail
-
reset
public void reset(Marker marker, boolean printDS, boolean printGP)
Clears existing data, and sets the current marker to the specified marker. If the FORMAT field contains a DS or GP subfield, the INFO field will include the AR2 (allele r2), DR2 (dose r2), and AF (ALT allele frequency) subfields.- Parameters:
marker- the marker to which data will be addedprintDS-trueif the FORMAT field in the VCF record for this marker will include a DS subfield, andfalseotherwiseprintGP-trueif the FORMAT field in the VCF record for this marker will include a GP subfield, andfalseotherwise- Throws:
java.lang.NullPointerException- ifmarker == null
-
marker
public Marker marker()
Returns the current marker. Returnsnullifthis.reset()has not been previously invoked.- Returns:
- the current marker.
-
printDS
public boolean printDS()
Returnstrueif the FORMAT field in the VCF record for this marker includes a DS subfield, andfalseotherwise- Returns:
trueif the FORMAT field in the VCF record for this marker includes a DS subfield
-
printGP
public boolean printGP()
Returnstrueif the FORMAT field in the VCF record for this marker includes a GP subfield, andfalseotherwise- Returns:
trueif the FORMAT field in the VCF record for this marker includes a GP subfield
-
addSampleData
public void addSampleData(double[] gtypeProbs)
Adds the FORMAT field for a sample to the VCF record for the current marker. If the specified posterior genotype probabilities do not sum to 1.0, the specified array will normalized to sum to 1.0.- Parameters:
gtypeProbs- the posterior genotype probabilities- Throws:
java.lang.IllegalArgumentException- ifgtProbs.length != this.marker().nGenotypes()java.lang.IllegalArgumentException- if any element of the specified array is not a finite non-negative numberjava.lang.IllegalStateException- ifthis.marker() == nulljava.lang.NullPointerException- ifgtProbs == null
-
addSampleData
public void addSampleData(double[] alProbs1, double[] alProbs2)Adds the FORMAT field for a sample to the VCF record for the current marker. If either of the specified posterior allele probabilities does not sum to 1.0, it will be normalized to sum to 1.0.- Parameters:
alProbs1- the posterior allele probabilities for the individual's first allelealProbs2- the posterior allele probabilities for the individual's second allele- Throws:
java.lang.IllegalArgumentException- ifalProbs1.length != this.marker().nAlleles()java.lang.IllegalArgumentException- ifalProbs2.length != this.marker().nAlleles()java.lang.IllegalArgumentException- if any element of the specified array is not a finite non-negative numberjava.lang.IllegalStateException- ifthis.marker() == nulljava.lang.NullPointerException- ifalProbs1 == null || alProbs2 == null
-
writeRec
public void writeRec(java.io.PrintWriter out, boolean isImputed)Prints the current VCF record for the current marker to the specifiedPrintWriter. If the FORMAT field contains a DS or GP subfield, the INFO field will include the AR2 (allele r2), DR2 (dose r2), and AF (ALT allele frequency) subfields. Invocation of this method has no effect ifthis.reset()has not previously been invoked.- Parameters:
out- thePrintWriterto which the VCF record will be printedisImputed-trueif the printed VCF record will have an IMP flag in the INFO field andfalseotherwise- Throws:
java.lang.NullPointerException- ifout == null
-
-