【问题标题】:Problem with python script calling subprocesspython脚本调用子进程的问题
【发布时间】:2019-11-06 10:11:12
【问题描述】:

以下是我在运行 growthpred-v1.07.py 脚本时遇到的错误(此脚本中的相关行粘贴在下方)

Traceback (most recent call last):
  File "./growthpred-v1.07.py", line 396, in <module>
    main()      
  File "./growthpred-v1.07.py", line 354, in main
    nucfreqs=Getnucfreq(dirbin, dirinput, othfile)
  File "./growthpred-v1.07.py", line 173, in Getnucfreq
    nucfreqs = subprocess.Popen(["%swcountq" %(direx), "%s%s" %(dirfile,file)], stdout=subprocess.PIPE).communicate()[0]
  File "/usr/lib/python2.7/subprocess.py", line 711, in __init__
    errread, errwrite)
  File "/usr/lib/python2.7/subprocess.py", line 1343, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

growthpred-v1.07.py 脚本中的相关行:

def Getnucfreq(direx, dirfile, file):
        #calculates nucleotide frequency in quartets (neutral selection)
        nucfreqs = subprocess.Popen(["%swcountq" %(direx), "%s%s" %(dirfile,file)], stdout=subprocess.PIPE).communicate()[0]
        A = str.split(nucfreqs)[45]
        C = str.split(nucfreqs)[48]
        G = str.split(nucfreqs)[51]
        return (A,C,G)

