如何通过python调用/运行软件?

Mah*_*ood 2 python file-io call

我正在尝试制作一个简单的脚本来逐个(一个接一个)运行不同的任务,但我不知道如何通过 python 脚本运行该程序!我知道这应该很简单!但我在任何地方都找不到它。我的例子是这样的:

samtools merge filename.bam file1.sorted.bam file2.sorted.bam file3.sorted.bam file4.sorted.bam

samtools index filename.bam 
samtools idxstats filename.bam > filename.txt 
samtools pileup -vcf path/filename.fa filename_sorted.bam
Run Code Online (Sandbox Code Playgroud)

我希望 python 运行第一个命令,完成后然后转到下一个命令!重要的是要等到它完成!

agf*_*agf 5

from subprocess import call # call runs an external program and waits for it to quit

for command in ("samtools merge filename.bam file1.sorted.bam file2.sorted.bam file3.sorted.bam file4.sorted.bam", 
                "samtools index filename.bam", 
                "samtools idxstats filename.bam > filename.txt", 
                "samtools pileup -vcf path/filename.fa filename_sorted.bam"):
    # shell=True is so you can handle redirects like in the 3rd command
    call(command, shell=True) 
Run Code Online (Sandbox Code Playgroud)