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

Annotation of /FigWebServices/genome_statistics.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.51 - (view) (download)

1 : redwards 1.10 # -*- perl -*-
2 : olson 1.33 #
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 : overbeek 1.1 #### start ####
20 : overbeek 1.5
21 : overbeek 1.1 use FIG;
22 : disz 1.35 use FIG_Config;
23 : overbeek 1.1
24 :     use HTML;
25 :     use strict;
26 :     use CGI;
27 : parrello 1.46 use FIG_CGI;
28 : overbeek 1.1 my $cgi = new CGI;
29 : parrello 1.46 print $cgi->header();
30 : overbeek 1.1
31 : parrello 1.46 use TemplateObject;
32 : parrello 1.47 use Tracer;
33 : parrello 1.46
34 :     if (0) {
35 : overbeek 1.1 my $VAR1;
36 :     eval(join("",`cat /tmp/statistics_parms`));
37 :     $cgi = $VAR1;
38 :     # print STDERR &Dumper($cgi);
39 :     }
40 :    
41 : parrello 1.46 if (0) {
42 : overbeek 1.1 print $cgi->header;
43 :     my @params = $cgi->param;
44 :     print "<pre>\n";
45 : parrello 1.46 foreach $_ (@params) {
46 :     print "$_\t:",join(",",$cgi->param($_)),":\n";
47 : overbeek 1.1 }
48 :    
49 : parrello 1.46 if (0) {
50 :     if (open(TMP,">/tmp/statistics_parms")) {
51 :     print TMP &Dumper($cgi);
52 :     close(TMP);
53 :     }
54 : overbeek 1.1 }
55 :     exit;
56 :     }
57 :    
58 : overbeek 1.32 # DISABLED ATTRIBUTES
59 :     # I have disabled attributes because it is taking so long to load. The places where I have disabled them are marked with "DISABLED ATTRIBUTES"
60 :     # RAE 10/25/05
61 :    
62 : overbeek 1.41 # RAE: 3/21/06
63 :     # Re-enabled attributes, but left old markers in place for now!
64 : overbeek 1.32
65 : overbeek 1.8 my @genomes = $cgi->param('genome');
66 :     my $request = $cgi->param('request');
67 : parrello 1.46 my $nmpdr = is_sprout($cgi);
68 : overbeek 1.9
69 : parrello 1.46 if (!$request) {
70 : overbeek 1.24 #
71 :     # Support for coming here from the NMPDR pages, where we have a form
72 :     # with a pair of submit buttons, one for subsystems summary, one for
73 :     # reactions summary.
74 :     #
75 :    
76 : parrello 1.46 if ($cgi->param("show_reactions")) {
77 :     $request = "show_reactions";
78 :     } elsif ($cgi->param("show_subsystems")) {
79 :     $request = "show_subsystems";
80 :     } elsif (@genomes == 0) {
81 :     $request = "show_all_genomes";
82 : overbeek 1.24 }
83 :     }
84 :    
85 : parrello 1.46 my $to = TemplateObject->new($cgi, php => 'Stats', $request);
86 :     $to->add("<TITLE>The SEED Statistics Page</TITLE>\n");
87 : overbeek 1.24
88 : parrello 1.46 my $fig;
89 :     my $sprout_param = "";
90 :     if ($nmpdr) {
91 :     $sprout_param = "&SPROUT=1";
92 :     $fig = SFXlate->new();
93 :     } else {
94 :     $fig = FIG->new();
95 : overbeek 1.9 }
96 : parrello 1.46
97 :     # RAE This little loop will add any genomes for any proteins that we know about to the list
98 :     push @genomes, map{$fig->genome_of($_)} $cgi->param('prot');
99 :    
100 :     my $parameters = { fig_object => $fig,
101 :     table_style => 'plain',
102 :     fig_disk => $FIG_Config::fig_disk . "/",
103 :     form_target => 'display_subsys.cgi'
104 :     };
105 :    
106 :     # Format the header information.
107 :     $to->titles($parameters);
108 :    
109 :     #### START PROCESSING ####
110 :    
111 :     if ($request eq "subsystems_summary") {
112 :     $to->add(results => &subsys_summary($fig,$cgi,$sprout_param));
113 :     } elsif ($request eq "edit_kv_stats") {
114 :     $to->add(results => &edit_kv_stats($fig,$cgi,$cgi->param('genome'), $sprout_param));
115 :     } elsif ($request eq "show_all_genomes") {
116 :     $to->add(results => &table_of_genomes($fig,$cgi,$sprout_param));
117 :     } elsif (! $request) {
118 :    
119 : overbeek 1.8 my $genome;
120 : parrello 1.46 foreach $genome (@genomes) {
121 :     $to->append(results => &basic_stats($fig, $cgi, $genome, $sprout_param));
122 :     $to->append(results => $cgi->hr);
123 :     $to->append(results => &assignment_stats($fig, $cgi, $genome, $sprout_param));
124 :     $to->append(results => $cgi->hr);
125 :     $to->append(results => &kv_peg_stats($fig, $cgi, $genome, $sprout_param));
126 :     $to->append(results => $cgi->hr);
127 :     $to->append(results => &kv_stats($fig, $cgi, $genome, $sprout_param));
128 :     my $user = $cgi->param('user');
129 :     $to->append(results => "<a href=./genome_statistics.cgi?genome=$genome&request=show_subsystems&user=$user$sprout_param>Show Subsystems</a><br>\n");
130 :     $to->append(results => "<a href=./genome_statistics.cgi?genome=$genome&request=show_reactions&user=$user$sprout_param>Show Reactions</a><br>\n");
131 :     if (! $nmpdr && &model_for_genome($genome)) {
132 :     $to->append(results => "<a href=./status_of_model.cgi?user=$user&model=$genome$sprout_param>PEGs in published reaction model that are not yet covered</a><br>\n");
133 :     }
134 :     $to->append(results => $cgi->br);
135 :     }
136 :     } elsif (@genomes == 0) {
137 :     $to->add(results => "<h1>Sorry, you need to specify at least one valid genome</h1>\n");
138 :     } else {
139 : parrello 1.51 $to->append(results => genome_search_box($fig,$cgi,$genomes[0],$sprout_param));
140 : parrello 1.46 if ($request eq "hypo_sub") {
141 : parrello 1.50 $to->append(results => &handle_hypo_sub($fig,$cgi,$genomes[0],$sprout_param));
142 : parrello 1.46 } elsif ($request eq "hypo_nosub") {
143 : parrello 1.50 $to->append(results => &handle_hypo_nosub($fig,$cgi,$genomes[0],$sprout_param));
144 : parrello 1.46 } elsif ($request eq "nothypo_sub") {
145 : parrello 1.50 $to->append(results => &handle_nothypo_sub($fig,$cgi,$genomes[0],$sprout_param));
146 : parrello 1.46 } elsif ($request eq "nothypo_nosub") {
147 : parrello 1.50 $to->append(results => &handle_nothypo_nosub($fig,$cgi,$genomes[0],$sprout_param));
148 : parrello 1.46 } elsif ($request eq "show_subsystems") {
149 : parrello 1.50 $to->append(results => &handle_show_subsystems($fig,$cgi,$genomes[0],$sprout_param));
150 : parrello 1.46 } elsif ($request eq "show_reactions") {
151 : parrello 1.50 $to->append(results => &handle_show_reactions($fig,$cgi,$genomes[0],$sprout_param));
152 : parrello 1.46 } else {
153 : parrello 1.50 $to->append(results => $cgi->h1("Invalid request: $request"));
154 : overbeek 1.8 }
155 : overbeek 1.3 }
156 : parrello 1.46 print $to->finish();
157 :     1;
158 : overbeek 1.3
159 : parrello 1.46 # Only subroutines below
160 : golsen 1.16
161 :    
162 : overbeek 1.3 sub basic_stats {
163 : parrello 1.46 my($fig,$cgi,$genome,$sprout_param) = @_;
164 :     my $retVal = "";
165 :     my($gname,$szdna,$num_contigs,$pegs,$rnas,$taxonomy) = &get_basic_stats($fig,$genome,$sprout_param);
166 :     $retVal .= &genome_search_box($fig, $cgi, $genome,$sprout_param) . "\n";
167 :     $retVal .= join("\n", $cgi->h1('Basic Statistics'),
168 :     "<b>Genome ID:</b> $genome", $cgi->br,
169 :     "<b>Name:</b> $gname", $cgi->br,
170 :     "<b>Size (bp):</b> $szdna", $cgi->br,
171 :     "<b>Number contigs:</b> $num_contigs", $cgi->br,
172 :     "<b>Number CDSs:</b> $pegs", $cgi->br,
173 :     "<b>Number rnas:</b> $rnas", $cgi->br,
174 :     "<b>Taxonomy:</b> $taxonomy", $cgi->br,
175 :     "<b>Complete:</b> ", $fig->is_complete($genome)?"Yes":"No", $cgi->br,
176 :     "");
177 :     $retVal .= project_description($fig, $genome );
178 :     return $retVal;
179 : overbeek 1.3 }
180 : overbeek 1.4
181 : parrello 1.46 # Sprout does not have project descriptions, so it returns a null string.
182 : golsen 1.16 sub project_description {
183 : parrello 1.46 my ($fig, $genome) = @_;
184 :     my $retVal = "";
185 :     if (! is_sprout($fig) && -d $FIG_Config::organisms
186 :     && -d "$FIG_Config::organisms/$genome"
187 :     && -f "$FIG_Config::organisms/$genome/PROJECT") {
188 :     Open(\*PROJECT, "<$FIG_Config::organisms/$genome/PROJECT" );
189 :     my @project = <PROJECT>;
190 :     close PROJECT;
191 :     $retVal = join("\n", "<b>Project description:</b>\n<pre>",
192 :     ( map { " " . $_ } @project ),
193 :     "</pre>"
194 :     );
195 :     }
196 :     return $retVal;
197 : golsen 1.16 }
198 :    
199 : parrello 1.46 # Put commas into a whole number.
200 : overbeek 1.4 sub commify {
201 :     my($n) = @_;
202 :     my(@n) = ();
203 :     my($i);
204 :    
205 :     for ($i = (length($n) - 3); ($i > 0); $i -= 3)
206 :     {
207 : parrello 1.46 unshift(@n,",",substr($n,$i,3));
208 : overbeek 1.4 }
209 :     unshift(@n,substr($n,0,$i+3));
210 :     return join("",@n);
211 :     }
212 :    
213 : parrello 1.46 sub count_stats {
214 :     my ($subsystem_data,$assignments_data) = @_;
215 : overbeek 1.5
216 :     my $hypo_sub = 0;
217 :     my $hypo_nosub = 0;
218 :     my $nothypo_sub = 0;
219 :     my $nothypo_nosub = 0;
220 : overbeek 1.6 my %in = map { $_->[2] => 1 } @$subsystem_data;
221 :     my $in = keys(%in);
222 : overbeek 1.5
223 : overbeek 1.34 my %sscount = map { $_->[0] => 1 } @$subsystem_data;
224 :     my $nss=scalar(keys(%sscount));
225 :    
226 : overbeek 1.6 foreach $_ (@$assignments_data)
227 : overbeek 1.5 {
228 : parrello 1.46 my($peg,$func) = @$_;
229 :     my $is_hypo = &FIG::hypo($func);
230 : overbeek 1.5
231 : parrello 1.46 if ($is_hypo && $in{$peg}) { $hypo_sub++ }
232 :     elsif ($is_hypo && ! $in{$peg}) { $hypo_nosub++ }
233 :     elsif ((! $is_hypo) && (! $in{$peg})) { $nothypo_nosub++ }
234 :     elsif ((! $is_hypo) && $in{$peg}) { $nothypo_sub++ }
235 : overbeek 1.5 }
236 :     my $tot = $hypo_sub + $nothypo_sub + $hypo_nosub + $nothypo_nosub;
237 : efrank 1.30
238 :     my ($fracHS, $fracNHS, $fracHNS, $fracNHNS);
239 :    
240 :     if ($tot == 0) {
241 : parrello 1.46 $fracHS = sprintf "%4.2f", 0.0;
242 :     $fracNHS = sprintf "%4.2f", 0.0;
243 :     $fracHNS = sprintf "%4.2f", 0.0;
244 :     $fracNHNS = sprintf "%4.2f", 0.0;
245 : efrank 1.30 } else {
246 : parrello 1.46 $fracHS = sprintf "%4.2f", $hypo_sub / $tot;
247 :     $fracNHS = sprintf "%4.2f", $nothypo_sub / $tot;
248 :     $fracHNS = sprintf "%4.2f", $hypo_nosub / $tot;
249 :     $fracNHNS = sprintf "%4.2f", $nothypo_nosub / $tot;
250 : efrank 1.30 }
251 : parrello 1.46 return ($hypo_sub, $hypo_nosub, $nothypo_nosub, $nothypo_sub, $fracHS, $fracNHS, $fracHNS, $fracNHNS, $nss);
252 :     }
253 :    
254 :     sub assignment_stats {
255 :     my($fig,$cgi,$genome, $sprout_param) = @_;
256 :    
257 :     my($subsystem_data,$assignments_data) = &get_data($fig,$cgi,$genome);
258 :    
259 :     my ($hypo_sub, $hypo_nosub, $nothypo_nosub, $nothypo_sub, $fracHS, $fracNHS, $fracHNS, $fracNHNS, $nss) =
260 :     count_stats($subsystem_data, $assignments_data);
261 : efrank 1.30
262 : overbeek 1.6 my $user = $cgi->param('user');
263 : overbeek 1.5
264 : parrello 1.46 my $retVal = join("\n", "<table>",
265 :     " <tr>",
266 :     " <th align=left>Number of subsystems:</th>",
267 :     " <td align=right><a href=\"subsys_vectors.cgi?korgs=$genome&allss=1$sprout_param\">$nss</a></td>",
268 :     " </tr>",
269 :     " <tr>",
270 :     " <th align=left>PEGs with hypothetical functions and in subsystem:</th>",
271 :     " <td align=right><a href=\"genome_statistics.cgi?user=$user&genome=$genome&request=hypo_sub$sprout_param\">$hypo_sub ($fracHS)</a></td>",
272 :     " </tr>",
273 :     " <tr>",
274 :     " <th align=left>PEGs with nonhypothetical functions and in subsystem:</th>",
275 :     " <td align=right><a href=\"genome_statistics.cgi?user=$user&genome=$genome&request=nothypo_sub$sprout_param\">$nothypo_sub ($fracNHS)</a></td>",
276 :     " </tr>",
277 :     " <tr>",
278 :     " <th align=left>PEGs with hypothetical functions and not in subsystem:</th>",
279 :     " <td align=right><a href=\"genome_statistics.cgi?user=$user&genome=$genome&request=hypo_nosub$sprout_param\">$hypo_nosub ($fracHNS)</a></td>",
280 :     " </tr>",
281 :     " <tr>",
282 :     " <th align=left>PEGs with nonhypothetical functions and not in subsystem:</th>",
283 :     " <td align=right><a href=\"genome_statistics.cgi?user=$user&genome=$genome&request=nothypo_nosub$sprout_param\">$nothypo_nosub ($fracNHNS)</a></td>",
284 :     " </tr>",
285 :     "</table>",
286 :     "");
287 :     return $retVal;
288 : overbeek 1.4 }
289 : parrello 1.46
290 : disz 1.35 sub sub_stats {
291 : parrello 1.46 my($fig,$cgi,$genome, $sprout_param) = @_;
292 : disz 1.35
293 :     my($subsystem_data,$assignments_data) = &get_data($fig,$cgi,$genome);
294 :    
295 : parrello 1.46 my ($hypo_sub, $hypo_nosub, $nothypo_nosub, $nothypo_sub, $fracHS, $fracNHS, $fracHNS, $fracNHNS, $nss) =
296 :     count_stats($subsystem_data, $assignments_data);
297 : disz 1.35
298 :     return ($fracHS, $fracHNS, $fracNHS, $fracNHNS);
299 :     }
300 : overbeek 1.4
301 : overbeek 1.5 sub handle_show_subsystems {
302 : parrello 1.46 my($fig,$cgi,$genome,$sprout_param) = @_;
303 : overbeek 1.19 my(%in,$sub,$role,$protein,$sub_link,$tuple,$categories);
304 : parrello 1.46 my $retVal = "";
305 : overbeek 1.6 my($subsystem_data,$assignments_data) = &get_data($fig,$cgi,$genome);
306 : overbeek 1.25 my $active = $fig->active_subsystems($genome);
307 : parrello 1.46 $retVal .= $cgi->h1($genome) . "\n";
308 :     foreach $_ (@$subsystem_data) {
309 :     ($sub,$role,$protein) = @$_;
310 :     if ($active->{$sub}) {
311 :     push(@{$in{$sub}->{$role}},&HTML::fid_link($cgi,$protein,0) . ": " . scalar $fig->function_of($protein));
312 :     }
313 : overbeek 1.6 }
314 : overbeek 1.19
315 :     my @subs = sort { ($a->[0] cmp $b->[0]) or
316 : parrello 1.46 ($a->[1] cmp $b->[1]) or
317 :     ($a->[2] cmp $b->[2]) or
318 :     ($a->[3] cmp $b->[3]) or
319 :     ($a->[4] cmp $b->[4])
320 :     }
321 : overbeek 1.19 map { $sub = $_;
322 : parrello 1.46 $categories = $fig->subsystem_classification($sub);
323 :     $categories = ((@$categories > 0) && $categories->[0]) ? $categories : ["Misc"];
324 :     [@$categories,$sub]
325 :     }
326 : overbeek 1.19 keys(%in);
327 :    
328 : overbeek 1.20 my $last1 = "";
329 :     my $last2 = "";
330 : overbeek 1.19 foreach $tuple (@subs)
331 :     {
332 : parrello 1.46 $sub = pop @{$tuple};
333 :     my $topic = $tuple->[0];
334 : overbeek 1.20
335 : parrello 1.46 if ($topic ne $last1)
336 :     {
337 :     $retVal .= $cgi->h1($topic) . "\n";
338 :     $last1 = $topic;
339 :     $last2 = "";
340 :     }
341 :    
342 :     $topic = $tuple->[1] ? $tuple->[1] : "";
343 :     if ($topic && ($topic ne $last2))
344 :     {
345 :     $retVal .= $cgi->h2($topic) . "\n";
346 :     $last2 = $topic;
347 :     }
348 :    
349 :     $sub_link = &sub_link($cgi,$sub,$sprout_param);
350 :     $retVal .= $cgi->h3($sub_link) . "\n";
351 :    
352 :     my $roles = [];
353 :     foreach $role (sort keys(%{$in{$sub}}))
354 :     {
355 :     push(@$roles,$cgi->ul($cgi->li($in{$sub}->{$role})));
356 :     }
357 :     $retVal .= $cgi->ul($cgi->li($roles));
358 : overbeek 1.6 }
359 : parrello 1.46 return $retVal;
360 : overbeek 1.4 }
361 : overbeek 1.5
362 : overbeek 1.21 sub handle_show_reactions {
363 : parrello 1.46 my($fig,$cgi,$genome,$sprout_param) = @_;
364 : overbeek 1.21 my($react_for_role,$r,%topic,%reaction,$sub,$role,$protein,$sub_link,$tuple,$categories);
365 :     my(%reactions_for_sub,%class,$reactions,$classL,$category);
366 : parrello 1.46 my $retVal = "";
367 : overbeek 1.21
368 :     my($subsystem_data,$assignments_data) = &get_data($fig,$cgi,$genome);
369 : overbeek 1.24
370 : overbeek 1.21 foreach $_ (@$subsystem_data)
371 :     {
372 : parrello 1.46 ($sub,$role,$protein) = @$_;
373 :     if (! defined($reactions_for_sub{$sub}))
374 :     {
375 : redwards 1.49 my $subsystem = $fig->get_subsystem($sub);
376 :     if ( $subsystem ) {
377 :     $reactions = $subsystem->get_reactions;
378 :     $reactions = $reactions ? $reactions : "";
379 :     $reactions_for_sub{$sub} = $reactions;
380 :     $class{$sub} = $fig->subsystem_classification($sub);
381 :     }
382 : parrello 1.46 }
383 :    
384 :     if (($reactions = $reactions_for_sub{$sub}) && ($react_for_role = $reactions->{$role}))
385 :     {
386 :     $classL = $class{$sub};
387 :     $category = ((@$classL > 0) && $classL->[0]) ? $classL->[0] : "Misc";
388 :     foreach $r (@$react_for_role)
389 :     {
390 :     if ($fig->valid_reaction_id($r))
391 :     {
392 :     $reaction{$r}->{$protein} = 1;
393 :     $topic{$category}->{$r} = 1;
394 :     }
395 :     }
396 :     }
397 : overbeek 1.21 }
398 :    
399 :     my @all = sort { $a cmp $b } keys(%topic);
400 : overbeek 1.24
401 : parrello 1.46 if (@all == 0) {
402 :     $retVal .= $cgi->p("No class reactions found.") . "\n";
403 : overbeek 1.24 }
404 : parrello 1.46 foreach $category (@all) {
405 :     $retVal .= &show_class_react($fig,$cgi,$category,[keys(%{$topic{$category}})],\%reaction,$sprout_param);
406 : overbeek 1.21 }
407 :    
408 : parrello 1.46 if ($_ = $topic{"Misc"}) {
409 :     $retVal .= &show_class_react($fig,$cgi,'Misc',[keys(%$_)],\%reaction,$sprout_param) . "\n";
410 :     } else {
411 :     $retVal .= $cgi->p("No misc reactions found.") . "\n";
412 : overbeek 1.24 }
413 : parrello 1.46 return $retVal;
414 : overbeek 1.21 }
415 :    
416 :     sub show_class_react {
417 : parrello 1.46 my($fig,$cgi,$class,$for_topic,$reaction,$sprout_param) = @_;
418 : overbeek 1.21 my($r,@pegs,$peg);
419 :    
420 : parrello 1.46 my $retVal = $cgi->h1($class) . "\n";
421 : overbeek 1.22 foreach $r (sort @$for_topic)
422 : overbeek 1.21 {
423 : parrello 1.46 my $disp_react = $fig->displayable_reaction($r);
424 :     $disp_react =~ s/^R\d+\: //;
425 : overbeek 1.21
426 : parrello 1.46 my $rstring = &HTML::reaction_link($r) . ": $disp_react";
427 :     $retVal .= $cgi->h2($rstring) . "\n";
428 :     @pegs = sort { &FIG::by_fig_id($a,$b) } keys(%{$reaction->{$r}});
429 :     $retVal .= "<ul>\n";
430 :     foreach $peg (@pegs) {
431 :     $retVal .= "<li>" . &HTML::fid_link($cgi,$peg) . " " . scalar $fig->function_of($peg) . "\n";
432 :     }
433 :     $retVal .= "</ul>\n";
434 : overbeek 1.21 }
435 : parrello 1.46 return $retVal;
436 :     }
437 : overbeek 1.21
438 : overbeek 1.5 sub handle_hypo_sub {
439 : parrello 1.46 my($fig,$cgi,$genome,$sprout_param) = @_;
440 : overbeek 1.5
441 : parrello 1.46 my $retVal = "";
442 : overbeek 1.6 my($subsystem_data,$assignments_data) = &get_data($fig,$cgi,$genome);
443 :     my %subs = map { $_->[2] => $_->[0] } @$subsystem_data;
444 :     my $col_hdrs = ["PEG","Function","Subsystem"];
445 :     my $tab = [];
446 :     foreach $_ (@$assignments_data)
447 :     {
448 : parrello 1.46 my($peg,$func) = @$_;
449 :     if (&FIG::hypo($func) && ($subs{$peg}))
450 :     {
451 :     push(@$tab,[&HTML::fid_link($cgi,$peg,0),$func,&sub_link($cgi,$subs{$peg},$sprout_param)]);
452 :     }
453 : overbeek 1.6 }
454 :     $_ = @$tab;
455 : parrello 1.46 $retVal .= &HTML::make_table($col_hdrs,$tab,"$_ Hypothetical Pegs in Subsystems");
456 :     return $retVal;
457 : overbeek 1.5 }
458 :    
459 :     sub handle_hypo_nosub {
460 : parrello 1.46 my($fig,$cgi,$genome,$sprout_param) = @_;
461 :     my $retVal = "";
462 : overbeek 1.6 my($subsystem_data,$assignments_data) = &get_data($fig,$cgi,$genome);
463 :     my %subs = map { $_->[2] => $_->[0] } @$subsystem_data;
464 :     my $col_hdrs = ["PEG","Function"];
465 :     my $tab = [];
466 :     foreach $_ (@$assignments_data)
467 :     {
468 : parrello 1.46 my($peg,$func) = @$_;
469 :     if (&FIG::hypo($func) && (! $subs{$peg}))
470 :     {
471 :     push(@$tab,[&HTML::fid_link($cgi,$peg,0),$func]);
472 :     }
473 : overbeek 1.6 }
474 :     $_ = @$tab;
475 : parrello 1.46 $retVal .= &HTML::make_table($col_hdrs,$tab,"$_ Hypothetical Pegs NOT in Subsystems") . "\n";
476 :     return $retVal;
477 : overbeek 1.5 }
478 :    
479 :     sub handle_nothypo_sub {
480 : parrello 1.46 my($fig,$cgi,$genome,$sprout_param) = @_;
481 :     my $retVal = "";
482 : overbeek 1.6 my($subsystem_data,$assignments_data) = &get_data($fig,$cgi,$genome);
483 :     my %subs = map { $_->[2] => $_->[0] } @$subsystem_data;
484 :     my $col_hdrs = ["PEG","Function","Subsystem"];
485 :     my $tab = [];
486 :     foreach $_ (@$assignments_data)
487 :     {
488 : parrello 1.46 my($peg,$func) = @$_;
489 :     if ((! &FIG::hypo($func)) && ($subs{$peg}))
490 :     {
491 :     push(@$tab,[&HTML::fid_link($cgi,$peg,0),$func,&sub_link($cgi,$subs{$peg},$sprout_param)]);
492 :     }
493 : overbeek 1.6 }
494 :     $_ = @$tab;
495 : parrello 1.46 $retVal .= &HTML::make_table($col_hdrs,$tab,"$_ Nonhypothetical Pegs in Subsystems");
496 :     return $retVal;
497 : overbeek 1.5 }
498 :    
499 :     sub handle_nothypo_nosub {
500 : parrello 1.46 my($fig,$cgi,$genome,$sprout_param) = @_;
501 :     my $retVal = "";
502 : overbeek 1.6 my($subsystem_data,$assignments_data) = &get_data($fig,$cgi,$genome);
503 :     my %subs = map { $_->[2] => $_->[0] } @$subsystem_data;
504 :     my $col_hdrs = ["PEG","Function"];
505 :     my $tab = [];
506 : parrello 1.46 foreach $_ (@$assignments_data) {
507 :     my($peg,$func) = @$_;
508 :     if ((! &FIG::hypo($func)) && (! $subs{$peg})) {
509 :     push(@$tab,[&HTML::fid_link($cgi,$peg,0),$func]);
510 :     }
511 : overbeek 1.6 }
512 :     $_ = @$tab;
513 : parrello 1.46 $retVal .= &HTML::make_table($col_hdrs,$tab,"$_ Nonhypothetical Pegs NOT in Subsystems");
514 :     return $retVal;
515 : overbeek 1.5 }
516 :    
517 : overbeek 1.6 sub get_data {
518 :     my($fig,$cgi,$genome) = @_;
519 :    
520 : parrello 1.46 my $subsystem_data = $fig->get_genome_subsystem_data($genome);
521 :     my $assignment_data = $fig->get_genome_assignment_data($genome);
522 : overbeek 1.6
523 :     return ($subsystem_data,$assignment_data);
524 :     }
525 :    
526 :     sub sub_link {
527 : parrello 1.46 my($cgi,$sub,$sprout_param) = @_;
528 : overbeek 1.6
529 : overbeek 1.29 my $genome = $cgi->param('genome');
530 : overbeek 1.6 my $user = $cgi->param('user');
531 : overbeek 1.19 $user = defined($user) ? $user : "";
532 : overbeek 1.40 my $sub_link = "<a href=./display_subsys.cgi?ssa_name=$sub$sprout_param&request=show_ssa&user=$user&focus=$genome&show_clusters=1>$sub</a>";
533 : overbeek 1.19
534 : overbeek 1.6 return $sub_link;
535 :     }
536 : overbeek 1.8
537 :     sub get_basic_stats {
538 : parrello 1.46 my($fig,$genome,$sprout_param) = @_;
539 : overbeek 1.8
540 : parrello 1.46 my($gname,$szdna,$pegs,$rnas,$taxonomy) = $fig->get_genome_stats($genome);
541 :     $szdna = &commify($szdna);
542 : overbeek 1.8 my $num_contigs = scalar $fig->all_contigs($genome);
543 :     return ($gname,$szdna,$num_contigs,$pegs,$rnas,$taxonomy);
544 :     }
545 :    
546 :     sub table_of_genomes {
547 : parrello 1.46 my($fig,$cgi,$sprout_param) = @_;
548 : overbeek 1.8 my(@genomes);
549 : parrello 1.46 my $retVal = "";
550 : disz 1.35 # push(@$html,"<pre>\n");
551 : overbeek 1.8 if ($cgi->param('complete'))
552 :     {
553 : parrello 1.46 @genomes = $fig->sort_genomes_by_taxonomy($fig->genomes("complete"));
554 : overbeek 1.8 }
555 :     else
556 :     {
557 : parrello 1.46 @genomes = $fig->sort_genomes_by_taxonomy($fig->genomes());
558 : overbeek 1.8 }
559 :    
560 : disz 1.35 my (@rows, @headings);
561 : overbeek 1.8 my $genome;
562 : disz 1.35 #push(@$html,join("\t","Genome ID","Complete","Genome Name","Size (bp)","Number Contigs","CDSs","RNAs","Taxonomy") . "\n");
563 :    
564 :     @headings = ("Genome ID","Complete","Genome Name",
565 : parrello 1.46 "Size (bp)", "Number Contigs", "CDSs", "Non-Hypothetical in Subsystem", "Non-Hypothetical not in Subsystem", "Hypothetical in Subsystem", "Hypothetical not in Subsystem", "RNAs","Taxonomy");
566 : disz 1.35 @rows = $cgi->th(\@headings);
567 :    
568 :     my $title;
569 :    
570 : disz 1.37 my $user = $cgi->param('user');
571 : overbeek 1.8 foreach $genome (@genomes)
572 :     {
573 : parrello 1.46 if (! $nmpdr || -f "$FIG_Config::organisms/$genome/NMPDR") {
574 :     my ($name, $size, $number_contigs, $cds, $rnas, $tax) = &get_basic_stats($fig, $genome);
575 :     my ($hs, $hns, $nhs, $nhns) = &sub_stats($fig, $cgi, $genome, $sprout_param);
576 :    
577 :    
578 :     push(@rows,$cgi->td([$genome, $fig->is_complete($genome)?"Yes":"No",
579 :     $name, $size, $number_contigs, $cds,
580 :     " <a href=./genome_statistics.cgi?user=$user&genome=$genome&request=nothypo_sub$sprout_param> $nhs</a>",
581 :     " <a href=./genome_statistics.cgi?user=$user&genome=$genome&request=nothypo_nosub$sprout_param> $nhns</a>",
582 :     " <a href=./genome_statistics.cgi?user=$user&genome=$genome&request=hypo_sub$sprout_param> $hs</a>",
583 :     " <a href=./genome_statistics.cgi?user=$user&genome=$genome&request=hypo_nosub$sprout_param> $hns</a>",
584 :     $rnas, $tax]));
585 :    
586 : disz 1.35
587 : parrello 1.46 }
588 : overbeek 1.8 }
589 : parrello 1.46 if ($sprout_param) {
590 :     $title = "NMPDR Genome Statistics";
591 : disz 1.35 } else {
592 : parrello 1.46 $title = "Genome Statistics";
593 : disz 1.35 }
594 : parrello 1.46 $retVal .= join("\n", $cgi->table({-border=>undef, -width=>'100%'},
595 :     $cgi->caption($cgi->h1($title)),
596 :     $cgi->Tr(\@rows),
597 :     ""));
598 :     return $retVal;
599 : overbeek 1.8 }
600 :    
601 : overbeek 1.9 sub subsys_summary {
602 : parrello 1.46 my($fig,$sprout_param) = @_;
603 :     my $retVal = "";
604 : overbeek 1.9 my($Nsubs,$genome,$sub,$role,$peg,$genome_instances,%genomes_in_use,$peg_instances,%pegs_in_use);
605 :     foreach $sub ($fig->all_subsystems)
606 :     {
607 : parrello 1.46 $Nsubs++;
608 :     foreach $genome (map { $_->[0] } @{$fig->subsystem_genomes($sub)})
609 :     {
610 :     $genome_instances++;
611 :     $genomes_in_use{$genome}++;
612 :     foreach $role ($fig->subsystem_to_roles($sub))
613 :     {
614 :     foreach $peg ($fig->pegs_in_subsystem_cell($sub,$genome,$role))
615 :     {
616 :     $peg_instances++;
617 :     $pegs_in_use{$peg}++;
618 :     }
619 :     }
620 :     }
621 : overbeek 1.9 }
622 :     my $Ngenomes = scalar keys(%genomes_in_use);
623 :     my $Npegs = scalar keys(%pegs_in_use);
624 :     my $g_in_sub = int($genome_instances / $Nsubs);
625 :     my $p_in_sub = int($peg_instances / $Nsubs);
626 : parrello 1.46 $retVal .= $cgi->h1('Subsystem Summary') . "\n";
627 :     $retVal .= join("\n", $cgi->br,
628 :     "<b>Number Subsystems:</b> $Nsubs",$cgi->br,
629 :     "<b>Genomes in Subsystems:</b> $Ngenomes",$cgi->br,
630 :     "<b>PEGs in Subsystems:</b> $Npegs",$cgi->br,
631 :     "<b>Avg genomes per subsystem:</b> $g_in_sub",$cgi->br,
632 :     "<b>Avg PEGs per subsystem:</b> $p_in_sub",$cgi->br,
633 :     "");
634 :     return $retVal;
635 : overbeek 1.9 }
636 : redwards 1.10
637 : redwards 1.14 sub kv_peg_stats {
638 : parrello 1.46 my ($fig, $cgi, $genome, $sprout_param)=@_;
639 :     my $retVal = "";
640 : overbeek 1.43 #RAE Added the coverage of each genome with different attributes for the PEGs to find the number of genes that have attributes
641 : parrello 1.51
642 : overbeek 1.32 # DISABLED ATTRIBUTES
643 : overbeek 1.41 #my $pegtags;
644 :     #push(@$html, "Sorry attributes are not working\n");
645 : parrello 1.51 Trace("PEG Attributes requested. Sprout param is $sprout_param.") if T(3);
646 :     if (! $sprout_param) {
647 :     $retVal .= "\n<div class=\"pegattributes\">\n<p><h2>PEG Attributes for " . $fig->genus_species($genome) . "</h2></p>\n";
648 :    
649 :     my $count;
650 :     foreach my $res ($fig->get_peg_keys_for_genome($genome)) {
651 :     $count->{$res->[1]}++;
652 :     }
653 :    
654 :     $retVal .= join("\n",
655 :     "<div class='tags'>",
656 :     (map {"PEGS with attribute: &nbsp; $_ : ".$count->{$_}."<br />\n"} sort {$count->{$b} <=> $count->{$a}} keys %$count),
657 :     "</div></div>",
658 :     ""
659 :     );
660 : redwards 1.14 }
661 :     }
662 :    
663 : redwards 1.10 sub kv_stats {
664 : parrello 1.46 my ($fig, $cgi, $genome, $sprout_param, $edit) = @_;
665 : redwards 1.10
666 :     # RAE Added tables for key value pairs for an organism, and allow you to edit them
667 :     # figure out kv's for the organism, and make a table with them
668 :    
669 :     # if the optional edit boolean is set and a user is supplied, we will make a table where you can edit the KV pairs
670 :     # else we will just make a blank table
671 :    
672 : redwards 1.12 # prepare the html so we can add form fields here
673 : parrello 1.46 my $retVal = "";
674 : parrello 1.51 Trace("PEG Attributes requested. Sprout param is $sprout_param.") if T(3);
675 :     if (! $sprout_param) {
676 :     $retVal .= "\n<div class=\"attributes\">\n<p><h2>Attributes for " . $fig->genus_species($genome) . "</h2></p>\n";
677 :     if ($edit) { $retVal .= $cgi->start_form(-action=>"genome_statistics.cgi"); }
678 :    
679 :    
680 :     my $tab=[];
681 :     my $user=$cgi->param('user');
682 :     my $col_hdrs=["Attribute", "Value"];
683 :     if ($user && $edit) {$col_hdrs=["Attribute", "Value", "URL"]}
684 :    
685 :     my $known;
686 :     # DISABLED ATTRIBUTES
687 :     # to disable attributes uncomment the two next lines and comment out the foreach my $key line
688 :     #if (0) {
689 :     # my $key; # remove this if reenabling attributes
690 :     foreach my $key (sort {$a->[1] cmp $b->[1]} $fig->get_attributes($genome)) {
691 :     $known->{$key->[1]}=1;
692 :     if ($user && $edit) {
693 :     push @$tab,
694 :     [
695 :     $key->[1],
696 :     $cgi->textfield(-name=>"value.".$key->[1], -default=>$key->[2], -size=>50),
697 :     $cgi->textfield(-name=>"url.".$key->[1], -default=>$key->[3], -size=>50),
698 :     ];
699 :     } else {
700 :     if ($key->[3] && $key->[3] =~ /^http/) {$key->[2] = "<a href=\"" . $key->[3] . "\">". $key->[2] . "</a>"}
701 :     push @$tab,
702 :     [
703 :     $key->[1],
704 :     $key->[2],
705 :     ];
706 :     }
707 :     }
708 :     if ($edit) {
709 :     # now we want to add some pull down menus for things that we can add. And some blank boxes too for free text entry.
710 :     # start with three of each
711 :     my $opt=$fig->get_tags("genome"); # all the tags we know about
712 :     my @options=sort {uc($a) cmp uc($b)} grep {!$known->{$_}} keys %$opt;
713 :     unshift(@options, undef); # a blank field at the start
714 :     for (my $i=1; $i<= (scalar @options + 5); $i++) {
715 :    
716 :     # we have the options, and 5 blank fields for free text entry
717 :     my $choice=$cgi->popup_menu(-name=>"key.$i", -values=>\@options);
718 :     if ($i >= scalar @options) {$choice = $cgi->textfield(-name=>"key.$i", -size=>50)}
719 :     push @$tab,
720 :     [
721 :     $choice,
722 :     $cgi->textfield(-name=>"value.$i", -size=>50),
723 :     $cgi->textfield(-name=>"url.$i", -size=>50),
724 :     ];
725 :     }
726 :     # we need to know how many possibilities we have to look through later. Just pass it as a hidden, rather than counting it next time
727 :     $retVal .= $cgi->hidden(-name=>"max new keys", -value=>scalar @options + 5);
728 :     }
729 : redwards 1.10
730 : parrello 1.51 # now just write the html
731 :     $retVal .= &HTML::make_table($col_hdrs,$tab,"Attributes");
732 :     if ($edit) {
733 :     $retVal .= $cgi->hidden("genome") . $cgi->hidden("user") . $cgi->hidden("request");
734 :     $retVal .= $cgi->submit('Change') . $cgi->reset();
735 :     }
736 :     $retVal .= "<p><a href=./genome_statistics.cgi?genome=$genome&request=edit_kv_stats&change=0&user=$user>Edit Key Value Pairs</a></p>\n</div>\n";
737 : redwards 1.10 }
738 : parrello 1.46 return $retVal;
739 : redwards 1.10 }
740 :    
741 :    
742 :     sub edit_kv_stats {
743 : parrello 1.46 my ($fig, $cgi, $genome, $sprout_param)=@_;
744 : overbeek 1.32
745 : parrello 1.46 my $retVal = "";
746 :     if ($sprout_param) {
747 :     $retVal .= "<h2>Error: invalid request for NMPDR.</h2>";
748 :     } else {
749 :     if ($cgi->param("Change")) {
750 :     # we have changed the values
751 :     # get the old kv pairs so we can see what has changed
752 :     my $changed; my $deleted;
753 :     foreach my $key ($fig->get_attributes($genome)) {
754 :     if (!$cgi->param('value.'.$key->[1]) && !$cgi->param('url.'.$key->[1])) {
755 :     $fig->delete_attribute($genome, $key->[1]);
756 :     push @$key, ["deleted", "td colspan=2 style=\"text-align: center\""];
757 :     push @$deleted, $key;
758 :     }
759 :     elsif (($cgi->param('value.'.$key->[1]) ne $key->[2]) || ($cgi->param('url.'.$key->[1]) ne $key->[3])) {
760 :     $fig->change_attribute($genome, $key->[1], $cgi->param('value.'.$key->[1]), $cgi->param('url.'.$key->[1]));
761 :     push @$key, $cgi->param('value.'.$key->[1]), $cgi->param('url.'.$key->[1]);
762 :     push @$changed, $key;
763 :     }
764 :     }
765 :    
766 :     my $added;
767 :     for (my $i=0; $i <= $cgi->param("max new keys"); $i++) {
768 :     if ($cgi->param("key.$i")) {
769 :     $fig->add_attribute($genome, $cgi->param("key.$i"), $cgi->param("value.$i"), $cgi->param("url.$i"));
770 :     push @$added, [$cgi->param("key.$i"), ["added", "td colspan=2 style=\"text-align: center\""], $cgi->param("value.$i"), $cgi->param("url.$i")];
771 :     }
772 :     }
773 :    
774 :     # now all we have to do is create a table to report what we have done.
775 :     my $tab=[];
776 :     $retVal .= join("\n", "<div class=\"altered\"><p><h2>Attributes Altered for ",
777 :     $fig->genus_species($genome), " ($genome)</h2></p>",
778 :     "");
779 :     my $col_hdrs=["Attribute", "Original Value", "Original URL", "New Value", "New URL"];
780 :     if ($changed) {push @$tab, [["<strong>Changed Attributes", "td colspan=5 bgcolor=gray style=\"text-align: center\""]], @$changed}
781 :     if ($deleted) {push @$tab, [["<strong>Deleted Attributes", "td colspan=5 bgcolor=gray style=\"text-align: center\""]], @$deleted}
782 :     if ($added) {push @$tab, [["<strong>Added Attributes", "td colspan=5 bgcolor=gray style=\"text-align: center\""]], @$added}
783 :    
784 :     $retVal .= &HTML::make_table($col_hdrs,$tab,"Changed Data");
785 :     }
786 :     else {
787 :     $retVal = kv_stats($fig, $cgi, $genome, $sprout_param, 1);
788 :     }
789 : redwards 1.10 }
790 : parrello 1.46 return $retVal;
791 : redwards 1.10 }
792 :    
793 : overbeek 1.23 sub model_for_genome {
794 :     my($genome) = @_;
795 :    
796 :     return -s "$FIG_Config::global/Models/$genome";
797 :     }
798 : overbeek 1.45
799 :    
800 :     sub genome_search_box {
801 : parrello 1.46 my($fig,$cgi,$genome,$sprout_param) = @_;
802 :     my @arr = ();
803 : parrello 1.51 if ($sprout_param) {
804 :     @arr=(
805 :     $cgi->start_form(-action => "SearchSkeleton.cgi"),
806 :     $cgi->hidden(-name => "Class", -value => "FidSearch"),
807 :     $cgi->hidden(-name => "genome", -value => "$genome"),
808 :     $cgi->hidden(-name => "subsystem", -value => "(all)"),
809 :     $cgi->h1("Search in ", $fig->genus_species($genome), " : &nbsp; ",
810 :     $cgi->textfield(-name => "keywords", -size => 20),
811 :     $cgi->submit(-name => "Search", -value => "Go"),
812 :     ),
813 :     $cgi->end_form
814 :     );
815 :     } else {
816 : parrello 1.46 @arr=(
817 : overbeek 1.45 $cgi->start_form(-action=>"index.cgi"),
818 :     $cgi->hidden(-name=>"korgs", -value=>"($genome)"),
819 :     $cgi->hidden(-name=>"Search genome selected below", -value=>1),
820 :     $cgi->hidden(-name=>"user"),
821 :     $cgi->h1("Search in ", $fig->genus_species($genome), " : &nbsp; ",
822 :     $cgi->textfield(-name=>"pattern", -size=>20),
823 :     ),
824 :     $cgi->submit, $cgi->reset, $cgi->end_form
825 :     );
826 : parrello 1.46 }
827 : overbeek 1.48 return join("", @arr);
828 : overbeek 1.45 }

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3