AttributeError: 'str' object has no attribute 'transID'
AttributeError: 'str' object has no attribute 'transID'
这是我在python3中定义的class。
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
就好像它是静态方法一样。所以你传递的字符串被绑定到 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()
这是我在python3中定义的class。
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
就好像它是静态方法一样。所以你传递的字符串被绑定到 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()