src/hg/lib/bamFile.c 1.9

1.9 2009/09/24 04:33:50 angie
Added bamGetQueryQuals for displaying sequence quality scores.
Index: src/hg/lib/bamFile.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/lib/bamFile.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -b -B -U 4 -r1.8 -r1.9
--- src/hg/lib/bamFile.c	23 Sep 2009 23:50:30 -0000	1.8
+++ src/hg/lib/bamFile.c	24 Sep 2009 04:33:50 -0000	1.9
@@ -93,8 +93,25 @@
     reverseComplement(qSeq, core->l_qseq);
 return qSeq;
 }
 
+UBYTE *bamGetQueryQuals(const bam1_t *bam)
+/* Return the base quality scores encoded in bam as an array of ubytes. */
+{
+const bam1_core_t *core = &bam->core;
+int qLen = core->l_qseq;
+UBYTE *arr = needMem(qLen);
+boolean isRc = bamIsRc(bam);
+UBYTE *qualStr = bam1_qual(bam);
+int i;
+for (i = 0;  i < qLen;  i++)
+    {
+    int offset = isRc ? (qLen - 1 - i) : i;
+    arr[offset] = (qualStr[0] == 255) ? 255 : qualStr[i];
+    }
+return arr;
+}
+
 char *bamGetCigar(const bam1_t *bam)
 /* Return a BAM-enhanced CIGAR string, decoded from the packed encoding in bam. */
 {
 unsigned int *cigarPacked = bam1_cigar(bam);