Package vcf
Class VcfRecBuilder
- java.lang.Object
-
- vcf.VcfRecBuilder
-
public final class VcfRecBuilder extends java.lang.Object
Class
VcfRecBuilder
contains 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
VcfRecBuilder
are not thread-safe.
-
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_INIT_SIZE
The default initial size for the string buffer, which is 50 characters.
-
Constructor Summary
Constructors Constructor Description VcfRecBuilder()
Constructs a newVcfRecBuilder
instance with initial buffer size equal toVcfRecBuilder.DEFAULT_INIT_SIZE
.VcfRecBuilder(int initSize)
Constructs a newVcfRecBuilder
instance with the specified initial buffer size.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addSampleData(double[] gtypeProbs)
Adds the FORMAT field for a sample to the VCF record for the current marker.void
addSampleData(double[] alProbs1, double[] alProbs2)
Adds the FORMAT field for a sample to the VCF record for the current marker.Marker
marker()
Returns the current marker.boolean
printDS()
Returnstrue
if the FORMAT field in the VCF record for this marker includes a DS subfield, andfalse
otherwiseboolean
printGP()
Returnstrue
if the FORMAT field in the VCF record for this marker includes a GP subfield, andfalse
otherwisevoid
reset(Marker marker, boolean printDS, boolean printGP)
Clears existing data, and sets the current marker to the specified marker.void
writeRec(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 newVcfRecBuilder
instance with initial buffer size equal toVcfRecBuilder.DEFAULT_INIT_SIZE
.
-
VcfRecBuilder
public VcfRecBuilder(int initSize)
Constructs a newVcfRecBuilder
instance 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
-true
if the FORMAT field in the VCF record for this marker will include a DS subfield, andfalse
otherwiseprintGP
-true
if the FORMAT field in the VCF record for this marker will include a GP subfield, andfalse
otherwise- Throws:
java.lang.NullPointerException
- ifmarker == null
-
marker
public Marker marker()
Returns the current marker. Returnsnull
ifthis.reset()
has not been previously invoked.- Returns:
- the current marker.
-
printDS
public boolean printDS()
Returnstrue
if the FORMAT field in the VCF record for this marker includes a DS subfield, andfalse
otherwise- Returns:
true
if the FORMAT field in the VCF record for this marker includes a DS subfield
-
printGP
public boolean printGP()
Returnstrue
if the FORMAT field in the VCF record for this marker includes a GP subfield, andfalse
otherwise- Returns:
true
if 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() == null
java.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() == null
java.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
- thePrintWriter
to which the VCF record will be printedisImputed
-true
if the printed VCF record will have an IMP flag in the INFO field andfalse
otherwise- Throws:
java.lang.NullPointerException
- ifout == null
-
-