Package htsjdk.variant.variantcontext
Class GenotypeLikelihoods
- java.lang.Object
-
- htsjdk.variant.variantcontext.GenotypeLikelihoods
-
public class GenotypeLikelihoods extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
GenotypeLikelihoods.GenotypeLikelihoodsAllelePair
-
Field Summary
Fields Modifier and Type Field Description protected static Map<Integer,List<List<Integer>>>
anyploidPloidyToPLIndexToAlleleIndices
A cache of PL index to a list of alleles for any ploidy.static int
MAX_DIPLOID_ALT_ALLELES_THAT_CAN_BE_GENOTYPED
The maximum number of diploid alternate alleles that we can represent as genotype likelihoodsstatic int
MAX_PL
protected static int[]
PLindexConversion
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected static List<List<Integer>>
calculateAnyploidPLcache(int altAlleles, int ploidy)
Calculate the cache of allele indices for each PL index for a ploidy.static int
calculatePLindex(int allele1Index, int allele2Index)
boolean
equals(Object aThat)
static GenotypeLikelihoods
fromGLField(String GLs)
Deprecated.static GenotypeLikelihoods
fromLog10Likelihoods(double[] log10Likelihoods)
static GenotypeLikelihoods
fromPLField(String PLs)
static GenotypeLikelihoods
fromPLs(int[] pls)
static GenotypeLikelihoods.GenotypeLikelihoodsAllelePair
getAllelePair(int PLindex)
Get the diploid allele index pair for the given PL indexstatic GenotypeLikelihoods.GenotypeLikelihoodsAllelePair
getAllelePairUsingDeprecatedOrdering(int PLindex)
Deprecated.since 2/5/13static List<Integer>
getAlleles(int PLindex, int ploidy)
Get the allele ploidy indices for the given PL index Must use the same ploidy as @see #initializeAnyploidPLIndexToAlleleIndicesEnumMap<GenotypeType,Double>
getAsMap(boolean normalizeFromLog10)
int[]
getAsPLs()
String
getAsString()
double[]
getAsVector()
The genotypes likelihoods in -10log10(x) vector format.static double
getGQLog10FromLikelihoods(int iOfChoosenGenotype, double[] likelihoods)
double
getLog10GQ(Genotype genotype, VariantContext context)
double
getLog10GQ(Genotype genotype, List<Allele> vcAlleles)
double
getLog10GQ(GenotypeType genotype)
Deprecated.since 2/5/13 usegetLog10GQ(Genotype, VariantContext)
orgetLog10GQ(Genotype, List)
static int[]
getPLIndecesOfAlleles(int allele1Index, int allele2Index)
Deprecated.7/18 usegetPLIndicesOfAlleles(int, int)
insteadstatic int[]
getPLIndicesOfAlleles(int allele1Index, int allele2Index)
get the PL indices (AA, AB, BB) for the given allele pair; assumes allele1Index <= allele2Index.int
hashCode()
static void
initializeAnyploidPLIndexToAlleleIndices(int altAlleles, int ploidy)
Initialize cache of allele anyploid indices If initialized multiple times with the same ploidy, the alternate alleles from the last initialization will be usedstatic int
numLikelihoods(int numAlleles, int ploidy)
Compute how many likelihood elements are associated with the given number of alleles Equivalent to asking in how many ways N non-negative integers can add up to P is S(N,P) where P = ploidy (number of chromosomes) and N = total # of alleles.String
toString()
-
-
-
Field Detail
-
MAX_PL
public static final int MAX_PL
- See Also:
- Constant Field Values
-
MAX_DIPLOID_ALT_ALLELES_THAT_CAN_BE_GENOTYPED
public static final int MAX_DIPLOID_ALT_ALLELES_THAT_CAN_BE_GENOTYPED
The maximum number of diploid alternate alleles that we can represent as genotype likelihoods- See Also:
- Constant Field Values
-
anyploidPloidyToPLIndexToAlleleIndices
protected static final Map<Integer,List<List<Integer>>> anyploidPloidyToPLIndexToAlleleIndices
A cache of PL index to a list of alleles for any ploidy. For example, for a ploidy of 3, the allele lists for each PL index is: {0,0,0}, {0,0,1}, {0,1,1}, {1,1,1}, {0,0,2}, {0,1,2}, {1,1,2}, {0,2,2}, {1,2,2}, {2,2,2}
-
PLindexConversion
protected static final int[] PLindexConversion
-
-
Method Detail
-
fromPLField
public static final GenotypeLikelihoods fromPLField(String PLs)
-
fromGLField
@Deprecated public static final GenotypeLikelihoods fromGLField(String GLs)
Deprecated.
-
fromLog10Likelihoods
public static final GenotypeLikelihoods fromLog10Likelihoods(double[] log10Likelihoods)
-
fromPLs
public static final GenotypeLikelihoods fromPLs(int[] pls)
-
getAsVector
public double[] getAsVector()
The genotypes likelihoods in -10log10(x) vector format. pr{AA} = x, this vector returns math.log10(x) for each of the genotypes. Can return null if the genotype likelihoods are "missing".- Returns:
- genotypes likelihoods in negative log10 vector format
-
getAsPLs
public int[] getAsPLs()
-
getAsString
public String getAsString()
-
getAsMap
public EnumMap<GenotypeType,Double> getAsMap(boolean normalizeFromLog10)
-
getLog10GQ
@Deprecated public double getLog10GQ(GenotypeType genotype)
Deprecated.since 2/5/13 usegetLog10GQ(Genotype, VariantContext)
orgetLog10GQ(Genotype, List)
This is really dangerous and returns completely wrong results for genotypes from a multi-allelic context. UsegetLog10GQ(Genotype,VariantContext)
orgetLog10GQ(Genotype,List<Allele>)
in place of it. If you know you're biallelic, usegetGQLog10FromLikelihoods
directly.- Parameters:
genotype
- - actually a genotype type (no call, hom ref, het, hom var)- Returns:
- an unsafe quantity that could be negative. In the bi-allelic case, the GQ resulting from best minus next best (if the type is the best).
-
getLog10GQ
public double getLog10GQ(Genotype genotype, VariantContext context)
-
getGQLog10FromLikelihoods
public static double getGQLog10FromLikelihoods(int iOfChoosenGenotype, double[] likelihoods)
-
calculateAnyploidPLcache
protected static List<List<Integer>> calculateAnyploidPLcache(int altAlleles, int ploidy)
Calculate the cache of allele indices for each PL index for a ploidy. Calculation in @see #calculatePLIndexToAlleleIndices- Parameters:
altAlleles
- Number of alternate allelesploidy
- Number of chromosomes in set- Returns:
- PL index to the alleles of general ploidy over all possible alternate alleles
-
numLikelihoods
public static int numLikelihoods(int numAlleles, int ploidy)
Compute how many likelihood elements are associated with the given number of alleles Equivalent to asking in how many ways N non-negative integers can add up to P is S(N,P) where P = ploidy (number of chromosomes) and N = total # of alleles. Each chromosome can be in one single state (0,...,N-1) and there are P of them. Naive solution would be to store N*P likelihoods, but this is not necessary because we can't distinguish chromosome states, but rather only total number of alt allele counts in all chromosomes. For example, S(3,2) = 6: For alleles A,B,C, on a diploid organism we have six possible genotypes: AA,AB,BB,AC,BC,CC. Another way of expressing is with vector (#of A alleles, # of B alleles, # of C alleles) which is then, for ordering above, (2,0,0), (1,1,0), (0,2,0), (1,1,0), (0,1,1), (0,0,2) In general, for P=2 (regular biallelic), then S(N,2) = N*(N+1)/2 Note this method caches the value for most common num Allele / ploidy combinations for efficiency For non-cached values, the result is calculated via a call to calcNumLikelihoods, which uses the Apache Commons CombinatoricsUtils class using the formula (numAlleles + ploidy - 1) choose ploidy- Parameters:
numAlleles
- Number of alleles (including ref)ploidy
- Ploidy, or number of chromosomes in set- Returns:
- Number of likelihood elements we need to hold.
-
calculatePLindex
public static int calculatePLindex(int allele1Index, int allele2Index)
-
getAllelePair
public static GenotypeLikelihoods.GenotypeLikelihoodsAllelePair getAllelePair(int PLindex)
Get the diploid allele index pair for the given PL index- Parameters:
PLindex
- the PL index- Returns:
- the diploid allele index pair
- Throws:
IllegalStateException
- if PLindex is negative value or greater than the cache computed by @see #calculateDiploidPLcache
-
initializeAnyploidPLIndexToAlleleIndices
public static void initializeAnyploidPLIndexToAlleleIndices(int altAlleles, int ploidy)
Initialize cache of allele anyploid indices If initialized multiple times with the same ploidy, the alternate alleles from the last initialization will be used- Parameters:
altAlleles
- number of alternate allelesploidy
- number of chromosomes- Throws:
IllegalArgumentException
- if altAlleles or ploidy <= 0
-
getAlleles
public static List<Integer> getAlleles(int PLindex, int ploidy)
Get the allele ploidy indices for the given PL index Must use the same ploidy as @see #initializeAnyploidPLIndexToAlleleIndices- Parameters:
PLindex
- the PL indexploidy
- number of chromosomes- Returns:
- the ploidy allele indices
- Throws:
IllegalStateException
- if @see #anyploidPloidyToPLIndexToAlleleIndices does not contain the requested ploidy or PL index
-
getAllelePairUsingDeprecatedOrdering
@Deprecated public static GenotypeLikelihoods.GenotypeLikelihoodsAllelePair getAllelePairUsingDeprecatedOrdering(int PLindex)
Deprecated.since 2/5/13get the allele index pair for the given PL using the deprecated PL ordering: AA,AB,AC,AD,BB,BC,BD,CC,CD,DD instead of AA,AB,BB,AC,BC,CC,AD,BD,CD,DD. Although it's painful to keep this conversion around, our DiploidSNPGenotypeLikelihoods class uses the deprecated ordering and I know with certainty that external users have built code on top of it; changing it now would cause a whole lot of heartache for our collaborators, so for now at least there's a standard conversion method. This method assumes at most 3 alternate alleles.- Parameters:
PLindex
- the PL index- Returns:
- the allele index pair
-
getPLIndecesOfAlleles
@Deprecated public static int[] getPLIndecesOfAlleles(int allele1Index, int allele2Index)
Deprecated.7/18 usegetPLIndicesOfAlleles(int, int)
insteadget the PL indices (AA, AB, BB) for the given allele pair; assumes allele1Index <= allele2Index.- Parameters:
allele1Index
- the index in VariantContext.getAllele() of the first alleleallele2Index
- the index in VariantContext.getAllele() of the second allele- Returns:
- the PL indexes
-
getPLIndicesOfAlleles
public static int[] getPLIndicesOfAlleles(int allele1Index, int allele2Index)
get the PL indices (AA, AB, BB) for the given allele pair; assumes allele1Index <= allele2Index.- Parameters:
allele1Index
- the index in VariantContext.getAllele() of the first alleleallele2Index
- the index in VariantContext.getAllele() of the second allele- Returns:
- the PL indexes
-
-