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

Annotation of /FigWebServices/protein_info.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.8 - (view) (download)

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3