minimap2
minimap2 copied to clipboard
Mappy fails while calling cigar_str if you use X/= instead M
If you align sequences using mappy
and using 0x4000000
flag (use X and = instead of M in CIGAR), and then if you try to print hits or print cigar_str
, the code will fail.
Ways to reproduce:
import random
import mappy
seq = ''.join(random.choices('ACGT', k=100))
aln = mappy.Aligner(seq=seq)
print(next(aln.map(seq)))
# 0 100 + N/A 100 0 100 100 100 60 tp:A:P ts:A:. cg:Z:100M
USE_EQX = 0x4000000
print(next(aln.map(seq, extra_flags=USE_EQX)))
# File "python/mappy.pyx", line 97, in mappy.Alignment.__str__
# File "python/mappy.pyx", line 85, in mappy.Alignment.cigar_str.__get__.lambda
# File "python/mappy.pyx", line 85, in mappy.Alignment.cigar_str.__get__.lambda
This is caused by cigar_str
function,
return "".join(map(lambda x: str(x[0]) + 'MIDNSH'[x[1]], self._cigar))
Thanks. If you change that line, can you get the correct output?
I did not try to change mappy code, but an external function
def cigar_str(hit):
return "".join(map(lambda x: str(x[0]) + 'MIDNSHP=X'[x[1]], hit.cigar))
works fine
Are there plans to include this change in the mappy code?
Fixed in 2.21.