This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Extract bam file to sam inside code?

Hi everyone, how can I check if a given file is zipped or not(sam or bam) without looking at the file name in C++ code? Then, how can I convert bam files to sam in C++ code? I can use samtools view in terminal, but how can do it with code?

bam sam

1 answer

A bam/cram is compressed with gzip. just look at the two first bytes, they should be 1f and 8b. https://stackoverflow.com/a/6059342/58082

but in the end, you should just use the htslib library https://github.com/samtools/htslib

Log in to answer this question.