类型对象"RestrictionType"没有属性"size" [英] type object 'RestrictionType' has no attribute 'size'
问题描述
我今天遇到了这个问题,想提出来看看是否有人看过它.搜索Google/SO/Biostars并没有帮助我.
I ran into this problem today, and wanted to bring it up to see if anyone else has seen it. Searching Google/SO/Biostars didn't get me anywhere.
我正在运行一个简单的限制性分析(针对随机生成的基因组"),并得到此错误.如果我单独寻找带有酶的切割位点,则每种酶都适用.但是,当我将它们放入RestrictionBatch
时,在类上出现错误:
I'm running a simple restriction analysis (on a randomly generated "genome"), and getting this error. If I look for cut sites with the enzymes individually, it works for each. However, when I put them into a RestrictionBatch
, I get an error on the class:
type object 'RestrictionType' has no attribute 'size'
我放了一个描述此内容的IPython笔记本.
版本: -Biopython 1.6.2 -IPython 1.1.0 -Python 2.7.6/Anaconda 1.8
Versions: - Biopython 1.6.2 - IPython 1.1.0 - Python 2.7.6/Anaconda 1.8
我还使用Python 3.3和Biopython中的最新拉动对此进行了尝试. Git存储库-同样的错误.
I've also tried this with Python 3.3 and the latest pull from the Biopython Git repository - same error.
推荐答案
这与iPython有关.可以通过以下方式隔离:
This is something with iPython. Can be isolated with:
from Bio import Restriction as rst
rst.EcoRI
最后一行使用AttributeError: type object 'RestrictionType' has no attribute 'size'
使IPython控制台崩溃,而在Python控制台中运行得很好.奇怪的是:
The last line crashes an IPython console with AttributeError: type object 'RestrictionType' has no attribute 'size'
, while it runs just fine in the Python console. Oddly both:
rst.EcoRI.size
getattr(rst.EcoRI, "size")
在IPython控制台中提供了预期的"6".
gives the expected "6" in the IPython console.
这是我的解决方法,可以在IPython上即时生成酶:
Here is my workaround, generating the enzimes on the fly (on 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,
...
这篇关于类型对象"RestrictionType"没有属性"size"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!