This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Samtools C Api Examples

Greetings,

I am writing a C++ program to analyze BAM files. I am new to C and C++. I was wondering if anyone had some examples using the Samtools C headers in C++. So far I have been using the awesome Bamtools API, but I want to try the faidx.h header to access fasta sequences.

I have read the documentation, but I learn best by reading through code.

samtools c api

Unless you absolutely want to go for speed, why not use a BAM API in a langauge you already know. Also maybe one the other API's already supports what you want to do.

Yup. If I was in "a get shit done mode" I would just hammer it out in a scripting language, but I am trying to learn a compiled language.

1 answer

I played with the samtools API: see http://variationtoolkit.googlecode.com/svn/trunk/src/ (warning , not everything here should be used in production, some sources are just some ideas I'm testing...)

See

http://variationtoolkit.googlecode.com/svn/trunk/src/xfaidx.cpp and xfaidx.h for a C++ wrapper around fai*

http://variationtoolkit.googlecode.com/svn/trunk/src/bam1sequence.h for a C++ wrapper around bam1_t

etc...

there is also http://samtools.sourceforge.net/sam-exam.shtml

well, I don't think using an external library like samtools is the best way to learn C/C++. It's rather complicated . You should start with the std library an try to implement some simple things like parsing a fasta file or implementing your own version of faidx.

I am comfortable with the STL, getting to the point of being able to write useful tools. It would be a good exercise to implement my own fasta indexing schema.

Log in to answer this question.