allpy
changeset 671:b0d3c9413cf9
Merge between me and central.
author | Boris Burkov <BurkovBA@gmail.com> |
---|---|
date | Fri, 01 Jul 2011 11:42:26 +0400 |
parents | 1a4a04829ba6 78e1700f589d |
children | d6a10130b441 |
files | allpy/base.py |
diffstat | 9 files changed, 137 insertions(+), 18 deletions(-) [+] |
line diff
1.1 --- a/.hgignore Fri Jul 01 11:40:00 2011 +0400 1.2 +++ b/.hgignore Fri Jul 01 11:42:26 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 Fri Jul 01 11:40:00 2011 +0400 2.2 +++ b/NEWS Fri Jul 01 11:42:26 2011 +0400 2.3 @@ -4,6 +4,8 @@ 2.4 * new: method allpy.base.Alignment.rows_as_strings() 2.5 * new: method allpy.base.Alignment.row_as_list(sequence) 2.6 * new: method allpy.base.Alignment.row_as_string(sequence) 2.7 + * new: columns_as_lists() returns list of lists, each has 'column' attribute 2.8 + * new: javascript viewer colors columns by conservedness 2.9 2.10 1.3.0 (2011-04-15) 2.11
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/blocks3d/www/Makefile Fri Jul 01 11:42:26 2011 +0400 3.3 @@ -0,0 +1,6 @@ 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 + python test.py > output/test.html 3.9 +
4.1 --- a/blocks3d/www/README Fri Jul 01 11:40:00 2011 +0400 4.2 +++ b/blocks3d/www/README Fri Jul 01 11:42:26 2011 +0400 4.3 @@ -4,8 +4,10 @@ 4.4 * libjs-jquery 4.5 4.6 build template file: 4.7 - cd www 4.8 - mkdir output 4.9 - r2w 4.10 + make 4.11 output file is build to output/index.html 4.12 4.13 +build test.html 4.14 + python test.py > test.html 4.15 +and open test.html in browser 4.16 +
5.1 --- a/blocks3d/www/input/blocks.js Fri Jul 01 11:40:00 2011 +0400 5.2 +++ b/blocks3d/www/input/blocks.js Fri Jul 01 11:42:26 2011 +0400 5.3 @@ -6,6 +6,7 @@ 5.4 int end; (inclusive) 5.5 IDs: list of IDs 5.6 cores: [] 5.7 + is_conservative: list, mapping pos to bool 5.8 } 5.9 */ 5.10 5.11 @@ -41,13 +42,32 @@ 5.12 // alignment_strings[ID] = string with sequence for <pre> 5.13 var alignment_strings = {}; 5.14 5.15 +var conservative_groups_dict = []; // list of dictsets of uppercased letters 5.16 5.17 // useful_positions[ID][position] = block id 5.18 // (if this element is a part of at least one block) 5.19 var useful_positions = {}; 5.20 5.21 +var blocks_inited = false; 5.22 5.23 -var blocks_inited = false; 5.24 +function is_conservative_column(column, sequences) 5.25 +{ 5.26 + var result = false; 5.27 + $.each(conservative_groups_dict, function(i, group) { 5.28 + var inside_group = true; 5.29 + $.each(sequences, function(j, ID) { 5.30 + if (!group[fasta_dict[ID].charAt(column).toUpperCase()]) 5.31 + { 5.32 + inside_group = false; 5.33 + } 5.34 + }); 5.35 + if (inside_group) 5.36 + { 5.37 + result = true; 5.38 + } 5.39 + }); 5.40 + return result; 5.41 +} 5.42 5.43 // run application 5.44 function blocks_init() 5.45 @@ -62,6 +82,18 @@ 5.46 var i, j, k; 5.47 var t = ''; 5.48 5.49 + for (i = 0; i < conservative_groups.length; i++) 5.50 + { 5.51 + var group = conservative_groups[i]; 5.52 + var d = {}; 5.53 + for (j = 0; j < group.length; j++) 5.54 + { 5.55 + var letter = group[j].toUpperCase(); 5.56 + d[letter] = true; 5.57 + } 5.58 + conservative_groups_dict.push(d); 5.59 + } 5.60 + 5.61 var seq; 5.62 5.63 // calculate max_ID_length 5.64 @@ -81,12 +113,6 @@ 5.65 IDs_count = 0; 5.66 $.each(fasta_dict, function(k,v) { IDs_count+=1}); 5.67 5.68 - // calculate a color for each block 5.69 - for (i = 0; i < blocks.length; i++) 5.70 - { 5.71 - blocks[i].color = crc32_color(json(blocks[i])); 5.72 - } 5.73 - 5.74 // mark colorable positions 5.75 useful_positions = {}; 5.76 for (ID in fasta_dict) 5.77 @@ -106,6 +132,24 @@ 5.78 } 5.79 } 5.80 5.81 + var is_conservative = []; 5.82 + var all_sequences = []; 5.83 + $.each(fasta_dict, function(ID, seq) { all_sequences.push(ID); }); 5.84 + for (j = 0; j < seq_length; j++) 5.85 + { 5.86 + is_conservative[j] = is_conservative_column(j, all_sequences); 5.87 + } 5.88 + 5.89 + for (i = 0; i < blocks.length; i++) 5.90 + { 5.91 + block = blocks[i]; 5.92 + block.is_conservative = []; 5.93 + for (j = block.start; j <= block.end; j++) 5.94 + { 5.95 + block.is_conservative[j] = is_conservative_column(j, block.IDs); 5.96 + } 5.97 + } 5.98 + 5.99 // pre-calculate strings for <pre> 5.100 alignment_strings = {}; 5.101 var block_i; 5.102 @@ -116,12 +160,16 @@ 5.103 for (j = 0; j < seq_length; j++) 5.104 { 5.105 block_i = useful_positions[ID][j]; 5.106 + block = blocks[block_i]; 5.107 if (block_i || block_i === 0) 5.108 { 5.109 // current element is a part of block 5.110 + var dark = block.is_conservative[j] && seq.charAt(j) != '-'; 5.111 + var color = crc32_color(json(block), dark); 5.112 t += '<font '; 5.113 - t += ' style="background:' + blocks[block_i].color + '; cursor:pointer;" ' ; 5.114 + t += ' style="background:' + color + '; cursor:pointer;" ' ; 5.115 t += ' onclick=letter_click("' + ID + '",' + j + ') ' ; 5.116 + t += ' class=block' + block_i + ' '; 5.117 t += '>'; 5.118 } 5.119 t += seq.charAt(j); 5.120 @@ -146,11 +194,30 @@ 5.121 current_number = '' + current_number; // convert to string 5.122 for (j = 0; j < legend_interval - current_number.length; j++) 5.123 { 5.124 - t += ' '; 5.125 + t += ' '; 5.126 } 5.127 t += current_number; 5.128 } 5.129 - t = '<pre><nobr>' + t + '</nobr></pre>'; 5.130 + var conservative_t = ''; 5.131 + for (i = 0; i < t.length; i++) 5.132 + { 5.133 + var dark = is_conservative[i]; 5.134 + var bgcolor = dark ? 'black' : 'white'; 5.135 + var fgcolor = dark ? 'white' : 'black'; 5.136 + var l; 5.137 + if (t.charAt(i) == ' ') 5.138 + { 5.139 + l = ' ' 5.140 + } 5.141 + else 5.142 + { 5.143 + l = t.charAt(i); 5.144 + } 5.145 + conservative_t += '<font '; 5.146 + conservative_t += ' style="background:' + bgcolor + ';color:' + fgcolor + ';" ' ; 5.147 + conservative_t += '>' + l + '</font>'; 5.148 + } 5.149 + t = '<pre><nobr>' + conservative_t + '</nobr></pre>'; 5.150 $('#legend').html(t); 5.151 5.152 // run 5.153 @@ -159,6 +226,19 @@ 5.154 blocks_show(); 5.155 } 5.156 5.157 +function blocks_bind_mouseover() 5.158 +{ 5.159 + for (var i = 0; i < blocks.length; i++) 5.160 + { 5.161 + var s = '.block' + i; 5.162 + $(s).mouseover({s: s}, function(event) { 5.163 + $(event.data.s).css('color', 'green'); 5.164 + }); 5.165 + $(s).mouseleave({s: s}, function(event) { 5.166 + $(event.data.s).css('color', 'black'); 5.167 + }); 5.168 + } 5.169 +} 5.170 // set width and height of main table 5.171 function set_table_width_height() 5.172 { 5.173 @@ -287,5 +367,6 @@ 5.174 } 5.175 $('#mainpanel').html(t); 5.176 blocks_make_pre(); 5.177 + blocks_bind_mouseover(); 5.178 } 5.179
6.1 --- a/blocks3d/www/input/crc32_color.js Fri Jul 01 11:40:00 2011 +0400 6.2 +++ b/blocks3d/www/input/crc32_color.js Fri Jul 01 11:42:26 2011 +0400 6.3 @@ -2,9 +2,12 @@ 6.4 /** 6.5 * returns color, corresponding to something (using crc32 value) 6.6 * 6.7 - * something -- string 6.8 + * @param string something string 6.9 + * @param bool dark Should color be dark 6.10 + * If dark is true, first bit of each byte from color is set to 0, 6.11 + * otherwise to 1 6.12 */ 6.13 -function crc32_color(something) 6.14 +function crc32_color(something, dark) 6.15 { 6.16 var crc = crc32(something); 6.17 var rgb = []; // [r, g, b] (3 last bytes of crc32 are used) 6.18 @@ -15,12 +18,18 @@ 6.19 // lighten 6.20 for (j = 0; j < 3; j++) 6.21 { 6.22 - rgb[j] |= 128; 6.23 + rgb[j] |= 0x80; 6.24 + } 6.25 + for (j = 0; j < 3; j++) 6.26 + { 6.27 + if (dark) 6.28 + { 6.29 + rgb[j] *= 0.8; 6.30 + } 6.31 } 6.32 for (j = 0; j < 3; j++) 6.33 { 6.34 rgb[j] = dechex(rgb[j]); 6.35 - 6.36 if (rgb[j].length == 1) 6.37 { 6.38 rgb[j] = '0' + rgb[j];
7.1 --- a/blocks3d/www/input/index.txt Fri Jul 01 11:40:00 2011 +0400 7.2 +++ b/blocks3d/www/input/index.txt Fri Jul 01 11:42:26 2011 +0400 7.3 @@ -16,7 +16,7 @@ 7.4 <div id="h1_header"><h1>Reliable blocks finding</h1></div> 7.5 </td> 7.6 </tr> 7.7 - 7.8 + 7.9 <tr align="left" valign="top"> 7.10 <td colspan="2"> 7.11 <div id="mainpanel">Enable Javascript!</div> 7.12 @@ -54,6 +54,7 @@ 7.13 {include_minified;crc32_color.js} 7.14 {include_minified;crc32.js} 7.15 {include_minified;dechex.js} 7.16 +{include_minified;conservative_groups.js} 7.17 {include_minified;blocks.js} 7.18 7.19 self_js_text
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 8.2 +++ b/blocks3d/www/test.py Fri Jul 01 11:42:26 2011 +0400 8.3 @@ -0,0 +1,10 @@ 8.4 + 8.5 +print open('output/index.html').read().replace('self_js_text', """ 8.6 +blocks = [{"start": 2, "end": 17, "IDs": ["B", "A"]}, 8.7 + {"start": 19, "end": 28, "IDs": ["B", "C"]}, 8.8 + {"start": 35, "end": 47, "IDs": ["B", "A", "C"]}]; 8.9 +fasta_dict = {"A": "SNAKIDQLSSDVQTLNAK-DQLSNDVNAARSDAQAAKDDAARANQRLDNM", 8.10 + "B": "SNAKIDQLSSDAQTANAK-DQASNDANAARSDAQAAKDDAARANQRLDNM", 8.11 + "C": "SNAARANQRLDNMKIDQLSSDAQTANAKA-SDAQAAKDDAARANQRLDNM"}; 8.12 +""") 8.13 +
9.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 9.2 +++ b/sequence_based_blocks_search/functional_groups_to_javascript.py Fri Jul 01 11:42:26 2011 +0400 9.3 @@ -0,0 +1,7 @@ 9.4 +import pprint 9.5 + 9.6 +from functional_groups import aminoacids2functional_groups 9.7 + 9.8 +print 'conservative_groups =' 9.9 +pprint.pprint(list(aminoacids2functional_groups.values())) 9.10 +