[英]How can I call/run a software by python?
I'm trying to make a simple script to run different tasks one by one (one after another) but I don't know how can I run the program by python script.我正在尝试制作一个简单的脚本来逐个(一个接一个)运行不同的任务,但我不知道如何通过 python 脚本运行程序。 I know that it should be simple: but I couldn't find it any where.我知道它应该很简单:但我在任何地方都找不到它。 my example is this:我的例子是这样的:
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
I want the python to run the first command and after its finished then goes to the next one!我希望 python 运行第一个命令,完成后转到下一个命令! it's important that it wait's until it's finished!重要的是要等到完成!
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)
Use the subprocess module .使用子流程模块。 There are lots of examples at the bottom of the page.页面底部有很多示例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.