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

View of /FigWebServices/cv.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (download) (annotate)
Wed Oct 19 20:20:07 2005 UTC (14 years, 3 months ago) by mkubal
Branch: MAIN
Changes since 1.1: +92 -33 lines
best cv.cgi yet

# -*- perl -*-
use InterfaceRoutines;
use FIG;
use FIG_Config;
use URI::Escape;  # uri_escape
use HTML;
use Data::Dumper;
#use strict;
use GenoGraphics;
use CGI;
use Tracer;

my $cgi = new CGI;

use HTML;
use raelib;
my $raelib=new raelib;

use LWP::Simple qw(!head); # see the caveat in perldoc LWP about importing two head methods.

#for testing

my $peg = $cgi->param('prot');
#my $peg = "fig|9598.2.peg.1";

my $fig;
eval {
    $fig = new FIG;
};  

if ($@ ne "")
{
    my $err = $@;
    
    my(@html);
    
    push(@html, $cgi->p("Error connecting to SEED database."));
    if ($err =~ /Could not connect to DBI:.*could not connect to server/)
    {
        push(@html, $cgi->p("Could not connect to relational database of type $FIG_Config::dbms named $FIG_Config::db on port $FIG_Config::dbport."));
    }   
    else
    {
        push(@html, $cgi->pre($err));
    }   
    &HTML::show_page($cgi, \@html, 1);
    exit;
}   
    
my $html = [];
my $user = $cgi->param('user');

unshift(@$html, "<TITLE>Controlled Vocabulary Workbench</TITLE>\n");

my $ids;
my $tag_to_id;
my $inputs;

if ($cgi->param('request') eq "Delete Checked Terms")
{
    my %id_term_to_source;
    my @checked;
    my @param_list = $cgi->param();
    if (@param_list) 
    {
        foreach my $p (@param_list)
	{
          if ( $p=~/delete_checked/)
          {
             if($cgi->param($p))
	     {
		 $value = $cgi->param($p);
                 push(@checked,$value)
             }
          }	
        }    
        
	for my $c (@checked)
	{ 
           @temp = split('\t',$c);
           $id_term_to_source{$temp[1]} = $temp[0];
        }
    }
    &delete_terms($fig,$cgi,$html,$peg,\%id_term_to_source);
}
elsif ($cgi->param('request') eq "Search Selected Controlled Vocabulary")
{
    if ($cgi->param('search_term')) {$search_term=$cgi->param('search_term')}
    if ($cgi->param('select_cv')) {$cv=$cgi->param('select_cv')}
    &search($fig,$cgi,$html,$peg,$cv,$search_term);
}
elsif ($cgi->param('request') eq "Add New Terms")
{
    my %id_term_to_source;
    my @checked;
    my @param_list = $cgi->param();
    if (@param_list) 
    {
        foreach my $p (@param_list)
	{
          if ( $p=~/add_checked/)
          {
	      print STDERR "checked_param:$p\n";
             if($cgi->param($p))
	     {
		 $value = $cgi->param($p);
                 push(@checked,$value)
             }
          }	
        }    
        
	for my $c (@checked)
	{ 
	   @temp = split("split_here",$c);
           $source = $temp[0];
           $id_term = $temp[1];  
           $id_term_to_source{$id_term} =$source ;
           print STDERR "checked_source:$source\n";
           print STDERR "checked_value:$c\n";
        }
    }
    &add_terms($fig,$cgi,$html,$peg,\%id_term_to_source);

}

elsif ($cgi->param('request') eq "Add Custom Term")
{
    my %id_term_to_source;
    my $id_term;
    if ($cgi->param('custom_source')) {$custom_source=$cgi->param('custom_source')}
    if ($cgi->param('custom_id')) {$custom_id=$cgi->param('custom_id')}
    if ($cgi->param('custom_term')) {$custom_term=$cgi->param('custom_term')}
    $id_term = $custom_id.": ".$custom_term;    
    $id_term_to_source{$id_term} = $custom_source; 
    &add_terms($fig,$cgi,$html,$peg,\%id_term_to_source);
}
 
else
{
  &show_initial($fig,$cgi,$html,$peg);
}

&HTML::show_page($cgi,$html,1);
exit;

sub delete_terms
{
   my ($fig,$cgi,$html,$peg,$id_term_to_source) = @_;
   my @id_term = keys(%{$id_term_to_source});   
   foreach my $it (@id_term){$fig->delete_attribute($peg,$id_term_to_source->{$it},$it)}  
   &show_initial($fig,$cgi,$html,$peg);
}

sub search
{
    my ($fig,$cgi,$html,$peg,$cv,$search_term) =@_;
    $file = $FIG_Config::global."/".$cv."_lookup.txt";
    open(LOOKUP,"$file");
    my @lines = <LOOKUP>;
    my @grep_results = grep(/$search_term/i,@lines);
    print STDERR "$grep_results[0]\n";
    my $search_results = [@grep_results];
    &show_search_results($fig,$cgi,$html,$peg,$cv,$search_results);
}

sub add_terms
{ 
    my ($fig,$cgi,$html,$peg,$id_term_to_source) =@_ ;
    my @id_term = keys(%{$id_term_to_source});   
    foreach my $it (@id_term)
    {
        print STDERR "added_source:$id_term_to_source->{$it}\n";
	print STDERR "added_value:$it\n";
        
	$fig->add_attribute($peg,$id_term_to_source->{$it},$it);
	
    }
    &show_initial($fig,$cgi,$html,$peg);  
}

