Package phase

Class SamplePhase

java.lang.Object
phase.SamplePhase

public final class SamplePhase extends Object

Each instance of class SamplePhase stores an estimated haplotype pair for a sample.

Instances of class SamplePhase are not thread-safe.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
     
  • Constructor Summary

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

    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[]
    Returns the (exclusive) end marker indices of each marker cluster.
    int
    clustSize(int cluster)
    Returns the size of the specified cluster
    clustType(int cluster)
    Returns the cluster type
    void
    getHaps(BitArray hap1, BitArray hap2)
    Copies the stored haplotypes to the specified BitList objects
    Returns the first haplotype.
    Returns the second haplotype.
    Returns the list of markers.
    void
    Marks the specified masked heterozygote genotype as phased.
    void
    Marks the specified unphased heterozygote genotype as phased.
    void
    maskHetCluster(int cluster)
    Masks the unphased heterozygote genotype in the specified cluster.
    void
    Masks the trailing unphased heterozygote or heterozygotes in any maximal sequence of consecutive unphased heterozygotes if the maximal sequence has size two or three and spans less than 3000 base pairs.
    int
    Returns the number of genotype clusters
    int
    Returns the number of homozygote clusters.
    int
    Returns the number of masked heterozygotes.
    int
    Returns the number of missing genotypes.
    int
    Returns the number of phased, non-masked heterozygotes.
    int
    Returns the number of unphased, non-masked heterozygotes.
    int
    Returns the sample index.
    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
    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.

    Methods inherited from class java.lang.Object

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

    • SamplePhase

      public SamplePhase(int sample, Markers markers, DoubleArray genPos, int[] hap1, int[] hap2, IntArray unphasedHets, IntArray missingGTs)
      Constructs a new SamplePhase instance from the specified data.
      Parameters:
      sample - the sample index
      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
      unphasedHets - the indices of markers whose genotype phase with respect to the preceding heterozygote is unknown
      missingGTs - the indices of markers whose genotype is missingGT
      Throws:
      IllegalArgumentException - if sample < 0
      IllegalArgumentException - if genPos.size() != markers.nMarkers()
      IllegalArgumentException - if hap1.length != markers.nMarkers() || hap2.length != markers.nMarkers()
      IllegalArgumentException - if the specified unphasedHet or missingGT list is not a strictly increasing list of marker indices between 0 (inclusive) and markers.nMarkers() (exclusive)
      NullPointerException - if any argument is null
  • Method Details

    • sample

      public int sample()
      Returns the sample index.
      Returns:
      the sample index
    • maskTrailingUnphasedHets

      public void maskTrailingUnphasedHets()
      Masks the trailing unphased heterozygote or heterozygotes in any maximal sequence of consecutive unphased heterozygotes if the maximal sequence has size two or three and spans less than 3000 base pairs.
    • maskHetCluster

      public void maskHetCluster(int cluster)
      Masks the unphased heterozygote genotype in the specified cluster.
      Parameters:
      cluster - a cluster index
      Throws:
      IllegalArgumentException - if this.clustType(cluster) != ClustType.UNPHASED_HET
      IndexOutOfBoundsException - if (cluster < 0 || cluster >= this.nClusters())
    • markUnphasedHetClusterAsPhased

      public void markUnphasedHetClusterAsPhased(int cluster)
      Marks the specified unphased heterozygote genotype as phased.
      Parameters:
      cluster - a cluster index
      Throws:
      IllegalArgumentException - if this.clustType(cluster) != ClustType.UNPHASED_HET
      IndexOutOfBoundsException - if (cluster < 0 || cluster >= this.nClusters())
    • markMaskedHetClusterAsPhased

      public void markMaskedHetClusterAsPhased(int cluster)
      Marks the specified masked heterozygote genotype as phased.
      Parameters:
      cluster - a cluster index
      Throws:
      IllegalArgumentException - if this.clustType(cluster) != ClustType.MASKED_HET
      IndexOutOfBoundsException - if (cluster < 0 || cluster >= this.nClusters())
    • 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
    • nClusters

      public int nClusters()
      Returns the number of genotype clusters
      Returns:
      the number of genotype clusters
    • clustSize

      public int clustSize(int cluster)
      Returns the size of the specified cluster
      Parameters:
      cluster - a cluster index
      Returns:
      the size of the specified cluster
      Throws:
      IllegalArgumentException - if (cluster < 0 || cluster >= this.nClusters())
    • clustType

      public SamplePhase.ClustType clustType(int cluster)
      Returns the cluster type
      Parameters:
      cluster - a cluster index
      Returns:
      the cluster type
      Throws:
      IndexOutOfBoundsException - if (cluster < 0 || cluster >= this.clustEnds().length())
    • nUnphased

      public int nUnphased()
      Returns the number of unphased, non-masked heterozygotes.
      Returns:
      the number of unphased, non-masked heterozygotes
    • nPhased

      public int nPhased()
      Returns the number of phased, non-masked heterozygotes.
      Returns:
      the number of phased, non-masked heterozygotes
    • nMasked

      public int nMasked()
      Returns the number of masked heterozygotes.
      Returns:
      the number of masked heterozygotes
    • nMissing

      public int nMissing()
      Returns the number of missing genotypes.
      Returns:
      the number of missing genotypes
    • nHomClusters

      public int nHomClusters()
      Returns the number of homozygote clusters.
      Returns:
      the number of homozygote clusters
    • 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:
      IllegalArgumentException - if hap1.size() != this.markers().sumHaplotypeBits()
      IllegalArgumentException - if hap2.size()!= this.markers().sumHaplotypeBits()
      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:
      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:
      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:
      IndexOutOfBoundsException - if marker < 0 || marker >= this.markers().nMarkers()
      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:
      IndexOutOfBoundsException - if marker < 0 || marker >= this.markers().nMarkers()
      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:
      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:
      NullPointerException - if estPhase == null