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

View of /FigWebServices/protein_by_ss.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.6 - (download) (annotate)
Thu Oct 25 22:42:44 2007 UTC (12 years ago) by redwards
Branch: MAIN
CVS Tags: mgrast_dev_08112011, rast_rel_2009_05_18, mgrast_dev_08022011, rast_rel_2014_0912, rast_rel_2008_06_18, myrast_rel40, rast_rel_2008_06_16, mgrast_dev_05262011, rast_rel_2008_12_18, mgrast_dev_04082011, rast_rel_2008_07_21, rast_rel_2010_0928, rast_2008_0924, mgrast_version_3_2, mgrast_dev_12152011, rast_rel_2008_04_23, mgrast_dev_06072011, rast_rel_2008_09_30, rast_rel_2009_0925, rast_rel_2010_0526, rast_rel_2014_0729, mgrast_dev_02212011, rast_rel_2010_1206, mgrast_release_3_0, mgrast_dev_03252011, rast_rel_2010_0118, mgrast_rel_2008_0924, mgrast_rel_2008_1110_v2, rast_rel_2009_02_05, rast_rel_2011_0119, mgrast_rel_2008_0625, mgrast_release_3_0_4, mgrast_release_3_0_2, mgrast_release_3_0_3, mgrast_release_3_0_1, mgrast_dev_03312011, mgrast_release_3_1_2, mgrast_release_3_1_1, mgrast_release_3_1_0, mgrast_dev_04132011, rast_rel_2008_10_09, mgrast_dev_04012011, rast_release_2008_09_29, mgrast_rel_2008_0806, mgrast_rel_2008_0923, mgrast_rel_2008_0919, rast_rel_2009_07_09, rast_rel_2010_0827, mgrast_rel_2008_1110, myrast_33, rast_rel_2011_0928, rast_rel_2008_09_29, mgrast_rel_2008_0917, rast_rel_2008_10_29, mgrast_dev_04052011, mgrast_dev_02222011, rast_rel_2009_03_26, mgrast_dev_10262011, rast_rel_2008_11_24, rast_rel_2008_08_07, HEAD
Changes since 1.5: +8 -84 lines
undoing horrible mistake

# -*- perl -*-
#
# Copyright (c) 2003-2006 University of Chicago and Fellowship
# for Interpretations of Genomes. All Rights Reserved.
#
# This file is part of the SEED Toolkit.
# 
# The SEED Toolkit is free software. You can redistribute
# it and/or modify it under the terms of the SEED Toolkit
# Public License. 
#
# You should have received a copy of the SEED Toolkit Public License
# along with this program; if not write to the University of Chicago
# at info@ci.uchicago.edu or the Fellowship for Interpretation of
# Genomes at veronika@thefig.info or download a copy from
# http://www.theseed.org/LICENSE.TXT.
#


=pod

=head1 proteininfo.cgi

Get some information about a bunch of proteins. 

=cut

# -*- perl -*-
use InterfaceRoutines;
use FIG;
use FIGGenDB;
use FIGjs;
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 $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 - Protein Information</TITLE>\n");

my $ids;
my $tag_to_id;
my $inputs;
if ($cgi->param('request') && $cgi->param('korgs') ) 
{
  push @orgs, $cgi->param('korgs');
  $org = $orgs[0];
  my $ids = &get_input_ids($org);
  &protein_info($fig,$cgi,$html,$ids);
}
else
{
  &show_initial($fig,$cgi,$html);
}


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


sub get_input_ids {
    my($org) = @_;

    my $input =$cgi->param('proteins');
    my @inputs = ();
    if ($input)
    {
	@inputs = grep { /^\S+$/ } split(/\s+/,$input);
    }
    elsif ($cgi->upload('fileupload'))
    {
	my $fh=$cgi->upload('fileupload');
	@inputs = map { ($_ =~ /\S+/g) } <$fh> ;
    }
    if ($cgi->param('request') eq "Protein Information by ID")
    {
	return &parse_by_alias($fig,\@inputs,$org);
    }
    if ($cgi->param('request') eq "Protein Information by Other")
    {
	return &parse_by_search($fig,\@inputs,$org);
    }

}

