Dear list, I would like to programmatically access the samtools library for a C++ program. Unfortunately, I cannot figure out how to sort a bam file. Indeed, bam.h states that it offers ways for sorting but I did not find a matching function:
------------------------------------------------------------------------ //streams samfile_t *in = 0, *out = 0; //open samfile for reading const char* csampath = sampath.c_str(); in = samopen(csampath, "r", 0); if (in == 0) { stop("Fail to open SAM file " + sampath); } //open bamfile for writing const char* cbampath = bampath.c_str(); out = samopen(cbampath, "wb", in->header); if (out == 0) { stop("Fail to open BAM file ." + bampath); } //read sam and write to bam: adapted from sam_view.c:232-244 bam1_t *b = bam_init1(); while (samread(in, b) >= 0) { // read one alignment from `in' samwrite(out, b); // write the alignment to `out' } bam_destroy1(b); //close streams samclose(in); samclose(out); //sort bam and build the index //bam_sort(); // bam_index_build(bampath.c_str()); //fails if bam is not correctly sorted ------------------------------------------------------------------------ Thanks in advance, -- Dipl.-Bioinf. Johannes Helmuth, PhD Student OWL Epigenomics Max Planck Institute for Molecular Genetics Ihnestraße 63-73 D-14195 Berlin, Germany Fon: (+4930) 8413 1173 Web: http://www.molgen.mpg.de/22701/Computational_Epigenomics ------------------------------------------------------------------------------ Dive into the World of Parallel Programming. The Go Parallel Website, sponsored by Intel and developed in partnership with Slashdot Media, is your hub for all things parallel software development, from weekly thought leadership blogs to news, videos, case studies, tutorials and more. Take a look and join the conversation now. http://goparallel.sourceforge.net/ _______________________________________________ Samtools-help mailing list Samtools-help@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/samtools-help