text: user6625: 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)
  
  
  user77: 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.
  
original_text: 6625: <p>Is it faster to use the PySam package to run a python script on a bam</p>
  
  <pre><code>for read in samfile.fetch('chr1', 100, 120):
   print read
  </code></pre>
  
  <p>compared to using a pipe and reading line by line from stdin in a python script. </p>
  
  <p><code>samtools view example.bam | python script.py.
  </code></p>
  
  <pre><code>for line in tqdm(sys.stdin, total=number_of_lines)
  </code></pre>
   77: <p>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.</p>
  