minimap2 icon indicating copy to clipboard operation
minimap2 copied to clipboard

Mappy fails while calling cigar_str if you use X/= instead M

Open tprodanov opened this issue 4 years ago • 4 comments

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))

tprodanov avatar Mar 11 '20 13:03 tprodanov

Thanks. If you change that line, can you get the correct output?

lh3 avatar Mar 11 '20 13:03 lh3

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

tprodanov avatar Mar 11 '20 15:03 tprodanov

Are there plans to include this change in the mappy code?

mnshgl0110 avatar May 18 '20 17:05 mnshgl0110

Fixed in 2.21.

jmarshall avatar Jul 07 '21 09:07 jmarshall