Is it faster to use the PySam package to run a python script on a bam

for read in samfile.fetch('chr1', 100, 120):
 print read

compared to using a pipe and reading line by line from stdin in a python script.

samtools view example.bam | python script.py.

for line in tqdm(sys.stdin, total=number_of_lines)

1 Answer 1


It's a bit hard to say with certainty, though I would suspect that offloading the BAM decompression by using a pipe will be very slightly faster. Note that decompressing and parsing the BAM file will not be the bottleneck in your processing, rather the python script itself will be.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.