Python 键入对象';限制类型';没有属性';尺寸';

Python 键入对象';限制类型';没有属性';尺寸';,python,biopython,Python,Biopython,我今天遇到了这个问题,想把它提出来看看是否有人见过它。搜索Google/SO/Biostars没有让我找到任何地方 我正在运行一个简单的限制分析(对随机生成的“基因组”),并得到这个错误。若我单独寻找含有酶的切割位点,它对每一个都有效。但是,当我将它们放入RestrictionBatch时,我在类中得到一个错误: type object 'RestrictionType' has no attribute 'size' 我贴了一张照片 版本: -Biopython 1.6.2 -IPython

我今天遇到了这个问题,想把它提出来看看是否有人见过它。搜索Google/SO/Biostars没有让我找到任何地方

我正在运行一个简单的限制分析(对随机生成的“基因组”),并得到这个错误。若我单独寻找含有酶的切割位点,它对每一个都有效。但是,当我将它们放入
RestrictionBatch
时,我在类中得到一个错误:

type object 'RestrictionType' has no attribute 'size'
我贴了一张照片

版本: -Biopython 1.6.2 -IPython 1.1.0 -Python 2.7.6/Anaconda 1.8


我也在Python3.3和Biopython Git存储库中尝试过这一点-同样的错误。

这是iPython的特点。可通过以下方式进行隔离:

from Bio import Restriction as rst

rst.EcoRI
最后一行使用
AttributeError:type对象'RestrictionType'没有属性'size'
,使IPython控制台崩溃,而它在Python控制台中运行正常。奇怪的是,两者都是:

rst.EcoRI.size
getattr(rst.EcoRI, "size")
在IPython控制台中给出预期的“6”


以下是我的解决方法,动态生成酶(在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,
                  ...