Hi Kristoffer,
good question. Some points to note:
1. The code within pysam to read through sam and bam-files is
identical - it calls
the c-samtools API. Hence any differences in speed are a consequence
of the c-samtools implementation.
2. Such things are very difficult to benchmark. Bam files are more
compact and require less I/O, but
require additional CPU cycles for decompression. Whether reading from
BAM or SAM files
is quicker or slower depends thus on your relative speed of I/O versus
CPU. Note that modern
servers with good memory are able to cache even large files into
memory which can bias
the results.
3. I have not benchmarked this, so the above is all conjecture.
Best wishes,
Andreas