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

Annotation of /FigWebServices/sigs.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.47 - (view) (download)

1 : overbeek 1.15 ##################################################################
2 : olson 1.14 # Copyright (c) 2003-2006 University of Chicago and Fellowship
3 :     # for Interpretations of Genomes. All Rights Reserved.
4 :     #
5 :     # This file is part of the SEED Toolkit.
6 :     #
7 :     # The SEED Toolkit is free software. You can redistribute
8 :     # it and/or modify it under the terms of the SEED Toolkit
9 :     # Public License.
10 :     #
11 :     # You should have received a copy of the SEED Toolkit Public License
12 :     # along with this program; if not write to the University of Chicago
13 :     # at info@ci.uchicago.edu or the Fellowship for Interpretation of
14 :     # Genomes at veronika@thefig.info or download a copy from
15 :     # http://www.theseed.org/LICENSE.TXT.
16 :     #
17 : overbeek 1.15 ##################################################################
18 : olson 1.14
19 : efrank 1.1 use FIG;
20 : olson 1.13 require SproutFIG;
21 : efrank 1.1
22 :     use HTML;
23 :     use CGI;
24 : parrello 1.20 use Tracer;
25 : parrello 1.36 use PageBuilder;
26 : efrank 1.1 my $cgi = new CGI;
27 :    
28 : overbeek 1.8 if (0) {
29 :     my $VAR1;
30 :     eval(join("",`cat /tmp/sig_parms`));
31 :     $cgi = $VAR1;
32 :     # print STDERR &Dumper($cgi);
33 :     }
34 :    
35 :     if (0) {
36 : efrank 1.1 print $cgi->header;
37 :     my @params = $cgi->param;
38 :     print "<pre>\n";
39 : overbeek 1.8 foreach $_ (@params) {
40 : parrello 1.36 print "$_\t:",join(",",$cgi->param($_)),":\n";
41 : overbeek 1.8 }
42 :    
43 :     if (0) {
44 :     if (open(TMP,">/tmp/sig_parms")) {
45 : parrello 1.36 print TMP &Dumper($cgi);
46 :     close(TMP);
47 :     }
48 : efrank 1.1 }
49 :     exit;
50 :     }
51 :    
52 :     my $html = [];
53 :    
54 : overbeek 1.9 my($fig_or_sprout);
55 :     if ($cgi->param('SPROUT')) {
56 :     $is_sprout = 1;
57 :     $fig_or_sprout = new SproutFIG($FIG_Config::sproutDB, $FIG_Config::sproutData);
58 :     } else {
59 :     $is_sprout = 0;
60 :     $fig_or_sprout = new FIG;
61 :     unshift @$html, "<TITLE>The SEED Signature Genes Page</TITLE>\n";
62 :     }
63 : parrello 1.45
64 :     # Initialize tracing.
65 : parrello 1.46 ETracing($cgi);
66 : parrello 1.45
67 : overbeek 1.42 my $bbhs = $cgi->param('bbhs');
68 :    
69 : efrank 1.1 my @tmp = grep { $_ =~ /^\d+\.\d+$/ } $cgi->param;
70 :     my @set1 = grep { $cgi->param($_) eq "set1" } @tmp;
71 :     my @set2 = grep { $cgi->param($_) eq "set2" } @tmp;
72 :    
73 :     my $given = $cgi->param('given');
74 :    
75 : parrello 1.41 # Determine the operating mode.
76 :     my $submit1 = $cgi->param("Find Common Proteins");
77 :     my $submit2 = $cgi->param("Find Discriminating Proteins");
78 :     # This will be set to 1 for common proteins and 2 for discriminating proteins.
79 :     my $mode = 0;
80 :    
81 :     if (! $given && ($submit1 || $submit2)) {
82 :     push @$html, $cgi->h3("You must select a given organism.");
83 :     } else {
84 :     # Here the user wantsd to process data. Insure the given organism is in
85 :     # set 1.
86 :     my @found = grep { $_ eq $given } @set1;
87 :     if (! @found) {
88 :     push @set1, $given;
89 :     }
90 :     if ($submit1) {
91 :     $mode = 1;
92 :     if (@set2 > 0) {
93 :     push @$html, $cgi->h3("Organisms from set 2 were ignored.");
94 :     }
95 :     } elsif ($submit2) {
96 :     if (@set2 == 0) {
97 :     push @$html, $cgi->h3("Could not process: set 2 was empty.");
98 :     } else {
99 :     $mode = 2;
100 :     }
101 :     }
102 :     }
103 :    
104 :     if ($mode == 0) {
105 : efrank 1.1
106 :     $col_hdrs = ["Given","Set 1","","Set 2","genome","Genus/Species"];
107 :     $tab = [];
108 : parrello 1.45 Trace("Retrieving genomes.") if T(2);
109 : overbeek 1.9 @orgs = $fig_or_sprout->genomes("complete");
110 : parrello 1.45 Trace("Processing genomes.") if T(2);
111 : efrank 1.1 foreach $org (@orgs)
112 :     {
113 : parrello 1.36 $full{$org} = $fig_or_sprout->genus_species($org);
114 : efrank 1.1 }
115 :     @orgs = sort { $full{$a} cmp $full{$b} } @orgs;
116 :    
117 :     @given = $cgi->radio_group(-name => 'given',
118 : parrello 1.36 -values => [@orgs],
119 :     -nolabels => 1);
120 : parrello 1.41 # We're going to create a navigation bar here that gets you automatically
121 :     # to the first organism beginning with a specified letter.
122 : parrello 1.45 Trace("Creating navigation bar.") if T(2);
123 : parrello 1.41 my $bar = $cgi->a({ name => "bar" },"");
124 :     my $currLetter = "";
125 : efrank 1.1 foreach $org (@orgs)
126 :     {
127 : parrello 1.41 my $name = $full{$org};
128 :     my $backToTop = "";
129 :     if (substr($name, 0, 1) ne $currLetter) {
130 :     # Here we have a navigation target: the first organism whose name begins
131 :     # with a new letter. We put in the name label
132 :     $currLetter = substr($name, 0, 1);
133 :     $bar .= $cgi->a({ href => "#$currLetter" }, $currLetter) . " ";
134 :     $name = $cgi->a({ name => $currLetter },"") . $name;
135 :     $backToTop = $cgi->a({ href => "#bar"}, "TOP");
136 :     }
137 : parrello 1.36 push(@$tab,[shift @given,
138 : efrank 1.1 $cgi->radio_group(-name => $org,
139 : parrello 1.36 -default => 'neither',
140 :     -values => ['set1','neither','set2'],
141 :     -nolabels => 1
142 :     ),
143 :     $org,
144 : parrello 1.41 $name, $backToTop]);
145 : efrank 1.1 }
146 : overbeek 1.10 my $sprout = $cgi->param('SPROUT') ? 1 : 0;
147 : parrello 1.41 # Create the navigation bar.
148 : efrank 1.1 push(@$html,$cgi->start_form(-action => 'sigs.cgi'),
149 : overbeek 1.42 $cgi->hidden(-name => 'SPROUT', -value => $sprout));
150 :     if (! $sprout)
151 :     {
152 :     push(@$html,"<br>",$cgi->checkbox( -name => 'bbhs', -value => 1, -override => 1, -label => 'Use BBHs' ),"<br>");
153 :     }
154 : parrello 1.45 Trace("Creating main form.") if T(2);
155 : overbeek 1.42 push(@$html,$cgi->h3("Find Proteins from Given Organism that Discriminate Set 1 from Set 2"),
156 : parrello 1.36 $cgi->br, "Similarity Cutoff: ",$cgi->textfield(-name => "cutoff", -size => 10, -value => 1.0e-10),
157 :     $cgi->br,
158 :     $cgi->checkbox( -name => 'sort_by_func', -value => 1, -override => 1, -checked => 0, -label => 'Sort by Function'),
159 :     $cgi->br,
160 :     $cgi->checkbox( -name => 'write_tab', -value => 1, -override => 1, -checked => 0, -label => 'Export Tab Delimited Table'),
161 :     $cgi->br,
162 : overbeek 1.42 $cgi->br,
163 : parrello 1.41 $cgi->submit("Find Discriminating Proteins"),$cgi->reset,
164 :     $cgi->br,
165 : parrello 1.36 $cgi->br,
166 : parrello 1.41 $cgi->h3("Find Proteins from Given Organism that are Common to Set 1"),
167 : parrello 1.36 $cgi->br,
168 : parrello 1.41 "Minimum matches from Set 1: ", $cgi->textfield(-name => minN, -size => 5),
169 : parrello 1.36 $cgi->br,
170 : parrello 1.41 $cgi->submit("Find Common Proteins"),$cgi->reset,
171 :     $cgi->br, $cgi->br,
172 :     $cgi->h3("Select Given, Set 1, and Set 2"),
173 :     $cgi->p($bar),
174 :     &HTML::make_table($col_hdrs,$tab,"Pick organisms for Set 1 and Set 2"),
175 :     $cgi->br);
176 : parrello 1.28 if ($cgi->param('TTYPE')) {
177 :     push @$html,
178 :     $cgi->br,
179 :     $cgi->br, "Tracing: ",$cgi->textfield(-name => "TRACE", -size => 30, -value => ""),
180 :     $cgi->hidden(-name => 'TTYPE', -value => $cgi->param('TTYPE'));
181 :     }
182 :     push @$html,
183 : parrello 1.36 $cgi->end_form,
184 :     "\n";
185 : parrello 1.41 } else {
186 :     # Mode 1 or 2
187 : efrank 1.1 my $sim_cutoff = $cgi->param('sim_cutoff');
188 :     if (! $sim_cutoff) { $sim_cutoff = 1.0e-10 }
189 : parrello 1.41 my @hits;
190 :     if ($mode == 2) {
191 : parrello 1.45 Trace("Computing discriminants.") if T(2);
192 : overbeek 1.42 @hits = &differentiating_genes(\@set1,\@set2,$given,$sim_cutoff,$is_sprout,$bbhs);
193 : parrello 1.41 Trace(scalar(@hits) . " hits found by differentiating_genes.") if T(3);
194 :     if ($cgi->param('sort_by_func')) {
195 :     @hits = sort { ($a->[2] cmp $b->[2]) or ($b->[1] <=> $a->[1]) or (&FIG::by_fig_id($a->[0],$b->[0])) } @hits;
196 :     } else {
197 :     @hits = sort { ($b->[1] <=> $a->[1]) || (&FIG::by_fig_id($a->[0],$b->[0])) } @hits;
198 :     }
199 : efrank 1.1
200 : parrello 1.41 if ($cgi->param('write_tab')) {
201 :     push(@$html,"<pre>\n");
202 :     foreach $_ (@hits) {
203 :     push(@$html,join("\t",@$_) . "\n");
204 : parrello 1.36 }
205 : parrello 1.41 push(@$html,"</pre>\n");
206 :     } else {
207 : overbeek 1.42 $col_hdrs = ["","Gene","Score","Function","Subsystems"];
208 : parrello 1.41 $tab = [];
209 :     my $gs = $fig_or_sprout->genus_species($given);
210 :     $title = "Genes in $gs that Discriminate";
211 :     my $subscript = 1;
212 :     foreach $_ (@hits) {
213 :     my($peg,$score,$function) = @$_;
214 : parrello 1.47 my @sub = grep { $fig_or_sprout->usable_subsystem($_) } $fig_or_sprout->peg_to_subsystems($peg);
215 :     my $sprout_param = ($cgi->param('SPROUT') ? "&SPROUT=1" : "");
216 :     my $user = $cgi->param('user') || "";
217 :     my @linkedSubs = map { $cgi->a({href => "./display_subsys.cgi?ssa_name=$_$sprout_param&request=show_ssa&user=$user&focus=$peg&show_clusters=1"},
218 :     $_) } @sub;
219 :     push(@$tab,[$subscript,&HTML::fid_link($cgi,$peg,"local"),$score,$function,join("<br>",@linkedSubs)]);
220 : parrello 1.41 $subscript++;
221 : parrello 1.36 }
222 : parrello 1.41 push(@$html,&HTML::make_table($col_hdrs,$tab,$title));
223 :     }
224 :     } else {
225 :     # Mode 1
226 :     my($i,$j,%which_col,$peg1,$func1,$link,$genome1,$hit);
227 :     my $minN = $cgi->param('minN');
228 :     $minN = $minN ? $minN : @set1;
229 : overbeek 1.42 @hits = &common_genes(\@set1,$given,$sim_cutoff,$minN,$is_sprout,$bbhs);
230 : parrello 1.41 $col_hdrs = ["",&FIG::abbrev($fig_or_sprout->genus_species($given)),"Score","Function"];
231 :     for ($i=0; ($i < @set1); $i++) {
232 :     $which_col{$set1[$i]} = $i+4;
233 :     push(@$col_hdrs,&FIG::abbrev($fig_or_sprout->genus_species($set1[$i])));
234 :     }
235 :    
236 :     $tab = [];
237 :     $title = "Genes in Common";
238 : parrello 1.36
239 : parrello 1.41 for ($j=0; ($j < @hits); $j++) {
240 :     my($peg,$score,$hits) = @{$hits[$j]};
241 :     my $func = scalar $fig_or_sprout->function_of($peg,$cgi->param('user'));
242 :     my $row = [$j+1,&HTML::fid_link($cgi,$peg,"local"),$score,$func];
243 :     for ($i=0; ($i < @set1); $i++) {
244 :     push(@$row,"");
245 : parrello 1.36 }
246 : parrello 1.41 foreach $hit (@$hits) {
247 :     ($peg1,$func1) = @$hit;
248 :     $genome1 = &FIG::genome_of($peg1);
249 :     $col = $which_col{$genome1};
250 :     $link = &HTML::fid_link($cgi,$peg1,"local");
251 :     $row->[$col] = ($func eq $func1) ? $link : "*$link";
252 : parrello 1.36 }
253 : parrello 1.41 push(@$tab,$row);
254 : parrello 1.36 }
255 : parrello 1.41 push(@$html,&HTML::make_table($col_hdrs,$tab,$title));
256 : efrank 1.1 }
257 :     }
258 : parrello 1.35 if ($is_sprout) {
259 :     # For sprout, we use a template.
260 : parrello 1.39 my $template = "$FIG_Config::template_url/Sigs_tmpl.php";
261 : parrello 1.45 my $traceList = QTrace("html");
262 : parrello 1.40 my $result = PageBuilder::Build($template, { data => join("\n", @$html),
263 :     tracing => $traceList }, "Html");
264 : parrello 1.38 print "CONTENT-TYPE: text/html\n\n";
265 : parrello 1.39 print $result;
266 : parrello 1.35 } else {
267 :     # For SEED, a normal SEED page.
268 : parrello 1.45 push @$html, QTrace("html");
269 : parrello 1.35 &HTML::show_page($cgi,$html);
270 :     }
271 : efrank 1.1
272 : overbeek 1.6 sub common_genes {
273 : overbeek 1.42 my($set1,$given,$sim_cutoff,$minN,$is_sprout,$bbhs) = @_;
274 : overbeek 1.6 my %set1 = map { $_ => 1 } @$set1;
275 :     if ($set1{$given})
276 :     {
277 : parrello 1.36 $minN--;
278 :     $set1{$given} = 0;
279 : overbeek 1.6 }
280 :    
281 : overbeek 1.9 foreach $peg ($fig_or_sprout->all_features($given,"peg"))
282 : overbeek 1.6 {
283 : parrello 1.36 undef %hits_set1;
284 : overbeek 1.42 foreach $sim (($is_sprout || $bbhs) ? $fig_or_sprout->bbhs($peg, $sim_cutoff) : $fig_or_sprout->sims($peg, 1000, $sim_cutoff, "fig"))
285 : parrello 1.36 {
286 : overbeek 1.42 $id2 = ($is_sprout || $bbhs) ? $sim->[0] : $sim->[1]; # id2
287 : parrello 1.36 if ($id2 =~ /^fig\|(\d+\.\d+)/)
288 :     {
289 :     my $org1 = $1;
290 :     if ($set1{$org1})
291 :     {
292 :     if (! $hits_set1{$org1})
293 :     {
294 :     $hits_set1{$org1} = $id2;
295 :     }
296 :     }
297 :     }
298 :     }
299 :     $sc = keys(%hits_set1);
300 :     if ($sc >= $minN)
301 :     {
302 :     push(@hits,[$peg,$sc,[map { [$hits_set1{$_}, scalar $fig_or_sprout->function_of($hits_set1{$_})] } keys(%hits_set1)]]);
303 :     }
304 : overbeek 1.6 }
305 :     return @hits;
306 :     }
307 : parrello 1.36
308 : efrank 1.1 sub differentiating_genes {
309 : overbeek 1.42 my($set1,$set2,$given,$sim_cutoff,$is_sprout,$bbhs) = @_;
310 : efrank 1.1 my %set1 = map { $_ => 1 } @$set1;
311 :     my %set2 = map { $_ => 1 } @$set2;
312 :    
313 :     my(%hits_set1,%hits_set2,@hits,$sim,$id2,$peg);
314 : parrello 1.40 my $pegCount = 0;
315 :     my $simCount = 0;
316 : overbeek 1.9 foreach $peg ($fig_or_sprout->all_features($given,"peg"))
317 : efrank 1.1 {
318 : parrello 1.40 $pegCount++;
319 : parrello 1.36 undef %hits_set1; undef %hits_set2;
320 :     $hits_set1{&FIG::genome_of($peg)} = 1;
321 : parrello 1.40 Trace("Processing $peg.") if T(4);
322 : overbeek 1.42 foreach $sim (($is_sprout || $bbhs) ? $fig_or_sprout->bbhs($peg, $sim_cutoff) : $fig_or_sprout->sims($peg, 1000, $sim_cutoff, "fig"))
323 : parrello 1.36 {
324 : parrello 1.40 $simCount++;
325 : overbeek 1.42 $id2 = ($is_sprout || $bbhs) ? $sim->[0] : $sim->[1];
326 : parrello 1.23 Trace("SIG tool sim check for $peg vs. $id2.") if T(4);
327 : parrello 1.36 if ($id2 =~ /^fig\|(\d+\.\d+)/)
328 :     {
329 :     my $org1 = $1;
330 :     if ($set1{$org1})
331 :     {
332 :     $hits_set1{$org1} = 1;
333 :     }
334 :     elsif ($set2{$org1})
335 :     {
336 :     $hits_set2{$org1} = 1;
337 :     }
338 :     }
339 :     }
340 :     my $n_set1 = keys(%hits_set1);
341 :     my $n_set2 = keys(%hits_set2);
342 :    
343 :     # my $sc = sprintf "%.3f", ($n_set1 / @set1) - (($n_set2 / @set2) * $fudge);
344 :     my $sc = sprintf "%.3f", &sig($n_set1,(@set1 - $n_set1),$n_set2,(@set2 - $n_set2));
345 :     if ($sc >= 1)
346 :     {
347 :     push(@hits,[$peg,$sc,scalar $fig_or_sprout->function_of($peg)]);
348 :     }
349 : efrank 1.1 }
350 : parrello 1.40 Trace(scalar(@hits) . " hits found by differentiator off of $simCount sims for $pegCount pegs with cutoff $sim_cutoff.") if T(3);
351 : efrank 1.1 return @hits;
352 :     }
353 :    
354 :     sub sig {
355 :     my($in_has,$in_has_not,$out_has,$out_has_not) = @_;
356 :     my($sx,$sy,$xx,$xy,$yy,$din,$dout);
357 :     $sx = $in_has + $in_has_not;
358 :     $sy = $out_has + $out_has_not;
359 :     $xx = ($in_has * $in_has) + ($in_has_not * $in_has_not);
360 :     $xy = ($in_has * $out_has) + ($in_has_not * $out_has_not);
361 :     $yy = ($out_has * $out_has) + ($out_has_not * $out_has_not);
362 :     (($sx > 0) && ($yy > 0) && ($sy > 0) && ($xx > 0)) || return 0;
363 :     $din = 1 - (($sy * $xy) / ($sx * $yy));
364 :     $dout = 1 - (($sx * $xy) / ($sy * $xx));
365 :     return $din+$dout;
366 :     }
367 :    

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3