sub show_initial {
 my ($fig,$cgi,$html)=@_;
 # generate a blank page
 push @$html, 
 $cgi->start_multipart_form(),
 "<h2>Generate information and links about a series of proteins</h2>\n",
 "<p>Please generate a list of protein IDs. There are several methods provided. You can choose one or more organisms from the scrolling list, you can paste some gene or protein IDs into the box or you can upload a file of IDs. Or you can do all three. We will then try and map the IDs that you find onto FIG IDs. If we are able to map them you will see a table of results. If we are unable to map some we'll let you know which ones. You can separate your accessions with spaces, returns, or commas.</p>\n",
 "<p>Typical IDs are in the following format:</p>\n",
 "<ol>\n<li><b>FIG</b>: &nbsp; fig|83333.1.peg.1697</li>\n<li><b>Genbank</b><ul><li>Refseq: &nbsp; begin with NP_ or NC_</li>\n",
 "<li>gi numbers &nbsp; These are just numeric, please add the characters 'gi|' to make a number like gi|16129669</li>\n",
 "<li>GenBank Accessions &nbsp; numbers and letters such as AAF12034</li>\n</ul>\n",
 "<li><b>SwissProt, PIR, Trembl, Uniprot</b> &nbsp; a single letter and some digits</li>\n",
 "<li>Other types of gene/protein identifiers can be used, but these take longer to process</li></ol>\n",
 "<p>","</p>\n",
 "<br><b>Choose one or more organisms from this list:</b><br>\n",
 $raelib->scrolling_org_list($cgi, "1"),
 "<b>Or paste some IDs here:</b><br>\n",
 $cgi->textarea(-name=>"proteins", -rows=>10, -columns=>40), "<br>\n", 
 "<br><b>Or choose a file here:</b><br>\n",
 $cgi->filefield(-name=>"fileupload", -size=>50), "<br>\n",
 
  $cgi->submit(-name=>'request', -value=>'Protein Information by ID'), 
  $cgi->submit(-name=>'request', -value=>'Protein Information by Other'),
  $cgi->reset, $cgi->end_form;

 return $html;
}

sub protein_info {
 my ($fig,$cgi,$html,$ids)=@_;
 my @no_ss_pegs; my $tab; my $no_ss_tab; my @unknowns; my $best_clusters_link; my $fc; my $sprout; 
# predefine the color section for the subsys link

# my @initial_ids = keys(%{$ids});
 foreach $_ (keys(%{$ids}))
 {
     if ($ids->{$_} =~ /^fig/)
     {
	 $pegs{$ids->{$_}} = $_;
     }
     else{push(@unknowns,$_)}
 }
 
 my @pegs = keys(%pegs);

 foreach $peg (@pegs)
 {
    my @subs = $fig->peg_to_subsystems($peg);
    if(!scalar(@subs)){ push(@no_ss_pegs,$peg)}
    else
    {
        foreach $sub ($fig->peg_to_subsystems($peg))
	{
            $pegs_in_subsys{$sub}->{$peg} = 1;
        }
    }
 }

 foreach $subsys (sort keys(%pegs_in_subsys))
 {
    
    my $ss_link = "<a href='display_subsys.cgi?user=$user&ssa_name=". $subsys."'>" . $subsys . "</a>";
       
    @pegs_in_subsys = keys(%{$pegs_in_subsys{$subsys}});
    foreach $peg (@pegs_in_subsys)
    {
       my $first = $pegs{$peg}; 	
       my $ffp=join "", map {"<a href='proteinfamilies.cgi?user=$user&family=$_'>" . $fig->family_function($_) . "</a><br>\n"} ($fig->families_for_protein($peg));
       unless ($ffp) {$ffp=" None "}
       $best_clusters_link = "<a href=" . &cgi_url . "/homologs_in_clusters.cgi?prot=$peg&user=$user&SPROUT=$sprout><img src=\"Html/button-cl.png\" border=\"0\"></a>";
  
       my $in_cluster = &in_cluster_with($fig,$cgi,$peg);
  
       if (defined(my $fc_sc = $in_cluster->{$peg})) 
       {
 	  $fc = &pin_link($cgi,$peg);
       }
       else
       {
          $fc    = "";
       }
     
       push @$tab, [$ss_link, $first, "<a href='protein.cgi?user=$user&prot=$peg'>$peg</a>\n", 
		  $fig->genus_species($fig->genome_of($peg)), scalar($fig->function_of($peg, $user)),$best_clusters_link,$fc,$ffp]; 
    
    }
  }
  
  foreach my $peg (@no_ss_pegs) 
  {
       my $first = $pegs{$peg}; 	
       my $ffp=join "", map {"<a href='proteinfamilies.cgi?user=$user&family=$_'>" . $fig->family_function($_) . "</a><br>\n"} ($fig->families_for_protein($peg));
       unless ($ffp) {$ffp=" None "}
       $best_clusters_link = "<a href=" . &cgi_url . "/homologs_in_clusters.cgi?prot=$peg&user=$user&SPROUT=$sprout><img src=\"Html/button-cl.png\" border=\"0\"></a>";
  
       my $in_cluster = &in_cluster_with($fig,$cgi,$peg);
  
       if (defined(my $fc_sc = $in_cluster->{$peg})) 
       {
 	  $fc = &pin_link($cgi,$peg);
       }
       else
       {
          $fc    = "";
       }
       
       push @$no_ss_tab, ["None", $first, "<a href='protein.cgi?user=$user&prot=$peg'>$peg</a>\n", 
		  $fig->genus_species($fig->genome_of($peg)), scalar($fig->function_of($peg, $user)),$best_clusters_link,$fc,$ffp]; 
   
   }

 $tab = [sort(@$tab)];
   
 push @$html, &HTML::make_table(["Subsystems<br><small>Link will color subsystem with all pegs</small>","ID", "FIG ID<br><small>Link goes to protein page</small>", "Genus Species", "Functional Role", "find<br>best<br>clusters","pins","Protein Families<br><small>Link will explore Protein Family</small>"], $tab, "IDs"), "\n";

 push (@$html,"<br><h3>Pegs Not in Subsystems</h3></br>");

 push @$html, &HTML::make_table(["Subsystems<br><small>Link will color subsystem with all pegs</small>","ID", "FIG ID<br><small>Link goes to protein page</small>", "Genus Species", "Functional Role", "find<br>best<br>clusters","pins","Protein Families<br><small>Link will explore Protein Family</small>"], $no_ss_tab, "IDs"), "\n";


 if (scalar @unknowns) 
 {
   open (OUT, ">$FIG_Config::temp/protein_info_not_found.$$.txt") || die "Can't open $FIG_Config::temp/protein_info_not_found.$$.txt";
   print OUT join "\n", "For request from ", $cgi->remote_host, " couldn't find the following IDs", @unknowns, '';
   close OUT;
   my $list=join "</li>\n<li>", @unknowns;
   push @$html, "<p>We do not know about the following IDs. Sorry.</p><ul><li>$list</li></ul>\n";
  }
 
}

