Python 属性错误:';str';对象没有属性';transID';
这是我在python3中定义的一个类Python 属性错误:';str';对象没有属性';transID';,python,class,error-handling,bioinformatics,Python,Class,Error Handling,Bioinformatics,这是我在python3中定义的一个类 class BlastHit(): ''' instance attributes: entry: one line from blast output file transID: transcript ID SPID: SwissProt ID (without the version number) ID: identity MM: mismatch
class BlastHit():
'''
instance attributes:
entry: one line from blast output file
transID: transcript ID
SPID: SwissProt ID (without the version number)
ID: identity
MM: mismatch
methods:
constructor
__repr__
goodMatchCheck:
method that returns whether the hit is a really good match (e.g. >95 identity)
'''
def __init__(self, entry):
self.entry = entry
splited_line = entry.rstrip().split("\t")
# Find transcript ID (transID)
qseqid = splited_line[0]
self.transID = qseqid.split("|")[0]
# Find SwissProt ID (SPID)
sseqid = splited_line[1]
sp = sseqid.split("|")[3]
self.SPID = sp.split(".")[0]
# Find identity (ID)
self.ID = splited_line[2]
# Find mismatch (MM)
self.MM = splited_line[4]
def __repr__(self):
return f"BlastHit('{self.entry}')"
def goodMatchCheck(self):
return float(self.MM) >= 95.0
def list_results(self):
results = list()
results += self.transID
return results
我试着运行以下程序:
if __name__ == "__main__":
BlastHit.list_results("c0_g1_i1|m.1 gi|74665200|sp|Q9HGP0.1|PVG4_SCHPO 100.00 372 0 0 1 372 1 372 0.0 754")
但是,系统一直给我相同的错误消息:
AttributeError:“str”对象没有属性“transID”
谁有想法,请与我分享。谢谢
BlastHit.list_results("c0_g1_i1|m.1 gi|74665200|sp|Q9HGP0.1|PVG4_SCHPO 100.00 372 0 0 1 372 1 372 0.0 754")
您正在调用列表\u结果
,就好像它是一个静态方法一样。因此,您要传递的字符串被绑定到self
您需要创建一个实例并使用它:
bh = BlastHit("c0_g1_i1|m.1 gi|74665200|sp|Q9HGP0.1|PVG4_SCHPO 100.00 372 0 0 1 372 1 372 0.0 754")
bh.list_results()
您正在调用列表\u结果
,就好像它是一个静态方法一样。因此,您要传递的字符串被绑定到self
您需要创建一个实例并使用它:
bh = BlastHit("c0_g1_i1|m.1 gi|74665200|sp|Q9HGP0.1|PVG4_SCHPO 100.00 372 0 0 1 372 1 372 0.0 754")
bh.list_results()