allpy
changeset 781:6f615b0a2359
allpy.base: when filling by_code3 tables, unmodified classes take precedence
author | Daniil Alexeyevsky <dendik@kodomo.fbb.msu.ru> |
---|---|
date | Tue, 12 Jul 2011 23:52:54 +0400 |
parents | 231d59689d40 |
children | 1f78a0cd124e |
files | allpy/base.py test/test_base.py |
diffstat | 2 files changed, 9 insertions(+), 2 deletions(-) [+] |
line diff
1.1 --- a/allpy/base.py Tue Jul 12 23:38:54 2011 +0400 1.2 +++ b/allpy/base.py Tue Jul 12 23:52:54 2011 +0400 1.3 @@ -52,11 +52,13 @@ 1.4 vars(module)[TheMonomer.__name__] = TheMonomer 1.5 if not is_modified: 1.6 cls.by_code1[code1] = TheMonomer 1.7 - cls.by_code3[code3] = TheMonomer 1.8 + if code3 not in cls.by_code3 or not is_modified: 1.9 + cls.by_code3[code3] = TheMonomer 1.10 cls.by_name[name] = TheMonomer 1.11 # We duplicate distinguished long names into Monomer itself, so that we 1.12 # can use Monomer.from_code3 to create the relevant type of monomer. 1.13 - Monomer.by_code3[code3] = TheMonomer 1.14 + if code3 not in Monomer.by_code3 or not is_modified: 1.15 + Monomer.by_code3[code3] = TheMonomer 1.16 Monomer.by_name[name] = TheMonomer 1.17 1.18 @classmethod
2.1 --- a/test/test_base.py Tue Jul 12 23:38:54 2011 +0400 2.2 +++ b/test/test_base.py Tue Jul 12 23:52:54 2011 +0400 2.3 @@ -36,6 +36,11 @@ 2.4 assert m.code3 == "ALA" 2.5 assert m.name == "Alanine" 2.6 2.7 + # This actually tests for proper overriding when there are many monomers 2.8 + # with the same code3. The unmodified one takes precedence. 2.9 + m = b.Monomer.from_code3('SEC') 2.10 + assert m.name == "Selenocysteine" 2.11 + 2.12 def assert_alignment(alignment, *body): 2.13 """Helper: check if alignment representation matches strings of body""" 2.14 s = StringIO()