Package vcf

Class 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 the addSampleData() 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 new VcfRecBuilder instance with initial buffer size equal to VcfRecBuilder.DEFAULT_INIT_SIZE.
      VcfRecBuilder​(int initSize)
      Constructs a new VcfRecBuilder 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()
      Returns true if the FORMAT field in the VCF record for this marker includes a DS subfield, and false otherwise
      boolean printGP()
      Returns true if the FORMAT field in the VCF record for this marker includes a GP subfield, and false otherwise
      void 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 specified PrintWriter.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 new VcfRecBuilder instance with initial buffer size equal to VcfRecBuilder.DEFAULT_INIT_SIZE.
      • VcfRecBuilder

        public VcfRecBuilder​(int initSize)
        Constructs a new VcfRecBuilder instance with the specified initial buffer size.
        Parameters:
        initSize - the initial buffer size
        Throws:
        java.lang.NegativeArraySizeException - if initCapacity < 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 added
        printDS - true if the FORMAT field in the VCF record for this marker will include a DS subfield, and false otherwise
        printGP - true if the FORMAT field in the VCF record for this marker will include a GP subfield, and false otherwise
        Throws:
        java.lang.NullPointerException - if marker == null
      • marker

        public Marker marker()
        Returns the current marker. Returns null if this.reset() has not been previously invoked.
        Returns:
        the current marker.
      • printDS

        public boolean printDS()
        Returns true if the FORMAT field in the VCF record for this marker includes a DS subfield, and false otherwise
        Returns:
        true if the FORMAT field in the VCF record for this marker includes a DS subfield
      • printGP

        public boolean printGP()
        Returns true if the FORMAT field in the VCF record for this marker includes a GP subfield, and false 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 - if gtProbs.length != this.marker().nGenotypes()
        java.lang.IllegalArgumentException - if any element of the specified array is not a finite non-negative number
        java.lang.IllegalStateException - if this.marker() == null
        java.lang.NullPointerException - if gtProbs == 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 allele
        alProbs2 - the posterior allele probabilities for the individual's second allele
        Throws:
        java.lang.IllegalArgumentException - if alProbs1.length != this.marker().nAlleles()
        java.lang.IllegalArgumentException - if alProbs2.length != this.marker().nAlleles()
        java.lang.IllegalArgumentException - if any element of the specified array is not a finite non-negative number
        java.lang.IllegalStateException - if this.marker() == null
        java.lang.NullPointerException - if alProbs1 == null || alProbs2 == null
      • writeRec

        public void writeRec​(java.io.PrintWriter out,
                             boolean isImputed)
        Prints the current VCF record for the current marker to the specified PrintWriter. 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 if this.reset() has not previously been invoked.
        Parameters:
        out - the PrintWriter to which the VCF record will be printed
        isImputed - true if the printed VCF record will have an IMP flag in the INFO field and false otherwise
        Throws:
        java.lang.NullPointerException - if out == null