allpy
changeset 735:632a0708ab33
blocks3d/www: allow blocks not to be continuous
Changes:
* javascript
* blocks_to_html method of AlignmentMixin
* test for blocks viewer (add one non-continuous block)
Currently block can have either "start" and "end" or "positions" attribute,
but not both. "start" and "end" attributes are not deprecated and can be
used if blocks are known to be continuous or while writting blocks
javascript by hands.
close #71
author | boris <bnagaev@gmail.com> |
---|---|
date | Fri, 08 Jul 2011 20:21:39 +0200 |
parents | eb2aa74497d5 |
children | c421263ef000 |
files | allpy/structure.py blocks3d/www/input/blocks.js blocks3d/www/test.py |
diffstat | 3 files changed, 31 insertions(+), 13 deletions(-) [+] |
line diff
1.1 --- a/allpy/structure.py Fri Jul 08 18:55:53 2011 +0200 1.2 +++ b/allpy/structure.py Fri Jul 08 20:21:39 2011 +0200 1.3 @@ -310,8 +310,13 @@ 1.4 p_from = column2pos[block.columns[0]] 1.5 p_to = column2pos[block.columns[-1]] 1.6 js_block = {} 1.7 - js_block['start'] = p_from 1.8 - js_block['end'] = p_to 1.9 + if len(block.columns) == p_to + 1 - p_from: 1.10 + # continuous block 1.11 + js_block['start'] = p_from 1.12 + js_block['end'] = p_to 1.13 + else: 1.14 + # not continuous block 1.15 + js_block['positions'] = [column2pos[c] for c in block.columns] 1.16 js_block['IDs'] = [] 1.17 for sequence in block.sequences: 1.18 js_block['IDs'].append(sequence.name)
2.1 --- a/blocks3d/www/input/blocks.js Fri Jul 08 18:55:53 2011 +0200 2.2 +++ b/blocks3d/www/input/blocks.js Fri Jul 08 20:21:39 2011 +0200 2.3 @@ -2,8 +2,9 @@ 2.4 /* 2.5 list of blocks 2.6 block = { 2.7 - int start; (inclusive) 2.8 - int end; (inclusive) 2.9 + int start; (inclusive) // do not use with positions 2.10 + int end; (inclusive) // do not use with positions 2.11 + int[] positions; // do not use with start and end 2.12 IDs: list of IDs 2.13 cores: [] 2.14 is_conservative: list, mapping pos to bool 2.15 @@ -96,6 +97,20 @@ 2.16 2.17 var seq; 2.18 2.19 + // generate positions for deprecated start-end blocks 2.20 + for (i = 0; i < blocks.length; i++) 2.21 + { 2.22 + block = blocks[i]; 2.23 + if (block.end) 2.24 + { 2.25 + block.positions = []; 2.26 + for (j = block.start; j <= block.end; j++) 2.27 + { 2.28 + block.positions.push(j); 2.29 + } 2.30 + } 2.31 + } 2.32 + 2.33 // calculate max_ID_length 2.34 max_ID_length = 0; 2.35 for (ID in fasta_dict) 2.36 @@ -125,10 +140,9 @@ 2.37 for (k = 0; k < block.IDs.length; k++) 2.38 { 2.39 ID = block.IDs[k]; 2.40 - for (j = block.start; j <= block.end; j++) 2.41 - { 2.42 - useful_positions[ID][j] = i; 2.43 - } 2.44 + $.each(block.positions, function(key, pos) { 2.45 + useful_positions[ID][pos] = i; 2.46 + }); 2.47 } 2.48 } 2.49 2.50 @@ -144,10 +158,9 @@ 2.51 { 2.52 block = blocks[i]; 2.53 block.is_conservative = []; 2.54 - for (j = block.start; j <= block.end; j++) 2.55 - { 2.56 - block.is_conservative[j] = is_conservative_column(j, block.IDs); 2.57 - } 2.58 + $.each(block.positions, function(key, pos) { 2.59 + block.is_conservative[j] = is_conservative_column(pos, block.IDs); 2.60 + }); 2.61 } 2.62 2.63 // pre-calculate strings for <pre>
3.1 --- a/blocks3d/www/test.py Fri Jul 08 18:55:53 2011 +0200 3.2 +++ b/blocks3d/www/test.py Fri Jul 08 20:21:39 2011 +0200 3.3 @@ -2,7 +2,7 @@ 3.4 print open('output/index.html').read().replace('self_js_text', """ 3.5 blocks = [{"start": 2, "end": 17, "IDs": ["B", "A"]}, 3.6 {"start": 19, "end": 28, "IDs": ["B", "C"]}, 3.7 - {"start": 35, "end": 47, "IDs": ["B", "A", "C"]}]; 3.8 + {"positions": [35, 36, 37, 45, 46, 47], "IDs": ["B", "A", "C"]}]; 3.9 fasta_dict = {"A": "SNAKIDQLSSDVQTLNAK-DQLSNDVNAARSDAQAAKDDAARANQRLDNM", 3.10 "B": "SNAKIDQLSSDAQTANAK-DQASNDANAARSDAQAAKDDAARANQRLDNM", 3.11 "C": "SNAARANQRLDNMKIDQLSSDAQTANAKA-SDAQAAKDDAARANQRLDNM"};