Package phase
Class SamplePhase
java.lang.Object
phase.SamplePhase
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 -
Constructor Summary
ConstructorsConstructorDescriptionSamplePhase
(int sample, Markers markers, DoubleArray genPos, int[] hap1, int[] hap2, IntArray unphasedHets, IntArray missingGTs) Constructs a newSamplePhase
instance from the specified data. -
Method Summary
Modifier and TypeMethodDescriptionint
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 clusterclustType
(int cluster) Returns the cluster typevoid
Copies the stored haplotypes to the specifiedBitList
objectshap1()
Returns the first haplotype.hap2()
Returns the second haplotype.markers()
Returns the list of markers.void
markMaskedHetClusterAsPhased
(int cluster) Marks the specified masked heterozygote genotype as phased.void
markUnphasedHetClusterAsPhased
(int cluster) 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 clustersint
Returns the number of homozygote clusters.int
nMasked()
Returns the number of masked heterozygotes.int
nMissing()
Returns the number of missing genotypes.int
nPhased()
Returns the number of phased, non-masked heterozygotes.int
Returns the number of unphased, non-masked heterozygotes.int
sample()
Returns the sample index.void
setAllele1
(int marker, int allele) Sets the allele on the first haplotype for the specified marker to the specified allelevoid
setAllele2
(int marker, int allele) Sets the allele on the second haplotype for the specified marker to the specified allelevoid
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.
-
Constructor Details
-
SamplePhase
public SamplePhase(int sample, Markers markers, DoubleArray genPos, int[] hap1, int[] hap2, IntArray unphasedHets, IntArray missingGTs) Constructs a newSamplePhase
instance from the specified data.- Parameters:
sample
- the sample indexmarkers
- the list of markersgenPos
- the genetic positions of the specifed markershap1
- the list of alleles on the first haplotypehap2
- the list of alleles on the second haplotypeunphasedHets
- the indices of markers whose genotype phase with respect to the preceding heterozygote is unknownmissingGTs
- the indices of markers whose genotype is missingGT- Throws:
IllegalArgumentException
- ifsample < 0
IllegalArgumentException
- ifgenPos.size() != markers.nMarkers()
IllegalArgumentException
- ifhap1.length != markers.nMarkers() || hap2.length != markers.nMarkers()
IllegalArgumentException
- if the specifiedunphasedHet
ormissingGT
list is not a strictly increasing list of marker indices between 0 (inclusive) andmarkers.nMarkers()
(exclusive)NullPointerException
- if any argument isnull
-
-
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
- ifthis.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
- ifthis.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
- ifthis.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
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
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
Copies the stored haplotypes to the specifiedBitList
objects- Parameters:
hap1
- aBitList
in which the sample's first haplotype's alleles will be storedhap2
- aBitList
in which the sample's second haplotype's alleles will be stored- Throws:
IllegalArgumentException
- ifhap1.size() != this.markers().sumHaplotypeBits()
IllegalArgumentException
- ifhap2.size()!= this.markers().sumHaplotypeBits()
NullPointerException
- ifhap1 == 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
- ifmarker < 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
- ifmarker < 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 indexallele
- the allele- Throws:
IndexOutOfBoundsException
- ifmarker < 0 || marker >= this.markers().nMarkers()
IndexOutOfBoundsException
- ifallele < 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 indexallele
- the allele- Throws:
IndexOutOfBoundsException
- ifmarker < 0 || marker >= this.markers().nMarkers()
IndexOutOfBoundsException
- ifallele < 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
- ifstart < 0 || start > end || start >= this.markers().nMarkers()
-
hap1
Returns the first haplotype. The haplotype is encoded with thethis.markers().allelesToBits()
method.- Returns:
- the first haplotype
-
hap2
Returns the second haplotype. The haplotype is encoded with thethis.markers().allelesToBits()
method.- Returns:
- the second haplotype
-
toBitLists
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
- ifestPhase == null
-