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

Annotation of /FigWebServices/sigs.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.39 - (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.20 my $tracing = $cgi->param('TRACE');
64 :     if ($tracing) {
65 : parrello 1.28 TSetup($tracing, $cgi->param('TTYPE'));
66 : parrello 1.20 }
67 : overbeek 1.9
68 : efrank 1.1 my @tmp = grep { $_ =~ /^\d+\.\d+$/ } $cgi->param;
69 :     my @set1 = grep { $cgi->param($_) eq "set1" } @tmp;
70 :     my @set2 = grep { $cgi->param($_) eq "set2" } @tmp;
71 :    
72 :     my $given = $cgi->param('given');
73 :    
74 :     if (((@set1 == 0) && (@set2 == 0)) || (! $given))
75 :     {
76 :    
77 :     $col_hdrs = ["Given","Set 1","","Set 2","genome","Genus/Species"];
78 :     $tab = [];
79 :    
80 : overbeek 1.9 @orgs = $fig_or_sprout->genomes("complete");
81 : efrank 1.1
82 :     foreach $org (@orgs)
83 :     {
84 : parrello 1.36 $full{$org} = $fig_or_sprout->genus_species($org);
85 : efrank 1.1 }
86 :     @orgs = sort { $full{$a} cmp $full{$b} } @orgs;
87 :    
88 :     @given = $cgi->radio_group(-name => 'given',
89 : parrello 1.36 -values => [@orgs],
90 :     -nolabels => 1);
91 : efrank 1.1
92 :     foreach $org (@orgs)
93 :     {
94 : parrello 1.36 push(@$tab,[shift @given,
95 : efrank 1.1 $cgi->radio_group(-name => $org,
96 : parrello 1.36 -default => 'neither',
97 :     -values => ['set1','neither','set2'],
98 :     -nolabels => 1
99 :     ),
100 :     $org,
101 :     $full{$org}]);
102 : efrank 1.1 }
103 : overbeek 1.10 my $sprout = $cgi->param('SPROUT') ? 1 : 0;
104 : efrank 1.1 push(@$html,$cgi->start_form(-action => 'sigs.cgi'),
105 : parrello 1.36 $cgi->hidden(-name => 'SPROUT', -value => $sprout),
106 :     $cgi->h1("Find Proteins that Discriminate Two Sets of Organisms or Are Common to a Set of Organisms"),
107 :     &HTML::make_table($col_hdrs,$tab,"Pick organisms for Set 1 and Set 2"),
108 :     $cgi->br, "Similarity Cutoff: ",$cgi->textfield(-name => "cutoff", -size => 10, -value => 1.0e-10),
109 :     $cgi->br,
110 :     $cgi->checkbox( -name => 'sort_by_func', -value => 1, -override => 1, -checked => 0, -label => 'Sort by Function'),
111 :     $cgi->br,
112 :     $cgi->checkbox( -name => 'write_tab', -value => 1, -override => 1, -checked => 0, -label => 'Export Tab Delimited Table'),
113 :     $cgi->br,
114 :     $cgi->br,
115 :     $cgi->submit("Find the Discriminating Proteins from Given Organism"),$cgi->reset,
116 :     $cgi->br,
117 :     $cgi->br,
118 :     $cgi->submit("Find Genes from Checked Organism and in Organisms from Set 1"),
119 :     " (minimum matches from Set 1: )", $cgi->textfield(-name => minN, -size => 5));
120 : parrello 1.28 if ($cgi->param('TTYPE')) {
121 :     push @$html,
122 :     $cgi->br,
123 :     $cgi->br, "Tracing: ",$cgi->textfield(-name => "TRACE", -size => 30, -value => ""),
124 :     $cgi->hidden(-name => 'TTYPE', -value => $cgi->param('TTYPE'));
125 :     }
126 :     push @$html,
127 : parrello 1.36 $cgi->end_form,
128 :     "\n";
129 : efrank 1.1 }
130 :     else
131 :     {
132 :     my $sim_cutoff = $cgi->param('sim_cutoff');
133 :     if (! $sim_cutoff) { $sim_cutoff = 1.0e-10 }
134 :    
135 : overbeek 1.6 if (@set1 > 0)
136 :     {
137 : parrello 1.36 my @hits;
138 :     if (@set2 > 0)
139 :     {
140 :     @hits = &differentiating_genes(\@set1,\@set2,$given,$sim_cutoff,$is_sprout);
141 : parrello 1.20 Trace(scalar(@hits) . " hits found by differentiating_genes.") if T(3);
142 : parrello 1.36 if ($cgi->param('sort_by_func'))
143 :     {
144 :     @hits = sort { ($a->[2] cmp $b->[2]) or ($b->[1] <=> $a->[1]) or (&FIG::by_fig_id($a->[0],$b->[0])) } @hits;
145 :     }
146 :     else
147 :     {
148 :     @hits = sort { ($b->[1] <=> $a->[1]) || (&FIG::by_fig_id($a->[0],$b->[0])) } @hits;
149 :     }
150 :    
151 :     if ($cgi->param('write_tab'))
152 :     {
153 :     push(@$html,"<pre>\n");
154 :     foreach $_ (@hits)
155 :     {
156 :     push(@$html,join("\t",@$_) . "\n");
157 :     }
158 :     push(@$html,"</pre>\n");
159 :     }
160 :     else
161 :     {
162 :     $col_hdrs = ["","Gene","Score","Function"];
163 :     $tab = [];
164 :     my $gs = $fig_or_sprout->genus_species($given);
165 :     $title = "Genes in $gs that Discriminate";
166 :     my $subscript = 1;
167 :     foreach $_ (@hits)
168 :     {
169 :     my($peg,$score,$function) = @$_;
170 :     push(@$tab,[$subscript,&HTML::fid_link($cgi,$peg,"local"),$score,$function]);
171 :     $subscript++;
172 :     }
173 :    
174 :     push(@$html,&HTML::make_table($col_hdrs,$tab,$title));
175 :     }
176 :     }
177 :     else
178 :     {
179 :     my($i,$j,%which_col,$peg1,$func1,$link,$genome1,$hit);
180 :     my $minN = $cgi->param('minN');
181 :     $minN = $minN ? $minN : @set1;
182 :     @hits = &common_genes(\@set1,$given,$sim_cutoff,$minN,$is_sprout);
183 :     $col_hdrs = ["",&FIG::abbrev($fig_or_sprout->genus_species($given)),"Score","Function"];
184 :     for ($i=0; ($i < @set1); $i++)
185 :     {
186 :     $which_col{$set1[$i]} = $i+4;
187 :     push(@$col_hdrs,&FIG::abbrev($fig_or_sprout->genus_species($set1[$i])));
188 :     }
189 : overbeek 1.6
190 : parrello 1.36 $tab = [];
191 :     $title = "Genes in Common";
192 : efrank 1.1
193 : parrello 1.36 for ($j=0; ($j < @hits); $j++)
194 :     {
195 :     my($peg,$score,$hits) = @{$hits[$j]};
196 :     my $func = scalar $fig_or_sprout->function_of($peg,$cgi->param('user'));
197 :     my $row = [$j+1,&HTML::fid_link($cgi,$peg,"local"),$score,$func];
198 :     for ($i=0; ($i < @set1); $i++)
199 :     {
200 :     push(@$row,"");
201 :     }
202 :     foreach $hit (@$hits)
203 :     {
204 :     ($peg1,$func1) = @$hit;
205 :     $genome1 = &FIG::genome_of($peg1);
206 :     $col = $which_col{$genome1};
207 :     $link = &HTML::fid_link($cgi,$peg1,"local");
208 :     $row->[$col] = ($func eq $func1) ? $link : "*$link";
209 :     }
210 :     push(@$tab,$row);
211 :     }
212 :     push(@$html,&HTML::make_table($col_hdrs,$tab,$title));
213 :     }
214 : overbeek 1.6 }
215 :     else
216 : efrank 1.1 {
217 : parrello 1.36 push(@$html,$cgi->h1("You need to fill in at least Set1"));
218 : efrank 1.1 }
219 :     }
220 : parrello 1.35 if ($is_sprout) {
221 :     # For sprout, we use a template.
222 : parrello 1.39 my $template = "$FIG_Config::template_url/Sigs_tmpl.php";
223 :     my $result = PageBuilder::Build($template, { data => join("\n", @$html) }, "Html");
224 : parrello 1.38 print "CONTENT-TYPE: text/html\n\n";
225 : parrello 1.39 print $result;
226 : parrello 1.35 } else {
227 :     # For SEED, a normal SEED page.
228 :     &HTML::show_page($cgi,$html);
229 :     }
230 : efrank 1.1
231 : overbeek 1.6 sub common_genes {
232 : overbeek 1.29 my($set1,$given,$sim_cutoff,$minN,$is_sprout) = @_;
233 : overbeek 1.6 my %set1 = map { $_ => 1 } @$set1;
234 :     if ($set1{$given})
235 :     {
236 : parrello 1.36 $minN--;
237 :     $set1{$given} = 0;
238 : overbeek 1.6 }
239 :    
240 : overbeek 1.9 foreach $peg ($fig_or_sprout->all_features($given,"peg"))
241 : overbeek 1.6 {
242 : parrello 1.36 undef %hits_set1;
243 :     foreach $sim ($is_sprout ? $fig_or_sprout->bbhs($peg, $sim_cutoff) : $fig_or_sprout->sims($peg, 1000, $sim_cutoff, "fig"))
244 :     {
245 :     $id2 = $is_sprout ? $sim->[0] : $sim->[1]; # id2
246 :     if ($id2 =~ /^fig\|(\d+\.\d+)/)
247 :     {
248 :     my $org1 = $1;
249 :     if ($set1{$org1})
250 :     {
251 :     if (! $hits_set1{$org1})
252 :     {
253 :     $hits_set1{$org1} = $id2;
254 :     }
255 :     }
256 :     }
257 :     }
258 :     $sc = keys(%hits_set1);
259 :     if ($sc >= $minN)
260 :     {
261 :     push(@hits,[$peg,$sc,[map { [$hits_set1{$_}, scalar $fig_or_sprout->function_of($hits_set1{$_})] } keys(%hits_set1)]]);
262 :     }
263 : overbeek 1.6 }
264 :     return @hits;
265 :     }
266 : parrello 1.36
267 : efrank 1.1 sub differentiating_genes {
268 : overbeek 1.29 my($set1,$set2,$given,$sim_cutoff,$is_sprout) = @_;
269 : efrank 1.1 my %set1 = map { $_ => 1 } @$set1;
270 :     my %set2 = map { $_ => 1 } @$set2;
271 :    
272 :     my(%hits_set1,%hits_set2,@hits,$sim,$id2,$peg);
273 :    
274 : overbeek 1.9 foreach $peg ($fig_or_sprout->all_features($given,"peg"))
275 : efrank 1.1 {
276 : parrello 1.36 undef %hits_set1; undef %hits_set2;
277 :     $hits_set1{&FIG::genome_of($peg)} = 1;
278 : parrello 1.30 Trace("Processing $peg.") if T(3);
279 : parrello 1.36 foreach $sim ($is_sprout ? $fig_or_sprout->bbhs($peg, $sim_cutoff) : $fig_or_sprout->sims($peg, 1000, $sim_cutoff, "fig"))
280 :     {
281 :     $id2 = $is_sprout ? $sim->[0] : $sim->[1];
282 : parrello 1.23 Trace("SIG tool sim check for $peg vs. $id2.") if T(4);
283 : parrello 1.36 if ($id2 =~ /^fig\|(\d+\.\d+)/)
284 :     {
285 :     my $org1 = $1;
286 :     if ($set1{$org1})
287 :     {
288 :     $hits_set1{$org1} = 1;
289 :     }
290 :     elsif ($set2{$org1})
291 :     {
292 :     $hits_set2{$org1} = 1;
293 :     }
294 :     }
295 :     }
296 :     my $n_set1 = keys(%hits_set1);
297 :     my $n_set2 = keys(%hits_set2);
298 :    
299 :     # my $sc = sprintf "%.3f", ($n_set1 / @set1) - (($n_set2 / @set2) * $fudge);
300 :     my $sc = sprintf "%.3f", &sig($n_set1,(@set1 - $n_set1),$n_set2,(@set2 - $n_set2));
301 :     if ($sc >= 1)
302 :     {
303 :     push(@hits,[$peg,$sc,scalar $fig_or_sprout->function_of($peg)]);
304 :     }
305 : efrank 1.1 }
306 : parrello 1.28 Trace(scalar(@hits) . " hits found by differentiator.") if T(3);
307 : efrank 1.1 return @hits;
308 :     }
309 :    
310 :     sub sig {
311 :     my($in_has,$in_has_not,$out_has,$out_has_not) = @_;
312 :     my($sx,$sy,$xx,$xy,$yy,$din,$dout);
313 :     $sx = $in_has + $in_has_not;
314 :     $sy = $out_has + $out_has_not;
315 :     $xx = ($in_has * $in_has) + ($in_has_not * $in_has_not);
316 :     $xy = ($in_has * $out_has) + ($in_has_not * $out_has_not);
317 :     $yy = ($out_has * $out_has) + ($out_has_not * $out_has_not);
318 :     (($sx > 0) && ($yy > 0) && ($sy > 0) && ($xx > 0)) || return 0;
319 :     $din = 1 - (($sy * $xy) / ($sx * $yy));
320 :     $dout = 1 - (($sx * $xy) / ($sy * $xx));
321 :     return $din+$dout;
322 :     }
323 :    

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3