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​(Marker marker, int nSamples)
      Constructs a new VcfRecBuilder instance with an initial capacity for the specified number of samples.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addSampleData​(int allele)
      Adds the specified haploid phased genotype to the VCF record for the current marker.
      void addSampleData​(int a1, int a2)
      Adds the specified diploid phased genotype to the VCF record for the current marker.
      Marker marker()
      Returns the current marker.
      void writeRec​(java.io.PrintWriter out)
      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​(Marker marker,
                             int nSamples)
        Constructs a new VcfRecBuilder instance with an initial capacity for the specified number of samples.
        Parameters:
        marker - the marker
        nSamples - the number of samples
        Throws:
        java.lang.IllegalArgumentException - if nSamples < 0
    • Method Detail

      • marker

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

        public void addSampleData​(int a1,
                                  int a2)
        Adds the specified diploid phased genotype to the VCF record for the current marker.
        Parameters:
        a1 - the first allele
        a2 - the second allele
        Throws:
        java.lang.IllegalStateException - if this.marker() == null
        java.lang.IndexOutOfBoundsException - if a1 < 0 || a1 >= this.marker().nAlleles()
        java.lang.IndexOutOfBoundsException - if a2 < 0 || a2 >= this.marker().nAlleles()
      • addSampleData

        public void addSampleData​(int allele)
        Adds the specified haploid phased genotype to the VCF record for the current marker.
        Parameters:
        allele - the allele
        Throws:
        java.lang.IllegalStateException - if this.marker() == null
        java.lang.IndexOutOfBoundsException - if allele < 0 || allele >= this.marker().nAlleles()
      • writeRec

        public void writeRec​(java.io.PrintWriter out)
        Prints the current VCF record for the current marker to the specified PrintWriter.
        Parameters:
        out - the PrintWriter to which the VCF record will be printed
        Throws:
        java.lang.NullPointerException - if out == null