Документ взят из кэша поисковой машины. Адрес оригинального документа : http://kodomo.fbb.msu.ru/hg/allpy/rev/88c246f20918
Дата изменения: Unknown
Дата индексирования: Tue Oct 2 01:03:03 2012
Кодировка:
allpy: 88c246f20918

allpy

changeset 645:88c246f20918

Fixed monomer pickling to avoid name clashes. This breaks pickle backwards-compatiblity! [see #35] Previosly all monomer classes were stored a single namespace, allpy.data.monomers. This caused a few name clashes, which were mostly resolved, and one name clash, that was not. (This caused one class to be named differently depending on the order in which modules were loaded). Now, instead of one allpy.data.monomers module we have allpy.data.monomers package with modules dna, rna, protein. This ensures that all name clashes are resolved uniformly upon any sequence of modules loading. This may also help in future to keep backward-compatibility longer in case we replace dynaminc monomer class creation with storing the classes in the module - if we want to retain independent loading of dna/rna/protein parts.
author Daniil Alexeyevsky <dendik@kodomo.fbb.msu.ru>
date Wed, 08 Jun 2011 21:31:02 +0400
parents 0386dc31676e
children e3f06e45de03
files allpy/base.py allpy/data/monomers.py allpy/data/monomers/__init__.py allpy/data/monomers/dna.py allpy/data/monomers/protein.py allpy/data/monomers/rna.py
diffstat 6 files changed, 28 insertions(+), 12 deletions(-) [+]
line diff
     1.1 --- a/allpy/base.py	Fri Jun 03 16:59:45 2011 +0400
     1.2 +++ b/allpy/base.py	Wed Jun 08 21:31:02 2011 +0400
     1.3 @@ -37,8 +37,9 @@
     1.4          name = name.strip().capitalize()
     1.5          code1 = code1.upper()
     1.6          code3 = code3.upper()
     1.7 +        module = vars(data.monomers)[cls.type]
     1.8          TheMonomer.__name__ = re.sub(r"\W", "_", name)
     1.9 -        TheMonomer.__module__ = data.monomers.__name__
    1.10 +        TheMonomer.__module__ = module.__name__
    1.11          TheMonomer.name = name
    1.12          TheMonomer.code1 = code1
    1.13          TheMonomer.code3 = code3
    1.14 @@ -46,11 +47,9 @@
    1.15          # Save the class in data.monomers so that it can be pickled
    1.16          # Some names are not unique, we append underscores to them
    1.17          # in order to fix it.
    1.18 -        # XXX: this WILL fail with dna 0AV != rna A2M, which both have
    1.19 -        # name "2'-O-METHYLADENOSINE 5'-(DIHYDROGEN PHOSPHATE)"
    1.20 -        while TheMonomer.__name__ in vars(data.monomers):
    1.21 +        while TheMonomer.__name__ in vars(module):
    1.22              TheMonomer.__name__ += "_"
    1.23 -        vars(data.monomers)[TheMonomer.__name__] = TheMonomer
    1.24 +        vars(module)[TheMonomer.__name__] = TheMonomer
    1.25          if not is_modified:
    1.26              cls.by_code1[code1] = TheMonomer
    1.27          cls.by_code3[code3] = TheMonomer
     2.1 --- a/allpy/data/monomers.py	Fri Jun 03 16:59:45 2011 +0400
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,7 +0,0 @@
     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
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/allpy/data/monomers/__init__.py	Wed Jun 08 21:31:02 2011 +0400
     3.3 @@ -0,0 +1,9 @@
     3.4 +"""This package stores classes for all monomer objects.
     3.5 +
     3.6 +These classes are currently created on-the-fly and not stored here directly.
     3.7 +For implementation details please see base.Monomer._subclass and
     3.8 +base.Monomer.initialize.
     3.9 +"""
    3.10 +import protein
    3.11 +import dna
    3.12 +import rna
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/allpy/data/monomers/dna.py	Wed Jun 08 21:31:02 2011 +0400
     4.3 @@ -0,0 +1,5 @@
     4.4 +"""Classes for DNA monomers.
     4.5 +
     4.6 +Contents of this module are created on-the-fly, see `allpy.base.Monomer`.
     4.7 +"""
     4.8 +pass
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/allpy/data/monomers/protein.py	Wed Jun 08 21:31:02 2011 +0400
     5.3 @@ -0,0 +1,5 @@
     5.4 +"""Classes for protein monomers.
     5.5 +
     5.6 +Contents of this module are created on-the-fly, see `allpy.base.Monomer`.
     5.7 +"""
     5.8 +pass
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/allpy/data/monomers/rna.py	Wed Jun 08 21:31:02 2011 +0400
     6.3 @@ -0,0 +1,5 @@
     6.4 +"""Classes for RNA monomers.
     6.5 +
     6.6 +Contents of this module are created on-the-fly, see `allpy.base.Monomer`.
     6.7 +"""
     6.8 +pass