From b22a3d65088cd5f8d91f94a82dab0ca544e06238 Mon Sep 17 00:00:00 2001 From: Mauricio Carneiro Date: Thu, 4 Aug 2011 17:49:08 -0400 Subject: [PATCH] Functional VCF output. It is outputting a VCF with the 'second best guess' for the alternate allele correctly. Annotations are added at the pool level, but may get overwritten at the lane and site level. Still need to implement the merging of the the annotations at higher levels. --- .../broadinstitute/sting/utils/BaseUtils.java | 12 ++++++++++ .../broadinstitute/sting/utils/MathUtils.java | 22 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/public/java/src/org/broadinstitute/sting/utils/BaseUtils.java b/public/java/src/org/broadinstitute/sting/utils/BaseUtils.java index de8c81031..673b1524d 100644 --- a/public/java/src/org/broadinstitute/sting/utils/BaseUtils.java +++ b/public/java/src/org/broadinstitute/sting/utils/BaseUtils.java @@ -436,6 +436,18 @@ public class BaseUtils { return mostFrequentBaseIndex; } + static public int mostFrequentBaseIndexNotRef(int[] baseCounts, int refBaseIndex) { + int tmp = baseCounts[refBaseIndex]; + baseCounts[refBaseIndex] = -1; + int result = mostFrequentBaseIndex(baseCounts); + baseCounts[refBaseIndex] = tmp; + return result; + } + + static public int mostFrequentBaseIndexNotRef(int[] baseCounts, byte refSimpleBase) { + return mostFrequentBaseIndexNotRef(baseCounts, simpleBaseToBaseIndex(refSimpleBase)); + } + /** * Returns the most common base in the basecounts array. To be used with pileup.getBaseCounts. * diff --git a/public/java/src/org/broadinstitute/sting/utils/MathUtils.java b/public/java/src/org/broadinstitute/sting/utils/MathUtils.java index 9bd3f603c..a0b970dbc 100755 --- a/public/java/src/org/broadinstitute/sting/utils/MathUtils.java +++ b/public/java/src/org/broadinstitute/sting/utils/MathUtils.java @@ -360,6 +360,23 @@ public class MathUtils { return Math.pow(10,log10MultinomialProbability(n, k, log10P)); } + /** + * calculate the Root Mean Square of an array of integers + * @param x an byte[] of numbers + * @return the RMS of the specified numbers. + */ + public static double rms(byte[] x) { + if ( x.length == 0 ) + return 0.0; + + double rms = 0.0; + for (int i : x) + rms += i * i; + rms /= x.length; + return Math.sqrt(rms); + } + + /** * calculate the Root Mean Square of an array of integers * @param x an int[] of numbers @@ -1074,6 +1091,11 @@ public class MathUtils { return ((-q)/10.0); } + /** + * Returns the phred scaled value of probability p + * @param p probability (between 0 and 1). + * @return phred scaled probability of p + */ public static byte probabilityToPhredScale (double p) { return (byte) ((-10) * Math.log10(p)); }