This is a problem with htslib, not pysam. The problem a bug in
bgzf_tell
or bgzf_seek
, apparently fixed here:
https://github.com/samtools/htslib/commit/c99ed6aa47b5af768053bc6de895d284a440638f
The bug is apparent on running the following command and looking at
the first output, the result of tell
following a seek.
$ pysam_example.py bam_mapping.bam
$ ./pysam_example.py bam_mapping.bam
0x25700000000 m140905_042212_sidney_c100564852550000001823085912221377_s1_X0/47698/10378_10609
0x2570709 m140905_042212_sidney_c100564852550000001823085912221377_s1_X0/47698/9675_10333
0x2571951 m140905_042212_sidney_c100564852550000001823085912221377_s1_X0/47698/9482_9628
0x2571e03 m140905_042212_sidney_c100564852550000001823085912221377_s1_X0/49194/845_1541
0x25731dc m140905_042212_sidney_c100564852550000001823085912221377_s1_X0/49194/0_798
0x25748c6 m140905_042212_sidney_c100564852550000001823085912221377_s1_X0/32328/387_1134
0x2575e1b m140905_042212_sidney_c100564852550000001823085912221377_s1_X0/32328/0_344
0x2576822 m140905_042212_sidney_c100564852550000001823085912221377_s1_X0/49050/48_1132
0x2578695 m140905_042212_sidney_c100564852550000001823085912221377_s1_X0/15641/3452_3567
$ ./pysam_example.py bam_mapping.bam
0x2570000 m140905_042212_sidney_c100564852550000001823085912221377_s1_X0/47698/10378_10609
0x2570709 m140905_042212_sidney_c100564852550000001823085912221377_s1_X0/47698/9675_10333
0x2571951 m140905_042212_sidney_c100564852550000001823085912221377_s1_X0/47698/9482_9628
0x2571e03 m140905_042212_sidney_c100564852550000001823085912221377_s1_X0/49194/845_1541
0x25731dc m140905_042212_sidney_c100564852550000001823085912221377_s1_X0/49194/0_798
0x25748c6 m140905_042212_sidney_c100564852550000001823085912221377_s1_X0/32328/387_1134
0x2575e1b m140905_042212_sidney_c100564852550000001823085912221377_s1_X0/32328/0_344
0x2576822 m140905_042212_sidney_c100564852550000001823085912221377_s1_X0/49050/48_1132
0x2578695 m140905_042212_sidney_c100564852550000001823085912221377_s1_X0/15641/3452_3567