@@ -14,9 +14,9 @@ cdef class Alignment:
1414 cdef int8_t _strand, _trans_strand
1515 cdef uint8_t _mapq, _is_primary
1616 cdef int _seg_id
17- cdef _ctg, _cigar, _cs, _MD # these are python objects
17+ cdef _ctg, _cigar, _cs, _ds, _MD # these are python objects
1818
19- def __cinit__ (self , ctg , cl , cs , ce , strand , qs , qe , mapq , cigar , is_primary , mlen , blen , NM , trans_strand , seg_id , cs_str , MD_str ):
19+ def __cinit__ (self , ctg , cl , cs , ce , strand , qs , qe , mapq , cigar , is_primary , mlen , blen , NM , trans_strand , seg_id , cs_str , ds_str , MD_str ):
2020 self ._ctg = ctg if isinstance (ctg, str ) else ctg.decode()
2121 self ._ctg_len, self ._r_st, self ._r_en = cl, cs, ce
2222 self ._strand, self ._q_st, self ._q_en = strand, qs, qe
@@ -27,6 +27,7 @@ cdef class Alignment:
2727 self ._trans_strand = trans_strand
2828 self ._seg_id = seg_id
2929 self ._cs = cs_str
30+ self ._ds = ds_str
3031 self ._MD = MD_str
3132
3233 @property
@@ -77,6 +78,9 @@ cdef class Alignment:
7778 @property
7879 def cs (self ): return self ._cs
7980
81+ @property
82+ def ds (self ): return self ._ds
83+
8084 @property
8185 def MD (self ): return self ._MD
8286
@@ -96,6 +100,7 @@ cdef class Alignment:
96100 a = [str (self ._q_st), str (self ._q_en), strand, self ._ctg, str (self ._ctg_len), str (self ._r_st), str (self ._r_en),
97101 str (self ._mlen), str (self ._blen), str (self ._mapq), tp, ts, " cg:Z:" + self .cigar_str]
98102 if self ._cs != " " : a.append(" cs:Z:" + self ._cs)
103+ if self ._ds != " " : a.append(" ds:Z:" + self ._ds)
99104 if self ._MD != " " : a.append(" MD:Z:" + self ._MD)
100105 return " \t " .join(a)
101106
@@ -165,7 +170,7 @@ cdef class Aligner:
165170 def __bool__ (self ):
166171 return (self ._idx != NULL )
167172
168- def map (self , seq , seq2 = None , name = None , buf = None , cs = False , MD = False , max_frag_len = None , extra_flags = None ):
173+ def map (self , seq , seq2 = None , name = None , buf = None , cs = False , ds = False , MD = False , max_frag_len = None , extra_flags = None ):
169174 cdef cmappy.mm_reg1_t * regs
170175 cdef cmappy.mm_hitpy_t h
171176 cdef ThreadBuffer b
@@ -206,19 +211,22 @@ cdef class Aligner:
206211 i = 0
207212 while i < n_regs:
208213 cmappy.mm_reg2hitpy(self ._idx, & regs[i], & h)
209- cigar, _cs, _MD = [], ' ' , ' '
214+ cigar, _cs, _ds, _MD = [], ' ' , ' ' , ' '
210215 for k in range (h.n_cigar32): # convert the 32-bit CIGAR encoding to Python array
211216 c = h.cigar32[k]
212217 cigar.append([c>> 4 , c& 0xf ])
213- if cs or MD: # generate the cs and/or the MD tag, if requested
218+ if cs or ds or MD: # generate the cs/ds and/or the MD tag, if requested
214219 _cur_seq = _seq2 if h.seg_id > 0 and seq2 is not None else _seq
215220 if cs:
216221 l_cs_str = cmappy.mm_gen_cs(km, & cs_str, & m_cs_str, self ._idx, & regs[i], _cur_seq, 1 )
217222 _cs = cs_str[:l_cs_str] if isinstance (cs_str, str ) else cs_str[:l_cs_str].decode()
223+ if ds:
224+ l_cs_str = cmappy.mm_gen_ds(km, & cs_str, & m_cs_str, self ._idx, & regs[i], _cur_seq, 1 )
225+ _ds = cs_str[:l_cs_str] if isinstance (cs_str, str ) else cs_str[:l_cs_str].decode()
218226 if MD:
219227 l_cs_str = cmappy.mm_gen_MD(km, & cs_str, & m_cs_str, self ._idx, & regs[i], _cur_seq)
220228 _MD = cs_str[:l_cs_str] if isinstance (cs_str, str ) else cs_str[:l_cs_str].decode()
221- yield Alignment(h.ctg, h.ctg_len, h.ctg_start, h.ctg_end, h.strand, h.qry_start, h.qry_end, h.mapq, cigar, h.is_primary, h.mlen, h.blen, h.NM, h.trans_strand, h.seg_id, _cs, _MD)
229+ yield Alignment(h.ctg, h.ctg_len, h.ctg_start, h.ctg_end, h.strand, h.qry_start, h.qry_end, h.mapq, cigar, h.is_primary, h.mlen, h.blen, h.NM, h.trans_strand, h.seg_id, _cs, _ds, _MD)
222230 cmappy.mm_free_reg1(& regs[i])
223231 i += 1
224232 finally :
0 commit comments