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

View of /FigWebServices/cv.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.9 - (download) (annotate)
Tue Oct 25 01:56:45 2005 UTC (14 years, 1 month ago) by mkubal
Branch: MAIN
Changes since 1.8: +2 -2 lines
user param fixed when passed to protein.cgi

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

if ($cgi->param('request') eq "Delete Checked Terms")
{
    if (!$cgi->param('user'))
    {	
	    my(@html);
	    push(@html, $cgi->p("You must be logged in as a user to edit controlled vocabulary terms."));
	    &HTML::show_page($cgi, \@html, 1);
	    exit;
    } 	
    else
    {	
	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('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")
{
    if (!$cgi->param('user'))
    {	
	    my(@html);
	    push(@html, $cgi->p("You must be logged in as a user to edit controlled vocabulary terms."));
	    &HTML::show_page($cgi, \@html, 1);
	    exit;
    } 	
    else
    {	
	my %id_term_to_source;
	my @checked;
	my @param_list = $cgi->param();
	if (@param_list) 
	{
	    foreach my $p (@param_list)
	    {
		if ( $p=~/add_checked/)
		{
		    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 ;
	    }
	}
	&add_terms($fig,$cgi,$html,$peg,\%id_term_to_source);

    }
}

elsif ($cgi->param('request') eq "Add Manual Term")
{
    if (!$cgi->param('user'))
    {	
	    my(@html);
	    push(@html, $cgi->p("You must be logged in as a user to edit controlled vocabulary terms."));
	    &HTML::show_page($cgi, \@html, 1);
	    exit;
    } 	
    else
    {
	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)
   {
       $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);
     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});   
    my %sources={};   #in case someday we allow adds from >1 vocab at once
    my $source;
    foreach my $it (@id_term)
    {
       $source = $id_term_to_source->{$it}; 
       $fig->add_attribute($peg,$source,$it);
       $sources{$source}=1;   #build unique list of source names
    }
    
    my %key_info_hash;
    $key_info_hash{"is_cv"} = 1;
    $key_info_hash{"single"} = 0;
    $key_info_hash{"readonly"} = 1;
    
    $fig->key_info($source,\%key_info_hash);

    #&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];
	$term = $temp[2];
	$id_and_term = $id.": ".$term;
	$cb_value = $cv."split_here".$id."; ".$term;
	$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);
    my $delete_table_rows;
    my $counter =0;
    for my $r (@results)
    {
	$row = [];
	$source = $r->[1];
        $cv_key_hash = $fig->key_info($source);
        if($cv_key_hash->{"is_cv"} == 1)
        {
	    $id_and_term = $r->[2];
	    $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 $user = $cgi->param('user');
    my $link = "protein.cgi?prot=$peg&user=$user";        
    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