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

View of /FigWebServices/cv.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.6 - (download) (annotate)
Fri Oct 21 22:27:40 2005 UTC (14 years, 1 month ago) by mkubal
Branch: MAIN
Changes since 1.5: +27 -11 lines
delete works

# -*- 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;

print STDERR "NEW LOAD of PAGE\n";

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.


my $peg;
if ($cgi->param('prot') ) 
{
    $peg = $cgi->param('prot');
} 
else 
{
    $peg = $cgi->param('prot');
    my(@html);
    push(@html, $cgi->p("Parameter error- prot is required."));
    &HTML::show_page($cgi, \@html, 1);
    exit;
}

# a global for the results of a search. overridden by an actual search

my $search_results= [];

my $error_message = "";


my $user = "";
if ($cgi->param('user') ) {
    $user = $cgi->param('user');
}

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 $ids;
my $tag_to_id;
my $inputs;
print STDERR "REQ: ", $cgi->param('request'), "\n";

if ($cgi->param('request') eq "Delete Checked Terms")
{
    print STDERR "HERE Delete Clicked\n";
    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);
                 print STDERR "delete_checked_value:$value\n";
		 push(@checked,$value)
             }
          }	
        }    
        	
        for my $c (@checked)
	{ 
	   print STDERR "checked_for_deletion:$c\n";
           @temp = split('split_here',$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') && $cgi->param('select_cv') ) {
	$search_term=$cgi->param('search_term');
	$cv=$cgi->param('select_cv');
	$search_results = &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 Manual Term")
{
    my %id_term_to_source;
    my $id_term;
    if ( $cgi->param('manual_source') && $cgi->param('manual_id') && $cgi->param('manual_term') ) {
	$manual_source=$cgi->param('manual_source');
	$manual_id=$cgi->param('manual_id');
	$manual_term=$cgi->param('manual_term');
	$id_term = $manual_id.": ".$manual_term;    
	$id_term_to_source{$id_term} = $manual_source; 
	&add_terms($fig,$cgi,$html,$peg,\%id_term_to_source);
    } else {
	$error_message = "Error in 'Add Terms Manually': supply all three items correctly.";
    }
}
else
{
    #no op.  Initial page display
}

&build_page($fig,$cgi,$html,$peg,$search_results);
&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)
   {
         print STDERR "key:$it\n";
	 print STDERR "value:$id_term_to_source->{$it}\n";
         $fig->delete_attribute($peg,$id_term_to_source->{$it},$it)
    }  
}

sub search
{
    my ($fig,$cgi,$html,$peg,$cv,$search_term) =@_;
    $file = $FIG_Config::global."/cv_search_".$cv.".txt";
    if (! open(LOOKUP,"$file") ) {
	$error_message="Search could not find vocabulary file, $file";
	return;
    }
    my @lines = <LOOKUP>;
    my @grep_results = grep(/$search_term/i,@lines);
    print STDERR "$grep_results[0]\n";
    return [@grep_results];
    #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 build_page {
    my ($fig,$cgi,$html,$peg,$search_results)=@_;


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

    # Build seach results table

    @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 = [];
	$cv=$cgi->param('select_cv');
	$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 $add_terms_button="";
    if ($counter > 0) {
	$add_terms_button= $cgi->submit(-name=>'request', -value=>'Add New Terms');
    }

    # build term deletions stuff
 
    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 "deleted_checked_source:$source\n";
	$id_and_term = $r->[2];
	print STDERR "deleted_id_and_term:$id_and_term\n";
        $value = $source."split_here".$id_and_term;
	$cb ="<input type=checkbox name='delete_checked_$counter' value='$value'>" ;
	push(@$row,$cb);
	push(@$row,$source);
	push(@$row,$id_and_term);
	push(@$delete_table_rows,$row);
	$counter = $counter + 1; 
    } 


    # build the page

    my $link = "protein.cgi?prot=$peg";        
    push @$html, 
    #$cgi->start_multipart_form(),
    $cgi->start_form(),
    $cgi->hidden(-name=>'prot', -value=>'$peg'),
    $cgi->hidden(-name=>'user', -value=>'$user'),
    $cgi->br,
    "<a href=$link>Back to protein page</a>",
    $cgi->br, 
    "<h2>Controlled Vocabulary Workbench for $peg</h2>",
    $cgi->hr,
    "<h1>$error_message</h1>",
    $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->end_form;

    push @$html, 
    $cgi->start_form(),
    $cgi->hidden(-name=>'prot', -value=>'$peg'),
    $cgi->hidden(-name=>'user', -value=>'$user'),
    $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,
    $cgi->br,
    &HTML::make_table($add_col_hdrs,$add_table_rows),
    $cgi->br,
    $add_terms_button,
    $cgi->end_form;

    push @$html, 
    $cgi->start_form(),
    $cgi->hidden(-name=>'prot', -value=>'$peg'),
    $cgi->hidden(-name=>'user', -value=>'$user'),
    $cgi->hr,
    "<h4>Add Terms Manually (WARNING: This is strongly discouraged to avoid data entry errors.)</h5>",
    "<h5>Vocabulary Name (single word, no spaces or punctuation), e.g., MyVocab </h5>\n",
    $cgi->textfield(-name => 'manual_source', -size => 48, -default=>'', -override=>1 ),
    "<h5>Term ID (single word, no spaces or punctuation), e.g., A147</h5>\n",
    $cgi->textfield(-name => 'manual_id', -size => 32, -default=>'', -override=>1),
    "<h5>Term text, e.g., catalytic activity</h5>\n",
    $cgi->textfield(-name => 'manual_term', -size => 70, -default=>'', -override=>1 ),
    $cgi->br,$cgi->br,
    $cgi->submit(-name=>'request', -value=>'Add Manual Term'), 
    $cgi->br,
    $cgi->hr,
    $cgi->end_form;

    return $html;
}


MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3