+inline void BamConverter::modifyTags(bam1_t* b, const Transcript& transcript) {
+ char strand = transcript.getStrand();
+ uint8_t *s = NULL;
+
+ if (strand == '-') {
+ s = bam_aux_get(b, "MD");
+ if ((s != NULL) && (*(s) == 'Z') && (bam_aux2Z(s) != NULL)) {
+ char *mis = bam_aux2Z(s);
+ int len = strlen(mis);
+ char *tmp = new char[len];
+ int cur_type = -1, fr = -1, type, base;
+ for (int i = 0; i < len; i++) {
+ type = (mis[i] >= '0' && mis[i] <= '9');
+ if (cur_type != type) {
+ switch(cur_type) {
+ case 0:
+ base = len - 1;
+ if (mis[fr] == '^') { tmp[len - i] = mis[fr]; ++fr; ++base; }
+ for (int j = fr; j < i; j++) tmp[base - j] = ((mis[j] == 'A' || mis[j] == 'C' || mis[j] == 'G' || mis[j] == 'T') ? getOpp(mis[j]) : mis[j]);
+ break;
+ case 1:
+ base = len - i - fr;
+ for (int j = fr; j < i; j++) tmp[base + j] = mis[j];
+ break;
+ }
+ cur_type = type;
+ fr = i;
+ }
+ }
+ switch(cur_type) {
+ case 0:
+ base = len - 1;
+ if (mis[fr] == '^') { tmp[0] = mis[fr]; ++fr; ++base; }
+ for (int j = fr; j < len; j++) tmp[base - j] = ((mis[j] == 'A' || mis[j] == 'C' || mis[j] == 'G' || mis[j] == 'T') ? getOpp(mis[j]) : mis[j]);
+ break;
+ case 1:
+ for (int j = fr; j < len; j++) tmp[j - fr] = mis[j];
+ break;
+ }
+ strncpy(mis, tmp, len);
+ delete[] tmp;
+ }
+ }
+
+ // append XS:A field if necessary
+ s = bam_aux_get(b, "XS");
+ if (s != NULL) bam_aux_del(b, s);