def GetCUB(direx,A,C,G,code,dirfile,file,type,outfile):
        #calculates codon usage bias indexes ENCp and P (Vieira-Silva and Rocha, PlosGen)
        print "Calculate codon usage bias indexes for %s sequences" %(type)
        p1 = subprocess.Popen('%sutilCUB -A %s -C %s -G %s -c %s -t < %s%s' %(direx,A,C,G,code,dirfile,file), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
        f1 = open("%s%s.errors" %(dirfile,outfile),"a")
        f1.write(p1[1])
        f1.close()  
        f2 = open("%s%s.%s.enc.si" %(dirfile,outfile,type),"w")
        f2.write(p1[0])
        f2.close() 

def Getgentime_single(direx,dirshare,dirfile,outfile,OGT):
        #calculates minimum generation time (Vieira-Silva and Rocha, PlosGen)
        print "Calculate predicted minimum generation time"
        p1 = subprocess.Popen('%sR --slave -q --no-save < %sgetd_single.R %s%s.OTH.enc.si %s%s.HEG.enc.si %s %s%s.results' %(direx,dirshare,dirfile,outfile,dirfile,outfile,OGT,dirfile,outfile), shell=Tru$
        f1 = open("%s%s.errors" %(dirfile,outfile),"a")
        f1.write(p1[1])
        f1.close()  

def Getgentime_mixed(direx,dirshare,dirfile,outfile,OGT):
        #calculates minimum generation time (Vieira-Silva and Rocha, PlosGen)
        print "Calculate predicted minimum generation time"
        p1 = subprocess.Popen('%sR --slave -q --no-save < %sgetd_mixed.R %s%s.OTH.enc.si %s%s.HEG.enc.si %s %s%s.results' %(direx,dirshare,dirfile,outfile,dirfile,outfile,OGT,dirfile,outfile), shell=True$
f1 = open("%s%s.errors" %(dirfile,outfile),"a")
        f1.write(p1[1])
        f1.close()      

def Getogt(direx, dirfile, file, code, dirbin):
        #calculates optimal growth temperature (Zeldovich et al, PlosCompBiol, 2007)
        print "Calculate predicted optimal growth temperature"
        ogt = subprocess.Popen(["%sget_OGT.sh" %(direx), "%s" %(code), "%s%s" %(dirfile,file),"%s" %(dirbin)], stdout=subprocess.PIPE, stderr=None).communicate()[0]
        return ogt

def Getheg(direx, dirfile, file, hegdb,diroutfile,outfile,blastall,getentryF):
        #retrieves the set of seq from input file that have high similarity (Evalue<0.00001, identity>40%) and similar length (+-10%) to ribosomal database seqs 
        print "Blast against ribosomal protein database"
        subprocess.Popen('%sget_rprots.sh %s%s %s %s%s %s %s' %(direx,dirfile,file,hegdb,diroutfile,outfile,blastall,getentryF), shell=True, stdout=None, stderr=None).communicate()[0]

def Getcai(diremb,dirfile,fileheg,fileoth):
        #calculates codon adaptation index (Sharp and LI, NAR, 1987)
        subprocess.Popen('%scusp %s%s %s%s.cusp' %(diremb,dirfile,fileheg,dirfile,fileheg), shell=True, stdout=None, stderr=None).communicate()
        subprocess.Popen('%scai %s%s -cfile %s%s.cusp %s%s.cai' %(diremb,dirfile,fileoth,dirfile,fileheg,dirfile,fileoth), shell=True, stdout=None, stderr=None).communicate()
        subprocess.Popen('rm -f %s%s.cusp' %(dirfile,fileheg), shell=True, stdout=None, stderr=None).communicate()

def Join(dirfile,fileenc,filecai,outfile):
        #Creates CUB file by joining ENCp+P file with CAI file
        print "Create codon usage bias indexes file"
        p1=subprocess.Popen('cut -f 2,4 -d " " %s%s' %(dirfile,filecai), shell=True, stdout=subprocess.PIPE)
        p2=subprocess.Popen('sort', shell=True, stdout=subprocess.PIPE, stdin=p1.stdout).communicate()
        f1 = open("%s%s.2" %(dirfile,filecai),"w")
        f1.write(p2[0])
        f1.close()
p1=subprocess.Popen('sort %s%s' %(dirfile,fileenc), shell=True, stdout=subprocess.PIPE).communicate()
        f1 = open("%s%s.2" %(dirfile,fileenc),"w")
        f1.write(p1[0])
        f1.close()
        f1 = open("%s%s" %(dirfile,outfile),"a")
        f1.write("# NB: The Codon Adaptation Index is only an appropriate proxy \n# for the expression level of genes in fast growing cells \n# minimal doubling times under ~2h \n")
        f1.write("SeqID ENC ENCp P CAI \n")
        p1=subprocess.Popen('join %s%s %s%s' %(dirfile,fileenc+".2",dirfile,filecai+".2"), shell=True, stdout=subprocess.PIPE).communicate()
        f1.write(p1[0])  
        f1.close()
        subprocess.Popen('rm -f %s%s %s%s %s%s %s%s' %(dirfile,fileenc,dirfile,filecai,dirfile,fileenc+".2",dirfile,filecai+".2"), shell=True, stdout=None, stderr=None).communicate()[0]

def main():

对于修复上述代码的任何意见,我将不胜感激,以避免在我的帖子开头指出的错误消息。

【问题讨论】:

    标签: python-2.7 subprocess


    【解决方案1】:

    关键信息在错误信息中:

    OSError: [Errno 2] 没有这样的文件或目录

    这可能意味着在目录direx 中找不到可执行文件wcountq。确保可执行文件存在并且为程序提供了正确的路径 (direx)。

    【讨论】:

    • 非常感谢您提供的重要线索。我提供了 wcountq 但现在还有另一个错误:*** 检测到缓冲区溢出 ***: ./Programs/utilCUB 终止 ======= Backtrace: ========= /lib/x86_64- linux-gnu/libc.so.6(+0x777e5)[0x14b3968f27e5] /lib/x86_64-linux-gnu/libc.so.6(__fortify_fail+0x5c)[0x14b39699415c] /lib/x86_64-linux-gnu/libc.so .6(+0x117160)[0x14b396992160] /lib/x86_64-linux-gnu/libc.so.6(+0x1164b2)[0x14b3969914b2] ./Programs/utilCUB[0x402123] ./Programs/utilCUB[0x401c70]
    • 嗯,那个看起来更棘手。此错误似乎源自GetCUB 方法,该方法调用了程序utilCUB,从而产生了缓冲区溢出。但这是一个相当普遍的错误,因此很难说确切的问题是什么。一些可能性:a) 输入序列太长 b) 输入序列太多。如果你能弄清楚参数,你可以尝试直接从命令行运行utilCUB./Programs/utilCUB -A [...] -C [...] -G [...] -c [...] -t &lt; sequences.fasta(将[...]替换为正确的值)
    • 非常感谢 user727089-非常感谢!我会尝试测试你的好建议
    猜你喜欢
    • 2012-07-31
    • 2011-11-01
    • 2017-06-04
    • 1970-01-01
    • 1970-01-01
    • 2014-06-04
    • 2017-10-30
    • 2021-08-30
    • 2017-12-22
    相关资源
    最近更新 更多