Skip to content

Commit 3b96dce

Browse files
committed
Mem should set the mate cigar tag.
1 parent 05c5013 commit 3b96dce

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

bwamem.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,19 @@ static inline int get_rlen(int n_cigar, const uint32_t *cigar)
809809
return l;
810810
}
811811

812+
static inline void add_cigar(const mem_opt_t *opt, mem_aln_t *p, kstring_t *str, int which)
813+
{
814+
int i;
815+
if (p->n_cigar) { // aligned
816+
for (i = 0; i < p->n_cigar; ++i) {
817+
int c = p->cigar[i]&0xf;
818+
if (!(opt->flag&MEM_F_SOFTCLIP) && !p->is_alt && (c == 3 || c == 4))
819+
c = which? 4 : 3; // use hard clipping for supplementary alignments
820+
kputw(p->cigar[i]>>4, str); kputc("MIDSH"[c], str);
821+
}
822+
} else kputc('*', str); // having a coordinate but unaligned (e.g. when copy_mate is true)
823+
}
824+
812825
void mem_aln2sam(const mem_opt_t *opt, const bntseq_t *bns, kstring_t *str, bseq1_t *s, int n, const mem_aln_t *list, int which, const mem_aln_t *m_)
813826
{
814827
int i, l_name;
@@ -835,14 +848,7 @@ void mem_aln2sam(const mem_opt_t *opt, const bntseq_t *bns, kstring_t *str, bseq
835848
kputs(bns->anns[p->rid].name, str); kputc('\t', str); // RNAME
836849
kputl(p->pos + 1, str); kputc('\t', str); // POS
837850
kputw(p->mapq, str); kputc('\t', str); // MAPQ
838-
if (p->n_cigar) { // aligned
839-
for (i = 0; i < p->n_cigar; ++i) {
840-
int c = p->cigar[i]&0xf;
841-
if (!(opt->flag&MEM_F_SOFTCLIP) && !p->is_alt && (c == 3 || c == 4))
842-
c = which? 4 : 3; // use hard clipping for supplementary alignments
843-
kputw(p->cigar[i]>>4, str); kputc("MIDSH"[c], str);
844-
}
845-
} else kputc('*', str); // having a coordinate but unaligned (e.g. when copy_mate is true)
851+
add_cigar(opt, p, str, which);
846852
} else kputsn("*\t0\t0\t*", 7, str); // without coordinte
847853
kputc('\t', str);
848854

@@ -899,6 +905,7 @@ void mem_aln2sam(const mem_opt_t *opt, const bntseq_t *bns, kstring_t *str, bseq
899905
kputsn("\tNM:i:", 6, str); kputw(p->NM, str);
900906
kputsn("\tMD:Z:", 6, str); kputs((char*)(p->cigar + p->n_cigar), str);
901907
}
908+
if (m->n_cigar) { kputsn("\tMC:Z:", 6, str); add_cigar(opt, m, str, which); }
902909
if (p->score >= 0) { kputsn("\tAS:i:", 6, str); kputw(p->score, str); }
903910
if (p->sub >= 0) { kputsn("\tXS:i:", 6, str); kputw(p->sub, str); }
904911
if (bwa_rg_id[0]) { kputsn("\tRG:Z:", 6, str); kputs(bwa_rg_id, str); }

0 commit comments

Comments
 (0)