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
3 class IntMarkupMixin(base.Markup):
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):
14 result[key] = int(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):
30 for number, monomer in enumerate(self.sequence, 1):
31 monomer.number = number
33 class SequenceIndexMarkup(base.SequenceMarkup):
38 for index, monomer in enumerate(self.sequence):
41 class AlignmentNumberMarkup(base.AlignmentMarkup):
46 for number, column in enumerate(self.alignment.columns, 1):
49 class AlignmentIndexMarkup(base.AlignmentMarkup):
54 for index, column in enumerate(self.alignment.columns):
57 class SequenceCaseMarkup(base.SequenceMarkup):
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'
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] == "'"
75 assert len(markup) == len(result.sequence)
76 for monomer, mark in zip(result.sequence, markup):
77 assert monomer.code1 == mark.upper()
79 monomer.case = 'upper'
81 monomer.case = 'lower'
86 for monomer in self.sequence:
87 case = self.get(monomer)
89 markup += monomer.code1.upper()
91 markup += monomer.code1.lower()
92 return {'markup': "'%s'" % markup, 'io-class': 'SequenceCaseMarkup'}
94 class SequencePdbResiMarkup(base.SequenceMarkup, IntMarkupMixin):
98 for monomer in self.sequence:
100 monomer.pdb_resi = monomer.pdb_residue.id[1]
104 def add_pdb(self, download_pdb=None, xyz_only=False):
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]
115 self.sequence.pdb_chain = pdb_chain
116 for monomer in self.sequence:
118 pdb_residue = pdb_chain[' ', monomer.pdb_resi, ' ']
119 monomer.ca_xyz = pdb_residue['CA'].get_vector()
121 monomer.pdb_residue = pdb_residue
123 # vim: set ts=4 sts=4 sw=4 et: