Документ взят из кэша поисковой машины. Адрес оригинального документа : http://kodomo.fbb.msu.ru/hg/allpy/file/835efa2a8c71/allpy/markups.py
Дата изменения: Unknown
Дата индексирования: Mon Feb 4 05:54:38 2013
Кодировка:
allpy: 835efa2a8c71 allpy/markups.py

allpy

view allpy/markups.py @ 817:835efa2a8c71

optimization of rasmol_homology: keep structure loaded of two sequences only One of steps of this program is superimposition of all sequences with main sequence and saving of all structures to pdb file. Loaded structure of all sequences is not needed to do this. At every moment only structure of main sequence and of superimposing sequence. This optimization results in essential memory saving. Output files should be the same to previous revision. To implement this optimization methods supeimpose and save_pdb of alignment were replaced with methods with same names of sequence. So some code is same as code of methods of alignment. Note: behaves as before, with superimpose and save_pdb methods of alignment. Model was returned by these methods but never used while generating spt script. This can result in collisions of rasmol selections when number of sequences is greater than max number of chains of one model.
author boris (kodomo) <bnagaev@gmail.com>
date Fri, 15 Jul 2011 02:23:27 +0400
parents 52ce523138d5
children 91e73fb1ac79
line source
1 import base
3 class IntMarkupMixin(base.Markup):
5 @classmethod
6 def from_record(cls, container, record, name=None):
7 assert record['io-class'] == 'IntMarkup'
8 result = cls(container, name=name)
9 separator = record.get('separator', ',')
10 values = record['markup'].split(separator)
11 assert len(values) == len(result.sorted_keys())
12 for key, value in zip(result.sorted_keys(), values):
13 if value:
14 result[key] = int(value)
15 return result
17 def to_record(self):
18 def fmt(value):
19 if value is None:
20 return ""
21 return str(value)
22 values = [fmt(self.get(key)) for key in self.sorted_keys()]
23 return {'markup': ','.join(values), 'io-class': 'IntMarkup'}
25 class SequenceNumberMarkup(base.SequenceMarkup):
27 name = 'number'
29 def refresh(self):
30 for number, monomer in enumerate(self.sequence, 1):
31 monomer.number = number
33 class SequenceIndexMarkup(base.SequenceMarkup):
35 name = 'index'
37 def refresh(self):
38 for index, monomer in enumerate(self.sequence):
39 monomer.index = index
41 class AlignmentNumberMarkup(base.AlignmentMarkup):
43 name = 'number'
45 def refresh(self):
46 for number, column in enumerate(self.alignment.columns, 1):
47 self[column] = number
49 class AlignmentIndexMarkup(base.AlignmentMarkup):
51 name = 'index'
53 def refresh(self):
54 for index, column in enumerate(self.alignment.columns):
55 self[column] = index
57 class SequenceCaseMarkup(base.SequenceMarkup):
59 name = 'case'
61 def refresh(self):
62 for monomer in self.sequence:
63 if monomer.input_code1.isupper():
64 monomer.case = 'upper'
65 elif monomer.input_code1.islower():
66 monomer.case = 'lower'
68 @classmethod
69 def from_record(cls, container, record, name=None):
70 assert record['io-class'] == 'SequenceCaseMarkup'
71 result = cls(container, name=name)
72 markup = record['markup']
73 assert markup[0] == markup[-1] == "'"
74 markup = markup[1:-1]
75 assert len(markup) == len(result.sequence)
76 for monomer, mark in zip(result.sequence, markup):
77 assert monomer.code1 == mark.upper()
78 if mark.isupper():
79 monomer.case = 'upper'
80 if mark.islower():
81 monomer.case = 'lower'
82 return result
84 def to_record(self):
85 markup = ''
86 for monomer in self.sequence:
87 case = self.get(monomer)
88 if case == 'upper':
89 markup += monomer.code1.upper()
90 elif case == 'lower':
91 markup += monomer.code1.lower()
92 return {'markup': "'%s'" % markup, 'io-class': 'SequenceCaseMarkup'}
94 class SequencePdbResiMarkup(base.SequenceMarkup, IntMarkupMixin):
95 name = 'pdb_resi'
97 def from_pdb(self):
98 for monomer in self.sequence:
99 try:
100 monomer.pdb_resi = monomer.pdb_residue.id[1]
101 except Exception:
102 pass
104 def add_pdb(self, download_pdb=None, xyz_only=False):
105 import structure
106 if download_pdb is None:
107 download_pdb = structure.cached_download_pdb
109 match = structure.pdb_id_parse(self.sequence.name)
110 code, model , chain = match['code'], match['model'], match['chain']
111 pdb_file = download_pdb(code)
112 pdb_structure = structure.get_structure(pdb_file, self.sequence.name)
113 pdb_chain = pdb_structure[0][chain]
114 if not xyz_only:
115 self.sequence.pdb_chain = pdb_chain
116 for monomer in self.sequence:
117 if monomer in self:
118 pdb_residue = pdb_chain[' ', monomer.pdb_resi, ' ']
119 monomer.ca_xyz = pdb_residue['CA'].get_vector()
120 if not xyz_only:
121 monomer.pdb_residue = pdb_residue
123 # vim: set ts=4 sts=4 sw=4 et: