问题
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.
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'
I put up an IPython notebook describing this.
Versions: - Biopython 1.6.2 - IPython 1.1.0 - Python 2.7.6/Anaconda 1.8
I've also tried this with Python 3.3 and the latest pull from the Biopython Git repository - same error.
回答1:
This is something with iPython. Can be isolated with:
from Bio import Restriction as rst
rst.EcoRI
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")
gives the expected "6" in the IPython console.
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,
...
来源:https://stackoverflow.com/questions/20381912/type-object-restrictiontype-has-no-attribute-size