Документ взят из кэша поисковой машины. Адрес оригинального документа : http://kodomo.fbb.msu.ru/hg/allpy/file/675b402094be/lib/monomer.py
Дата изменения: Unknown
Дата индексирования: Sat Mar 1 19:26:22 2014
Кодировка:
allpy: 675b402094be lib/monomer.py

allpy

view lib/monomer.py @ 151:675b402094be

day commit -- a lot of changes fasta.py: universal save_fasta() determine_long_line -- for determine length of fasta sequence string in user input everywhere: standart long_line=60 --> 70 blocK.sequences_chains: returns sequences in order as in project added monomer pdb_secstr to store secondary structure pdb adding: some improvements and fixes fix in from_pdb_chain: use all peptides, not only first Sequence.pdb_files added to store information about pdb file for each chain dssp bindings to get secondary structure /sec_str -- tool to map secondary structure on each sequence of alignment
author boris (netbook) <bnagaev@gmail.com>
date Tue, 26 Oct 2010 00:40:36 +0400
parents f7dead025719
children ff68a1bef5eb
line source
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
4 from allpy_data.AAdict import AAdict
5 import Bio.PDB
7 index_code3 = {}
8 index_code1_protein = {}
9 index_name = {}
12 class MonomerType(object):
13 """ Monomer type
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
19 """
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
29 @staticmethod
30 def from_code3(code3):
31 return index_code3[code3.upper()]
32 @staticmethod
33 def from_name(name):
34 return index_name[name.capitalize()]
36 @staticmethod
37 def from_pdb_residue(pdb_residue):
38 return MonomerType.from_code3(pdb_residue.get_resname())
40 # TO DISCUSS
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):
49 """ Monomer
51 type -- link to MonomerType object
52 pdb_residues -- dictionary like {Bio.PDB.Chain: Bio.PDB.Residue}
53 pdb_secstr -- dictionary like {Bio.PDB.Chain: 'Secondary structure'}
54 Code Secondary structure
55 H ??-helix
56 B Isolated ??-bridge residue
57 E Strand
58 G 3-10 helix
59 I ??-helix
60 T Turn
61 S Bend
62 - Other
63 """
64 def __init__(self, monomer_type):
65 self.type = monomer_type
66 self.pdb_residues = {}
67 self.pdb_secstr = {}
69 def pdb_residue_add(self, chain, residue):
70 self.pdb_residues[chain] = residue
72 def __eq__(self, other):
73 return self.type == other.type
75 def __ne__(self, other):
76 return not (self == other)
78 class AminoAcidType(MonomerType):
79 def __init__(self, name, code1, code3, is_modified=False):
80 MonomerType.__init__(self, name, code1, code3, is_modified)
81 if not is_modified:
82 index_code1_protein[self.code1] = self
84 @staticmethod
85 def from_code1(code1):
86 return index_code1_protein[code1.upper()]
87 def instance(self):
88 """ Returns new AminoAcid object of this type """
89 return AminoAcid(self)
92 class AminoAcid(Monomer):
93 """ Amino acid """
94 pass
97 # prepare all aminoacids
99 for code3, data in AAdict.items():
100 code1, m_type, is_modified, none, name = data
101 if m_type == 'p':
102 AminoAcidType(name, code1, code3, is_modified)
104 del code3, data, code1, m_type, is_modified, none, name