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

Q: how to read BAM from internally generated stream

andreas-wilm opened this issue · comments

Hi Brent,

what's the recommended way to parse internally generated BAM streams? The use case here is that I call BWA internally using osproc, returning lines on stdout as iterator. open() can't be used, unless I use a named pipe as intermediate. Is there a way to generate a Record from a SAM/BAM line?

Thanks,
Andreas

You could do this with sam_hdr_parse for the header and sam_parse1 for the records. I'll see about making this more convenient.

I am implementing this in hts-nim now so it'll be more ergonomic to accomplish. Should have it up today.

I just pushed methods for making this simpler. See the tests added in a95d8f1 for an example.

Very cool. Works like a charm. Thanks a lot!

Just a side note: I had a simple import hts in my code and using Header() triggered Error: ambiguous identifier: 'Header' --use bam.Header or vcf.Header. Using import hts.bam solves the problem. Might be cleaner to change the names in the longrun...

thanks for following up, glad it worked for you. I think Header is the proper name in both cases and specifying vcf.Header is an understandable change. I could have namespaced so that importing specific packages was required, but I didn't do that by accident and now I prefer it that way.