Документ взят из кэша поисковой машины. Адрес оригинального документа : http://kodomo.fbb.msu.ru/hg/allpy/file/0c7f6117481b/lib/monomer.py
Дата изменения: Unknown
Дата индексирования: Sun Feb 3 23:23:18 2013
Кодировка:
allpy: 0c7f6117481b lib/monomer.py

allpy

view lib/monomer.py @ 153:0c7f6117481b

idea implemented: pdb and sec_str data moved from monomer to sequence
author boris <bnagaev@gmail.com>
date Tue, 26 Oct 2010 21:53:23 +0400
parents ff68a1bef5eb
children 9b601bbb1fde
line source
1 #!/usr/bin/python
3 from allpy_data.AAdict import AAdict
4 import Bio.PDB
6 index_code3 = {}
7 index_code1_protein = {}
8 index_name = {}
11 class MonomerType(object):
12 """ Monomer type
14 name -- string like "Valine"
15 code1 -- one-letter code (in upper case)
16 code3 -- three-letter code (in upper case)
17 is_modified -- True of False
18 """
19 def __init__(self, name, code1, code3, is_modified=False):
20 self.name = name.capitalize()
21 self.code1 = code1.upper()
22 self.code3 = code3.upper()
23 self.is_modified = bool(is_modified) # ugly
25 index_name[self.name] = self
26 index_code3[self.code3] = self
28 @staticmethod
29 def from_code3(code3):
30 return index_code3[code3.upper()]
31 @staticmethod
32 def from_name(name):
33 return index_name[name.capitalize()]
35 @staticmethod
36 def from_pdb_residue(pdb_residue):
37 return MonomerType.from_code3(pdb_residue.get_resname())
39 # TO DISCUSS
40 def __eq__(self, other):
41 return self.code1 == other.code1
43 def __ne__(self, other):
44 return not (self == other)
47 class Monomer(object):
48 """ Monomer
50 type -- link to MonomerType object
52 Idea: move pdb_residues and pdb_secstr to Sequence object
53 """
54 def __init__(self, monomer_type):
55 self.type = monomer_type
57 def __eq__(self, other):
58 return self.type == other.type
60 def __ne__(self, other):
61 return not (self == other)
63 class AminoAcidType(MonomerType):
64 def __init__(self, name, code1, code3, is_modified=False):
65 MonomerType.__init__(self, name, code1, code3, is_modified)
66 if not is_modified:
67 index_code1_protein[self.code1] = self
69 @staticmethod
70 def from_code1(code1):
71 return index_code1_protein[code1.upper()]
72 def instance(self):
73 """ Returns new AminoAcid object of this type """
74 return AminoAcid(self)
77 class AminoAcid(Monomer):
78 """ Amino acid """
79 pass
82 # prepare all aminoacids
84 for code3, data in AAdict.items():
85 code1, m_type, is_modified, none, name = data
86 if m_type == 'p':
87 AminoAcidType(name, code1, code3, is_modified)
89 del code3, data, code1, m_type, is_modified, none, name