Package phase

Class SamplePhase


  • public final class SamplePhase
    extends java.lang.Object

    Each instance of class SamplePhase stores an estimated haplotype pair for a sample, the list of markers with missing genotypes for the sample, a list of markers whose genotype phase with respect to the preceding heterozygote genotype is considered to be uncertain for the sample, and a set of marker clusters for the sample.

    Instances of class SamplePhase are not thread-safe.

    • Constructor Summary

      Constructors 
      Constructor Description
      SamplePhase​(Markers markers, DoubleArray genPos, int[] hap1, int[] hap2, IntArray unphased, IntArray missing)
      Constructs a new SamplePhase instance from the specified data.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int allele1​(int marker)
      Returns the allele on the first haplotype for the specified marker.
      int allele2​(int marker)
      Returns the allele on the second haplotype for the specified marker.
      int[] clustEnds()
      Returns the (exclusive) end marker indices of each marker cluster.
      void getHaps​(BitArray hap1, BitArray hap2)
      Copies the stored haplotypes to the specified BitList objects
      BitArray hap1()
      Returns the first haplotype.
      BitArray hap2()
      Returns the second haplotype.
      Markers markers()
      Returns the list of markers.
      IntArray missing()
      Returns a list of marker indices in increasing order for which the genotype is missing.
      void setAllele1​(int marker, int allele)
      Sets the allele on the first haplotype for the specified marker to the specified allele
      void setAllele2​(int marker, int allele)
      Sets the allele on the second haplotype for the specified marker to the specified allele
      void setUnphased​(IntArray unphased)
      Sets the list of markers whose genotype phase with respect to the preceding non-missing heterozygote genotype is unknown.
      void swapHaps​(int start, int end)
      Swaps the alleles of the two haplotypes in the specified range of markers.
      static BitArray[] toBitLists​(EstPhase estPhase)
      Returns the current estimated phased genotypes.
      IntArray unphased()
      Returns a list of marker indices in increasing order whose genotype phase with respect to the preceding non-missing heterozygote genotype is unknown.
      • Methods inherited from class java.lang.Object

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

      • SamplePhase

        public SamplePhase​(Markers markers,
                           DoubleArray genPos,
                           int[] hap1,
                           int[] hap2,
                           IntArray unphased,
                           IntArray missing)
        Constructs a new SamplePhase instance from the specified data.
        Parameters:
        markers - the list of markers
        genPos - the genetic positions of the specifed markers
        hap1 - the list of alleles on the first haplotype
        hap2 - the list of alleles on the second haplotype
        unphased - the indices of markers whose genotype phase with respect to the preceding heterozygote is unknown
        missing - the indices of markers whose genotype is missing
        Throws:
        java.lang.IllegalArgumentException - if genPos.size() != markers.nMarkers()
        java.lang.IllegalArgumentException - if hap1.length != markers.nMarkers() || hap2.length != markers.nMarkers()
        java.lang.IllegalArgumentException - if the specified unphased or missing list is not a strictly increasing list of marker indices between 0 (inclusive) and markers.nMarkers() (exclusive)
        java.lang.NullPointerException - if any argument is null
    • Method Detail

      • clustEnds

        public int[] clustEnds()
        Returns the (exclusive) end marker indices of each marker cluster. The returned list is sorted in increasing order.
        Returns:
        the (exclusive) end marker indices of each marker cluster
      • markers

        public Markers markers()
        Returns the list of markers.
        Returns:
        the list of markers
      • missing

        public IntArray missing()
        Returns a list of marker indices in increasing order for which the genotype is missing.
        Returns:
        a list of marker indices in increasing order for which the genotype is missing
      • unphased

        public IntArray unphased()
        Returns a list of marker indices in increasing order whose genotype phase with respect to the preceding non-missing heterozygote genotype is unknown.
        Returns:
        a list of markers indices in increasing order whose genotype phase with respect to the preceding non-missing heterozygote genotype is unknown
      • setUnphased

        public void setUnphased​(IntArray unphased)
        Sets the list of markers whose genotype phase with respect to the preceding non-missing heterozygote genotype is unknown.
        Parameters:
        unphased - a list of markers whose genotype phase with respect to the preceding non-missing heterozygote genotype is unknown
        Throws:
        java.lang.IllegalArgumentException - if the specified list or marker indices is not a strictly increasing list of indices between 0 (inclusive) and this.markers().nMarkers() (exclusive)
        java.lang.NullPointerException - if unphased == null
      • getHaps

        public void getHaps​(BitArray hap1,
                            BitArray hap2)
        Copies the stored haplotypes to the specified BitList objects
        Parameters:
        hap1 - a BitList in which the sample's first haplotype's alleles will be stored
        hap2 - a BitList in which the sample's second haplotype's alleles will be stored
        Throws:
        java.lang.IllegalArgumentException - if hap1.size() != this.markers().sumHaplotypeBits()
        java.lang.IllegalArgumentException - if hap2.size()!= this.markers().sumHaplotypeBits()
        java.lang.NullPointerException - if hap1 == null || hap2 == null
      • allele1

        public int allele1​(int marker)
        Returns the allele on the first haplotype for the specified marker.
        Parameters:
        marker - the marker index
        Returns:
        the allele on the first haplotype for the specified marker
        Throws:
        java.lang.IndexOutOfBoundsException - if marker < 0 || marker >= this.markers().nMarkers()
      • allele2

        public int allele2​(int marker)
        Returns the allele on the second haplotype for the specified marker.
        Parameters:
        marker - the marker index
        Returns:
        the allele on the second haplotype for the specified marker
        Throws:
        java.lang.IndexOutOfBoundsException - if marker < 0 || marker >= this.markers().nMarkers()
      • setAllele1

        public void setAllele1​(int marker,
                               int allele)
        Sets the allele on the first haplotype for the specified marker to the specified allele
        Parameters:
        marker - the marker index
        allele - the allele
        Throws:
        java.lang.IndexOutOfBoundsException - if marker < 0 || marker >= this.markers().nMarkers()
        java.lang.IndexOutOfBoundsException - if allele < 0 || allele >= this.markers().marker(marker).nAlleles()
      • setAllele2

        public void setAllele2​(int marker,
                               int allele)
        Sets the allele on the second haplotype for the specified marker to the specified allele
        Parameters:
        marker - the marker index
        allele - the allele
        Throws:
        java.lang.IndexOutOfBoundsException - if marker < 0 || marker >= this.markers().nMarkers()
        java.lang.IndexOutOfBoundsException - if allele < 0 || allele >= this.markers().marker(marker).nAlleles()
      • swapHaps

        public void swapHaps​(int start,
                             int end)
        Swaps the alleles of the two haplotypes in the specified range of markers.
        Parameters:
        start - the start marker index (inclusive)
        end - the end marker index (exclusive)
        Throws:
        java.lang.IndexOutOfBoundsException - if start < 0 || start > end || start >= this.markers().nMarkers()
      • hap1

        public BitArray hap1()
        Returns the first haplotype. The haplotype is encoded with the this.markers().allelesToBits() method.
        Returns:
        the first haplotype
      • hap2

        public BitArray hap2()
        Returns the second haplotype. The haplotype is encoded with the this.markers().allelesToBits() method.
        Returns:
        the second haplotype
      • toBitLists

        public static BitArray[] toBitLists​(EstPhase estPhase)
        Returns the current estimated phased genotypes. This method converts column-major data into row-major data.
        Parameters:
        estPhase - the current estimated phased genotypes for each target sample
        Returns:
        the current estimated phased genotypes
        Throws:
        java.lang.NullPointerException - if estPhase == null