allpy
changeset 587:6a50c2042d0e
structure.py: fix add_surrounded_columns()
nongap columns only should be considered
author | boris (kodomo) <bnagaev@gmail.com> |
---|---|
date | Sat, 26 Mar 2011 01:09:05 +0300 |
parents | 27e89e4a9346 |
children | 7a72febf12f6 |
files | allpy/structure.py |
diffstat | 1 files changed, 14 insertions(+), 4 deletions(-) [+] |
line diff
1.1 --- a/allpy/structure.py Sat Mar 26 00:42:07 2011 +0300 1.2 +++ b/allpy/structure.py Sat Mar 26 01:09:05 2011 +0300 1.3 @@ -293,6 +293,15 @@ 1.4 'fasta_dict': json.dumps(js_fasta_dict)} 1.5 file.write(template.replace('self_js_text', self_js_test)) 1.6 1.7 + def nongap_columns(self): 1.8 + """ return list of not pure gap columns """ 1.9 + self_sequences = set(self.sequences) 1.10 + columns = [] 1.11 + for column in self.columns: 1.12 + if set(column.keys()) & self_sequences: 1.13 + columns.append(column) 1.14 + return columns 1.15 + 1.16 class BlockMixin(base.Block, AlignmentMixin): 1.17 """Mixin to add 3D properties to blocks. 1.18 1.19 @@ -303,13 +312,14 @@ 1.20 1.21 def add_surrounded_columns(self, column_set): 1.22 """ add to column_set non-gap columns surrounded by column_set """ 1.23 - for i, column in enumerate(self.columns): 1.24 + nongap_columns = self.nongap_columns() 1.25 + for i, column in enumerate(nongap_columns) 1.26 if column not in column_set: 1.27 if not set(self.sequences) - set(column.keys()): # no gaps 1.28 if i > 0\ 1.29 - and self.columns[i-1] in column_set\ 1.30 - and i < len(self.columns)-1\ 1.31 - and self.columns[i+1] in column_set: 1.32 + and nongap_columns[i-1] in column_set\ 1.33 + and i < len(nongap_columns)-1\ 1.34 + and nongap_columns[i+1] in column_set: 1.35 column_set.add(column) 1.36 1.37 def geometrical_cores(self, max_delta=config.delta,