我正试图通过下面的命令子流程调用()
command = ['htseq-count', '-t', 'miRNA', '-i', 'Name', f, annot_file, out_file]
运行时,我注意到htseq count至少需要2个参数,这意味着它无法识别命令中是否有输入文件。你知道吗
在运行时打印出命令会产生以下结果:
['htseq-count', '-t', 'miRNA', '-i', 'Name', 'KDRD1XX_ACAGTG_L001_R1_001_trimmedaligned.sam', 'hsa.gff3', 'KDRD1XX.htseq.sam']
这是正确的文件输入。你知道吗
插入打印出来的命令(当然没有逗号和引号)工作正常,因此没有问题。你知道吗
我以前对使用变量列表没有异议子流程调用()任何帮助都将不胜感激!你知道吗
完整代码:
import sys
import subprocess
import os
annot_file='hsa.gff3'
dirs= os.listdir('.')
for f in dirs:
if f.endswith("_trimmedaligned.sam"):
of=f.split('_')
outfile='>'+of[0]+'.htseq.sam'
command=['htseq-count','-t','miRNA','-i','Name',f,annot_file, out_file]
#print(command)
subprocess.call(command)
>
是shell语法。它是一个文件的标准输出。这意味着您需要在shell中使用subprocess.call(command, shell=True)
运行命令但由于这需要仔细引用所有参数以防止shell command injection,因此我建议运行命令并保存Python的输出:
PS:上面的例子对于小的输出文件很有效。它在内存中缓冲所有输出。如果输出文件将达到合理的大小,您可以使用
poll()
流式传输命令的输出,如这里所述:https://stackoverflow.com/a/2716032/171318相关问题 更多 >
编程相关推荐