首页 > 解决方案 > Biopython Blast - AttributeError:“分析”对象没有属性“dbtype”

问题描述

我正在尝试使用 BLAST for python 分析序列,这是我收到的原始代码。有人告诉我,这段代码可以工作,但由于库更新,它已经损坏了。

我试过寻找类似的代码,看看这是否被修改过,但没有这样的运气。

下面的第一行出现错误,我复制了整个定义,看看是否有帮助。我也一直试图弄清楚它从哪里调用,但收效甚微。

def blast(self):
    if self.dbtype == "nucl" and self.querytype=="nucl":
        self.blastn_cline = NCBIblast.NcbiblastnCommandline(query=self.outputfasta, db=self.format_filepath, outfmt=5, out=self.outputfasta + ".xml")
        stdout, stderr = self.blastn_cline()
    elif self.dbtype == "prot" and self.querytype=="nucl":
        self.blastx_cline = NCBIblast.NcbiblastxCommandline(query=self.outputfasta, db=self.format_filepath, outfmt=5, out=self.outputfasta + ".xml", seg='no')
        stdout, stderr = self.blastx_cline()
    elif self.dbtype == "nucl" and self.querytype=="prot":
        self.tblastn_cline = NCBIblast.NcbitblastnCommandline(query=self.outputfasta, db=self.format_filepath, outfmt=5, out=self.outputfasta + ".xml", seg='no')
        stdout, stderr = self.tblastn_cline()
    elif self.dbtype == "prot" and self.querytype=="prot":
        self.blastp_cline = NCBIblast.NcbiblastpCommandline(query=self.outputfasta, db=self.format_filepath, outfmt=5, out=self.outputfasta + ".xml", seg='no')
        stdout, stderr = self.blastp_cline()
    result_handle = open(self.outputfasta + ".xml")
    blast_records = NCBIXML.parse(result_handle)
    self.simpleresults = {}
    self.tophits = {}
    for record in blast_records:
        for hit in record.alignments:
            for hsp in hit.hsps:
                try:
                    self.simpleresults[record.query].append([hit.hit_id.strip(), hsp.identities, hsp.align_length, hsp.query.strip(), hsp.match, hsp.sbjct, hsp.query_start, hsp.sbjct_start, hsp.sbjct_end, hsp.query_end])

                except:
                    self.simpleresults[record.query]=[[hit.hit_id.strip(), hsp.identities, hsp.align_length, hsp.query.strip(), hsp.match, hsp.sbjct, hsp.query_start, hsp.sbjct_start, hsp.sbjct_end, hsp.query_end]]
            self.tophits[record.query]=self.simpleresults[record.query][0]
    x=0
    Label(self.result_frame, text="Query").grid(row=0, column = 1)
    Label(self.result_frame, text="Hit").grid(row=0, column=2)
    Label(self.result_frame, text="Percent ID").grid(row=0, column=3)
    Label(self.result_frame, text="Hit Coverage").grid(row=0, column=4)
    Label(self.result_frame, text="Ref Length").grid(row=0, column=5)
    for key in sorted(self.tophits.keys()):
        if int(100*self.tophits[key][1]/self.tophits[key][2])>=80:
            q=Text(self.result_frame, height=1, width=60)
            q.insert(1.0, key)
            q.grid(row=x+1, column=1)
            h=Text(self.result_frame, height=1, width=60)
            h.insert(1.0, self.tophits[key][0])
            h.grid(row=x+1, column=2)
            q.configure(relief=FLAT)
            h.configure(relief=FLAT)
            Label(self.result_frame, text=str(int(100*self.tophits[key][1]/self.tophits[key][2]))).grid(row=x+1, column=3)
            try:
                Label(self.result_frame, text=str(int(100*self.tophits[key][2]/len(self.refsequences[self.tophits[key][0]])))).grid(row=x+1, column=4)
            except:
                Label(self.result_frame, text=str(int(100*self.tophits[key][2]/len(self.tophits[key][5])))).grid(row=x+1, column=4)
            try:
                Label(self.result_frame, text=str(len(self.refsequences[self.tophits[key][0]]))).grid(row=x+1, column=5)
            except:
                Label(self.result_frame, text=str(len(self.tophits[key][5]))).grid(row=x+1, column=5)
            Button(self.result_frame, text="View alignment", command=lambda arg1=key : self.viewalignment(arg1)).grid(row=x+1, column=6)
            x+=1
    self.b3.destroy()

和错误:

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Users\lukec\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py", line 1702, in __call__
    return self.func(*args)
  File "C:/Code/2018-07-31_New/sequencetools.py", line 1183, in blast
    if self.dbtype == "nucl" and self.querytype=="nucl":
AttributeError: 'Analyze' object has no attribute 'dbtype'

关于如何让 BLAST 再次工作的任何解决方案?

编辑:我已经能够使用控制台命令发现 dbtype 适用于 blast 的衍生品,但是对于我的脚本使用它们的方式,将它们移植过来的最佳方法是什么?见:https ://www.biostars.org/p/298929/

标签: pythonpython-3.xblast

解决方案


推荐阅读