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

Annotation of /FigWebServices/sigs.cgi

Parent Directory Parent Directory | Revision Log Revision Log


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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3