From caf689821f97dbfb85bdc9f58ff31abea33a37e3 Mon Sep 17 00:00:00 2001 From: ebanks Date: Mon, 12 Oct 2009 02:33:22 +0000 Subject: [PATCH] added method to get normalized posteriors git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@1809 348d0f76-0448-11de-a6fe-93d51630548a --- .../genotyper/GenotypeLikelihoods.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/GenotypeLikelihoods.java b/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/GenotypeLikelihoods.java index 864db8693..b0d64ef43 100644 --- a/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/GenotypeLikelihoods.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/GenotypeLikelihoods.java @@ -148,6 +148,32 @@ public abstract class GenotypeLikelihoods implements Cloneable { return getPosteriors()[g.ordinal()]; } + + /** + * Returns an array of posteriors for each genotype, indexed by DiploidGenotype.ordinal values(). + * + * @return normalized posterors as a double array + */ + public double[] getNormalizedPosteriors() { + double[] normalized = new double[posteriors.length]; + double sum = 0.0; + + // collect the posteriors + for ( DiploidGenotype g : DiploidGenotype.values() ) { + double posterior = Math.pow(10, getPosterior(g)); + normalized[g.ordinal()] = posterior; + sum += posterior; + } + + // normalize + for (int i = 0; i < normalized.length; i++) + normalized[i] /= sum; + + return normalized; + } + + + public DiploidGenotypePriors getPriorObject() { return priors; }