python脚本调用子进程的问题

问题描述 投票:1回答:1

下面是我在运行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个回答
0
投票

关键信息在错误消息中:

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

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

© www.soinside.com 2019 - 2024. All rights reserved.