ksprintf(&str, "\t%c%c:", key[0], key[1]);
if (type == 'A') { ksprintf(&str, "A:%c", *s); ++s; }
else if (type == 'C') { ksprintf(&str, "i:%u", *s); ++s; }
- else if (type == 'c') { ksprintf(&str, "i:%d", *s); ++s; }
+ else if (type == 'c') { ksprintf(&str, "i:%d", *(int8_t*)s); ++s; }
else if (type == 'S') { ksprintf(&str, "i:%u", *(uint16_t*)s); s += 2; }
else if (type == 's') { ksprintf(&str, "i:%d", *(int16_t*)s); s += 2; }
else if (type == 'I') { ksprintf(&str, "i:%u", *(uint32_t*)s); s += 4; }
free(s);
}
-const char *bam_get_library(const bam_header_t *header, const bam1_t *b)
+// FIXME: we should also check the LB tag associated with each alignment
+const char *bam_get_library(bam_header_t *h, const bam1_t *b)
{
const uint8_t *rg;
+ if (h->dict == 0) h->dict = sam_header_parse2(h->text);
+ if (h->rg2lib == 0) h->rg2lib = sam_header2tbl(h->dict, "RG", "ID", "LB");
rg = bam_aux_get(b, "RG");
- return (rg == 0)? 0 : sam_tbl_get(header->rg2lib, (const char*)(rg + 1));
+ return (rg == 0)? 0 : sam_tbl_get(h->rg2lib, (const char*)(rg + 1));
}