allpy
changeset 658:1c2f88eedb18
Improve javascript blocks viewer
* mark conservative columns darker
* create script to generate javascript config file with conservative groups
from python config file (from project sequence_based_blocks_search)
* add Makefile
* index.txt: remove unwanted spaces
author | boris <bnagaev@gmail.com> |
---|---|
date | Mon, 27 Jun 2011 13:42:42 +0400 |
parents | d32ebf19e75a |
children | 720c15589a90 7999f8756c77 |
files | .hgignore NEWS blocks3d/www/Makefile blocks3d/www/input/blocks.js blocks3d/www/input/crc32_color.js blocks3d/www/input/index.txt sequence_based_blocks_search/functional_groups_to_javascript.py |
diffstat | 7 files changed, 89 insertions(+), 14 deletions(-) [+] |
line diff
1.1 --- a/.hgignore Sat Jun 25 00:46:13 2011 +0400 1.2 +++ b/.hgignore Mon Jun 27 13:42:42 2011 +0400 1.3 @@ -19,6 +19,7 @@ 1.4 1.5 # Temporary files from building 1.6 allpy/data/components.cif 1.7 +blocks3d/www/input/conservative_groups.js 1.8 1.9 # Temporary files from sphinx 1.10 docs/build
2.1 --- a/NEWS Sat Jun 25 00:46:13 2011 +0400 2.2 +++ b/NEWS Mon Jun 27 13:42:42 2011 +0400 2.3 @@ -5,6 +5,7 @@ 2.4 * new: method allpy.base.Alignment.row_as_list(sequence) 2.5 * new: method allpy.base.Alignment.row_as_string(sequence) 2.6 * new: columns_as_lists() returns list of lists, each has 'column' attribute 2.7 + * new: javascript viewer marks conservative columns darker 2.8 2.9 1.3.0 (2011-04-15) 2.10
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/blocks3d/www/Makefile Mon Jun 27 13:42:42 2011 +0400 3.3 @@ -0,0 +1,5 @@ 3.4 + 3.5 +build: 3.6 + python ../../sequence_based_blocks_search/functional_groups_to_javascript.py > input/conservative_groups.js 3.7 + r2w 3.8 +
4.1 --- a/blocks3d/www/input/blocks.js Sat Jun 25 00:46:13 2011 +0400 4.2 +++ b/blocks3d/www/input/blocks.js Mon Jun 27 13:42:42 2011 +0400 4.3 @@ -41,12 +41,12 @@ 4.4 // alignment_strings[ID] = string with sequence for <pre> 4.5 var alignment_strings = {}; 4.6 4.7 +var conservative_groups_dict = []; // list of dictsets of uppercased letters 4.8 4.9 // useful_positions[ID][position] = block id 4.10 // (if this element is a part of at least one block) 4.11 var useful_positions = {}; 4.12 4.13 - 4.14 var blocks_inited = false; 4.15 4.16 // run application 4.17 @@ -62,6 +62,18 @@ 4.18 var i, j, k; 4.19 var t = ''; 4.20 4.21 + for (i = 0; i < conservative_groups.length; i++) 4.22 + { 4.23 + var group = conservative_groups[i]; 4.24 + var d = {}; 4.25 + for (j = 0; j < group.length; j++) 4.26 + { 4.27 + var letter = group[j].toUpperCase(); 4.28 + d[letter] = true; 4.29 + } 4.30 + conservative_groups_dict.push(d); 4.31 + } 4.32 + 4.33 var seq; 4.34 4.35 // calculate max_ID_length 4.36 @@ -81,12 +93,6 @@ 4.37 IDs_count = 0; 4.38 $.each(fasta_dict, function(k,v) { IDs_count+=1}); 4.39 4.40 - // calculate a color for each block 4.41 - for (i = 0; i < blocks.length; i++) 4.42 - { 4.43 - blocks[i].color = crc32_color(json(blocks[i])); 4.44 - } 4.45 - 4.46 // mark colorable positions 4.47 useful_positions = {}; 4.48 for (ID in fasta_dict) 4.49 @@ -106,6 +112,29 @@ 4.50 } 4.51 } 4.52 4.53 + var is_conservative = []; 4.54 + for (j = 0; j < seq_length; j++) 4.55 + { 4.56 + for (i = 0; i < conservative_groups_dict.length; i++) 4.57 + { 4.58 + var inside_group = true; 4.59 + var group = conservative_groups_dict[i]; 4.60 + for (ID in fasta_dict) 4.61 + { 4.62 + if (!group[fasta_dict[ID].charAt(j).toUpperCase()]) 4.63 + { 4.64 + inside_group = false; 4.65 + break; 4.66 + } 4.67 + } 4.68 + if (inside_group) 4.69 + { 4.70 + is_conservative[j] = true; 4.71 + break; 4.72 + } 4.73 + } 4.74 + } 4.75 + 4.76 // pre-calculate strings for <pre> 4.77 alignment_strings = {}; 4.78 var block_i; 4.79 @@ -119,8 +148,10 @@ 4.80 if (block_i || block_i === 0) 4.81 { 4.82 // current element is a part of block 4.83 + var dark = is_conservative[j] && seq.charAt(j) != '-'; 4.84 + var color = crc32_color(json(blocks[block_i]), dark); 4.85 t += '<font '; 4.86 - t += ' style="background:' + blocks[block_i].color + '; cursor:pointer;" ' ; 4.87 + t += ' style="background:' + color + '; cursor:pointer;" ' ; 4.88 t += ' onclick=letter_click("' + ID + '",' + j + ') ' ; 4.89 t += '>'; 4.90 } 4.91 @@ -146,11 +177,30 @@ 4.92 current_number = '' + current_number; // convert to string 4.93 for (j = 0; j < legend_interval - current_number.length; j++) 4.94 { 4.95 - t += ' '; 4.96 + t += ' '; 4.97 } 4.98 t += current_number; 4.99 } 4.100 - t = '<pre><nobr>' + t + '</nobr></pre>'; 4.101 + var conservative_t = ''; 4.102 + for (i = 0; i < t.length; i++) 4.103 + { 4.104 + var dark = is_conservative[i]; 4.105 + var bgcolor = dark ? 'black' : 'white'; 4.106 + var fgcolor = dark ? 'white' : 'black'; 4.107 + var l; 4.108 + if (t.charAt(i) == ' ') 4.109 + { 4.110 + l = ' ' 4.111 + } 4.112 + else 4.113 + { 4.114 + l = t.charAt(i); 4.115 + } 4.116 + conservative_t += '<font '; 4.117 + conservative_t += ' style="background:' + bgcolor + ';color:' + fgcolor + ';" ' ; 4.118 + conservative_t += '>' + l + '</font>'; 4.119 + } 4.120 + t = '<pre><nobr>' + conservative_t + '</nobr></pre>'; 4.121 $('#legend').html(t); 4.122 4.123 // run
5.1 --- a/blocks3d/www/input/crc32_color.js Sat Jun 25 00:46:13 2011 +0400 5.2 +++ b/blocks3d/www/input/crc32_color.js Mon Jun 27 13:42:42 2011 +0400 5.3 @@ -2,9 +2,12 @@ 5.4 /** 5.5 * returns color, corresponding to something (using crc32 value) 5.6 * 5.7 - * something -- string 5.8 + * @param string something string 5.9 + * @param bool dark Should color be dark 5.10 + * If dark is true, first bit of each byte from color is set to 0, 5.11 + * otherwise to 1 5.12 */ 5.13 -function crc32_color(something) 5.14 +function crc32_color(something, dark) 5.15 { 5.16 var crc = crc32(something); 5.17 var rgb = []; // [r, g, b] (3 last bytes of crc32 are used) 5.18 @@ -15,7 +18,14 @@ 5.19 // lighten 5.20 for (j = 0; j < 3; j++) 5.21 { 5.22 - rgb[j] |= 128; 5.23 + if (dark) 5.24 + { 5.25 + rgb[j] &= 0x7F; 5.26 + } 5.27 + else 5.28 + { 5.29 + rgb[j] |= 0x80; 5.30 + } 5.31 } 5.32 for (j = 0; j < 3; j++) 5.33 {
6.1 --- a/blocks3d/www/input/index.txt Sat Jun 25 00:46:13 2011 +0400 6.2 +++ b/blocks3d/www/input/index.txt Mon Jun 27 13:42:42 2011 +0400 6.3 @@ -16,7 +16,7 @@ 6.4 <div id="h1_header"><h1>Reliable blocks finding</h1></div> 6.5 </td> 6.6 </tr> 6.7 - 6.8 + 6.9 <tr align="left" valign="top"> 6.10 <td colspan="2"> 6.11 <div id="mainpanel">Enable Javascript!</div> 6.12 @@ -54,6 +54,7 @@ 6.13 {include_minified;crc32_color.js} 6.14 {include_minified;crc32.js} 6.15 {include_minified;dechex.js} 6.16 +{include_minified;conservative_groups.js} 6.17 {include_minified;blocks.js} 6.18 6.19 self_js_text
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 7.2 +++ b/sequence_based_blocks_search/functional_groups_to_javascript.py Mon Jun 27 13:42:42 2011 +0400 7.3 @@ -0,0 +1,7 @@ 7.4 +import pprint 7.5 + 7.6 +from functional_groups import aminoacids2functional_groups 7.7 + 7.8 +print 'conservative_groups =' 7.9 +pprint.pprint(list(aminoacids2functional_groups.values())) 7.10 +