簡體   English   中英

進行subprocess.call命令

[英]Making a subprocess.call for a command

我通過聯機檢查器運行了腳本,將其完全格式化。 我希望它運行如下:

script.py --i smth

它執行subprocess.call並從raw_input定義字符串。

我相信subprocess.call SED是錯誤的。 原始命令是sed -i 's/#include "martini.itp"/#include "martini_v2.1-dna.itp"\\n#include "martini_v2.0_ions.itp"/' cg-1rna.top

import getopt
import sys
import subprocess

inputfile = ''
try:
    opts, args = getopt.getopt(sys.argv[1:], "v", ["ifile"])
    for opt, arg in opts:
        if opt in ("-i", "-sfile"):
            inputfile = arg
    subprocess.call(["grep", "-v", "HETATM", "rna.pdb", ">", "aa-1rna.pdb"])
    subprocess.call(["gmx", "editconf", "-f", "aa-1rna.pdb", "-o", "aa-1rna.gro"])
    subprocess.call(["python", "martinize-nucleotide.py", "-type", inputfile, "-f", "aa-1rna.gro", "-o", "cg-1rna.top", "-x", "cg-1rna.pdb"])
    subprocess.call(["cp", "cg-1rna.top", "cg-1rna.top.bak"])
    subprocess.call(["sed", "-i", "'s/#include", '"martini.itp"/#include', '"martini_v2.1-dna.itp"\n#include#', '"martini_v2.0_ions.itp"/', "cg-1rna.top"])
    subprocess.call(["vmd", "cg-1rna.pdb"])
    dvalue = raw_input("Cancel script using CTRL+C or write the distance between the first and last nucleotide with a total of 4 decimals (in nm): ")
    subprocess.call(["gmx", "editconf", "-f", "cg-1rna.pdb", "-d", dvalue, "-bt", "dodecahedron", "-o", "box.gro"])
    subprocess.call(["gmx", "solvate", "-cp", "box.gro", "-cs", "water.gro", "-o", "bw.gro"])
    subprocess.call(["vmd", "bw.gro"])
    wvalue = raw_input("Cancel script using CTRL+C or write the number of water molecules added: ")
    subprocess.call(["printf", '"\nW', "        ", wvalue + '"', ">>", "cg-1rna.top"])
    subprocess.call(["gmx", "grompp", "-f", "em.mdp", "-c", "bw.gro", "-p", "cg-1rna.top", "-o", "01-em"])
    nnvalue = raw_input("Warning: Last input step! Cancel script using CTRL+C or write the number of sodium ions to be added: ")
    subprocess.call(["gmx", "genion", "-s", "01-em.tpr", "-o", "bw.gro", "-p", "cg-1rna.top", "-pname", "NA", "-nname NA", "-nn", nnvalue])
    subprocess.call(["gmx", "mdrun", "-v", "-deffnm", "01-eq"])
    subprocess.call(["gmx", "grompp", "-f", "equil.mdp", "-c", "01-em.gro", "-p", "cg-1rna.top", "-o", "02-eq", "-maxwarn 1"])
    subprocess.call(["gmx", "mdrun", "-v", "-deffnm", "02-eq"])
    subprocess.call(["gmx", "grompp", "-f", "mdrun.mdp", "-c", "02-eq.gro", "-p", "cg-1rna.top", "-o", "output"])
    subprocess.call(["gmx", "mdrun", "-v", "-deffnm", "output"])
except getopt.GetoptError:
    print "rnascript.py --i <networkmodeltype>"
sys.exit(2)

subprocess.call每個參數都應該是一個單獨的shell參數。

這將是一個shell參數:

's/#include "martini.itp"/#include "martini_v2.1-dna.itp"\\n#include "martini_v2.0_ions.itp"/'

您已在內部在空格處進行了拆分:

subprocess.call(["sed", "-i", "'s/#include", '"martini.itp"/#include', '"martini_v2.1-dna.itp"\n#include#', '"martini_v2.0_ions.itp"/', "cg-1rna.top"])

sed接收到這幾個參數時,它可能不知道該怎么辦並出錯。 看到錯誤了嗎? 我建議您下次閱讀並包括在您的問題中。

嘗試將單個shell參數作為單個參數發送到subprocess.call ,也許像這樣:

subprocess.call(["sed", "-i", 's/#include "martini.itp"/#include "martini_v2.1-dna.itp"\n#include "martini_v2.0_ions.itp"/', "cg-1rna.top"])

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM