Package vcf

Class HapsGT

  • All Implemented Interfaces:
    GT

    public final class HapsGT
    extends java.lang.Object
    implements GT

    Class HapsGT implements the vcf.GT interface by storing the haplotypes as bit arrays.

    Instances of HapsGT are immutable.

    • Constructor Summary

      Constructors 
      Constructor Description
      HapsGT​(Markers markers, Samples samples, LongArray[] haps)
      Constructs a new HapsGT instance from the specified data.
      HapsGT​(Markers markers, Samples samples, java.util.concurrent.atomic.AtomicReferenceArray<LongArray> haps)
      Constructs a new HapsGT instance from the specified data.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int allele​(int marker, int haplotype)
      Returns the allele on the specified haplotype for the specified marker or return -1 if the allele is missing.
      int allele1​(int marker, int hapPair)
      Returns the first allele for the specified marker and sample or return -1 if the allele is missing.
      int allele2​(int marker, int hapPair)
      Returns the second allele for the specified marker and sample or return -1 if the allele is missing.
      boolean isPhased()
      Returns true if the genotype for each marker and sample is a phased, non-missing genotype, and returns false otherwise.
      Marker marker​(int marker)
      Returns the specified marker.
      Markers markers()
      Returns the list of markers.
      int nHaps()
      Returns the number of haplotypes.
      int nMarkers()
      Returns the number of markers.
      int nSamples()
      Returns the number of samples.
      GT restrict​(Markers markers, int[] indices)
      Returns a GT instance restricted to genotype data for the specified markers.
      Samples samples()
      Returns the list of samples.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • HapsGT

        public HapsGT​(Markers markers,
                      Samples samples,
                      LongArray[] haps)
        Constructs a new HapsGT instance from the specified data. Two haplotypes for the k-th sample are required to stored in the 2*k and 2*k + 1 elements of the haps array.
        Parameters:
        markers - the list of markers
        samples - the list of samples
        haps - the list of haplotypes
        Throws:
        java.lang.IllegalArgumentException - if haps.length != 2*samples.nSamples()
        java.lang.IllegalArgumentException - if there exists a j such that (0 <= j && j < haps.length) and (haps[j].size() < (markers.sumHaplotypeBits() + 63)/64)
        java.lang.NullPointerException - if markers == null || samples == null || haps == null
        java.lang.NullPointerException - if any elements of haps is null
      • HapsGT

        public HapsGT​(Markers markers,
                      Samples samples,
                      java.util.concurrent.atomic.AtomicReferenceArray<LongArray> haps)
        Constructs a new HapsGT instance from the specified data. Two haplotypes for the k-th sample are required to stored in the 2*k and 2*k + 1 elements of the haps array.
        Parameters:
        markers - the list of markers
        samples - the list of samples
        haps - the list of haplotypes
        Throws:
        java.lang.IllegalArgumentException - if haps.length() != 2*samples.nSamples()
        java.lang.IllegalArgumentException - if there exists a j such that (0 <= j && j < haps.length) and (haps[j].size() < (markers.sumHaplotypeBits() + 63)/64)
        java.lang.NullPointerException - if markers == null || samples == null || haps == null
        java.lang.NullPointerException - if any elements of haps is null
    • Method Detail

      • isPhased

        public boolean isPhased()
        Description copied from interface: GT
        Returns true if the genotype for each marker and sample is a phased, non-missing genotype, and returns false otherwise.
        Specified by:
        isPhased in interface GT
        Returns:
        true if the genotype for each marker and sample is a phased, non-missing genotype
      • allele1

        public int allele1​(int marker,
                           int hapPair)
        Description copied from interface: GT
        Returns the first allele for the specified marker and sample or return -1 if the allele is missing. The two alleles for a sample are arbitrarily ordered if this.unphased(marker, sample) == false.
        Specified by:
        allele1 in interface GT
        Parameters:
        marker - the marker index
        hapPair - the sample index
        Returns:
        the first allele for the specified marker and sample
      • allele2

        public int allele2​(int marker,
                           int hapPair)
        Description copied from interface: GT
        Returns the second allele for the specified marker and sample or return -1 if the allele is missing. The two alleles for a sample are arbitrarily ordered if this.unphased(marker, sample) == false.
        Specified by:
        allele2 in interface GT
        Parameters:
        marker - the marker index
        hapPair - the sample index
        Returns:
        the allele for the specified marker and sample
      • allele

        public int allele​(int marker,
                          int haplotype)
        Description copied from interface: GT
        Returns the allele on the specified haplotype for the specified marker or return -1 if the allele is missing. The two alleles for an individual are arbitrarily ordered if this.unphased(marker, hap/2) == false.
        Specified by:
        allele in interface GT
        Parameters:
        marker - the marker index
        haplotype - the haplotype index
        Returns:
        the allele on the specified haplotype for the specified marker
      • nMarkers

        public int nMarkers()
        Description copied from interface: GT
        Returns the number of markers.
        Specified by:
        nMarkers in interface GT
        Returns:
        the number of markers
      • markers

        public Markers markers()
        Description copied from interface: GT
        Returns the list of markers.
        Specified by:
        markers in interface GT
        Returns:
        the list of markers
      • marker

        public Marker marker​(int marker)
        Description copied from interface: GT
        Returns the specified marker.
        Specified by:
        marker in interface GT
        Parameters:
        marker - a marker index
        Returns:
        the specified marker
      • nHaps

        public int nHaps()
        Description copied from interface: GT
        Returns the number of haplotypes. The returned value is equal to 2*this.nSamples().
        Specified by:
        nHaps in interface GT
        Returns:
        the number of haplotypes
      • nSamples

        public int nSamples()
        Description copied from interface: GT
        Returns the number of samples.
        Specified by:
        nSamples in interface GT
        Returns:
        the number of samples
      • restrict

        public GT restrict​(Markers markers,
                           int[] indices)
        Description copied from interface: GT
        Returns a GT instance restricted to genotype data for the specified markers.
        Specified by:
        restrict in interface GT
        Parameters:
        markers - the list of markers in the returned instance
        indices - a list of distinct marker indices (from this.markers()) in increasing order
        Returns:
        a GT instance restricted to genotype data for the specified markers
      • samples

        public Samples samples()
        Description copied from interface: GT
        Returns the list of samples.
        Specified by:
        samples in interface GT
        Returns:
        the list of samples