+ if (in->header->l_text > 0) {
+ char comment[] = "@CO\tThis BAM file is processed by rsem-tbam2gam to convert from transcript coordinates into genomic coordinates.\n";
+ int comment_len = strlen(comment);
+
+ //Filter @SQ fields if the BAM file is user provided
+ char *text = in->header->text;
+ int l_text = in->header->l_text;
+ char *new_text = new char[l_text + comment_len];
+ int pos = 0, s = 0;
+ while (pos < l_text) {
+ if ((pos + 2 < l_text) && (text[pos] == '@') && (text[pos + 1] == 'S') && (text[pos + 2] == 'Q')) {
+ pos += 3;
+ while (pos < l_text && text[pos] != '\n') ++pos;
+ }
+ else new_text[s++] = text[pos];
+ ++pos;
+ }
+ strncpy(new_text + s, comment, comment_len);
+ s += comment_len;
+
+ append_header_text(out_header, new_text, s);
+ delete[] new_text;
+ }