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

View of /FigWebServices/cv.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (download) (annotate)
Thu Oct 20 00:26:29 2005 UTC (14 years, 1 month ago) by efrank
Branch: MAIN
Changes since 1.2: +163 -159 lines
getting closer.  many fixes.

- merged two almost same show_init and show_search into a common build page.
- broke form into 3 forms so that textfields couple to correct submit buttons
- some improved testing on input, e.g., do not add custom CV if not all 3
  items are provided
- say what peg we're on
- make add button go away if no search results returned (afraid of corner case
  of it getting thwapped)
-

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


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 $custom_term_error = "";


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")
{
    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') && $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 Custom Term")
{
    my %id_term_to_source;
    my $id_term;
    if ( $cgi->param('custom_source') && $cgi->param('custom_id') && $cgi->param('custom_term') ) {
	$custom_source=$cgi->param('custom_source');
	$custom_id=$cgi->param('custom_id');
	$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 {
	$custom_term_error = "Error: supply all three items correctly.";
    }
}
else
{
    my(@html);
    push(@html, $cgi->p("Program error- unexpected request or logic error."));
    &HTML::show_page($cgi, \@html, 1);
    exit;
}

&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."_lookup.txt";
    open(LOOKUP,"$file");
    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 "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; 
    } 


    # 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,
    "<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 Custom Terms (WARNING: This is strongly discouraged to avoid data entry errors.)</h5>",
    "<h3>$custom_term_error</h3>",
    "<h5>Vocabulary Name (single word, no spaces or punctuation), e.g., MyVocab </h5>\n",
    $cgi->textfield(-name => 'custom_source', -size => 48, -default=>'', -override=>1 ),
    "<h5>Term ID (single word, no spaces or punctuation), e.g., A147</h5>\n",
    $cgi->textfield(-name => 'custom_id', -size => 32, -default=>'', -override=>1),
    "<h5>Term text, e.g., catalytic activity</h5>\n",
    $cgi->textfield(-name => 'custom_term', -size => 70, -default=>'', -override=>1 ),
    $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