From 72c34f11dd963f74441bae31d8b7e3c9846e041d Mon Sep 17 00:00:00 2001 From: hanna Date: Wed, 14 Oct 2009 19:32:22 +0000 Subject: [PATCH] Bug fixing for BWA output formats. git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@1841 348d0f76-0448-11de-a6fe-93d51630548a --- .../sting/alignment/bwa/bwt/Counts.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/java/src/org/broadinstitute/sting/alignment/bwa/bwt/Counts.java b/java/src/org/broadinstitute/sting/alignment/bwa/bwt/Counts.java index 950849b9b..5a70848ca 100644 --- a/java/src/org/broadinstitute/sting/alignment/bwa/bwt/Counts.java +++ b/java/src/org/broadinstitute/sting/alignment/bwa/bwt/Counts.java @@ -68,9 +68,10 @@ public class Counts implements Cloneable { int[] countArray = new int[counts.size()]; if(cumulative) { int index = 0; + boolean first = true; for(byte base: Bases.instance) { - if(index == 0) { - index++; + if(first) { + first = false; continue; } countArray[index++] = getCumulative(base); @@ -80,7 +81,7 @@ public class Counts implements Cloneable { else { int index = 0; for(byte base: Bases.instance) - countArray[index] = get(base); + countArray[index++] = counts.get(base); } return countArray; } @@ -98,6 +99,7 @@ public class Counts implements Cloneable { throw new StingException("Unable to clone counts object", ex); } other.counts = new HashMap(counts); + other.cumulativeCounts = new HashMap(cumulativeCounts); return other; } @@ -107,10 +109,10 @@ public class Counts implements Cloneable { */ public void increment(byte base) { counts.put(base,counts.get(base)+1); - int previous = 0; + boolean increment = false; for(byte cumulative: Bases.instance) { - cumulativeCounts.put(cumulative,counts.get(cumulative)+previous); - previous += counts.get(cumulative); + if(increment) cumulativeCounts.put(cumulative,cumulativeCounts.get(cumulative)+1); + increment |= (cumulative == base); } } @@ -126,9 +128,8 @@ public class Counts implements Cloneable { } /** - * Gets a count of the number of bases of each seen type. - * Note that counts in this case are cumulative (counts for A,C,G,T - * are independent). + * Gets a count of the number of bases seen before this base. + * Note that counts in this case are cumulative. * @param base Base for which to query counts. * @return Number of bases of this type seen. */