view allpy/monomer.py @ 198:bae30e5037b1
Added rules for building Debian packages.
Also, modified .hgignore to hide all of the debian-generated junk.
The debianisation is still to be tested.
author |
Daniil Alexeyevsky <me.dendik@gmail.com> |
date |
Mon, 22 Nov 2010 13:43:23 +0300 |
parents |
be4773230e65 |
children |
346a6cd4fc1d |
line source
3 from allpy_data.AAdict import AAdict
7 index_code1_protein = {}
8 index_code1_nucleotide = {}
12 class MonomerType(object):
15 name -- string like "Valine"
16 code1 -- one-letter code (in upper case)
17 code3 -- three-letter code (in upper case)
18 is_modified -- True of False
20 def __init__(self, name, code1, code3, is_modified=False):
21 self.name = name.capitalize()
22 self.code1 = code1.upper()
23 self.code3 = code3.upper()
24 self.is_modified = bool(is_modified) # ugly
26 index_name[self.name] = self
27 index_code3[self.code3] = self
30 def from_code3(code3):
31 return index_code3[code3.upper()]
34 return index_name[name.capitalize()]
37 def from_pdb_residue(pdb_residue):
38 return MonomerType.from_code3(pdb_residue.get_resname())
41 def __eq__(self, other):
42 return self.code1 == other.code1
44 def __ne__(self, other):
45 return not (self == other)
48 class Monomer(object):
51 type -- link to MonomerType object
53 def __init__(self, monomer_type):
54 self.type = monomer_type
56 def __eq__(self, other):
57 return self.type == other.type
59 def __ne__(self, other):
60 return not (self == other)
62 class AminoAcidType(MonomerType):
63 def __init__(self, name, code1, code3, is_modified=False):
64 MonomerType.__init__(self, name, code1, code3, is_modified)
66 index_code1_protein[self.code1] = self
69 def from_code1(code1):
70 return index_code1_protein[code1.upper()]
72 """ Returns new AminoAcid object of this type """
73 return AminoAcid(self)
75 class DNAType(MonomerType):
76 def __init__(self, name, code1, code3, is_modified=False):
77 MonomerType.__init__(self, name, code1, code3, is_modified)
79 index_code1_nucleotide[self.code1] = self
82 def from_code1(code1):
83 return index_code1_nucleotide[code1.upper()]
85 """ Returns new AminoAcid object of this type """
88 class AminoAcid(Monomer):
93 """ Deoxyribonucleic acid """
96 # prepare all aminoacids
98 for code3, data in AAdict.items():
99 code1, m_type, is_modified, none, name = data
101 AminoAcidType(name, code1, code3, is_modified)
103 DNAType(name, code1, code3, is_modified)
104 del code3, data, code1, m_type, is_modified, none, name