From 64c65c7751822bac6072866799c631efe48a4314 Mon Sep 17 00:00:00 2001 From: kiran Date: Thu, 14 May 2009 16:50:31 +0000 Subject: [PATCH] New methods to generated compressed SQ quality elements in line with the SAM spec. git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@699 348d0f76-0448-11de-a6fe-93d51630548a --- .../sting/utils/QualityUtils.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/java/src/org/broadinstitute/sting/utils/QualityUtils.java b/java/src/org/broadinstitute/sting/utils/QualityUtils.java index c06ba3b08..3c212cf7c 100755 --- a/java/src/org/broadinstitute/sting/utils/QualityUtils.java +++ b/java/src/org/broadinstitute/sting/utils/QualityUtils.java @@ -73,6 +73,18 @@ public class QualityUtils { return compressedQual; } + static public byte baseAndProbDiffToCompressedQuality(int baseIndex, double probdiff) { + byte compressedQual = 0; + + compressedQual = (byte) baseIndex; + + byte cprob = (byte) probdiff; + byte qualmask = (byte) 252; + compressedQual += ((cprob << 2) & qualmask); + + return compressedQual; + } + /** * From a compressed base, extract the base index (0:A, 1:C, 2:G, 3:T) * @@ -98,6 +110,15 @@ public class QualityUtils { return ((double) x2)/100.0; } + static public double compressedQualityToProbDiff(byte compressedQual) { + // Because java natives are signed, extra care must be taken to avoid + // shifting a 1 into the sign bit in the implicit promotion of 2 to an int. + int x2 = ((int) compressedQual) & 0xff; + x2 = (x2 >>> 2); + + return ((double) x2); + } + /** * Return the complement of a base index. *