可变的输入和输出文件作为参数perl脚本我有可以从控制台如下执行的perl脚本:调用与蟒蛇
perl perlscript.pl -i input.txt -o output.txt --append
我想从我的Python代码执行这个脚本。我发现subprocess.Popen
可以用来连接到perl,我可以传递我的论点。但是,我也想传递一个变量(通过分割一个文本文件)来代替input.txt。 我曾尝试以下,但它似乎没有工作,在第8行给出了一个明显的类型错误:
import re, shlex, subprocess, StringIO
f=open('fulltext.txt','rb')
text= f.read()
l = re.split('\n\n',str(text))
intxt = StringIO.StringIO()
for i in range(len(l)):
intxt.write(l[i])
command_line='perl cnv_ltrfinder2gff.pl -i '+intxt+' -o output.gff --append'
args=shlex.split(command_line)
p = subprocess.Popen(args)
是否有其他变通方法吗?
编辑:这是文件fulltext.txt的一个示例。条目由一行分隔。
Predict protein Domains 0.021 second
>Sequence: seq1 Len:13143 [1] seq1 Len:13143 Location : 9 - 13124 Len: 13116 Strand:+ Score : 6 [LTR region similarity:0.959] Status : 11110110000 5'-LTR : 9 - 501 Len: 493 3'-LTR : 12633 - 13124 Len: 492 5'-TG : TG , TG 3'-CA : CA , CA TSR : NOT FOUND Sharpness: 1,1 Strand + : PBS : [14/20] 524 - 543 (LysTTT) PPT : [12/15] 12553 - 12567
Predict protein Domains 0.019 second
>Sequence: seq5 Len:11539 [1] seq5 Len:11539 Location : 7 - 11535 Len: 11529 Strand:+ Score : 6 [LTR region similarity:0.984] Status : 11110110000 5'-LTR : 7 - 506 Len: 500 3'-LTR : 11036 - 11535 Len: 500 5'-TG : TG , TG 3'-CA : CA , CA TSR : NOT FOUND Sharpness: 1,1 Strand + : PBS : [15/22] 515 - 536 (LysTTT) PPT : [11/15] 11020 - 11034
我想分开它们并将每个入口块传递给perl脚本。所有文件都在同一个目录中。
Perl脚本可以从stdin而不是文件读取输入吗? – choroba
不,它不能。我正在使用的脚本是:[链接](https://github.com/jestill/dawgpaws/blob/fb0a40506be1ed8afce0049b6cfe3e4b52cd58dc/scripts/cnv_ltrfinder2gff.pl) –
@RimjhimRoyChoudhury:代码说它可以接受来自标准输入(它甚至提醒关于它:[*“期待从STDIN输入”*)(https://github.com/jestill/dawgpaws/blob/fb0a40506be1ed8afce0049b6cfe3e4b52cd58dc/scripts/cnv_ltrfinder2gff.pl#L294))。尝试省略'infile'选项或在bash中传递一个空的''''文件名或''-''或'/ dev/stdin'。 – jfs