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

View of /FigWebServices/proteinfamilies.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (download) (annotate)
Tue Jul 12 14:34:15 2005 UTC (14 years, 8 months ago) by redwards
Branch: MAIN
CVS Tags: merge-trunktag-bodev_news-3
Changes since 1.2: +16 -14 lines
Changing attributes and modifying protein.cgi with show/hides

# -*- perl -*-

=pod

=head1 proteinfamilies.cgi

A base web interface for getting information about protein families in and out. Initially we are going to make a 3 (or 4) column table of protein, family and other proteins.

=cut

use strict;
use FIG;
use HTML;
use raelib;
use CGI;
my $cgi=new CGI;
use LWP::Simple qw(!head); # see the caveat in perldoc LWP about importing two head methods.

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>The SEED - Global Protein Families </TITLE>\n");

my %proteinbase=(
 "fig" 	=> "/FIG/protein.cgi?user=$user&prot=fig|",
 "cog"  => "http://www.ncbi.nlm.nih.gov/COG/old/palox.cgi?",
 "sp"   => "http://www.expasy.org/uniprot/",
 "tr"   => "http://www.expasy.org/uniprot/",
 "kegg" => "http://www.genome.jp/dbget-bin/www_bget?",
);



if ($cgi->param('Show Proteins In Each Family')) 
{
 my @needed=grep {$cgi->param($_)} $cgi->param("allfams");
 $cgi->param(-name=>'family', -value=>\@needed);
 &show_family($fig,$cgi,$html);
}
elsif ($cgi->param("Combine Families With And"))
{
 &combine_families($fig,$cgi,$html);
}
elsif ($cgi->param('Compare FIG Functions'))
{
 my @needed=grep {$cgi->param($_)} $cgi->param("allfams");
 $cgi->param(-name=>'family', -value=>\@needed);
 &compare_functions($fig,$cgi,$html);
}
elsif ($cgi->param('family'))
{
 &show_family($fig,$cgi,$html);
}
elsif ($cgi->param('prot')) 
{
 &show_protein($fig,$cgi,$html);
}
else
{
  &show_initial($fig,$cgi,$html);
}

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


sub show_initial {
 my ($fig,$cgi,$html)=@_;
 # generate a blank page
 push @$html, 
 "<h2>Protein Families</h2>\n",
 "<p>Please enter a protein ID . You will recieve a list of all the families that protein is in. \n",
 "You can use a FIG ID such as fig|83333.1.peg.3, or an ID from SwissProt, KEGG, NCBI, and others.</p>",
 $cgi->start_form(), 
 "Please enter a protein id: ", $cgi->textfield(-name=>"prot", -size=>40), "<br>", 
 "<p>Alternately, you can enter a family. Please enter a family name in the format pir|PIRSF001547 or fig|PF002363.</p>",
 "Please enter a family id:  ", $cgi->textfield(-name=>"family", -size=>40), "<br>",
 $cgi->submit, $cgi->reset, $cgi->end_form;
 return $html;
}

sub show_protein {
 my ($fig,$cgi,$html)=@_;
 foreach my $peg ($cgi->param('prot')) {
  my @families=$fig->families_for_protein($peg);
  unless (@families) 
  {
   push @$html, "<h2 style='color: red'>Sorry, $peg is not in any protein families</h2>";
   return;
  }
 
  my $tab=[];
  my $self=$cgi->url;
  foreach my $fam (@families) {
   push @$tab, ["<a href='$self?family=$fam'>$fam</a>", $fig->family_function($fam), $fig->sz_family($fam), $cgi->checkbox(-name=>$fam, -label=>'')];
  }
 
  my $col_hdrs=['Family ID', 'Family Function', 'Number of Unique Proteins in Family', 'Choose Family'];
  push @$html, "<h2>Families for $peg</h2>\n", 
  $cgi->start_form,
  "<p>$peg is in the following ", scalar(@families), " families. Please choose one or more families using the checkboxes</p>\n",
  &HTML::make_table($col_hdrs, $tab, "Families for $peg"),  "\n",
  $cgi->submit('Show Proteins In Each Family'), $cgi->submit("Combine Families With And"), $cgi->submit("Compare FIG Functions"),
  $cgi->hidden(-name=>"allfams", -value=>\@families), "\n",
  $cgi->reset, $cgi->end_form;
 }
}
 
