From 7578678f9933bd82fdf5996fec16052929445078 Mon Sep 17 00:00:00 2001 From: kcibul Date: Tue, 2 Mar 2010 16:40:03 +0000 Subject: [PATCH] refactored to provide a sum of mismatch quality scores capability as well (used by Cancer) git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@2911 348d0f76-0448-11de-a6fe-93d51630548a --- .../sting/utils/AlignmentUtils.java | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/java/src/org/broadinstitute/sting/utils/AlignmentUtils.java b/java/src/org/broadinstitute/sting/utils/AlignmentUtils.java index 2499f58eb..e09bfc136 100644 --- a/java/src/org/broadinstitute/sting/utils/AlignmentUtils.java +++ b/java/src/org/broadinstitute/sting/utils/AlignmentUtils.java @@ -194,13 +194,25 @@ public class AlignmentUtils { * @return the number of mismatches */ public static int mismatchesInRefWindow(PileupElement p, ReferenceContext ref, boolean ignoreTargetSite) { + return mismatchesInRefWindow(p, ref, ignoreTargetSite, false); + } - int mismatches = 0; + /** Returns the number of mismatches in the pileup element within the given reference context. + * + * @param p the pileup element + * @param ref the reference context + * @param ignoreTargetSite if true, ignore mismatches at the target locus (i.e. the center of the window) + * @param qualitySumInsteadOfMismatchCount if true, return the quality score sum of the mismatches rather than the count + * @return the number of mismatches + */ + public static int mismatchesInRefWindow(PileupElement p, ReferenceContext ref, boolean ignoreTargetSite, boolean qualitySumInsteadOfMismatchCount) { + int sum = 0; int windowStart = (int)ref.getWindow().getStart(); int windowStop = (int)ref.getWindow().getStop(); char[] refBases = ref.getBases(); byte[] readBases = p.getRead().getReadBases(); + byte[] readQualities = p.getRead().getBaseQualities(); Cigar c = p.getRead().getCigar(); int readIndex = 0; @@ -228,8 +240,8 @@ public class AlignmentUtils { continue; char readChr = (char)readBases[readIndex]; - if ( Character.toUpperCase(readChr) != Character.toUpperCase(refChr) ) - mismatches++; + if ( Character.toUpperCase(readChr) != Character.toUpperCase(refChr) ) + sum += (qualitySumInsteadOfMismatchCount) ? readQualities[readIndex] : 1; } break; case I: @@ -246,10 +258,9 @@ public class AlignmentUtils { // fail silently return 0; } - } - return mismatches; + return sum; } /** Returns number of alignment blocks (continuous stretches of aligned bases) in the specified alignment.