sub show_search_results {
 my ($fig,$cgi,$html,$peg,$cv,$search_results)=@_;
 @sr = @$search_results;
 my $add_col_hdrs = ["Add","Source","ID: Term"];
 my $add_table_rows;
 my $counter = 0; 
 for my $r (@sr)
 {
     @temp = split("\t",$r);
     $row = [];
     $source = $cv;
     $id= $temp[1];
     print STDERR "id:$id\n";
     $term = $temp[2];
     print STDERR "term:$term\n"; 
     $id_and_term = $id.": ".$term;
     $cb_value = $cv."split_here".$id.": ".$term;
     print STDERR "iandt:$id_and_term\n";
     $cb ="<input type=checkbox name=add_checked_$counter value='$cb_value'>" ;
     push(@$row,$cb);
     push(@$row,$source);
     push(@$row,$id_and_term);
     push(@$add_table_rows,$row);
     $counter = $counter + 1; 
 } 

 my $delete_col_hdrs = ["Delete","Source","ID: Term"];
 my @results = $fig->get_attributes($peg,'GO');
 my $delete_table_rows;
 $counter = 0;
 for my $r (@results)
 {
     $row = [];
     $source = $r->[1];

     $id_and_term = $r->[2];
     $cb ="<input type=checkbox name=delete_checked_$counter value=$id_and_term>" ;
     push(@$row,$cb);
     push(@$row,$source);
     push(@$row,$id_and_term);
     push(@$delete_table_rows,$row);
     $counter = $counter + 1; 
 } 
         
 push @$html, 
 $cgi->start_multipart_form(),
 "<h2>Controlled Vocabulary Workbench</h2>\n",
 $cgi->hr,
 "<h4>Current Terms Assigned To Peg </h4>\n",
 &HTML::make_table($delete_col_hdrs,$delete_table_rows),
 $cgi->br,
 $cgi->submit(-name=>'request', -value=>'Delete Checked Terms'),   
 $cgi->hr,
 $cgi->br,
 "<h4>Search for New Terms to Add </h4>\n",
 "<select name=select_cv>
	<option value=go  >Gene Ontology</option>
  </select> &nbsp;&nbsp",
 $cgi->textfield(-name => "search_term", -size => 20),
 $cgi->submit(-name=>'request', -value=>'Search Selected Controlled Vocabulary'), 
 $cgi->br,
 &HTML::make_table($add_col_hdrs,$add_table_rows),
 $cgi->br,
 $cgi->submit(-name=>'request', -value=>'Add New Terms'), 
 $cgi->hr,
 $cgi->br,
 "<h4>Add Custom Terms </h4>\n",
 "<h5>Source </h5>\n",
 $cgi->textfield(-name => "custom_source", -size => 20),
 "<h5>ID</h5>\n",
 $cgi->textfield(-name => "custom_id", -size => 20),
 "<h5>Term</h5>\n",
 $cgi->textfield(-name => "custom_term", -size => 20),
 $cgi->br,$cgi->br,
 $cgi->submit(-name=>'request', -value=>'Add Custom Term'), 
 $cgi->br,
 $cgi->hr,
 $cgi->end_form;

 return $html;
}

sub show_initial {
 my ($fig,$cgi,$html,$peg)=@_;
 # generate a blank page
 
 my $delete_col_hdrs = ["Delete","Source","ID: Term"];
 my @results = $fig->get_attributes($peg);
 print STDERR "@results\n";
 print STDERR "peg:$peg\n";
 my $delete_table_rows;
 my $counter =0;
 for my $r (@results)
 {
     $row = [];
     $source = $r->[1];
     print STDERR "source:$source\n";
     $id_and_term = $r->[2];
     $cb ="<input type=checkbox name=delete_checked_$counter value=$source\t$id_and_term>" ;
     push(@$row,$cb);
     push(@$row,$source);
     push(@$row,$id_and_term);
     push(@$delete_table_rows,$row);
     $counter = $counter + 1; 
 } 
 my $link = "protein.cgi?prot=$peg";        
 push @$html, 
 $cgi->start_multipart_form(),
 $cgi->br,
 "<a href=$link>Back to protein page</a>",
 $cgi->br, 
 "<h2>Controlled Vocabulary Workbench</h2>\n",
 $cgi->hr,
 "<h4>Current Terms Assigned To Peg </h4>\n",
 &HTML::make_table($delete_col_hdrs,$delete_table_rows),
 $cgi->br,
 $cgi->submit(-name=>'request', -value=>'Delete Checked Terms'),   
 $cgi->hr,
 $cgi->br,
 "<h4>Search for New Terms to Add </h4>\n",
 "<select name=select_cv>
	<option value=GO  >Gene Ontology</option>
  </select> &nbsp;&nbsp",
 $cgi->textfield(-name => 'search_term', -size => 20),
 $cgi->submit(-name=>'request', -value=>'Search Selected Controlled Vocabulary'), 
 $cgi->hr,
 $cgi->br,
 "<h4>Add Custom Terms </h4>\n",
 "<h5>Source </h5>\n",
 $cgi->textfield(-name => 'custom_source', -size => 20),
 "<h5>ID</h5>\n",
 $cgi->textfield(-name => 'custom_id', -size => 20),
 "<h5>Term</h5>\n",
 $cgi->textfield(-name => 'custom_term', -size => 20),
 $cgi->br,$cgi->br,
 $cgi->submit(-name=>'request', -value=>'Add Custom Term'), 
 $cgi->br,
 $cgi->hr,
 $cgi->end_form;

 return $html;
}


MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3