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

Annotation of /FigWebServices/genome_statistics.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.25 - (view) (download)

1 : redwards 1.10 # -*- perl -*-
2 : overbeek 1.1 #### start ####
3 : overbeek 1.5
4 : overbeek 1.1 use FIG;
5 :     my $fig = new FIG;
6 :    
7 :     use HTML;
8 :     use strict;
9 :     use CGI;
10 :     my $cgi = new CGI;
11 :    
12 : overbeek 1.2 if (0)
13 : overbeek 1.1 {
14 :     my $VAR1;
15 :     eval(join("",`cat /tmp/statistics_parms`));
16 :     $cgi = $VAR1;
17 :     # print STDERR &Dumper($cgi);
18 :     }
19 :    
20 :     if (0)
21 :     {
22 :     print $cgi->header;
23 :     my @params = $cgi->param;
24 :     print "<pre>\n";
25 :     foreach $_ (@params)
26 :     {
27 :     print "$_\t:",join(",",$cgi->param($_)),":\n";
28 :     }
29 :    
30 :     if (0)
31 :     {
32 :     if (open(TMP,">/tmp/statistics_parms"))
33 :     {
34 :     print TMP &Dumper($cgi);
35 :     close(TMP);
36 :     }
37 :     }
38 :     exit;
39 :     }
40 :    
41 :     my $html = [];
42 : olson 1.7 unshift @$html, "<TITLE>The SEED Statistics Page</TITLE>\n";
43 : overbeek 1.1
44 : overbeek 1.8 my @genomes = $cgi->param('genome');
45 :     my $request = $cgi->param('request');
46 : overbeek 1.9
47 : overbeek 1.24 if (!$request)
48 :     {
49 :     #
50 :     # Support for coming here from the NMPDR pages, where we have a form
51 :     # with a pair of submit buttons, one for subsystems summary, one for
52 :     # reactions summary.
53 :     #
54 :    
55 :     if ($cgi->param("show_reactions"))
56 :     {
57 :     warn "have show readtions\n";
58 :     $request = "show_reactions";
59 :     }
60 :     elsif ($cgi->param("show_subsystems"))
61 :     {
62 :     warn "have show subsystems\n";
63 :     $request = "show_subsystems";
64 :     }
65 :     }
66 :    
67 :     warn "REQ='$request'\n";
68 :    
69 : overbeek 1.9 if ($request eq "subsystems_summary")
70 :     {
71 :     &subsys_summary($fig,$cgi,$html);
72 :     }
73 : redwards 1.10 elsif ($request eq "edit_kv_stats") {
74 :     &edit_kv_stats($fig,$cgi,$html, $cgi->param('genome'));
75 :     }
76 : overbeek 1.9 elsif ((@genomes == 0) && (! $request))
77 : overbeek 1.8 {
78 :     &table_of_genomes($fig,$cgi,$html);
79 :     }
80 :     elsif (! $request)
81 :     {
82 :     my $genome;
83 :     foreach $genome (@genomes)
84 :     {
85 :     &basic_stats($fig,$cgi,$html,$genome);
86 :     push(@$html,$cgi->hr);
87 :     &assignment_stats($fig,$cgi,$html,$genome);
88 :     push(@$html,$cgi->hr);
89 : redwards 1.14 &kv_peg_stats($fig, $cgi, $html, $genome);
90 :     push(@$html,$cgi->hr);
91 : redwards 1.10 &kv_stats($fig, $cgi, $html, $genome);
92 : overbeek 1.19 my $user = $cgi->param('user');
93 : overbeek 1.21 push(@$html,"<a href=./genome_statistics.cgi?genome=$genome&request=show_subsystems&user=$user>Show Subsystems</a><br>\n");
94 :     push(@$html,"<a href=./genome_statistics.cgi?genome=$genome&request=show_reactions&user=$user>Show Reactions</a><br>\n");
95 : overbeek 1.23 if (&model_for_genome($genome))
96 :     {
97 :     push(@$html,"<a href=./status_of_model.cgi?user=$user&model=$genome>PEGs in published reaction model that are not yet covered</a><br>\n");
98 :     }
99 : overbeek 1.8 push(@$html,$cgi->br);
100 :     }
101 :     }
102 :     elsif (@genomes == 0)
103 : overbeek 1.1 {
104 : overbeek 1.8 push(@$html,"<h1>Sorry, you need to specify at least one valid genome</h1>\n");
105 : overbeek 1.1 }
106 : overbeek 1.3 else
107 :     {
108 : golsen 1.16 if ($request eq "hypo_sub") { &handle_hypo_sub($fig,$cgi,$html,$genomes[0]) }
109 : overbeek 1.8 elsif ($request eq "hypo_nosub") { &handle_hypo_nosub($fig,$cgi,$html,$genomes[0]) }
110 :     elsif ($request eq "nothypo_sub") { &handle_nothypo_sub($fig,$cgi,$html,$genomes[0]) }
111 :     elsif ($request eq "nothypo_nosub") { &handle_nothypo_nosub($fig,$cgi,$html,$genomes[0]) }
112 :     elsif ($request eq "show_subsystems") { &handle_show_subsystems($fig,$cgi,$html,$genomes[0]) }
113 : overbeek 1.21 elsif ($request eq "show_reactions") { &handle_show_reactions($fig,$cgi,$html,$genomes[0]) }
114 : overbeek 1.8 else
115 :     {
116 :     push(@$html,$cgi->h1("Invalid request: $request"));
117 :     }
118 : overbeek 1.3 }
119 : overbeek 1.1 &HTML::show_page($cgi,$html);
120 :     exit;
121 : overbeek 1.3
122 : golsen 1.16
123 :     # Only subroutines below
124 :    
125 :    
126 : overbeek 1.3 sub basic_stats {
127 :     my($fig,$cgi,$html,$genome) = @_;
128 :    
129 : overbeek 1.8 my($gname,$szdna,$num_contigs,$pegs,$rnas,$taxonomy) = &get_basic_stats($fig,$genome);
130 : golsen 1.16 push @$html, $cgi->h1('Basic Statistics'), "\n",
131 :     "<b>Genome ID:</b> $genome", $cgi->br, "\n",
132 :     "<b>Name:</b> $gname", $cgi->br, "\n",
133 :     "<b>Size (bp):</b> $szdna", $cgi->br, "\n",
134 :     "<b>Number contigs:</b> $num_contigs", $cgi->br, "\n",
135 :     "<b>Number CDSs:</b> $pegs", $cgi->br, "\n",
136 :     "<b>Number rnas:</b> $rnas", $cgi->br, "\n",
137 :     "<b>Taxonomy:</b> $taxonomy", $cgi->br, "\n";
138 :     push @$html, project_description( $genome );
139 : overbeek 1.3 return
140 :     }
141 : overbeek 1.4
142 : golsen 1.16
143 :     sub project_description {
144 :     ( my $genome = shift @_ ) or return ();
145 :     -d $FIG_Config::organisms && -d "$FIG_Config::organisms/$genome"
146 :     && -f "$FIG_Config::organisms/$genome/PROJECT"
147 :     || return ();
148 :     open( PROJECT, "<$FIG_Config::organisms/$genome/PROJECT" ) || return ();
149 :     my @project = <PROJECT>;
150 :     close PROJECT;
151 :     return ( "<b>Project description:</b>\n<pre>",
152 :     ( map { " " . $_ } @project ),
153 :     "</pre>\n"
154 :     );
155 :     }
156 :    
157 :    
158 : overbeek 1.4 sub commify {
159 :     my($n) = @_;
160 :     my(@n) = ();
161 :     my($i);
162 :    
163 :     for ($i = (length($n) - 3); ($i > 0); $i -= 3)
164 :     {
165 :     unshift(@n,",",substr($n,$i,3));
166 :     }
167 :     unshift(@n,substr($n,0,$i+3));
168 :     return join("",@n);
169 :     }
170 :    
171 :     sub assignment_stats {
172 :     my($fig,$cgi,$html,$genome) = @_;
173 :    
174 : overbeek 1.5 my $rdbH = $fig->db_handle;
175 :    
176 :     my $hypo_sub = 0;
177 :     my $hypo_nosub = 0;
178 :     my $nothypo_sub = 0;
179 :     my $nothypo_nosub = 0;
180 :    
181 : overbeek 1.6 my($subsystem_data,$assignments_data) = &get_data($fig,$cgi,$genome);
182 :     my %in = map { $_->[2] => 1 } @$subsystem_data;
183 :     my $in = keys(%in);
184 : overbeek 1.5
185 : overbeek 1.6 foreach $_ (@$assignments_data)
186 : overbeek 1.5 {
187 :     my($peg,$func) = @$_;
188 :     my $is_hypo = &FIG::hypo($func);
189 :    
190 :     if ($is_hypo && $in{$peg}) { $hypo_sub++ }
191 :     elsif ($is_hypo && ! $in{$peg}) { $hypo_nosub++ }
192 :     elsif ((! $is_hypo) && (! $in{$peg})) { $nothypo_nosub++ }
193 :     elsif ((! $is_hypo) && $in{$peg}) { $nothypo_sub++ }
194 :     }
195 :     my $tot = $hypo_sub + $nothypo_sub + $hypo_nosub + $nothypo_nosub;
196 :     my $fracHS = sprintf "%4.2f", $hypo_sub / $tot;
197 :     my $fracNHS = sprintf "%4.2f", $nothypo_sub / $tot;
198 :     my $fracHNS = sprintf "%4.2f", $hypo_nosub / $tot;
199 :     my $fracNHNS = sprintf "%4.2f", $nothypo_nosub / $tot;
200 : overbeek 1.6
201 :     my $user = $cgi->param('user');
202 : overbeek 1.5
203 : golsen 1.16 push @$html, "<table>\n",
204 :     " <tr>\n",
205 :     " <th align=left>PEGs with hypothetical functions and in subsystem:</th>\n",
206 :     " <td align=right><a href=./genome_statistics.cgi?user=$user&genome=$genome&request=hypo_sub>$hypo_sub ($fracHS)</a></td>\n",
207 :     " </tr>\n",
208 :     " <tr>\n",
209 :     " <th align=left>PEGs with nonhypothetical functions and in subsystem:</th>\n",
210 :     " <td align=right><a href=./genome_statistics.cgi?user=$user&genome=$genome&request=nothypo_sub>$nothypo_sub ($fracNHS)</a></td>\n",
211 :     " </tr>\n",
212 :     " <tr>\n",
213 :     " <th align=left>PEGs with hypothetical functions and not in subsystem:</th>\n",
214 :     " <td align=right><a href=./genome_statistics.cgi?user=$user&genome=$genome&request=hypo_nosub>$hypo_nosub ($fracHNS)</a></td>\n",
215 :     " </tr>\n",
216 :     " <tr>\n",
217 :     " <th align=left>PEGs with nonhypothetical functions and not in subsystem:</th>\n",
218 :     " <td align=right><a href=./genome_statistics.cgi?user=$user&genome=$genome&request=nothypo_nosub>$nothypo_nosub ($fracNHNS)</a></td>\n",
219 :     " </tr>\n",
220 :     "</table>\n";
221 : overbeek 1.4 }
222 :    
223 : overbeek 1.5 sub handle_show_subsystems {
224 : overbeek 1.4 my($fig,$cgi,$html,$genome) = @_;
225 : overbeek 1.19 my(%in,$sub,$role,$protein,$sub_link,$tuple,$categories);
226 : overbeek 1.4
227 : overbeek 1.6 my($subsystem_data,$assignments_data) = &get_data($fig,$cgi,$genome);
228 : overbeek 1.25 my $active = $fig->active_subsystems($genome);
229 : overbeek 1.6 foreach $_ (@$subsystem_data)
230 :     {
231 :     ($sub,$role,$protein) = @$_;
232 : overbeek 1.25 if ($active->{$sub})
233 :     {
234 :     push(@{$in{$sub}->{$role}},&HTML::fid_link($cgi,$protein,0) . ": " . scalar $fig->function_of($protein));
235 :     }
236 : overbeek 1.6 }
237 : overbeek 1.19
238 :     my @subs = sort { ($a->[0] cmp $b->[0]) or
239 :     ($a->[1] cmp $b->[1]) or
240 :     ($a->[2] cmp $b->[2]) or
241 :     ($a->[3] cmp $b->[3]) or
242 :     ($a->[4] cmp $b->[4])
243 :     }
244 :     map { $sub = $_;
245 :     $categories = $fig->subsystem_classification($sub);
246 :     $categories = ((@$categories > 0) && $categories->[0]) ? $categories : ["Misc"];
247 :     [@$categories,$sub]
248 :     }
249 :     keys(%in);
250 :    
251 : overbeek 1.20 my $last1 = "";
252 :     my $last2 = "";
253 : overbeek 1.19 foreach $tuple (@subs)
254 :     {
255 :     $sub = pop @{$tuple};
256 :     my $topic = $tuple->[0];
257 : overbeek 1.20
258 :     if ($topic ne $last1)
259 :     {
260 :     push(@$html,$cgi->h1($topic));
261 :     $last1 = $topic;
262 :     $last2 = "";
263 :     }
264 :    
265 :     $topic = $tuple->[1] ? $tuple->[1] : "";
266 :     if ($topic && ($topic ne $last2))
267 : overbeek 1.19 {
268 :     push(@$html,$cgi->h2($topic));
269 : overbeek 1.20 $last2 = $topic;
270 : overbeek 1.19 }
271 : overbeek 1.20
272 : overbeek 1.6 $sub_link = &sub_link($cgi,$sub);
273 : overbeek 1.19 push(@$html,$cgi->h3($sub_link));
274 :    
275 : overbeek 1.6 my $roles = [];
276 :     foreach $role (sort keys(%{$in{$sub}}))
277 :     {
278 :     push(@$roles,$cgi->ul($cgi->li($in{$sub}->{$role})));
279 :     }
280 :     push(@$html,$cgi->ul($cgi->li($roles)));
281 :     }
282 : overbeek 1.4 }
283 : overbeek 1.5
284 : overbeek 1.21 sub handle_show_reactions {
285 :     my($fig,$cgi,$html,$genome) = @_;
286 :     my($react_for_role,$r,%topic,%reaction,$sub,$role,$protein,$sub_link,$tuple,$categories);
287 :     my(%reactions_for_sub,%class,$reactions,$classL,$category);
288 :    
289 :     my($subsystem_data,$assignments_data) = &get_data($fig,$cgi,$genome);
290 : overbeek 1.24
291 : overbeek 1.21 foreach $_ (@$subsystem_data)
292 :     {
293 :     ($sub,$role,$protein) = @$_;
294 :     if (! defined($reactions_for_sub{$sub}))
295 :     {
296 :     my $subsystem = new Subsystem($sub,$fig,0);
297 :     $reactions = $subsystem->get_reactions;
298 :     $reactions = $reactions ? $reactions : "";
299 :     $reactions_for_sub{$sub} = $reactions;
300 :     $class{$sub} = $fig->subsystem_classification($sub);
301 :     }
302 :    
303 :     if (($reactions = $reactions_for_sub{$sub}) && ($react_for_role = $reactions->{$role}))
304 :     {
305 :     $classL = $class{$sub};
306 :     $category = ((@$classL > 0) && $classL->[0]) ? $classL->[0] : "Misc";
307 :     foreach $r (@$react_for_role)
308 :     {
309 :     $reaction{$r}->{$protein} = 1;
310 : overbeek 1.22 $topic{$category}->{$r} = 1;
311 : overbeek 1.21 }
312 :     }
313 :     }
314 :    
315 :     my @all = sort { $a cmp $b } keys(%topic);
316 : overbeek 1.24
317 :     if (@all == 0)
318 :     {
319 :     push(@$html, $cgi->p("No class reactions found."));
320 :     }
321 : overbeek 1.21 foreach $category (@all)
322 :     {
323 : overbeek 1.22 &show_class_react($fig,$cgi,$html,$category,[keys(%{$topic{$category}})],\%reaction);
324 : overbeek 1.21 }
325 :    
326 :     if ($_ = $topic{"Misc"})
327 :     {
328 : overbeek 1.22 &show_class_react($fig,$cgi,$html,'Misc',[keys(%$_)],\%reaction);
329 : overbeek 1.21 }
330 : overbeek 1.24 else
331 :     {
332 :     push(@$html, $cgi->p("No misc reactions found."));
333 :     }
334 :    
335 : overbeek 1.21 }
336 :    
337 :     sub show_class_react {
338 :     my($fig,$cgi,$html,$class,$for_topic,$reaction) = @_;
339 :     my($r,@pegs,$peg);
340 :    
341 :     push(@$html,$cgi->h1($class));
342 : overbeek 1.22 foreach $r (sort @$for_topic)
343 : overbeek 1.21 {
344 :     my $disp_react = $fig->displayable_reaction($r);
345 :     $disp_react =~ s/^R\d+\: //;
346 :    
347 :     my $rstring = &HTML::reaction_link($r) . ": $disp_react";
348 :     push(@$html,$cgi->h2($rstring),"\n");
349 :     @pegs = sort { &FIG::by_fig_id($a,$b) } keys(%{$reaction->{$r}});
350 :     push(@$html,"<ul>\n");
351 :     foreach $peg (@pegs)
352 :     {
353 :     push(@$html,"<li>" . &HTML::fid_link($cgi,$peg) . " " . scalar $fig->function_of($peg) . "\n");
354 :     }
355 :     push(@$html,"</ul>\n");
356 :     }
357 :     }
358 :    
359 : overbeek 1.5 sub handle_hypo_sub {
360 :     my($fig,$cgi,$html,$genome) = @_;
361 :    
362 : overbeek 1.6 my($subsystem_data,$assignments_data) = &get_data($fig,$cgi,$genome);
363 :     my %subs = map { $_->[2] => $_->[0] } @$subsystem_data;
364 :     my $col_hdrs = ["PEG","Function","Subsystem"];
365 :     my $tab = [];
366 :     foreach $_ (@$assignments_data)
367 :     {
368 :     my($peg,$func) = @$_;
369 :     if (&FIG::hypo($func) && ($subs{$peg}))
370 :     {
371 :     push(@$tab,[&HTML::fid_link($cgi,$peg,0),$func,&sub_link($cgi,$subs{$peg})]);
372 :     }
373 :     }
374 :     $_ = @$tab;
375 :     push(@$html,&HTML::make_table($col_hdrs,$tab,"$_ Hypothetical Pegs in Subsystems"));
376 : overbeek 1.5 }
377 :    
378 :     sub handle_hypo_nosub {
379 :     my($fig,$cgi,$html,$genome) = @_;
380 :    
381 : overbeek 1.6 my($subsystem_data,$assignments_data) = &get_data($fig,$cgi,$genome);
382 :     my %subs = map { $_->[2] => $_->[0] } @$subsystem_data;
383 :     my $col_hdrs = ["PEG","Function"];
384 :     my $tab = [];
385 :     foreach $_ (@$assignments_data)
386 :     {
387 :     my($peg,$func) = @$_;
388 :     if (&FIG::hypo($func) && (! $subs{$peg}))
389 :     {
390 :     push(@$tab,[&HTML::fid_link($cgi,$peg,0),$func]);
391 :     }
392 :     }
393 :     $_ = @$tab;
394 :     push(@$html,&HTML::make_table($col_hdrs,$tab,"$_ Hypothetical Pegs NOT in Subsystems"));
395 : overbeek 1.5 }
396 :    
397 :     sub handle_nothypo_sub {
398 :     my($fig,$cgi,$html,$genome) = @_;
399 :    
400 : overbeek 1.6 my($subsystem_data,$assignments_data) = &get_data($fig,$cgi,$genome);
401 :     my %subs = map { $_->[2] => $_->[0] } @$subsystem_data;
402 :     my $col_hdrs = ["PEG","Function","Subsystem"];
403 :     my $tab = [];
404 :     foreach $_ (@$assignments_data)
405 :     {
406 :     my($peg,$func) = @$_;
407 :     if ((! &FIG::hypo($func)) && ($subs{$peg}))
408 :     {
409 :     push(@$tab,[&HTML::fid_link($cgi,$peg,0),$func,&sub_link($cgi,$subs{$peg})]);
410 :     }
411 :     }
412 :     $_ = @$tab;
413 :     push(@$html,&HTML::make_table($col_hdrs,$tab,"$_ Nonhypothetical Pegs in Subsystems"));
414 : overbeek 1.5 }
415 :    
416 :     sub handle_nothypo_nosub {
417 :     my($fig,$cgi,$html,$genome) = @_;
418 :    
419 : overbeek 1.6 my($subsystem_data,$assignments_data) = &get_data($fig,$cgi,$genome);
420 :     my %subs = map { $_->[2] => $_->[0] } @$subsystem_data;
421 :     my $col_hdrs = ["PEG","Function"];
422 :     my $tab = [];
423 :     foreach $_ (@$assignments_data)
424 :     {
425 :     my($peg,$func) = @$_;
426 :     if ((! &FIG::hypo($func)) && (! $subs{$peg}))
427 :     {
428 :     push(@$tab,[&HTML::fid_link($cgi,$peg,0),$func]);
429 :     }
430 :     }
431 :     $_ = @$tab;
432 :     push(@$html,&HTML::make_table($col_hdrs,$tab,"$_ Nonhypothetical Pegs NOT in Subsystems"));
433 : overbeek 1.5 }
434 :    
435 : overbeek 1.6 sub get_data {
436 :     my($fig,$cgi,$genome) = @_;
437 :    
438 :     my $rdbH = $fig->db_handle;
439 :     my $subsystem_data = $rdbH->SQL("SELECT DISTINCT subsystem,role,protein FROM subsystem_index WHERE ( protein like 'fig\|$genome.peg.%')");
440 :     my $assignment_data = $rdbH->SQL("SELECT prot,assigned_function FROM assigned_functions WHERE ( prot like 'fig\|$genome.peg.%' AND made_by = 'master' )");
441 :    
442 :     return ($subsystem_data,$assignment_data);
443 :     }
444 :    
445 :     sub sub_link {
446 :     my($cgi,$sub) = @_;
447 :    
448 :     my $user = $cgi->param('user');
449 : overbeek 1.19 $user = defined($user) ? $user : "";
450 :     my $sub_link = "<a href=./subsys.cgi?ssa_name=$sub&request=show_ssa&user=$user>$sub</a>";
451 :    
452 : overbeek 1.6 return $sub_link;
453 :     }
454 : overbeek 1.8
455 :     sub get_basic_stats {
456 :     my($fig,$genome) = @_;
457 :    
458 :     my $rdbH = $fig->db_handle;
459 :     my $relational_db_response = $rdbH->SQL("SELECT gname,szdna,pegs,rnas,taxonomy FROM genome WHERE genome = '$genome'");
460 :     my($gname,$szdna,$pegs,$rnas,$taxonomy) = @{$relational_db_response->[0]};
461 :     my $szdna = &commify($szdna);
462 :     my $num_contigs = scalar $fig->all_contigs($genome);
463 :     return ($gname,$szdna,$num_contigs,$pegs,$rnas,$taxonomy);
464 :     }
465 :    
466 :     sub table_of_genomes {
467 :     my($fig,$cgi,$html) = @_;
468 :     my(@genomes);
469 :    
470 :     push(@$html,"<pre>\n");
471 :     if ($cgi->param('complete'))
472 :     {
473 :     @genomes = $fig->genomes("complete");
474 :     }
475 :     else
476 :     {
477 :     @genomes = $fig->genomes;
478 :     }
479 :    
480 :     my $genome;
481 :     push(@$html,join("\t","Genome ID","Complete","Genome Name","Size (bp)","Number Contigs","CDSs","RNAs","Taxonomy") . "\n");
482 :     my $genome;
483 :     foreach $genome (@genomes)
484 :     {
485 :     push(@$html,join("\t",($genome,$fig->is_complete($genome),&get_basic_stats($fig,$genome))) . "\n");
486 :     }
487 :     push(@$html,"</pre>\n");
488 :     }
489 :    
490 :    
491 : overbeek 1.9 sub subsys_summary {
492 :     my($fig,$cgi,$html) = @_;
493 :     my($Nsubs,$genome,$sub,$role,$peg,$genome_instances,%genomes_in_use,$peg_instances,%pegs_in_use);
494 :     foreach $sub ($fig->all_subsystems)
495 :     {
496 :     $Nsubs++;
497 :     foreach $genome (map { $_->[0] } @{$fig->subsystem_genomes($sub)})
498 :     {
499 :     $genome_instances++;
500 :     $genomes_in_use{$genome}++;
501 :     foreach $role ($fig->subsystem_to_roles($sub))
502 :     {
503 :     foreach $peg ($fig->pegs_in_subsystem_cell($sub,$genome,$role))
504 :     {
505 :     $peg_instances++;
506 :     $pegs_in_use{$peg}++;
507 :     }
508 :     }
509 :     }
510 :     }
511 :     my $Ngenomes = scalar keys(%genomes_in_use);
512 :     my $Npegs = scalar keys(%pegs_in_use);
513 :     my $g_in_sub = int($genome_instances / $Nsubs);
514 :     my $p_in_sub = int($peg_instances / $Nsubs);
515 :     push(@$html,$cgi->h1('Subsystem Summary'));
516 :     push(@$html,$cgi->br,
517 :     "<b>Number Subsystems:</b> $Nsubs",$cgi->br,
518 :     "<b>Genomes in Subsystems:</b> $Ngenomes",$cgi->br,
519 :     "<b>PEGs in Subsystems:</b> $Npegs",$cgi->br,
520 :     "<b>Avg genomes per subsystem:</b> $g_in_sub",$cgi->br,
521 :     "<b>Avg PEGs per subsystem:</b> $p_in_sub",$cgi->br
522 :     );
523 :     return
524 :    
525 :     }
526 : redwards 1.10
527 : redwards 1.14 sub kv_peg_stats {
528 :     my ($fig, $cgi, $html, $genome)=@_;
529 :    
530 :     #RAE Added the coverage of each genome with different attributes for the PEGs to find the number of genes that are in pirsf, etc
531 :     push(@$html, "\n<div class=\"pegattributes\">\n<p><h2>PEG Attributes for ", $fig->genus_species($genome), "</h2></p>\n");
532 :    
533 :     my $pegtags=$fig->get_tags('peg');
534 :     foreach my $type (sort {$a cmp $b} keys %$pegtags)
535 :     {
536 : redwards 1.15 my @result = grep {$_ =~ /$genome/} @{$pegtags->{$type}};
537 :     push(@$html, "\nPEGS with tag: $type : ", scalar(@result), $cgi->br, "\n");
538 : redwards 1.14 }
539 :     }
540 :    
541 : redwards 1.10 sub kv_stats {
542 :     my ($fig, $cgi, $html, $genome, $edit)=@_;
543 :    
544 :     # RAE Added tables for key value pairs for an organism, and allow you to edit them
545 :     # figure out kv's for the organism, and make a table with them
546 :    
547 :     # if the optional edit boolean is set and a user is supplied, we will make a table where you can edit the KV pairs
548 :     # else we will just make a blank table
549 :    
550 : redwards 1.12 # prepare the html so we can add form fields here
551 :     push(@$html, "\n<div class=\"attributes\">\n<p><h2>Attributes for ", $fig->genus_species($genome), "</h2></p>\n");
552 :     if ($edit) {push(@$html, $cgi->start_form(-action=>"genome_statistics.cgi"))}
553 :    
554 :    
555 : redwards 1.10 my $tab=[];
556 :     my $user=$cgi->param('user');
557 :     my $col_hdrs=["Attribute", "Value"];
558 : redwards 1.11 if ($user && $edit) {$col_hdrs=["Attribute", "Value", "URL"]}
559 : redwards 1.10
560 :     my $known;
561 : redwards 1.13 foreach my $key (sort {$a->[1] cmp $b->[1]} $fig->get_attributes($genome)) {
562 :     $known->{$key->[1]}=1;
563 : redwards 1.10 if ($user && $edit) {
564 :     push @$tab,
565 :     [
566 : redwards 1.13 $key->[1],
567 :     $cgi->textfield(-name=>"value.".$key->[1], -default=>$key->[2], -size=>50),
568 :     $cgi->textfield(-name=>"url.".$key->[1], -default=>$key->[3], -size=>50),
569 : redwards 1.10 ];
570 :     } else {
571 : redwards 1.13 if ($key->[3] && $key->[3] =~ /^http/) {$key->[2] = "<a href=\"" . $key->[3] . "\">". $key->[2] . "</a>"}
572 : redwards 1.10 push @$tab,
573 :     [
574 : redwards 1.13 $key->[1],
575 :     $key->[2],
576 : redwards 1.10 ];
577 :     }
578 :     }
579 :    
580 :    
581 :     if ($edit) {
582 :     # now we want to add some pull down menus for things that we can add. And some blank boxes too for free text entry.
583 :     # start with three of each
584 :     my $opt=$fig->get_tags("genome"); # all the tags we know about
585 :     my @options=sort {uc($a) cmp uc($b)} grep {!$known->{$_}} keys %$opt;
586 :     unshift(@options, undef); # a blank field at the start
587 :     for (my $i=1; $i<= (scalar @options + 5); $i++) {
588 :    
589 :     # we have the options, and 5 blank fields for free text entry
590 :     my $choice=$cgi->popup_menu(-name=>"key.$i", -values=>\@options);
591 :     if ($i >= scalar @options) {$choice = $cgi->textfield(-name=>"key.$i", -size=>50)}
592 :     push @$tab,
593 :     [
594 :     $choice,
595 :     $cgi->textfield(-name=>"value.$i", -size=>50),
596 :     $cgi->textfield(-name=>"url.$i", -size=>50),
597 :     ];
598 :     }
599 : redwards 1.12 # we need to know how many possibilities we have to look through later. Just pass it as a hidden, rather than counting it next time
600 :     push(@$html, $cgi->hidden(-name=>"max new keys", -value=>scalar @options + 5));
601 : redwards 1.10 }
602 :    
603 :     # now just write the html
604 :     push(@$html,&HTML::make_table($col_hdrs,$tab,"Attributes"));
605 :     if ($edit) {
606 :     push(@$html, $cgi->hidden("genome"), $cgi->hidden("user"), $cgi->hidden("request"));
607 :     push(@$html, $cgi->submit('Change'), $cgi->reset());
608 :     }
609 :     else {
610 :     push(@$html,"<p><a href=./genome_statistics.cgi?genome=$genome&request=edit_kv_stats&change=0&user=$user>Edit Key Value Pairs</a></p>\n</div>\n");
611 :     }
612 :     }
613 :    
614 :    
615 :     sub edit_kv_stats {
616 :     my ($fig, $cgi, $html, $genome)=@_;
617 :     if ($cgi->param("Change")) {
618 :     # we have changed the values
619 :     # get the old kv pairs so we can see what has changed
620 :     my $changed; my $deleted;
621 :     foreach my $key ($fig->get_attributes($genome)) {
622 : redwards 1.13 if (!$cgi->param('value.'.$key->[1]) && !$cgi->param('url.'.$key->[1])) {
623 :     $fig->delete_attribute($genome, $key->[1]);
624 : redwards 1.10 push @$key, ["deleted", "td colspan=2 style=\"text-align: center\""];
625 :     push @$deleted, $key;
626 :     }
627 : redwards 1.13 elsif (($cgi->param('value.'.$key->[1]) ne $key->[2]) || ($cgi->param('url.'.$key->[1]) ne $key->[3])) {
628 :     $fig->change_attribute($genome, $key->[1], $cgi->param('value.'.$key->[1]), $cgi->param('url.'.$key->[1]));
629 :     push @$key, $cgi->param('value.'.$key->[1]), $cgi->param('url.'.$key->[1]);
630 : redwards 1.10 push @$changed, $key;
631 :     }
632 :     }
633 :    
634 :     my $added;
635 : redwards 1.12 for (my $i=0; $i <= $cgi->param("max new keys"); $i++) {
636 : redwards 1.10 if ($cgi->param("key.$i")) {
637 :     $fig->add_attribute($genome, $cgi->param("key.$i"), $cgi->param("value.$i"), $cgi->param("url.$i"));
638 :     push @$added, [$cgi->param("key.$i"), ["added", "td colspan=2 style=\"text-align: center\""], $cgi->param("value.$i"), $cgi->param("url.$i")];
639 :     }
640 :     }
641 :    
642 :     # now all we have to do is create a table to report what we have done.
643 :     my $tab=[];
644 :     push (@$html, "<div class=\"altered\"><p><h2>Attributes Altered for ", $fig->genus_species($genome), " ($genome)</h2></p>");
645 :     my $col_hdrs=["Attribute", "Original Value", "Original URL", "New Value", "New URL"];
646 :     if ($changed) {push @$tab, [["<strong>Changed Attributes", "td colspan=5 bgcolor=gray style=\"text-align: center\""]], @$changed}
647 :     if ($deleted) {push @$tab, [["<strong>Deleted Attributes", "td colspan=5 bgcolor=gray style=\"text-align: center\""]], @$deleted}
648 :     if ($added) {push @$tab, [["<strong>Added Attributes", "td colspan=5 bgcolor=gray style=\"text-align: center\""]], @$added}
649 :    
650 :     push(@$html,&HTML::make_table($col_hdrs,$tab,"Changed Data"));
651 :     }
652 :     else {
653 :     return kv_stats($fig, $cgi, $html, $genome, 1);
654 :     }
655 :     }
656 :    
657 : overbeek 1.23 sub model_for_genome {
658 :     my($genome) = @_;
659 :    
660 :     return -s "$FIG_Config::global/Models/$genome";
661 :     }

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3