From 56092a0fc21ebb4670cd9ea2cad5b19dcae200e6 Mon Sep 17 00:00:00 2001 From: depristo Date: Fri, 19 Mar 2010 13:18:08 +0000 Subject: [PATCH] Slight cleanup for mathutils git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@3042 348d0f76-0448-11de-a6fe-93d51630548a --- .../gatk/walkers/TrioGenotyperWalker.java | 2 +- .../broadinstitute/sting/utils/MathUtils.java | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/java/src/org/broadinstitute/sting/playground/gatk/walkers/TrioGenotyperWalker.java b/java/src/org/broadinstitute/sting/playground/gatk/walkers/TrioGenotyperWalker.java index 0b4b4378e..216323fbc 100755 --- a/java/src/org/broadinstitute/sting/playground/gatk/walkers/TrioGenotyperWalker.java +++ b/java/src/org/broadinstitute/sting/playground/gatk/walkers/TrioGenotyperWalker.java @@ -122,7 +122,7 @@ public class TrioGenotyperWalker extends RefWalker{ } } - double[] posteriors = MathUtils.log10posteriorsFromLog10L(L); + double[] posteriors = MathUtils.normalizeFromLog10(L, true); log10POfGenotype = posteriors[bestIndex]; } //log10POfViolation = Math.min(log10POfViolation, 0); diff --git a/java/src/org/broadinstitute/sting/utils/MathUtils.java b/java/src/org/broadinstitute/sting/utils/MathUtils.java index 4fcd28092..d93ec1137 100755 --- a/java/src/org/broadinstitute/sting/utils/MathUtils.java +++ b/java/src/org/broadinstitute/sting/utils/MathUtils.java @@ -277,9 +277,13 @@ public class MathUtils { /** * normalizes the log10-based array + * * @param array the array to be normalized + * @param takeLog10OfOutput if true, the output will be transformed back into log10 units + * + * @return a newly allocated array corresponding the normalized values in array, maybe log10 transformed */ - public static double[] normalizeFromLog10(double[] array) { + public static double[] normalizeFromLog10(double[] array, boolean takeLog10OfOutput) { double[] normalized = new double[array.length]; // for precision purposes, we need to add (or really subtract, since they're @@ -292,9 +296,16 @@ public class MathUtils { double sum = 0.0; for (int i = 0; i < array.length; i++) sum += normalized[i]; - for (int i = 0; i < array.length; i++) - normalized[i] /= sum; + for (int i = 0; i < array.length; i++) { + double x = normalized[i] / sum; + if ( takeLog10OfOutput ) x = Math.log10(x); + normalized[i] = x; + } return normalized; } + + public static double[] normalizeFromLog10(double[] array) { + return normalizeFromLog10(array, false); + } }