Get query length from CIGAR?
sdwfrost opened this issue · comments
Simon Frost commented
Dear @brentp
I'm trying to get the query length from the CIGAR string, which is in htslib as int bam_cigar2qlen(int n_cigar, const uint32_t *cigar)
, and is exported from hts/private/hts_concat
, but the fields of Cigar
aren't exported. Could you add the following (or something similar) to cigar.nim
(seems too tiny for a PR).
proc qlen*(c: Cigar): int {. inline .} =
result = int(bam_cigar2qlen(c.n.cint, cast[ptr uint32](c.cig)))
Brent Pedersen commented
I guess I am open to adding this, but you can achieve this with (something like):
proc qlen*(c:Cigar): int {.inline.} =
for op in cigar:
if op.consumes.query:
result += op.len
which will generate effectively the same code as the bam_cigar2qlen
code.
Does that do what you want?
Brent Pedersen commented
closing this as resolved. but I can be convinced otherwise.