Skip to content

Commit 177eef2

Browse files
jmarshalllh3
authored andcommitted
Use the full MIDNSHP=X string whenever printing CIGAR strings
Define MM_CIGAR_STR to the full string of CIGAR operators (including the 'B' operator as well) and use it throughout the C code. It would be possible to use it from the Cython code too, but it's easier to keep that as a Cython string literal to avoid adding extra runtime code to handle locale conversion.
1 parent 459ce04 commit 177eef2

File tree

6 files changed

+10
-8
lines changed

6 files changed

+10
-8
lines changed

align.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ static void mm_align_pair(void *km, const mm_mapopt_t *opt, int qlen, const uint
333333
int i;
334334
fprintf(stderr, "score=%d, cigar=", ez->score);
335335
for (i = 0; i < ez->n_cigar; ++i)
336-
fprintf(stderr, "%d%c", ez->cigar[i]>>4, "MIDN"[ez->cigar[i]&0xf]);
336+
fprintf(stderr, "%d%c", ez->cigar[i]>>4, MM_CIGAR_STR[ez->cigar[i]&0xf]);
337337
fprintf(stderr, "\n");
338338
}
339339
}

example.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ int main(int argc, char *argv[])
4747
printf("%s\t%d\t%d\t%d\t%c\t", ks->name.s, ks->seq.l, r->qs, r->qe, "+-"[r->rev]);
4848
printf("%s\t%d\t%d\t%d\t%d\t%d\t%d\tcg:Z:", mi->seq[r->rid].name, mi->seq[r->rid].len, r->rs, r->re, r->mlen, r->blen, r->mapq);
4949
for (i = 0; i < r->p->n_cigar; ++i) // IMPORTANT: this gives the CIGAR in the aligned regions. NO soft/hard clippings!
50-
printf("%d%c", r->p->cigar[i]>>4, "MIDNSH"[r->p->cigar[i]&0xf]);
50+
printf("%d%c", r->p->cigar[i]>>4, MM_CIGAR_STR[r->p->cigar[i]&0xf]);
5151
putchar('\n');
5252
free(r->p);
5353
}

format.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ void mm_write_paf3(kstring_t *s, const mm_idx_t *mi, const mm_bseq1_t *t, const
325325
uint32_t k;
326326
mm_sprintf_lite(s, "\tcg:Z:");
327327
for (k = 0; k < r->p->n_cigar; ++k)
328-
mm_sprintf_lite(s, "%d%c", r->p->cigar[k]>>4, "MIDNSHP=XB"[r->p->cigar[k]&0xf]);
328+
mm_sprintf_lite(s, "%d%c", r->p->cigar[k]>>4, MM_CIGAR_STR[r->p->cigar[k]&0xf]);
329329
}
330330
if (r->p && (opt_flag & (MM_F_OUT_CS|MM_F_OUT_MD)))
331331
write_cs_or_MD(km, s, mi, t, r, !(opt_flag&MM_F_OUT_CS_LONG), opt_flag&MM_F_OUT_MD, 1);
@@ -382,7 +382,7 @@ static void write_sam_cigar(kstring_t *s, int sam_flag, int in_tag, int qlen, co
382382
assert(clip_len[0] < qlen && clip_len[1] < qlen);
383383
if (clip_len[0]) mm_sprintf_lite(s, "%d%c", clip_len[0], clip_char);
384384
for (k = 0; k < r->p->n_cigar; ++k)
385-
mm_sprintf_lite(s, "%d%c", r->p->cigar[k]>>4, "MIDNSHP=XB"[r->p->cigar[k]&0xf]);
385+
mm_sprintf_lite(s, "%d%c", r->p->cigar[k]>>4, MM_CIGAR_STR[r->p->cigar[k]&0xf]);
386386
if (clip_len[1]) mm_sprintf_lite(s, "%d%c", clip_len[1], clip_char);
387387
}
388388
}

minimap.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646

4747
#define MM_MAX_SEG 255
4848

49+
#define MM_CIGAR_STR "MIDNSHP=XB"
50+
4951
#ifdef __cplusplus
5052
extern "C" {
5153
#endif

misc/paftools.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,7 +1419,7 @@ function paf_view(args)
14191419

14201420
var s_ref = new Bytes(), s_qry = new Bytes(), s_mid = new Bytes(); // these are used to show padded alignment
14211421
var re_cs = /([:=\-\+\*])(\d+|[A-Za-z]+)/g;
1422-
var re_cg = /(\d+)([MIDNSH])/g;
1422+
var re_cg = /(\d+)([MIDNSHP=X])/g;
14231423

14241424
var buf = new Bytes();
14251425
var file = args[getopt.ind] == "-"? new File() : new File(args[getopt.ind]);
@@ -1899,7 +1899,7 @@ function paf_splice2bed(args)
18991899
a.length = 0;
19001900
}
19011901

1902-
var re = /(\d+)([MIDNSH])/g;
1902+
var re = /(\d+)([MIDNSHP=X])/g;
19031903
var c, fmt = "bed", fn_name_conv = null, keep_multi = false;
19041904
while ((c = getopt(args, "f:n:m")) != null) {
19051905
if (c == 'f') fmt = getopt.arg;
@@ -2369,7 +2369,7 @@ function paf_junceval(args)
23692369

23702370
file = getopt.ind+1 >= args.length || args[getopt.ind+1] == '-'? new File() : new File(args[getopt.ind+1]);
23712371
var last_qname = null;
2372-
var re_cigar = /(\d+)([MIDNSHX=])/g;
2372+
var re_cigar = /(\d+)([MIDNSHP=X])/g;
23732373
while (file.readline(buf) >= 0) {
23742374
var m, t = buf.toString().split("\t");
23752375
var ctg_name = null, cigar = null, pos = null, qname = t[0];

python/mappy.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ cdef class Alignment:
8282

8383
@property
8484
def cigar_str(self):
85-
return "".join(map(lambda x: str(x[0]) + 'MIDNSH'[x[1]], self._cigar))
85+
return "".join(map(lambda x: str(x[0]) + 'MIDNSHP=XB'[x[1]], self._cigar))
8686

8787
def __str__(self):
8888
if self._strand > 0: strand = '+'

0 commit comments

Comments
 (0)