From a8a6c63a32237390faf65ec7f11915a87be54a67 Mon Sep 17 00:00:00 2001 From: kiran Date: Thu, 2 Apr 2009 22:06:15 +0000 Subject: [PATCH] A class with some static methods that aid the manipulation of quality scores and probabilities (including a method to compress a base and quality score into a byte for SAM output. git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@271 348d0f76-0448-11de-a6fe-93d51630548a --- .../sting/utils/QualityUtils.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100755 java/src/org/broadinstitute/sting/utils/QualityUtils.java diff --git a/java/src/org/broadinstitute/sting/utils/QualityUtils.java b/java/src/org/broadinstitute/sting/utils/QualityUtils.java new file mode 100755 index 000000000..7d0082ee1 --- /dev/null +++ b/java/src/org/broadinstitute/sting/utils/QualityUtils.java @@ -0,0 +1,22 @@ +package org.broadinstitute.sting.utils; + +public class QualityUtils { + private QualityUtils() {} + + static public double qualToProb(byte qual) { + return 1.0 - Math.pow(10.0, ((double) qual)/-10.0); + } + + static public byte probToQual(double prob) { + return (byte) Math.round(-10.0*Math.log10(1.0 - prob + 0.0001)); + } + + static public byte qualAndProbToCompressedQuality(int baseIndex, double prob) { + byte compressedQual = (byte) baseIndex; + byte cprob = (byte) (100.0*prob); + byte qualmask = (byte) 252; + compressedQual += ((cprob << 2) & qualmask); + + return compressedQual; + } +}