[Bio] / FigWebServices / heat_map.cgi Repository:
ViewVC logotype

Annotation of /FigWebServices/heat_map.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (view) (download)

1 : overbeek 1.1 #__perl__
2 :    
3 :     =pod
4 :    
5 :     =head1 heat_map.cgi
6 :    
7 :     A simple "microarray" like program that I wanted. Just display a table with no borders, where the rows are the ss and the cols are the samples, and the cells are the intensity
8 :    
9 :     A gui representation of data. I want to represent the connections to subsystems between different genomes. This allows us to compare the relative amounts of each metabolism occuring in each genome.
10 :    
11 :     The connections to subsystems are stored as attributes, and are generated by the script:
12 :    
13 :     get_ss_connections
14 :    
15 :     =cut
16 :    
17 :     use strict;
18 :     use FIG;
19 :     use HTML;
20 :     use CGI;
21 :     use FIG_CGI;
22 :     use CGI::Carp qw(fatalsToBrowser);
23 :     my $html=["<TITLE>Heat Map NQ</title>"];
24 :     use raelib;
25 :     use raedraw;
26 :     my $raedraw=new raedraw;
27 :     my $raelib=new raelib;
28 :    
29 :     my ($fig, $cgi, $user);
30 :     eval {
31 :     ($fig, $cgi, $user) = FIG_CGI::init(debug_save => 0,
32 :     debug_load => 0,
33 :     print_params => 0);
34 :     };
35 :    
36 :     if ($@ ne ""){
37 :     my $err = $@;
38 :    
39 :     my(@html);
40 :    
41 :     push(@html, $cgi->p("Error connecting to SEED database."));
42 :     if ($err =~ /Could not connect to DBI:.*could not connect to server/)
43 :     {
44 :     push(@html, $cgi->p("Could not connect to relational database of type $FIG_Config::dbms named $FIG_Config::db on port $FIG_Config::dbport."));
45 :     }
46 :     else
47 :     {
48 :     push(@html, $cgi->pre($err));
49 :     }
50 :     &HTML::show_page($cgi, \@html, 1, undef, {"default"=>"Html/css/heatmap.css"});
51 :     exit;
52 :     }
53 :    
54 :    
55 :    
56 :     unless ($cgi->param("korgs"))
57 :     {
58 :     my %options;
59 :     map {$options{$_} = $fig->genus_species($_) . " ($_)"} &genomes_with_cnx();
60 :    
61 :     my %limit=(""=>1);
62 :     foreach my $ssc ($fig->all_subsystem_classifications()) {$limit{$ssc->[0]}=1}
63 :    
64 :     # logo
65 :     # $cgi->p({style=>"text-align: center;"}, $cgi->a({href=>$cgi->url}, $cgi->img({alt=>"Heat Map NR", src=>"/heatmapnq.png"}))),
66 :    
67 :     push @$html, (
68 :     $cgi->start_form(),
69 :     $cgi->h2("Heat Map NQ"),
70 :     $cgi->p(
71 :     "Heat map NQ is designed to show relationships between subsystems in different genomes. This is the prototype\n",
72 :     "My reccommendation is that you display different areas of metabolism, with non-quantitative differences grouped in either 5 or 10 groups.\n",
73 :     "You can also see the raw data by using the quantitative analysis. For this version, you can not select genomes (that will be coming), and so ",
74 :     "if you compare all of metabolism the non-quantitative analysis will be biased by one or two outliers\n",
75 :     "You can also overcome the outlier effect by trimming off the maximums, so that anything above that value is set as the maximum. Note that the ",
76 :     " maximum value is from the un-modified raw score.",
77 :     ),
78 :     $cgi->h2("Dataset"),
79 :     $cgi->p(
80 :     $cgi->br("Please choose some genomes: &nbsp; ",
81 :     $raelib->scrolling_org_list($cgi, 1, 0, [&genomes_with_cnx()]),
82 :     $cgi->br("Please choose a subset to show: &nbsp; ", $cgi->popup_menu(-name=>"limit", -values=>[sort {uc($a) cmp uc($b)}keys %limit], -default=>""), " &nbsp; (leave blank to see all of metabolism\n"),
83 :     )),
84 :     $cgi->h2("Non-quantitative Analysis"),
85 :     $cgi->p(
86 :     $cgi->p("Non quantitive analysis groups the data into a set of groups and colors the boxes accordingly. This is the default that you should probably use.\n"),
87 :     $cgi->br("Number of groups: &nbsp; ", $cgi->textfield(-name=>"ng", -default=>5, -size=>3)),
88 :     $cgi->br("Effective raw score maximum: &nbsp; ", $cgi->textfield(-name=>"fmax", -size=>5), " (a good value for this is about .01)\n"),
89 :     ),
90 :     $cgi->h2("Quantitative Analysis"),
91 :     $cgi->p(
92 :     $cgi->p("Quantitive analysis will show you the number of subsystems in each sample. This is the ratio of the number of times that subsystem is hit to the total number of subsystems that are found in the sample.\n The ratio is multiplied by a fiddle factor to normalize the data. Set the multiplier here, or use the default\n"),
93 :     $cgi->br($cgi->checkbox(-name=>"quant", -label=>"Use quantitative analysis")," &nbsp; Multiplier: &nbsp; ", $cgi->textfield(-name=>"fiddle", -default=>5000, -size=>5)),
94 :     ),
95 :     $cgi->h2("Display"),
96 :     $cgi->p(
97 :     "The default is to use a blue color as the extreme, but you can change that to red or green\n",
98 :     $cgi->br($cgi->popup_menu(-name=>"color", -label=>"Default color scheme", -values=>['blue', 'red', 'green'], -default=>'blue')),
99 :     ),
100 :     $cgi->submit, $cgi->reset, $cgi->end_form());
101 :    
102 :     &HTML::show_page($cgi, $html, 1, undef, {"default"=>"Html/css/heatmap.css"});
103 :     exit(0);
104 :     }
105 :    
106 :    
107 :    
108 :    
109 :     my @genomes=$cgi->param('korgs');
110 :     my $scores; my $max;
111 :     for (my $i=0; $i<=$#genomes; $i++)
112 :     {
113 :     next unless ($fig->is_genome($genomes[$i]));
114 :     foreach my $attr ($fig->get_attributes($genomes[$i], "ss_connections"))
115 :     {
116 :     $attr->[2] =~ /^(.*):(\d+\.\d+)$/;
117 :     my ($ss, $score)=($1, $2);
118 :     unless ($ss && defined $score) {die "Can't parse a ss and a score from ".(join("\n", @$attr))}
119 :     ($score > $max) ? ($max=$score) : 1;
120 :     unless (defined $scores->{$ss}) {$#{$scores->{$ss}}=$#genomes}
121 :     $scores->{$ss}->[$i]=$score;
122 :     }
123 :     }
124 :    
125 :     my @data;
126 :     foreach my $ss (keys %$scores)
127 :     {
128 :     my @class=@{$fig->subsystem_classification($ss)};
129 :     if (($cgi->param('limit') && ($cgi->param('limit') eq "unclassified" || $cgi->param('limit') eq $class[0])) || !$cgi->param('limit'))
130 :     {
131 :     push @data, [@class, $ss, @{$scores->{$ss}}];
132 :     }
133 :     }
134 :    
135 :     #fix the effective maximum if we have set it
136 :     ($cgi->param('fmax')) ? ($max=$cgi->param('fmax')) : 1;
137 :    
138 :     unless ($data[0] && $max)
139 :     {
140 :     push @$html,
141 :     (
142 :     $cgi->p({style=>'color: red; background-color: yellow; font-size: 1.2em; font-weight: bolder;'}, "Sorry, no subsystems matched your query. <br>Please use your back button to try again"),
143 :     );
144 :     &HTML::show_page($cgi, $html, 1, undef, {"default"=>"Html/css/heatmap.css"});
145 :     exit(0);
146 :     }
147 :    
148 :    
149 :     # now we have the max, we need to figure out what the groups are.
150 :     # we want $ng groups, and so mapping will have the range from 0 to 100
151 :     # @mapping has all the data, in order
152 :     my $ng=$cgi->param('ng');
153 :     my @mapping=(0);
154 :     my %mapped = (0=>0);
155 :     my $count=int(100/$ng);
156 :     for (my $i=$max/$ng; $i<= ($max-($max/$ng)); $i+=$max/$ng)
157 :     {
158 :     push @mapping, $i;
159 :     $mapped{$i}=$count;
160 :     $count+=int(100/$ng);
161 :     }
162 :     # define $max as 100
163 :     push @mapping, 100;
164 :     $mapped{100}=100;
165 :    
166 :     my $tab;
167 :     foreach my $a (@data)
168 :     {
169 :     # delete this part to remove the links to the ss
170 :     my $ssn=$a->[2];
171 :     $ssn =~ s/ /_/g;
172 :     $a->[2] = &HTML::sub_link($cgi, $a->[2]);
173 :    
174 :     my @row;
175 :     foreach my $cell (@$a)
176 :     {
177 :     if ($raelib->is_number($cell)) {
178 :     if ($cgi->param('quant'))
179 :     {
180 :     $cell *= $cgi->param('fiddle');
181 :     }
182 :     else
183 :     {
184 :     my $changed;
185 :     for (my $i=0; $i<=$#mapping; $i++)
186 :     {
187 :     last if ($changed);
188 :     if ($cell < $mapping[$i]) {$cell=$mapped{$mapping[$i]}; $changed=1}
189 :     }
190 :     unless ($changed) {$cell=100}
191 :     }
192 :     my @color=$raedraw->heat_map_color($cell, $cgi->param('color'));
193 :     my $bgcolor;
194 :     map {$_=int($_*255); $bgcolor.=sprintf("%x", $_)} @color;
195 :     $cell =~ s/(\.\d\d)\d+/$1/;
196 :     push @row, [" $cell ", "td bgcolor='#$bgcolor' align='center'"]
197 :     #push @row, [" $cell ($hue) ", "td"]
198 :     }
199 :     elsif (!defined $cell) {push @row, [" &nbsp; ", "td"]}
200 :     else {push @row, [$cell, "td"]}
201 :     }
202 :     push @$tab, \@row;
203 :     }
204 :    
205 :     @$tab=sort {$a->[0]->[0] cmp $b->[0]->[0]} @$tab;
206 :    
207 :     # merge the table
208 :     # skip the data columns
209 :     my $skip;
210 :     map {$skip->{$_}=1} (2..10);
211 :     unless ($cgi->param('create_excel')) {$tab=&HTML::merge_table_rows($tab, $skip)}
212 :    
213 :     # finally make the HTML
214 :    
215 :    
216 :     my $border=0;
217 :     if ($cgi->param('border')) {$border=1}
218 :     my @headers=("Class 1", "Class 2", "Subsystem");
219 :     push @headers, map {$fig->genus_species($_) . "<br />$_"} @genomes;
220 :    
221 :     my %options=("border"=>0);
222 :     if ($cgi->param('create_excel')) {$options{"excelfile"}="SubsystemConnections"}
223 :    
224 :     # this is the link to the logo, which I removed
225 :     # $cgi->p({style=>"text-align: center;"}, $cgi->a({href=>$cgi->url}, $cgi->img({alt=>"Heat Map NR", src=>"/heatmapnq.png"}))),
226 :    
227 :     $cgi->submit("create_excel", "Create excel file");
228 :     push @$html,
229 :     (
230 :     $cgi->start_form,
231 :     $cgi->hidden('korgs'),
232 :     $cgi->hidden('border'),
233 :     $cgi->hidden('fiddle'),
234 :     $cgi->hidden('quant'),
235 :     $cgi->hidden('ng'),
236 :     $cgi->hidden('fmax'),
237 :     $cgi->hidden('limit'),
238 :     $cgi->hidden('color'),
239 :     &HTML::make_table([], &control_color_table(), ""),
240 :     &HTML::make_table(\@headers, $tab, "", %options),
241 :     $cgi->submit("create_excel", "Create excel file of this table"),
242 :     );
243 :    
244 :     &HTML::show_page($cgi, $html, 1, undef, {"default"=>"Html/css/heatmap.css"});
245 :    
246 :     exit(0);
247 :    
248 :    
249 :     sub genomes_with_cnx {
250 :     my %gcx;
251 :     foreach my $attr ($fig->get_attributes(undef, "ss_connections"))
252 :     {
253 :     $gcx{$attr->[0]}=1;
254 :     }
255 :     return keys %gcx;
256 :     }
257 :    
258 :     sub control_color_table {
259 :     # controltab is the table at the top that shows what the colors are.
260 :     my $controltab;
261 :     {
262 :     my $row;
263 :     for (my $i=0; $i<=100; $i+=2)
264 :     {
265 :     my @color=$raedraw->heat_map_color($i, $cgi->param('color'));
266 :     my $bgcolor;
267 :     map {$_=int($_*255); $bgcolor.=sprintf("%x", $_)} @color;
268 :     push @$row, [" $i ", "td bgcolor='#$bgcolor' align='center'"];
269 :     #if ($i && !($i % 20)) {push @$controltab, $row; undef $row}
270 :     }
271 :     push @$controltab, $row;
272 :     }
273 :     return $controltab;
274 :     }
275 :    

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3