I am trying to write a python script that loops through SAM files in a directory and uses samtools view
to convert those SAM files to BAM files. Here's what I have, but am struggling with how to input the SAM file (i) into the bash command in the last line.
import os
import glob
for i in glob.iglob('/file/path/to/files/*.sam'):
os.system("samtools view -S -b %i > %i.bam" %i)
Thank you for your help!