Package vcf
Interface RefGTRec
- All Known Implementing Classes:
AlleleRefGTRec,HapRefGTRec,IntArrayRefGTRec,TwoAlleleRefGTRec
Interface RefGTRec represents represents phased genotype data
for one marker. For implementations of this interface, unless otherwise
specified in the implementation documentation, if the isAlleleCoded()
method returns false, the majorAllele(),
alleleCount(), and hapIndex() methods will be computationally
expensive with compute time proportional to the number of haplotypes.
Alternatively if the isAlleleCoded() method returns
true, the maps() and map() methods will be
computationally expensive with compute time proportional to the number
of haplotypes.
All instances of RefGTRec are required to be immutable.
-
Method Summary
Modifier and TypeMethodDescriptionintalleleCount(int allele) Returns the number of haplotypes that carry the specified non-major allele.int[]Returns an array of lengththis.nAlleles()whosej-th element is the allele count of thej-th allele.static RefGTRecalleleRefGTRec(Marker marker, Samples samples, int[][] alleleToHaps) Constructs and returns a new allele-codedRefGTRecinstance from the specified data.static RefGTRecalleleRefGTRec(RefGTRec rec) Returns an allele-codedRefGTRecinstance for the specified data.static RefGTRecConstructs and returns a new allele-codedRefGTRecinstance from the specified data.int[][]Returns an array of lengththis.marker().nAlleles()whosej-th element isnullor is a list of the haplotypes in increasing order that carry allelej.inthapIndex(int allele, int copy) Returns index of the haplotype that carries the specified copy of the specified allele.Returns anIndexArraywiththis.size()elements that maps haplotype to allele.booleanReturnstrueif this instance stores the indices of haplotypes that carry non-major alleles, and returnsfalseotherwise.booleanisCarrier(int allele, int hap) Returnstrueif the specified haplotype carries the specified allele and returnfalseotherwise.booleanisPhased()Returnstrue.booleanisPhased(int sample) Returnstrue.intReturns the major allele with lowest index.map(int index) Returnsthis.maps()[index].IntArray[]maps()Returns an array of maps, which when composed map haplotype indices to alleles.intReturns the sum of the lengths of non-null rows ofthis.alleleToHaps().intnMaps()Returnsthis.maps().length
-
Method Details
-
alleleRefGTRec
Returns an allele-codedRefGTRecinstance for the specified data.- Parameters:
rec- the phased, non-missing genotype data- Returns:
- an allele-coded
RefGTRecinstance for the specified data - Throws:
NullPointerException- ifrec == null
-
alleleRefGTRec
Constructs and returns a new allele-codedRefGTRecinstance from the specified data.- Parameters:
gtp- a VCF record parser that extracts sample genotypes- Returns:
- an allele-coded
RefGTRecinstance - Throws:
IllegalArgumentException- if the VCF record contains an unphased genotype or missing alleleIllegalArgumentException- if a format error is detected in the VCF recordNullPointerException- ifgtp == null
-
alleleRefGTRec
Constructs and returns a new allele-codedRefGTRecinstance from the specified data.- Parameters:
marker- the markersamples- the samplesalleleToHaps- an array whosej-th element isnullifjis the major allele and otherwise is a list of haplotypes sorted in increasing order that carry thej-th allele. If there is more than one allele with a maximal allele count, the major allele is the smallest allele with maximal allele count. If a haplotype is contained in a list for more than one non-major allele, the haplotype will be assumed to carry the smallest allele.- Returns:
- an allele-coded
RefGTRecinstance - Throws:
IllegalArgumentException- if the(hapIndices[j] == null)andjis not the major allele or if(hapIndices[j] != null)andjis the major alleleIllegalArgumentException- if any non-null element ofhapIndicesis not a sorted list of distinct haplotype indices between 0 (inclusive) and2*samples.size()(exclusive)IllegalArgumentException- ifmarker.nAlleles() != hapIndices.lengthNullPointerException- ifmarker == null || samples == null || hapIndices == null
-
alleleToHaps
int[][] alleleToHaps()Returns an array of lengththis.marker().nAlleles()whosej-th element isnullor is a list of the haplotypes in increasing order that carry allelej. Exactly one element of the returned array must benull. It is recommended that thenullelement correspond to the major allele with lowest index, but this is not a requirement for implementations of this method.- Returns:
- Returns an array of length
this..marker().nAlleles()whosej-th element isnullor is a list of the haplotypes in increasing order that carry allelej
-
hapToAllele
IndexArray hapToAllele()Returns anIndexArraywiththis.size()elements that maps haplotype to allele.- Returns:
- an
IndexArraywiththis.size()elements that maps haplotype to allele
-
nAlleleCodedHaps
int nAlleleCodedHaps()Returns the sum of the lengths of non-null rows ofthis.alleleToHaps().- Returns:
- the sum of the lengths of non-null rows of
this.alleleToHaps()
-
isPhased
boolean isPhased(int sample) Returnstrue.- Specified by:
isPhasedin interfaceGTRec- Parameters:
sample- the sample index- Returns:
true- Throws:
IndexOutOfBoundsException- ifsample < 0 || sample >= this.nSamples()
-
isPhased
boolean isPhased()Returnstrue. -
isAlleleCoded
boolean isAlleleCoded()Returnstrueif this instance stores the indices of haplotypes that carry non-major alleles, and returnsfalseotherwise.- Returns:
trueif this instance stores the indices of haplotypes that carry non-major alleles
-
majorAllele
int majorAllele()Returns the major allele with lowest index.- Returns:
- the major allele with lowest index
-
alleleCounts
int[] alleleCounts()Returns an array of lengththis.nAlleles()whosej-th element is the allele count of thej-th allele.- Returns:
- an array of allele counts
-
alleleCount
int alleleCount(int allele) Returns the number of haplotypes that carry the specified non-major allele.- Parameters:
allele- an allele index- Returns:
- the number of haplotypes that carry the specified non-major allele
- Throws:
IllegalArgumentException- ifallele == this.majorAllele()IndexOutOfBoundsException- ifallele < 0 || allele >= this.nAlleles()
-
hapIndex
int hapIndex(int allele, int copy) Returns index of the haplotype that carries the specified copy of the specified allele.- Parameters:
allele- an allele indexcopy- a copy index- Returns:
- index of the haplotype that carries the specified allele
- Throws:
IllegalArgumentException- ifallele == this.majorAllele()IndexOutOfBoundsException- ifallele < 0 || allele >= this.nAlleles()IndexOutOfBoundsException- ifcopy < 0 || copy >= this.alleleCount(allele)
-
isCarrier
boolean isCarrier(int allele, int hap) Returnstrueif the specified haplotype carries the specified allele and returnfalseotherwise.- Parameters:
allele- an allele indexhap- a haplotype index- Returns:
trueif the specified haplotype carries the specified allele- Throws:
IndexOutOfBoundsException- ifhap < 0 || hap >= this.size()IndexOutOfBoundsException- ifallele < 0 || allele >= this.nAlleles()
-
nMaps
int nMaps()Returnsthis.maps().length- Returns:
- this.maps().length
-
maps
IntArray[] maps()Returns an array of maps, which when composed map haplotype indices to alleles. The allele on haplotypehis determined by the following calculation:IntArray[] maps = this.maps(); int value = maps[0].get(h); for (int j=1; j<maps.length; ++j) { value = indexArrays[j].get(value); } int allele = value- Returns:
- an array of maps, which when composed map haplotype indices to alleles
-
map
Returnsthis.maps()[index].- Parameters:
index- the index inthis.maps()- Returns:
this.maps()[index]- Throws:
IndexOutOfBoundsException- ifindex < 0 || index >= this.nMaps()
-