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

Annotation of /FigWebServices/genome_statistics.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.20 - (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 :     if ($request eq "subsystems_summary")
48 :     {
49 :     &subsys_summary($fig,$cgi,$html);
50 :     }
51 : redwards 1.10 elsif ($request eq "edit_kv_stats") {
52 :     &edit_kv_stats($fig,$cgi,$html, $cgi->param('genome'));
53 :     }
54 : overbeek 1.9 elsif ((@genomes == 0) && (! $request))
55 : overbeek 1.8 {
56 :     &table_of_genomes($fig,$cgi,$html);
57 :     }
58 :     elsif (! $request)
59 :     {
60 :     my $genome;
61 :     foreach $genome (@genomes)
62 :     {
63 :     &basic_stats($fig,$cgi,$html,$genome);
64 :     push(@$html,$cgi->hr);
65 :     &assignment_stats($fig,$cgi,$html,$genome);
66 :     push(@$html,$cgi->hr);
67 : redwards 1.14 &kv_peg_stats($fig, $cgi, $html, $genome);
68 :     push(@$html,$cgi->hr);
69 : redwards 1.10 &kv_stats($fig, $cgi, $html, $genome);
70 : overbeek 1.19 my $user = $cgi->param('user');
71 :     push(@$html,"<a href=./genome_statistics.cgi?genome=$genome&request=show_subsystems&user=$user>Show Subsystems</a>");
72 : overbeek 1.8 push(@$html,$cgi->br);
73 :     }
74 :     }
75 :     elsif (@genomes == 0)
76 : overbeek 1.1 {
77 : overbeek 1.8 push(@$html,"<h1>Sorry, you need to specify at least one valid genome</h1>\n");
78 : overbeek 1.1 }
79 : overbeek 1.3 else
80 :     {
81 : golsen 1.16 if ($request eq "hypo_sub") { &handle_hypo_sub($fig,$cgi,$html,$genomes[0]) }
82 : overbeek 1.8 elsif ($request eq "hypo_nosub") { &handle_hypo_nosub($fig,$cgi,$html,$genomes[0]) }
83 :     elsif ($request eq "nothypo_sub") { &handle_nothypo_sub($fig,$cgi,$html,$genomes[0]) }
84 :     elsif ($request eq "nothypo_nosub") { &handle_nothypo_nosub($fig,$cgi,$html,$genomes[0]) }
85 :     elsif ($request eq "show_subsystems") { &handle_show_subsystems($fig,$cgi,$html,$genomes[0]) }
86 :     else
87 :     {
88 :     push(@$html,$cgi->h1("Invalid request: $request"));
89 :     }
90 : overbeek 1.3 }
91 : overbeek 1.1 &HTML::show_page($cgi,$html);
92 :     exit;
93 : overbeek 1.3
94 : golsen 1.16
95 :     # Only subroutines below
96 :    
97 :    
98 : overbeek 1.3 sub basic_stats {
99 :     my($fig,$cgi,$html,$genome) = @_;
100 :    
101 : overbeek 1.8 my($gname,$szdna,$num_contigs,$pegs,$rnas,$taxonomy) = &get_basic_stats($fig,$genome);
102 : golsen 1.16 push @$html, $cgi->h1('Basic Statistics'), "\n",
103 :     "<b>Genome ID:</b> $genome", $cgi->br, "\n",
104 :     "<b>Name:</b> $gname", $cgi->br, "\n",
105 :     "<b>Size (bp):</b> $szdna", $cgi->br, "\n",
106 :     "<b>Number contigs:</b> $num_contigs", $cgi->br, "\n",
107 :     "<b>Number CDSs:</b> $pegs", $cgi->br, "\n",
108 :     "<b>Number rnas:</b> $rnas", $cgi->br, "\n",
109 :     "<b>Taxonomy:</b> $taxonomy", $cgi->br, "\n";
110 :     push @$html, project_description( $genome );
111 : overbeek 1.3 return
112 :     }
113 : overbeek 1.4
114 : golsen 1.16
115 :     sub project_description {
116 :     ( my $genome = shift @_ ) or return ();
117 :     -d $FIG_Config::organisms && -d "$FIG_Config::organisms/$genome"
118 :     && -f "$FIG_Config::organisms/$genome/PROJECT"
119 :     || return ();
120 :     open( PROJECT, "<$FIG_Config::organisms/$genome/PROJECT" ) || return ();
121 :     my @project = <PROJECT>;
122 :     close PROJECT;
123 :     return ( "<b>Project description:</b>\n<pre>",
124 :     ( map { " " . $_ } @project ),
125 :     "</pre>\n"
126 :     );
127 :     }
128 :    
129 :    
130 : overbeek 1.4 sub commify {
131 :     my($n) = @_;
132 :     my(@n) = ();
133 :     my($i);
134 :    
135 :     for ($i = (length($n) - 3); ($i > 0); $i -= 3)
136 :     {
137 :     unshift(@n,",",substr($n,$i,3));
138 :     }
139 :     unshift(@n,substr($n,0,$i+3));
140 :     return join("",@n);
141 :     }
142 :    
143 :     sub assignment_stats {
144 :     my($fig,$cgi,$html,$genome) = @_;
145 :    
146 : overbeek 1.5 my $rdbH = $fig->db_handle;
147 :    
148 :     my $hypo_sub = 0;
149 :     my $hypo_nosub = 0;
150 :     my $nothypo_sub = 0;
151 :     my $nothypo_nosub = 0;
152 :    
153 : overbeek 1.6 my($subsystem_data,$assignments_data) = &get_data($fig,$cgi,$genome);
154 :     my %in = map { $_->[2] => 1 } @$subsystem_data;
155 :     my $in = keys(%in);
156 : overbeek 1.5
157 : overbeek 1.6 foreach $_ (@$assignments_data)
158 : overbeek 1.5 {
159 :     my($peg,$func) = @$_;
160 :     my $is_hypo = &FIG::hypo($func);
161 :    
162 :     if ($is_hypo && $in{$peg}) { $hypo_sub++ }
163 :     elsif ($is_hypo && ! $in{$peg}) { $hypo_nosub++ }
164 :     elsif ((! $is_hypo) && (! $in{$peg})) { $nothypo_nosub++ }
165 :     elsif ((! $is_hypo) && $in{$peg}) { $nothypo_sub++ }
166 :     }
167 :     my $tot = $hypo_sub + $nothypo_sub + $hypo_nosub + $nothypo_nosub;
168 :     my $fracHS = sprintf "%4.2f", $hypo_sub / $tot;
169 :     my $fracNHS = sprintf "%4.2f", $nothypo_sub / $tot;
170 :     my $fracHNS = sprintf "%4.2f", $hypo_nosub / $tot;
171 :     my $fracNHNS = sprintf "%4.2f", $nothypo_nosub / $tot;
172 : overbeek 1.6
173 :     my $user = $cgi->param('user');
174 : overbeek 1.5
175 : golsen 1.16 push @$html, "<table>\n",
176 :     " <tr>\n",
177 :     " <th align=left>PEGs with hypothetical functions and in subsystem:</th>\n",
178 :     " <td align=right><a href=./genome_statistics.cgi?user=$user&genome=$genome&request=hypo_sub>$hypo_sub ($fracHS)</a></td>\n",
179 :     " </tr>\n",
180 :     " <tr>\n",
181 :     " <th align=left>PEGs with nonhypothetical functions and in subsystem:</th>\n",
182 :     " <td align=right><a href=./genome_statistics.cgi?user=$user&genome=$genome&request=nothypo_sub>$nothypo_sub ($fracNHS)</a></td>\n",
183 :     " </tr>\n",
184 :     " <tr>\n",
185 :     " <th align=left>PEGs with hypothetical functions and not in subsystem:</th>\n",
186 :     " <td align=right><a href=./genome_statistics.cgi?user=$user&genome=$genome&request=hypo_nosub>$hypo_nosub ($fracHNS)</a></td>\n",
187 :     " </tr>\n",
188 :     " <tr>\n",
189 :     " <th align=left>PEGs with nonhypothetical functions and not in subsystem:</th>\n",
190 :     " <td align=right><a href=./genome_statistics.cgi?user=$user&genome=$genome&request=nothypo_nosub>$nothypo_nosub ($fracNHNS)</a></td>\n",
191 :     " </tr>\n",
192 :     "</table>\n";
193 : overbeek 1.4 }
194 :    
195 : overbeek 1.5 sub handle_show_subsystems {
196 : overbeek 1.4 my($fig,$cgi,$html,$genome) = @_;
197 : overbeek 1.19 my(%in,$sub,$role,$protein,$sub_link,$tuple,$categories);
198 : overbeek 1.4
199 : overbeek 1.6 my($subsystem_data,$assignments_data) = &get_data($fig,$cgi,$genome);
200 :     foreach $_ (@$subsystem_data)
201 :     {
202 :     ($sub,$role,$protein) = @$_;
203 :     push(@{$in{$sub}->{$role}},&HTML::fid_link($cgi,$protein,0) . ": " . scalar $fig->function_of($protein));
204 :     }
205 : overbeek 1.19
206 :     my @subs = sort { ($a->[0] cmp $b->[0]) or
207 :     ($a->[1] cmp $b->[1]) or
208 :     ($a->[2] cmp $b->[2]) or
209 :     ($a->[3] cmp $b->[3]) or
210 :     ($a->[4] cmp $b->[4])
211 :     }
212 :     map { $sub = $_;
213 :     $categories = $fig->subsystem_classification($sub);
214 :     $categories = ((@$categories > 0) && $categories->[0]) ? $categories : ["Misc"];
215 :     [@$categories,$sub]
216 :     }
217 :     keys(%in);
218 :    
219 : overbeek 1.20 my $last1 = "";
220 :     my $last2 = "";
221 : overbeek 1.19 foreach $tuple (@subs)
222 :     {
223 :     $sub = pop @{$tuple};
224 :     my $topic = $tuple->[0];
225 : overbeek 1.20
226 :     if ($topic ne $last1)
227 :     {
228 :     push(@$html,$cgi->h1($topic));
229 :     $last1 = $topic;
230 :     $last2 = "";
231 :     }
232 :    
233 :     $topic = $tuple->[1] ? $tuple->[1] : "";
234 :     if ($topic && ($topic ne $last2))
235 : overbeek 1.19 {
236 :     push(@$html,$cgi->h2($topic));
237 : overbeek 1.20 $last2 = $topic;
238 : overbeek 1.19 }
239 : overbeek 1.20
240 : overbeek 1.6 $sub_link = &sub_link($cgi,$sub);
241 : overbeek 1.19 push(@$html,$cgi->h3($sub_link));
242 :    
243 : overbeek 1.6 my $roles = [];
244 :     foreach $role (sort keys(%{$in{$sub}}))
245 :     {
246 :     push(@$roles,$cgi->ul($cgi->li($in{$sub}->{$role})));
247 :     }
248 :     push(@$html,$cgi->ul($cgi->li($roles)));
249 :     }
250 : overbeek 1.4 }
251 : overbeek 1.5
252 :     sub handle_hypo_sub {
253 :     my($fig,$cgi,$html,$genome) = @_;
254 :    
255 : overbeek 1.6 my($subsystem_data,$assignments_data) = &get_data($fig,$cgi,$genome);
256 :     my %subs = map { $_->[2] => $_->[0] } @$subsystem_data;
257 :     my $col_hdrs = ["PEG","Function","Subsystem"];
258 :     my $tab = [];
259 :     foreach $_ (@$assignments_data)
260 :     {
261 :     my($peg,$func) = @$_;
262 :     if (&FIG::hypo($func) && ($subs{$peg}))
263 :     {
264 :     push(@$tab,[&HTML::fid_link($cgi,$peg,0),$func,&sub_link($cgi,$subs{$peg})]);
265 :     }
266 :     }
267 :     $_ = @$tab;
268 :     push(@$html,&HTML::make_table($col_hdrs,$tab,"$_ Hypothetical Pegs in Subsystems"));
269 : overbeek 1.5 }
270 :    
271 :     sub handle_hypo_nosub {
272 :     my($fig,$cgi,$html,$genome) = @_;
273 :    
274 : overbeek 1.6 my($subsystem_data,$assignments_data) = &get_data($fig,$cgi,$genome);
275 :     my %subs = map { $_->[2] => $_->[0] } @$subsystem_data;
276 :     my $col_hdrs = ["PEG","Function"];
277 :     my $tab = [];
278 :     foreach $_ (@$assignments_data)
279 :     {
280 :     my($peg,$func) = @$_;
281 :     if (&FIG::hypo($func) && (! $subs{$peg}))
282 :     {
283 :     push(@$tab,[&HTML::fid_link($cgi,$peg,0),$func]);
284 :     }
285 :     }
286 :     $_ = @$tab;
287 :     push(@$html,&HTML::make_table($col_hdrs,$tab,"$_ Hypothetical Pegs NOT in Subsystems"));
288 : overbeek 1.5 }
289 :    
290 :     sub handle_nothypo_sub {
291 :     my($fig,$cgi,$html,$genome) = @_;
292 :    
293 : overbeek 1.6 my($subsystem_data,$assignments_data) = &get_data($fig,$cgi,$genome);
294 :     my %subs = map { $_->[2] => $_->[0] } @$subsystem_data;
295 :     my $col_hdrs = ["PEG","Function","Subsystem"];
296 :     my $tab = [];
297 :     foreach $_ (@$assignments_data)
298 :     {
299 :     my($peg,$func) = @$_;
300 :     if ((! &FIG::hypo($func)) && ($subs{$peg}))
301 :     {
302 :     push(@$tab,[&HTML::fid_link($cgi,$peg,0),$func,&sub_link($cgi,$subs{$peg})]);
303 :     }
304 :     }
305 :     $_ = @$tab;
306 :     push(@$html,&HTML::make_table($col_hdrs,$tab,"$_ Nonhypothetical Pegs in Subsystems"));
307 : overbeek 1.5 }
308 :    
309 :     sub handle_nothypo_nosub {
310 :     my($fig,$cgi,$html,$genome) = @_;
311 :    
312 : overbeek 1.6 my($subsystem_data,$assignments_data) = &get_data($fig,$cgi,$genome);
313 :     my %subs = map { $_->[2] => $_->[0] } @$subsystem_data;
314 :     my $col_hdrs = ["PEG","Function"];
315 :     my $tab = [];
316 :     foreach $_ (@$assignments_data)
317 :     {
318 :     my($peg,$func) = @$_;
319 :     if ((! &FIG::hypo($func)) && (! $subs{$peg}))
320 :     {
321 :     push(@$tab,[&HTML::fid_link($cgi,$peg,0),$func]);
322 :     }
323 :     }
324 :     $_ = @$tab;
325 :     push(@$html,&HTML::make_table($col_hdrs,$tab,"$_ Nonhypothetical Pegs NOT in Subsystems"));
326 : overbeek 1.5 }
327 :    
328 : overbeek 1.6 sub get_data {
329 :     my($fig,$cgi,$genome) = @_;
330 :    
331 :     my $rdbH = $fig->db_handle;
332 :     my $subsystem_data = $rdbH->SQL("SELECT DISTINCT subsystem,role,protein FROM subsystem_index WHERE ( protein like 'fig\|$genome.peg.%')");
333 :     my $assignment_data = $rdbH->SQL("SELECT prot,assigned_function FROM assigned_functions WHERE ( prot like 'fig\|$genome.peg.%' AND made_by = 'master' )");
334 :    
335 :     return ($subsystem_data,$assignment_data);
336 :     }
337 :    
338 :     sub sub_link {
339 :     my($cgi,$sub) = @_;
340 :    
341 :     my $user = $cgi->param('user');
342 : overbeek 1.19 $user = defined($user) ? $user : "";
343 :     my $sub_link = "<a href=./subsys.cgi?ssa_name=$sub&request=show_ssa&user=$user>$sub</a>";
344 :    
345 : overbeek 1.6 return $sub_link;
346 :     }
347 : overbeek 1.8
348 :     sub get_basic_stats {
349 :     my($fig,$genome) = @_;
350 :    
351 :     my $rdbH = $fig->db_handle;
352 :     my $relational_db_response = $rdbH->SQL("SELECT gname,szdna,pegs,rnas,taxonomy FROM genome WHERE genome = '$genome'");
353 :     my($gname,$szdna,$pegs,$rnas,$taxonomy) = @{$relational_db_response->[0]};
354 :     my $szdna = &commify($szdna);
355 :     my $num_contigs = scalar $fig->all_contigs($genome);
356 :     return ($gname,$szdna,$num_contigs,$pegs,$rnas,$taxonomy);
357 :     }
358 :    
359 :     sub table_of_genomes {
360 :     my($fig,$cgi,$html) = @_;
361 :     my(@genomes);
362 :    
363 :     push(@$html,"<pre>\n");
364 :     if ($cgi->param('complete'))
365 :     {
366 :     @genomes = $fig->genomes("complete");
367 :     }
368 :     else
369 :     {
370 :     @genomes = $fig->genomes;
371 :     }
372 :    
373 :     my $genome;
374 :     push(@$html,join("\t","Genome ID","Complete","Genome Name","Size (bp)","Number Contigs","CDSs","RNAs","Taxonomy") . "\n");
375 :     my $genome;
376 :     foreach $genome (@genomes)
377 :     {
378 :     push(@$html,join("\t",($genome,$fig->is_complete($genome),&get_basic_stats($fig,$genome))) . "\n");
379 :     }
380 :     push(@$html,"</pre>\n");
381 :     }
382 :    
383 :    
384 : overbeek 1.9 sub subsys_summary {
385 :     my($fig,$cgi,$html) = @_;
386 :     my($Nsubs,$genome,$sub,$role,$peg,$genome_instances,%genomes_in_use,$peg_instances,%pegs_in_use);
387 :     foreach $sub ($fig->all_subsystems)
388 :     {
389 :     $Nsubs++;
390 :     foreach $genome (map { $_->[0] } @{$fig->subsystem_genomes($sub)})
391 :     {
392 :     $genome_instances++;
393 :     $genomes_in_use{$genome}++;
394 :     foreach $role ($fig->subsystem_to_roles($sub))
395 :     {
396 :     foreach $peg ($fig->pegs_in_subsystem_cell($sub,$genome,$role))
397 :     {
398 :     $peg_instances++;
399 :     $pegs_in_use{$peg}++;
400 :     }
401 :     }
402 :     }
403 :     }
404 :     my $Ngenomes = scalar keys(%genomes_in_use);
405 :     my $Npegs = scalar keys(%pegs_in_use);
406 :     my $g_in_sub = int($genome_instances / $Nsubs);
407 :     my $p_in_sub = int($peg_instances / $Nsubs);
408 :     push(@$html,$cgi->h1('Subsystem Summary'));
409 :     push(@$html,$cgi->br,
410 :     "<b>Number Subsystems:</b> $Nsubs",$cgi->br,
411 :     "<b>Genomes in Subsystems:</b> $Ngenomes",$cgi->br,
412 :     "<b>PEGs in Subsystems:</b> $Npegs",$cgi->br,
413 :     "<b>Avg genomes per subsystem:</b> $g_in_sub",$cgi->br,
414 :     "<b>Avg PEGs per subsystem:</b> $p_in_sub",$cgi->br
415 :     );
416 :     return
417 :    
418 :     }
419 : redwards 1.10
420 : redwards 1.14 sub kv_peg_stats {
421 :     my ($fig, $cgi, $html, $genome)=@_;
422 :    
423 :     #RAE Added the coverage of each genome with different attributes for the PEGs to find the number of genes that are in pirsf, etc
424 :     push(@$html, "\n<div class=\"pegattributes\">\n<p><h2>PEG Attributes for ", $fig->genus_species($genome), "</h2></p>\n");
425 :    
426 :     my $pegtags=$fig->get_tags('peg');
427 :     foreach my $type (sort {$a cmp $b} keys %$pegtags)
428 :     {
429 : redwards 1.15 my @result = grep {$_ =~ /$genome/} @{$pegtags->{$type}};
430 :     push(@$html, "\nPEGS with tag: $type : ", scalar(@result), $cgi->br, "\n");
431 : redwards 1.14 }
432 :     }
433 :    
434 : redwards 1.10 sub kv_stats {
435 :     my ($fig, $cgi, $html, $genome, $edit)=@_;
436 :    
437 :     # RAE Added tables for key value pairs for an organism, and allow you to edit them
438 :     # figure out kv's for the organism, and make a table with them
439 :    
440 :     # if the optional edit boolean is set and a user is supplied, we will make a table where you can edit the KV pairs
441 :     # else we will just make a blank table
442 :    
443 : redwards 1.12 # prepare the html so we can add form fields here
444 :     push(@$html, "\n<div class=\"attributes\">\n<p><h2>Attributes for ", $fig->genus_species($genome), "</h2></p>\n");
445 :     if ($edit) {push(@$html, $cgi->start_form(-action=>"genome_statistics.cgi"))}
446 :    
447 :    
448 : redwards 1.10 my $tab=[];
449 :     my $user=$cgi->param('user');
450 :     my $col_hdrs=["Attribute", "Value"];
451 : redwards 1.11 if ($user && $edit) {$col_hdrs=["Attribute", "Value", "URL"]}
452 : redwards 1.10
453 :     my $known;
454 : redwards 1.13 foreach my $key (sort {$a->[1] cmp $b->[1]} $fig->get_attributes($genome)) {
455 :     $known->{$key->[1]}=1;
456 : redwards 1.10 if ($user && $edit) {
457 :     push @$tab,
458 :     [
459 : redwards 1.13 $key->[1],
460 :     $cgi->textfield(-name=>"value.".$key->[1], -default=>$key->[2], -size=>50),
461 :     $cgi->textfield(-name=>"url.".$key->[1], -default=>$key->[3], -size=>50),
462 : redwards 1.10 ];
463 :     } else {
464 : redwards 1.13 if ($key->[3] && $key->[3] =~ /^http/) {$key->[2] = "<a href=\"" . $key->[3] . "\">". $key->[2] . "</a>"}
465 : redwards 1.10 push @$tab,
466 :     [
467 : redwards 1.13 $key->[1],
468 :     $key->[2],
469 : redwards 1.10 ];
470 :     }
471 :     }
472 :    
473 :    
474 :     if ($edit) {
475 :     # now we want to add some pull down menus for things that we can add. And some blank boxes too for free text entry.
476 :     # start with three of each
477 :     my $opt=$fig->get_tags("genome"); # all the tags we know about
478 :     my @options=sort {uc($a) cmp uc($b)} grep {!$known->{$_}} keys %$opt;
479 :     unshift(@options, undef); # a blank field at the start
480 :     for (my $i=1; $i<= (scalar @options + 5); $i++) {
481 :    
482 :     # we have the options, and 5 blank fields for free text entry
483 :     my $choice=$cgi->popup_menu(-name=>"key.$i", -values=>\@options);
484 :     if ($i >= scalar @options) {$choice = $cgi->textfield(-name=>"key.$i", -size=>50)}
485 :     push @$tab,
486 :     [
487 :     $choice,
488 :     $cgi->textfield(-name=>"value.$i", -size=>50),
489 :     $cgi->textfield(-name=>"url.$i", -size=>50),
490 :     ];
491 :     }
492 : 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
493 :     push(@$html, $cgi->hidden(-name=>"max new keys", -value=>scalar @options + 5));
494 : redwards 1.10 }
495 :    
496 :     # now just write the html
497 :     push(@$html,&HTML::make_table($col_hdrs,$tab,"Attributes"));
498 :     if ($edit) {
499 :     push(@$html, $cgi->hidden("genome"), $cgi->hidden("user"), $cgi->hidden("request"));
500 :     push(@$html, $cgi->submit('Change'), $cgi->reset());
501 :     }
502 :     else {
503 :     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");
504 :     }
505 :     }
506 :    
507 :    
508 :     sub edit_kv_stats {
509 :     my ($fig, $cgi, $html, $genome)=@_;
510 :     if ($cgi->param("Change")) {
511 :     # we have changed the values
512 :     # get the old kv pairs so we can see what has changed
513 :     my $changed; my $deleted;
514 :     foreach my $key ($fig->get_attributes($genome)) {
515 : redwards 1.13 if (!$cgi->param('value.'.$key->[1]) && !$cgi->param('url.'.$key->[1])) {
516 :     $fig->delete_attribute($genome, $key->[1]);
517 : redwards 1.10 push @$key, ["deleted", "td colspan=2 style=\"text-align: center\""];
518 :     push @$deleted, $key;
519 :     }
520 : redwards 1.13 elsif (($cgi->param('value.'.$key->[1]) ne $key->[2]) || ($cgi->param('url.'.$key->[1]) ne $key->[3])) {
521 :     $fig->change_attribute($genome, $key->[1], $cgi->param('value.'.$key->[1]), $cgi->param('url.'.$key->[1]));
522 :     push @$key, $cgi->param('value.'.$key->[1]), $cgi->param('url.'.$key->[1]);
523 : redwards 1.10 push @$changed, $key;
524 :     }
525 :     }
526 :    
527 :     my $added;
528 : redwards 1.12 for (my $i=0; $i <= $cgi->param("max new keys"); $i++) {
529 : redwards 1.10 if ($cgi->param("key.$i")) {
530 :     $fig->add_attribute($genome, $cgi->param("key.$i"), $cgi->param("value.$i"), $cgi->param("url.$i"));
531 :     push @$added, [$cgi->param("key.$i"), ["added", "td colspan=2 style=\"text-align: center\""], $cgi->param("value.$i"), $cgi->param("url.$i")];
532 :     }
533 :     }
534 :    
535 :     # now all we have to do is create a table to report what we have done.
536 :     my $tab=[];
537 :     push (@$html, "<div class=\"altered\"><p><h2>Attributes Altered for ", $fig->genus_species($genome), " ($genome)</h2></p>");
538 :     my $col_hdrs=["Attribute", "Original Value", "Original URL", "New Value", "New URL"];
539 :     if ($changed) {push @$tab, [["<strong>Changed Attributes", "td colspan=5 bgcolor=gray style=\"text-align: center\""]], @$changed}
540 :     if ($deleted) {push @$tab, [["<strong>Deleted Attributes", "td colspan=5 bgcolor=gray style=\"text-align: center\""]], @$deleted}
541 :     if ($added) {push @$tab, [["<strong>Added Attributes", "td colspan=5 bgcolor=gray style=\"text-align: center\""]], @$added}
542 :    
543 :     push(@$html,&HTML::make_table($col_hdrs,$tab,"Changed Data"));
544 :     }
545 :     else {
546 :     return kv_stats($fig, $cgi, $html, $genome, 1);
547 :     }
548 :     }
549 :    

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3