我今天遇到了这个问题,想提出来看看有没有人看到过。搜索 Google/SO/Biostars 并没有带我到任何地方。
我正在运行一个简单的限制性分析(在随机生成的“基因组”上),并收到此错误。如果我单独寻找 enzyme 的切割位点,它对每个都有效。但是,当我将它们放入 RestrictionBatch 时,我在类中遇到错误:
type object 'RestrictionType' has no attribute 'size'
我放了一个 IPython notebook describing this .
版本: - 生物蟒 1.6.2 - IPython 1.1.0 - Python 2.7.6/Anaconda 1.8
我也用 Python 3.3 和 latest pull 试过这个来自 Biopython Git 存储库 - 同样的错误。
请您参考如下方法:
这是 iPython 的东西。可以隔离:
from Bio import Restriction as rst
rst.EcoRI
最后一行使 IPython 控制台崩溃并出现 AttributeError: type object 'RestrictionType' has no attribute 'size',而它在 Python 控制台中运行得很好。奇怪的是:
rst.EcoRI.size
getattr(rst.EcoRI, "size")
在 IPython 控制台中给出预期的“6”。
这是我的解决方法,即时生成 enzyme (在 IPython 上):
from Bio.Restriction import Restriction as rst
from Bio.Restriction.Restriction_Dictionary import rest_dict, typedict
def create_enzyme(name):
e_types = [x for t, (x, y) in typedict.items() if name in y][0]
enzyme_types = tuple(getattr(rst, x) for x in e_types)
return rst.RestrictionType(name, enzyme_types, rest_dict[name])
rb = create_enzyme("EcoRI") + create_enzyme("MstI")
# Or if you have a long list of restriction enzymes:
# enzyme_list = ["EcoRI", "MstI"]
# rb = reduce(lambda x, y: x + y, map(create_enzyme, enzyme_list))
# Now it works
ana = rst.Analysis(rb, g, linear=True)
ana.with_sites()
Out[43]:
{__main__.EcoRI: [1440,
4108,
12547,
...
