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

View of /FigWebServices/cv.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (download) (annotate)
Wed Oct 19 14:39:06 2005 UTC (14 years, 3 months ago) by mkubal
Branch: MAIN
controlled vocabulary iface- still coming to life.

# -*- 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 = "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 Custom 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')}
    
    my $triple = [$custom_source,$custom_id,$custom_term]; 
    &add_custom_term($fig,$cgi,$html,$peg,$triple);
}
 
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) =@_;
    open(LOOKUP,"$FIG_config::global/$cv_lookup.txt");
    my @lines = <LOOKUP>;
    my $search_results = grep(/$search_term/i,@lines);
    &show_search_results($fig,$cgi,$html,$peg,$cv,$search_results);
}

sub add_custom_term
{ 
    my ($fig,$cgi,$html,$peg,$triple) =@_ ;
    my @input = @$triple;
    my $key = $input[0];
    my $id = $input[1];
    my $term = $input[2];
    $value = $id.": ".$term;
    $fig->add_attribute($peg,$key,$value);
}

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;
 for my $r (@sr)
 {
     @temp = split("\t",$r);
     $row = [];
     $source = $cv;
     $id_and_term = $temp[1];
     $cb ="<input type=checkbox name=add_checked value=$id_and_term>" ;
     push(@$row,$cb);
     push(@$row,$source);
     push(@$row,$id_and_term);
     push(@$add_table_rows,$row); 
 } 

 my $delete_col_hdrs = ["Delete","Source","ID: Term"];
 my @results = $fig->get_attributes($peg,'GO');
 my $delete_table_rows;
 my $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=all >all CVs</option>
	<option value=go  >Gene Ontology</option>
	<option value=omim >OMIM</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->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 $col_hdrs = ["Delete","Source","ID: Term"];
 my @results = $fig->get_attributes($peg,'GO');
 my $table_rows;
 for my $r (@results)
 {
     $row = [];
     $source = $r->[1];
     $id_and_term = $r->[2];
     $cb ="<input type=checkbox name=delete_checked value=$source\t$id_and_term>" ;
     push(@$row,$cb);
     push(@$row,$source);
     push(@$row,$id_and_term);
     push(@$table_rows,$row); 
 } 
         
  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($col_hdrs,$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=all >all CVs</option>
	<option value=go  >Gene Ontology</option>
	<option value=omim >OMIM</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