Package vcf

Class XRefGT

  • All Implemented Interfaces:
    GT

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

    Class XRefGT represents phased, non-missing genotypes for a list of samples that are stored in column-major (i.e. haplotype-major) order.

    Instances of class XRefGT are immutable.

    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int allele​(int marker, int hap)
      Returns the allele on the specified haplotype for the specified marker or return -1 if the allele is missing.
      int allele1​(int marker, int sample)
      Returns the first allele for the specified marker and sample or return -1 if the allele is missing.
      int allele2​(int marker, int sample)
      Returns the second allele for the specified marker and sample or return -1 if the allele is missing.
      static XRefGT combine​(XRefGT first, XRefGT second)
      Returns a new XRefGT instance from the specified data.
      void copyTo​(int hap, int start, int end, BitArray bitList)
      Copies the specified bit sequence to the specified bitList
      static XRefGT from​(Markers markers, Samples samples, BitArray[] haps)
      Returns a new XRefGT instance from the specified data.
      static XRefGT from​(Samples samples, java.util.concurrent.atomic.AtomicReferenceArray<SamplePhase> phase)
      Returns a new XRefGT instance from the specified data.
      static XRefGT fromPhasedGT​(GT gt, int nThreads)
      Returns a new XRefGT instance from the specified data.
      int hash​(int hap, int start, int end)
      Returns a hash code for the specified alleles.
      boolean isPhased()
      Returns true if the genotype for each marker and sample has non-missing alleles and is either haploid or diploid with a phased allele separator, and returns false otherwise.
      boolean isReversed()
      Returns true if the markers are ordered by decreasing chromosome base position, and returns false otherwise.
      Marker marker​(int markerIndex)
      Returns the specified marker.
      Markers markers()
      Returns the list of markers in order of increasing chromosome position.
      int nHaps()
      Returns the number of haplotypes.
      int nMarkers()
      Returns the number of markers.
      int nSamples()
      Returns the number of samples.
      XRefGT restrict​(int start, int end)
      Returns a new GT instance restricted to genotype data for the specified markers.
      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.
      BitArray[] toBitLists​(int nThreads)
      Returns the phased, non-missing genotypes as a BitArray[].
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Method Detail

      • combine

        public static XRefGT combine​(XRefGT first,
                                     XRefGT second)
        Returns a new XRefGT instance from the specified data. The order of samples and haplotypes is preserved. Samples in the first XRefGT parameter are placed before samples in the second XRefGT parameter in the returned XRefGT instance.
        Parameters:
        first - phased genotype data for a list of samples
        second - phased genotype data for a list of samples
        Returns:
        a new XRefGT instance
        Throws:
        java.lang.NullPointerException - if first == null || second == null
        java.lang.IllegalArgumentException - if the lists of samples in the two specified XRefGT parameters are not disjoint
        java.lang.IllegalArgumentException - if first.markers().equals(second.markers()) == false
      • from

        public static XRefGT from​(Markers markers,
                                  Samples samples,
                                  BitArray[] haps)
        Returns a new XRefGT instance from the specified data. The specified haplotypes will be copied, and the returned XRefGT instance will not contain a reference to the specified haplotypes.
        Parameters:
        markers - the list of markers
        samples - the list of samples
        haps - the list of haplotypes corresponding to the list of samples
        Returns:
        a newXRefGT instance
        Throws:
        java.lang.IllegalArgumentException - if there exists (0 <= j && j < haps.length) such that (haps[j].size() != markers.sumHaplotypeBits())
        java.lang.IllegalArgumentException - if 2*samples.size() != haps.length
        java.lang.NullPointerException - if markers == null || samples == null || haps == null
      • from

        public static XRefGT from​(Samples samples,
                                  java.util.concurrent.atomic.AtomicReferenceArray<SamplePhase> phase)
        Returns a new XRefGT instance from the specified data.
        Parameters:
        samples - the list of samples
        phase - the phased genotypes
        Returns:
        a new XRefGT instance
        Throws:
        java.lang.IllegalArgumentException - if phase.length()==0 || samples.size() != phase.length()
        java.lang.IllegalArgumentException - if if there exists j such that (0 <= j && j < phase.length() && phase.get(j).markers().equals(phase.get(j).markers())==false
        java.lang.NullPointerException - if samples == null || phase == null
        java.lang.NullPointerException - if there exists j such that (0 <= j && j < phase.length() && phase.get(j) == null)
      • toBitLists

        public BitArray[] toBitLists​(int nThreads)
        Returns the phased, non-missing genotypes as a BitArray[].
        Parameters:
        nThreads - the maximum number of computational threads for object construction
        Returns:
        the phased, non-missing genotypes as a BitArray[]
        Throws:
        java.lang.IllegalArgumentException - if nThreads < 1
      • fromPhasedGT

        public static XRefGT fromPhasedGT​(GT gt,
                                          int nThreads)
        Returns a new XRefGT instance from the specified data. The returned XRefGT instance will represent the same genotypes, the same list of markers, and same list of samples as the specified genotype data,
        Parameters:
        gt - phased, nonmissing genotype data
        nThreads - the maximum number of computational threads for object construction
        Returns:
        an XRefGT instance
        Throws:
        java.lang.IllegalArgumentException - if gt.isPhased() == false
        java.lang.IllegalArgumentException - if nThreads < 1
        java.lang.NullPointerException - if refGT == null
      • hash

        public int hash​(int hap,
                        int start,
                        int end)
        Returns a hash code for the specified alleles.
        Parameters:
        hap - a haplotype
        start - the first marker (inclusive)
        end - the last marker (exclusive)
        Returns:
        a hash code for the specified alleles
        Throws:
        java.lang.IndexOutOfBoundsException - if hap < 0 || hap >= this.nHaps()
        java.lang.IndexOutOfBoundsException - if start < 0 || start > to || end >= this.nMarkers()
      • isReversed

        public boolean isReversed()
        Description copied from interface: GT
        Returns true if the markers are ordered by decreasing chromosome base position, and returns false otherwise.
        Specified by:
        isReversed in interface GT
        Returns:
        true if the markers are ordered by decreasing chromosome base position
      • 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
      • marker

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

        public Markers markers()
        Description copied from interface: GT
        Returns the list of markers in order of increasing chromosome position. If (this.isReversed() == false) then (this.markers().marker(j).equals(this.marker(j)) == true) for all (0 <= j && j < this.nMarkers()). If (this.isReversed() == true) then (this.markers().marker(this.nMarkers() - 1 - j).equals(this.marker(j)) == true) for all (0 <= j && j < this.nMarkers())
        Specified by:
        markers in interface GT
        Returns:
        the list of markers in order of increasing chromosome position
      • 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
      • 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
      • isPhased

        public boolean isPhased()
        Description copied from interface: GT
        Returns true if the genotype for each marker and sample has non-missing alleles and is either haploid or diploid with a phased allele separator, 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 sample)
        Description copied from interface: GT
        Returns the first allele for the specified marker and sample or return -1 if the allele is missing. The order of the two alleles is unspecified if this.isPhased() == false.
        Specified by:
        allele1 in interface GT
        Parameters:
        marker - the marker index
        sample - the sample index
        Returns:
        the first allele for the specified marker and sample
      • allele2

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

        public int allele​(int marker,
                          int hap)
        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 order of the two alleles is unspecified if this.isPhased() == false.
        Specified by:
        allele in interface GT
        Parameters:
        marker - the marker index
        hap - the haplotype index
        Returns:
        the allele on the specified haplotype for the specified marker
      • 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
      • restrict

        public XRefGT restrict​(int start,
                               int end)
        Description copied from interface: GT
        Returns a new GT instance restricted to genotype data for the specified markers.
        Specified by:
        restrict in interface GT
        Parameters:
        start - the start marker (inclusive)
        end - the end marker (exclusive)
        Returns:
        a GT instance restricted to genotype data for the specified markers
      • copyTo

        public void copyTo​(int hap,
                           int start,
                           int end,
                           BitArray bitList)
        Copies the specified bit sequence to the specified bitList
        Parameters:
        hap - the haplotype index
        start - the start marker
        end - the end marker
        bitList - the destination bitList
        Throws:
        java.lang.IllegalArgumentException - if start > end
        java.lang.IndexOutOfBoundsException - if hap < 0 || hap >= this.nHaps()
        java.lang.IndexOutOfBoundsException - if start < 0 || end > this.markers()
        java.lang.IndexOutOfBoundsException - if end <= this.markers() && bitList.size() < this.markers().sumHaplotypeBits(end)
        java.lang.NullPointerException - if bitList == null
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object