Skip to content

Commit

Permalink
Merge pull request #433 from broadinstitute/eb_finish_chartl_likeliho…
Browse files Browse the repository at this point in the history
…od_posteriors

Introducing the latest-and-greatest in genotyping: CalculatePosteriors.
  • Loading branch information
eitanbanks committed Nov 27, 2013
2 parents 1581c7c + 5ae85ac commit 105f951
Show file tree
Hide file tree
Showing 5 changed files with 385 additions and 10 deletions.
30 changes: 30 additions & 0 deletions public/java/src/org/broadinstitute/sting/utils/MathUtils.java
Expand Up @@ -1472,4 +1472,34 @@ public static <T> List<T> randomSubset(final List<T> list, final int N) {
return sliceListByIndices(sampleIndicesWithoutReplacement(list.size(),N),list);
}

/**
* Return the likelihood of observing the counts of categories having sampled a population
* whose categorial frequencies are distributed according to a Dirichlet distribution
* @param dirichletParams - params of the prior dirichlet distribution
* @param dirichletSum - the sum of those parameters
* @param counts - the counts of observation in each category
* @param countSum - the sum of counts (number of trials)
* @return - associated likelihood
*/
public static double dirichletMultinomial(final double[] dirichletParams, final double dirichletSum,
final int[] counts, final int countSum) {
if ( dirichletParams.length != counts.length ) {
throw new IllegalStateException("The number of dirichlet parameters must match the number of categories");
}
// todo -- lots of lnGammas here. At some point we can safely switch to x * ( ln(x) - 1)
double likelihood = log10MultinomialCoefficient(countSum,counts);
likelihood += log10Gamma(dirichletSum);
likelihood -= log10Gamma(dirichletSum+countSum);
for ( int idx = 0; idx < counts.length; idx++ ) {
likelihood += log10Gamma(counts[idx] + dirichletParams[idx]);
likelihood -= log10Gamma(dirichletParams[idx]);
}

return likelihood;
}

public static double dirichletMultinomial(double[] params, int[] counts) {
return dirichletMultinomial(params,sum(params),counts,(int) sum(counts));
}

}
14 changes: 14 additions & 0 deletions public/java/src/org/broadinstitute/sting/utils/Utils.java
Expand Up @@ -835,4 +835,18 @@ public static byte[] trimArray(final byte[] seq, final int trimFromFront, final
// don't perform array copies if we need to copy everything anyways
return ( trimFromFront == 0 && trimFromBack == 0 ) ? seq : Arrays.copyOfRange(seq, trimFromFront, seq.length - trimFromBack);
}

/**
* Simple wrapper for sticking elements of a int[] array into a List<Integer>
* @param ar - the array whose elements should be listified
* @return - a List<Integer> where each element has the same value as the corresponding index in @ar
*/
public static List<Integer> listFromPrimitives(final int[] ar) {
final ArrayList<Integer> lst = new ArrayList<>(ar.length);
for ( final int d : ar ) {
lst.add(d);
}

return lst;
}
}
Expand Up @@ -565,11 +565,11 @@ private static boolean likelihoodsAreUninformative(final double[] likelihoods) {
* @param newLikelihoods a vector of likelihoods to use if the method requires PLs, should be log10 likelihoods, cannot be null
* @param allelesToUse the alleles we are using for our subsetting
*/
protected static void updateGenotypeAfterSubsetting(final List<Allele> originalGT,
final GenotypeBuilder gb,
final GenotypeAssignmentMethod assignmentMethod,
final double[] newLikelihoods,
final List<Allele> allelesToUse) {
public static void updateGenotypeAfterSubsetting(final List<Allele> originalGT,
final GenotypeBuilder gb,
final GenotypeAssignmentMethod assignmentMethod,
final double[] newLikelihoods,
final List<Allele> allelesToUse) {
gb.noAD();
switch ( assignmentMethod ) {
case SET_TO_NO_CALL:
Expand Down

0 comments on commit 105f951

Please sign in to comment.