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

Diff of /FigWebServices/genome_statistics.cgi

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.9, Fri Jan 14 13:56:37 2005 UTC revision 1.10, Fri Mar 4 06:22:10 2005 UTC
# Line 1  Line 1 
1    # -*- perl -*-
2  #### start ####  #### start ####
3    
4  use FIG;  use FIG;
# Line 47  Line 48 
48  {  {
49      &subsys_summary($fig,$cgi,$html);      &subsys_summary($fig,$cgi,$html);
50  }  }
51    elsif ($request eq "edit_kv_stats") {
52        &edit_kv_stats($fig,$cgi,$html, $cgi->param('genome'));
53    }
54  elsif ((@genomes == 0) && (! $request))  elsif ((@genomes == 0) && (! $request))
55  {  {
56      &table_of_genomes($fig,$cgi,$html);      &table_of_genomes($fig,$cgi,$html);
# Line 60  Line 64 
64          push(@$html,$cgi->hr);          push(@$html,$cgi->hr);
65          &assignment_stats($fig,$cgi,$html,$genome);          &assignment_stats($fig,$cgi,$html,$genome);
66          push(@$html,$cgi->hr);          push(@$html,$cgi->hr);
67            &kv_stats($fig, $cgi, $html, $genome);
68          my $user = $cgi->param('user');          my $user = $cgi->param('user');
69          push(@$html,"<a href=./genome_statistics.cgi?genome=$genome&request=show_subsystems&user=$user>Show Subsystems</a>");          push(@$html,"<a href=./genome_statistics.cgi?genome=$genome&request=show_subsystems&user=$user>Show Subsystems</a>");
70          push(@$html,$cgi->br);          push(@$html,$cgi->br);
# Line 352  Line 357 
357      return      return
358    
359  }  }
360    
361    sub kv_stats {
362     my ($fig, $cgi, $html, $genome, $edit)=@_;
363    
364     # RAE Added tables for key value pairs for an organism, and allow you to edit them
365     # figure out kv's for the organism, and make a table with them
366    
367     # if the optional edit boolean is set and a user is supplied, we will make a table where you can edit the KV pairs
368     # else we will just make a blank table
369    
370     my $tab=[];
371     my $user=$cgi->param('user');
372     my $col_hdrs=["Attribute", "Value"];
373    
374     my $known;
375     foreach my $key (sort {$a->[0] cmp $b->[0]} $fig->get_attributes($genome)) {
376      $known->{$key->[0]}=1;
377      if ($user && $edit) {
378       push @$tab,
379        [
380           $key->[0],
381           $cgi->textfield(-name=>"value.".$key->[0], -default=>$key->[1], -size=>50),
382           $cgi->textfield(-name=>"url.".$key->[0], -default=>$key->[2], -size=>50),
383        ];
384      } else {
385       if ($key->[2] && $key->[2] =~ /^http/) {$key->[1] = "<a href=\"" . $key->[2] . "\">". $key->[1] . "</a>"}
386       push @$tab,
387        [
388           $key->[0],
389           $key->[1],
390        ];
391       }
392      }
393    
394    
395     if ($edit) {
396      # now we want to add some pull down menus for things that we can add. And some blank boxes too for free text entry.
397      # start with three of each
398      my $opt=$fig->get_tags("genome"); # all the tags we know about
399      my @options=sort {uc($a) cmp uc($b)} grep {!$known->{$_}} keys %$opt;
400      unshift(@options, undef); # a blank field at the start
401      for (my $i=1; $i<= (scalar @options + 5); $i++) {
402    
403       # we have the options, and 5 blank fields for free text entry
404       my $choice=$cgi->popup_menu(-name=>"key.$i", -values=>\@options);
405       if ($i >= scalar @options) {$choice = $cgi->textfield(-name=>"key.$i", -size=>50)}
406       push @$tab,
407         [
408            $choice,
409            $cgi->textfield(-name=>"value.$i", -size=>50),
410            $cgi->textfield(-name=>"url.$i", -size=>50),
411         ];
412      }
413     }
414    
415     # now just write the html
416     if ($edit) {push(@$html, $cgi->start_form(-action=>"genome_statistics.cgi"))}
417     push(@$html, "\n<div class=\"attributes\">\n<p><h2>Attributes for ", $fig->genus_species($genome), "</h2></p>\n");
418     push(@$html,&HTML::make_table($col_hdrs,$tab,"Attributes"));
419     if ($edit) {
420      push(@$html, $cgi->hidden("genome"), $cgi->hidden("user"), $cgi->hidden("request"));
421      push(@$html, $cgi->submit('Change'), $cgi->reset());
422     }
423     else {
424      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");
425     }
426    }
427    
428    
429    sub edit_kv_stats {
430     my ($fig, $cgi, $html, $genome)=@_;
431     if ($cgi->param("Change")) {
432      # we have changed the values
433      # get the old kv pairs so we can see what has changed
434      my $changed; my $deleted;
435      foreach my $key ($fig->get_attributes($genome)) {
436       if (!$cgi->param('value.'.$key->[0]) && !$cgi->param('url.'.$key->[0])) {
437        $fig->delete_attribute($genome, $key->[0]);
438        push @$key, ["deleted", "td colspan=2 style=\"text-align: center\""];
439        push @$deleted, $key;
440       }
441       elsif (($cgi->param('value.'.$key->[0]) ne $key->[1]) || ($cgi->param('url.'.$key->[0]) ne $key->[2]))  {
442         $fig->change_attribute($genome, $key->[0], $cgi->param('value.'.$key->[0]), $cgi->param('url.'.$key->[0]));
443         push @$key, $cgi->param('value.'.$key->[0]), $cgi->param('url.'.$key->[0]);
444         push @$changed, $key;
445       }
446      }
447    
448      my $added;
449      for (my $i=0; $i <=6; $i++) {
450       if ($cgi->param("key.$i")) {
451        $fig->add_attribute($genome, $cgi->param("key.$i"), $cgi->param("value.$i"), $cgi->param("url.$i"));
452        push @$added, [$cgi->param("key.$i"), ["added", "td colspan=2 style=\"text-align: center\""], $cgi->param("value.$i"), $cgi->param("url.$i")];
453       }
454      }
455    
456      # now all we have to do is create a table to report what we have done.
457      my $tab=[];
458      push (@$html, "<div class=\"altered\"><p><h2>Attributes Altered for ", $fig->genus_species($genome), " ($genome)</h2></p>");
459      my $col_hdrs=["Attribute", "Original Value", "Original URL", "New Value", "New URL"];
460      if ($changed) {push @$tab, [["<strong>Changed Attributes", "td colspan=5 bgcolor=gray style=\"text-align: center\""]], @$changed}
461      if ($deleted) {push @$tab, [["<strong>Deleted Attributes", "td colspan=5 bgcolor=gray style=\"text-align: center\""]], @$deleted}
462      if ($added)   {push @$tab, [["<strong>Added Attributes",   "td colspan=5 bgcolor=gray style=\"text-align: center\""]], @$added}
463    
464      push(@$html,&HTML::make_table($col_hdrs,$tab,"Changed Data"));
465     }
466     else {
467      return kv_stats($fig, $cgi, $html, $genome, 1);
468     }
469    }
470    
471    

Legend:
Removed from v.1.9  
changed lines
  Added in v.1.10

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3