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

Annotation of /FigWebServices/genome_statistics.cgi

Parent Directory Parent Directory | Revision Log Revision Log


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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3