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

Annotation of /FigWebServices/protein_info.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.10 - (view) (download)

1 : redwards 1.1 # -*- perl -*-
2 : olson 1.10 #
3 :     # Copyright (c) 2003-2006 University of Chicago and Fellowship
4 :     # for Interpretations of Genomes. All Rights Reserved.
5 :     #
6 :     # This file is part of the SEED Toolkit.
7 :     #
8 :     # The SEED Toolkit is free software. You can redistribute
9 :     # it and/or modify it under the terms of the SEED Toolkit
10 :     # Public License.
11 :     #
12 :     # You should have received a copy of the SEED Toolkit Public License
13 :     # along with this program; if not write to the University of Chicago
14 :     # at info@ci.uchicago.edu or the Fellowship for Interpretation of
15 :     # Genomes at veronika@thefig.info or download a copy from
16 :     # http://www.theseed.org/LICENSE.TXT.
17 :     #
18 :    
19 : redwards 1.1
20 :     =pod
21 :    
22 :     =head1 proteininfo.cgi
23 :    
24 :     Get some information about a bunch of proteins.
25 :    
26 :     =cut
27 :    
28 :     use strict;
29 :     use FIG;
30 :     use HTML;
31 :     use raelib;
32 :     my $raelib=new raelib;
33 :     use CGI;
34 :     my $cgi=new CGI;
35 :     use LWP::Simple qw(!head); # see the caveat in perldoc LWP about importing two head methods.
36 :    
37 :     my $fig;
38 :     eval {
39 :     $fig = new FIG;
40 :     };
41 :    
42 :     if ($@ ne "")
43 :     {
44 :     my $err = $@;
45 :    
46 :     my(@html);
47 :    
48 :     push(@html, $cgi->p("Error connecting to SEED database."));
49 :     if ($err =~ /Could not connect to DBI:.*could not connect to server/)
50 :     {
51 :     push(@html, $cgi->p("Could not connect to relational database of type $FIG_Config::dbms named $FIG_Config::db on port $FIG_Config::dbport."));
52 :     }
53 :     else
54 :     {
55 :     push(@html, $cgi->pre($err));
56 :     }
57 :     &HTML::show_page($cgi, \@html, 1);
58 :     exit;
59 :     }
60 :    
61 :     my $html = [];
62 :     my $user = $cgi->param('user');
63 :    
64 :     unshift(@$html, "<TITLE>The SEED - Protein Information</TITLE>\n");
65 :    
66 : overbeek 1.8 my $ids;
67 :     if ($cgi->param('request')) {
68 :     # figure out if we have any proteins and find out what they are
69 :     my @proteins=$cgi->param('proteins');
70 :     if ($cgi->upload('fileupload'))
71 :     {
72 :     my $fh=$cgi->upload('fileupload');
73 :     push @proteins, (<$fh>);
74 :     }
75 :     if ($cgi->param('korgs'))
76 :     {
77 :     push @proteins, map {$fig->pegs_of($_)} $cgi->param('korgs');
78 :     }
79 :     $ids=&parse_ids(@proteins); # this does it all in one but does not allow error checking
80 :     }
81 : redwards 1.1
82 : overbeek 1.8 if ($ids && $cgi->param('request') eq "Protein Information")
83 : redwards 1.1 {
84 : overbeek 1.8 &protein_info($fig,$cgi,$html,$ids);
85 :     }
86 :     elsif ($ids && $cgi->param('request') eq "Subsystem Information")
87 :     {
88 :     &subsystem_info($fig,$cgi,$html,$ids);
89 : redwards 1.1 }
90 :     else
91 :     {
92 :     &show_initial($fig,$cgi,$html);
93 :     }
94 :    
95 :     &HTML::show_page($cgi,$html,1);
96 :     exit;
97 :    
98 :    
99 :     sub show_initial {
100 :     my ($fig,$cgi,$html)=@_;
101 :     # generate a blank page
102 :     push @$html,
103 : redwards 1.6 $cgi->start_multipart_form(),
104 : redwards 1.2 "<h2>Generate information and links about a series of proteins</h2>\n",
105 : overbeek 1.8 "<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",
106 : redwards 1.2 "<p>Typical IDs are in the following format:</p>\n",
107 :     "<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",
108 :     "<li>gi numbers &nbsp; These are just numeric, please add the characters 'gi|' to make a number like gi|16129669</li>\n",
109 :     "<li>GenBank Accessions &nbsp; numbers and letters such as AAF12034</li>\n</ul>\n",
110 :     "<li><b>SwissProt, PIR, Trembl, Uniprot</b> &nbsp; a single letter and some digits</li></ol>\n",
111 : overbeek 1.8 "<p>", $cgi->submit(-name=>'request', -value=>'Protein Information'), $cgi->submit(-name=>'request', -value=>'Subsystem Information'), $cgi->reset, "</p>\n",
112 :     "<br><b>Choose one or more organisms from this list:</b><br>\n",
113 :     $raelib->scrolling_org_list($cgi, "1"),
114 :     "<b>Or paste some IDs here:</b><br>\n",
115 : redwards 1.6 $cgi->textarea(-name=>"proteins", -rows=>10, -columns=>40), "<br>\n",
116 : overbeek 1.8 "<br><b>Or choose a file here:</b><br>\n",
117 : redwards 1.6 $cgi->filefield(-name=>"fileupload", -size=>50), "<br>\n",
118 : overbeek 1.8 $cgi->submit(-name=>'request', -value=>'Protein Information'), $cgi->submit(-name=>'request', -value=>'Subsystem Information'), $cgi->reset, $cgi->end_form;
119 : redwards 1.1 return $html;
120 :     }
121 :    
122 : overbeek 1.8 sub protein_info {
123 :     my ($fig,$cgi,$html,$ids)=@_;
124 : redwards 1.6 # predefine the color section for the subsys link
125 :     my $color="&color=" . join("&color=", map {@{$ids->{$_}}} keys %$ids);
126 :    
127 : redwards 1.1 my $tab; my @unknowns;
128 :     foreach my $key (keys %$ids) {
129 :     unless (scalar(@{$ids->{$key}})) {
130 :     push @unknowns, $key;
131 :     next;
132 :     }
133 :     my $cs="td rowspan=".scalar(@{$ids->{$key}});
134 :     my $first=[$key, $cs];
135 :     foreach my $peg (@{$ids->{$key}}) {
136 : redwards 1.6
137 :     # OLD STYLE: Regular link into the subsystems page
138 : redwards 1.1 # link to ss is: subsys.cgi?can_alter=$can_alter&SPROUT=$sprout&user=$user&ssa_name=$esc_sub&request=show_ssa&show_clusters=1&sort=by_phylo"
139 : redwards 1.6 #my $ss = join "<br>\n",
140 :     # map {"<a href='subsys.cgi?&user=$user&ssa_name=". $_->[0] ."&request=show_ssa&show_clusters=1&sort=by_phylo'>" . $_->[0] . "</a>"}
141 :     # (sort $fig->subsystems_for_peg($peg));
142 :    
143 :     # NEW STYLE: Link to displaysubsys.cgi
144 :     #display_subsys.cgi?ssa_name=Capsular_polysaccharide_biosynthesis_in_Staphylococcus&color=uni|P95695&color=uni|Q99X66&uni|Q99X65
145 : redwards 1.1 my $ss = join "<br>\n",
146 : redwards 1.6 map {"<a href='display_subsys.cgi?user=$user&ssa_name=". $_->[0] . "$color'>" . $_->[0] . "</a>"}
147 :     (sort $fig->subsystems_for_peg($peg));
148 :    
149 : redwards 1.1 unless ($ss) {$ss=" None "}
150 : redwards 1.6 my $ffp=join "", map {"<a href='proteinfamilies.cgi?user=$user&family=$_'>" . $fig->family_function($_) . "</a><br>\n"} ($fig->families_for_protein($peg));
151 : redwards 1.1 unless ($ffp) {$ffp=" None "}
152 : redwards 1.2 if ($first)
153 :     {
154 : redwards 1.6 push @$tab, [$first, "<a href='protein.cgi?user=$user&prot=$peg'>$peg</a>\n",
155 : redwards 1.5 $fig->genus_species($fig->genome_of($peg)), scalar($fig->function_of($peg, $user)), $ss, $ffp]; undef($first)
156 : redwards 1.2 }
157 :     else
158 :     {
159 : redwards 1.6 push @$tab, ["<a href='protein.cgi?user=$user&prot=$peg'>$peg</a>\n", $fig->genus_species($fig->genome_of($peg)),
160 : redwards 1.5 scalar($fig->function_of($peg, $user)), $ss, $ffp]
161 : redwards 1.2 }
162 : redwards 1.1 }
163 :     }
164 :    
165 : redwards 1.6 push @$html, &HTML::make_table(["ID", "FIG ID<br><small>Link goes to protein page</small>", "Genus Species", "Functional Role", "Subsystems<br><small>Link will color subsystem with all pegs</small>", "Protein Families<br><small>Link will explore Protein Family</small>"], $tab, "IDs"), "\n";
166 : redwards 1.2 if (scalar @unknowns)
167 :     {
168 :     open (OUT, ">$FIG_Config::temp/protein_info_not_found.$$.txt") || die "Can't open $FIG_Config::temp/protein_info_not_found.$$.txt";
169 :     print OUT join "\n", "For request from ", $cgi->remote_host, " couldn't find the following IDs", @unknowns, '';
170 :     close OUT;
171 :     my $list=join "</li>\n<li>", @unknowns;
172 :     push @$html, "<p>We do not know about the following IDs. Sorry.</p><ul><li>$list</li></ul>\n";
173 :     }
174 : redwards 1.1
175 :     }
176 :    
177 :    
178 : overbeek 1.8 sub subsystem_info {
179 :     my ($fig,$cgi,$html,$ids)=@_;
180 :     # predefine the color section for the subsys link
181 :     my $color="&color=" . join("&color=", map {@{$ids->{$_}}} keys %$ids);
182 :    
183 :     my $ss; my $pegcount;
184 :     map {
185 :     my $peg=$_;
186 :     map {$ss->{$_->[0]}->{$peg}++; $pegcount->{$peg}++}
187 :     $fig->subsystems_for_peg($peg);
188 :     }
189 :     map {@{$ids->{$_}}} keys %$ids;
190 :    
191 :     # generate the links to subsystems
192 :     push @$html, "<h3>Subsystems: # of pegs with matching expression level</h3>\n<ul>\n";
193 :     push @$html, map {
194 :     my $color="&color=" . join("&color=", keys %{$ss->{$_}});
195 :     $_="<li><a href='display_subsys.cgi?user=$user&ssa_name=$_$color'>$_</a> (".(scalar(keys %{$ss->{$_}})).")</li>\n";
196 :     }
197 :     sort {scalar(keys %{$ss->{$b}}) <=> scalar(keys %{$ss->{$a}})} keys %$ss;
198 :     push @$html, "</ul>\n";
199 :    
200 :     # now generate the ones that don't have links
201 :     push @$html, "<hr>\n<h3>Pegs Not in Subsystem</h3>\n<ul>";
202 :     push @$html,
203 :     map {$_="<li><a href='protein.cgi?user=$user&prot=$_'>$_</a></li>\n"}
204 :     grep {!$pegcount->{$_}}
205 :     map {@{$ids->{$_}}}
206 :     sort {$a cmp $b} keys %$ids;
207 :     push @$html, "</ul>\n";
208 :    
209 :     }
210 : redwards 1.1
211 :    
212 :    
213 :    
214 :     =head2 parse_ids
215 :    
216 :     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.
217 :    
218 :     =cut
219 :    
220 :     sub parse_ids {
221 :     my @given=@_;
222 :    
223 :    
224 :     # here were are going to parse out what we were given. We will split on whitespace and commas
225 :    
226 :     my $want;
227 :     # If you look through the code, and find a really long run on line, blame GJO
228 :     # he complained about having to delete my beautifully functional code. Perhaps he is worried about
229 :     # disk space or something.
230 : redwards 1.3 map {
231 :     s/^\s+//; s/\s+$//;
232 :     if (/^\d+$/) {$_="gi|".$_}
233 : redwards 1.4 elsif (/^[A-Z]\d+$/) {$_="uni|".$_}
234 : redwards 1.3 @{$want->{$_}}=$fig->by_alias($_) if ($_);
235 :     }
236 :     map {split /[\s*\,]/, $_}
237 :     @given;
238 : overbeek 1.9
239 : redwards 1.1 return $want;
240 :     }
241 :    

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3