allpy
changeset 642:a1307c0bb030
Added necessary hooks for monomer pickling [closes #35]
Current implementation is lazy and does not store all monomer classes
explicitly in some module. They are still generated on the fly.
Some monomer classes have the same name as per PDB database. In order to avoid
name clashes, we add underscores to classes, if same name class already exists.
WARNING.
This may and WILL cause trouble, if such clashes occur between different types
of monomers, in which case different names will be generated for the same class
depending on the order of loading modules.
The only example of such clash in the current database is dna monomer "0AV" and
rna "A2M", which both have name "2'-O-METHYLADENOSINE 5'-(DIHYDROGEN PHOSPHATE)"
author | Daniil Alexeyevsky <dendik@kodomo.fbb.msu.ru> |
---|---|
date | Fri, 03 Jun 2011 16:49:44 +0400 |
parents | e90119f01df8 |
children | 2386b2e0d78c |
files | allpy/base.py allpy/data/monomers.py |
diffstat | 2 files changed, 18 insertions(+), 1 deletions(-) [+] |
line diff
1.1 --- a/allpy/base.py Fri Jun 03 15:30:48 2011 +0400 1.2 +++ b/allpy/base.py Fri Jun 03 16:49:44 2011 +0400 1.3 @@ -3,6 +3,7 @@ 1.4 1.5 import util 1.6 import fileio 1.7 +import data.monomers 1.8 1.9 # import this very module as means of having all related classes in one place 1.10 import base 1.11 @@ -36,11 +37,20 @@ 1.12 name = name.strip().capitalize() 1.13 code1 = code1.upper() 1.14 code3 = code3.upper() 1.15 - TheMonomer.__name__ = re.sub(r"[^\w]", "_", name) 1.16 + TheMonomer.__name__ = re.sub(r"\W", "_", name) 1.17 + TheMonomer.__module__ = data.monomers.__name__ 1.18 TheMonomer.name = name 1.19 TheMonomer.code1 = code1 1.20 TheMonomer.code3 = code3 1.21 TheMonomer.is_modified = is_modified 1.22 + # Save the class in data.monomers so that it can be pickled 1.23 + # Some names are not unique, we append underscores to them 1.24 + # in order to fix it. 1.25 + # XXX: this WILL fail with dna 0AV != rna A2M, which both have 1.26 + # name "2'-O-METHYLADENOSINE 5'-(DIHYDROGEN PHOSPHATE)" 1.27 + while TheMonomer.__name__ in vars(data.monomers): 1.28 + TheMonomer.__name__ += "_" 1.29 + vars(data.monomers)[TheMonomer.__name__] = TheMonomer 1.30 if not is_modified: 1.31 cls.by_code1[code1] = TheMonomer 1.32 cls.by_code3[code3] = TheMonomer
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/allpy/data/monomers.py Fri Jun 03 16:49:44 2011 +0400 2.3 @@ -0,0 +1,7 @@ 2.4 +"""This module stores classes for all monomer objects. 2.5 + 2.6 +These classes are currently created on-the-fly and not stored here directly. 2.7 +For implementation details please see base.Monomer._subclass and 2.8 +base.Monomer.initialize. 2.9 +""" 2.10 +pass