gpt4 book ai didi

python - 属性错误 : 'str' object has no attribute 'transID'

转载 作者:行者123 更新时间:2023-12-03 08:09:37 25 4
gpt4 key购买 nike

这是我在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

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' object has no attribute '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")

您调用 list_result好像它是一个静态方法。所以你传递的字符串被绑定(bind)到 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()

关于python - 属性错误 : 'str' object has no attribute 'transID' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61277551/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com