sub show_family {
 my ($fig,$cgi,$html)=@_;
 foreach my $fam ($cgi->param('family')) {
  my @eids=sort {$a <=> $b} $fig->ids_in_family($fam);
  my $tab=[];
  my $col_hdrs=['Cluster ID', 'Polypeptides with same amino acid sequence'];
  foreach my $eid (@eids) {
   my @pegs=$fig->eid_to_prots($eid);
   foreach my $p (@pegs) {
    foreach my $k (keys %proteinbase) {
     if ($p =~ /^$k/) {$p =~ s/^(.*?)\|//; $p = "<a href='$proteinbase{$k}$p'>$1|$p</a>"}
    }
   }
   push @$tab, [$eid, (join ", ", (@pegs))];
  }

  push @$html, "<h2>$fam Family</h2>\n",
  "<p>The family $fam has the function ", $fig->family_function($fam), ", and contains ", $fig->sz_family($fam), " proteins, as shown in the table below.<br>",
  "Each of the sequences with a given ID have the same amino acid sequence, and hence are the same polypeptide, ",
  "even though they may come from different organisms.</p>",
  "<p>The links will take you to the respective databases for each of the other protein families.\n</p>",
  $cgi->start_form,
  &HTML::make_table($col_hdrs, $tab, "Proteins in " . $fig->family_function($fam) . " ($fam)"),
  $cgi->hidden(-name=>'family', -value=>"$fam"), $cgi->submit("Compare FIG Functions"),
  $cgi->end_form;
 }
}

sub combine_families {
 my ($fig,$cgi,$html)=@_;
 # first find all the families and all the eids in those families
 my $eids; my @families; my $allprots;
 foreach my $f (grep {$cgi->param($_)} $cgi->param("allfams"))
 {
  push @families, $f;
  foreach my $e ($fig->ids_in_family($f)) {$eids->{$e}->{$f}=1; $allprots++}
 }
 
 # now figure out those eids that are in all families
 # we are going to do this with a boolean switch rather than just counting occurences
 my @wanted;
 foreach my $eid (keys %$eids) {
  my $keep=1;
  foreach my $f (@families) {undef $keep unless ($eids->{$eid}->{$f})}
  push @wanted, $eid if ($keep);
 }
 
 my $tab=[];
 my $col_hdrs=['Cluster ID', 'Polypeptides with same amino acid sequence'];
 foreach my $eid (sort {$a <=> $b} @wanted) {
  my @pegs=$fig->eid_to_prots($eid);
  foreach my $p (@pegs) {
   foreach my $k (keys %proteinbase) {
    if ($p =~ /^$k/) {$p =~ s/^(.*?)\|//; $p = "<a href='$proteinbase{$k}$p'>$1|$p</a>"}
   }
  }
  push @$tab, [$eid, (join ", ", (@pegs))];
 }
			      
  
 push @$html, "<h2>Proteins in ", (join ", ", (@families)), " families</h2>\n",
 "<h3>Summary</h3>\n<p>There were $allprots proteins in the ", scalar(@families), " families that you selected.\n<br>",
 "Out of a those proteins, there were ", scalar(keys %$eids),
 " unique proteins, and ", scalar(@wanted), " proteins are present in the ",
 scalar(@families), " families.</p>\n",
 "Each of the sequences with a given ID have the same amino acid sequence, and hence are the same polypeptide, even though they may come from different organisms.</p>",
 "<p>The links will take you to the respective databases for each of the other protein families.\n</p>",
 $cgi->start_form,
 &HTML::make_table($col_hdrs, $tab, "Proteins in " . (join ", ", (@families)) . " families"),
 $cgi->end_form;  
}
 
sub compare_functions {
 my ($fig,$cgi,$html)=@_;
 foreach my $fam ($cgi->param('family')) {
  my @eids=sort {$a <=> $b} $fig->ids_in_family($fam);
  my $tab=[];
  my $col_hdrs=['FIG ID', 'Genome', 'Assigned Function'];
  foreach my $eid (@eids) {
   foreach my $peg (grep {/^fig/} $fig->eid_to_prots($eid)) {
    my $p=$peg;
    $p =~ s/fig\|//; 
    $p = "<a href='$proteinbase{'fig'}$p'>$peg</a>";
    push @$tab, [$p, ($fig->genus_species($fig->genome_of($peg))), scalar($fig->function_of($peg))];
   }
  }

  push @$html, "<h2>Functions in $fam Family</h2>\n",
  "<p>The family $fam has the function ", $fig->family_function($fam), ".\n",
  "The functions shown here are the functions of just the proteins in the SEED database from this family</p>",
  $cgi->start_form,
  &HTML::make_table($col_hdrs, $tab, "Proteins in " . $fig->family_function($fam) . " ($fam)"),
  $cgi->hidden(-name=>'family', -value=>"$fam"), $cgi->submit("Compare FIG Functions"),
  $cgi->end_form;
 }
}
 

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3