brentp / hts-nim

nim wrapper for htslib for parsing genomics data files

Home Page:https://brentp.github.io/hts-nim/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Get query length from CIGAR?

sdwfrost opened this issue · comments

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

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?

closing this as resolved. but I can be convinced otherwise.