类型对象“RestrictionType”没有属性“size”

2024-04-24 05:22:39 发布

您现在位置:Python中文网/ 问答频道 /正文

我今天碰到这个问题,想把它提出来看看有没有人见过。搜索Google/SO/Biostars都找不到我。在

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

type object 'RestrictionType' has no attribute 'size'

我贴了一张IPython notebook describing this。在

版本: -生物圈1.6.2 -IPython 1.1.0版 -Python 2.7.6/Python1.8

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


Tags: no基因组soobjecttype错误ipythongoogle
1条回答
网友
1楼 · 发布于 2024-04-24 05:22:39

这是iPython的事。可通过以下方式隔离:

from Bio import Restriction as rst

rst.EcoRI

{{ipythan}在最后一行ipythan}上运行时,{ipythan}会崩溃。奇怪的是:

^{pr2}$

在IPython控制台中给出预期的“6”。在


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

相关问题 更多 >