sub ev_link {
    my($cgi,$neigh,$sc) = @_;

    my $prot = $cgi->param('prot');
    my $sprout = $cgi->param('SPROUT');
    my $link = $cgi->url() . "?request=show_coupling_evidence&prot=$prot&to=$neigh&SPROUT=$sprout";
    return "<a href=$link>$sc</a>";
}

=head2 parse_ids

Given an array or list of IDs in any format separated from each other by spaces or commas, this will return a reference to a hash. The key is the ID, and the value is a reference to an arrays of the FIG IDs that match.

=cut

sub parse_by_search
{

    my ($fig,$given,$org) =@_;
    my %hash;
  
    foreach my $id (@$given)
    {
	 chomp($id);
         my $temp = $id; 
         my $value = "none";
         if($id !~/fig/)
         {
    	     my ($peg_index_data,undef) = $fig->search_index($id);
             foreach my $peg (map { $_->[0] } @$peg_index_data)
             {
		 if ($peg  =~ /$org/ )
		 {  
		     $value = $peg;
	         }
             }
         }
         
         else{ $value = $temp};
  
	 $hash{$id} = $value;
    
  }
  return \%hash;
}

sub parse_by_alias 
{

    my ($fig,$given,$org) =@_;
    my %hash;
  
    foreach my $id (@$given)
    {
	 chomp($id);
         my $temp = $id; 
         my $value = "none";
         if($id !~/fig/)
         {
    	     my @pegs = $fig->by_alias($id);
             foreach my $peg (@pegs)
             {
		 if ($peg  =~ /$org/ )
		 {  
		     $value = $peg;
	         }
             }
         }
         
         else{ $value = $temp};
  
	 $hash{$id} = $value;
    
  }
  return \%hash;
}



sub pin_link {
    my($cgi,$peg) = @_;
    my $user = $cgi->param('user');
    $user = defined($user) ? $user : "";

    my $sprout = $cgi->param('SPROUT') ? 1 : "";
    my $cluster_url  = "chromosomal_clusters.cgi?prot=$peg&user=$user&uni=1&SPROUT=$sprout";

    my $cluster_img = 0 ? "*" : '<img src="Html/button-pins-1.png" border="0">';
    my $cluster_link = "<a href=\"$cluster_url\" target=pinned_region.$$>$cluster_img</a>";
    return $cluster_link;
}

sub in_cluster_with 
{
    my($fig_or_sprout,$cgi,$peg) = @_;
    my %in_cluster;

    if ($fig_or_sprout->table_exists('fc_pegs') && $fig_or_sprout->is_complete(&FIG::genome_of($peg)))
    {
	%in_cluster = map { $_->[0] => &ev_link($cgi,$_->[0],$_->[1]) } $fig_or_sprout->coupled_to($peg);
	if (keys(%in_cluster) > 0)
	{
	    $in_cluster{$peg} = "";
	}
	elsif ($cgi->param('fc'))
	{
	    %in_cluster = map { $_ => "" } $fig_or_sprout->in_cluster_with($peg);
	    if (keys(%in_cluster) == 1)
	    {
		my @tmp = keys(%in_cluster);
		delete $in_cluster{$tmp[0]};
	    }
	}
    }
    return \%in_cluster;
}

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3