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

Annotation of /FigWebServices/subsys_summary.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (view) (download)

1 : redwards 1.1
2 :     =pod
3 :    
4 :     =head1
5 :    
6 :     Create a summary of subsystems
7 :    
8 :     =cut
9 :    
10 :     use strict;
11 :     use FIG;
12 :     use HTML;
13 :     use raelib;
14 :     use CGI;
15 :     my $cgi=new CGI;
16 :    
17 :    
18 :     my $fig;
19 :     eval {
20 :     $fig = new FIG;
21 :     };
22 :    
23 :     if ($@ ne "")
24 :     {
25 :     my $err = $@;
26 :    
27 :     my(@html);
28 :    
29 :     push(@html, $cgi->p("Error connecting to SEED database."));
30 :     if ($err =~ /Could not connect to DBI:.*could not connect to server/)
31 :     {
32 :     push(@html, $cgi->p("Could not connect to relational database of type $FIG_Config::dbms named $FIG_Config::db on port $FIG_Config::dbport."));
33 :     }
34 :     else
35 :     {
36 :     push(@html, $cgi->pre($err));
37 :     }
38 :     &HTML::show_page($cgi, \@html, 1);
39 :     exit;
40 :     }
41 :    
42 :    
43 :    
44 :     $ENV{"PATH"} = "$FIG_Config::bin:$FIG_Config::ext_bin:" . $ENV{"PATH"};
45 :    
46 :     my $html = [];
47 :    
48 :    
49 :     if ($cgi->param('submit') eq "Summarize Subsystems")
50 :     {
51 :     summarize_ss();
52 :     }
53 :     else
54 :     {
55 :     show_initial();
56 :     }
57 :    
58 :     unshift @$html, "<TITLE>The SEED - Subsystem summarizer </TITLE>\n";
59 :     &HTML::show_page($cgi, $html, 1);
60 :     exit;
61 :    
62 :    
63 :    
64 :    
65 :    
66 :    
67 :    
68 :    
69 :    
70 :    
71 :     sub summarize_ss {
72 :     my @wants;
73 :     foreach my $w ($cgi->param('korgs')) {
74 :     $w =~ /\((\d+\.\d+)\)/;
75 :     push @wants, $1;
76 :     }
77 :    
78 :    
79 :     my @th;
80 : redwards 1.2 if ($cgi->param('levels')) {push @th, ('Level 1', 'Level 2')}
81 :     push @th, 'Subsystem'; # we should have this, at least
82 :     if ($cgi->param('genomes')) {push @th, ('Organisms')}
83 :     if ($cgi->param('stats')) {push @th, ('Roles', 'Total Pegs', @wants)}
84 :     elsif ($cgi->param('roles')) {push @th, ('Roles', @wants)}
85 : redwards 1.1
86 :     my $tableheader="<tr><th>". (join "</th><th>", @th) . "</th></tr>\n\n";
87 :    
88 :     my $cols=scalar @th;
89 :     my $table;
90 :     foreach my $subsys ($fig->all_subsystems) {
91 :    
92 :     # add a header
93 : redwards 1.2 unless ($cgi->param('stats')) {$table .= "<tr><td colspan=$cols align=center><strong>Subsystem: $subsys</strong></td></tr>\n"}
94 : redwards 1.1
95 :     # figure out how many roles we have, as this will determine the number of rows in the table
96 :     my @roles=$fig->subsystem_to_roles($subsys);
97 :     my $rows=1;
98 : redwards 1.2 if (!$cgi->param('stats') && $cgi->param('roles')) {$rows=scalar @roles}
99 : redwards 1.1
100 :     # figure out which genomes are in this subsystem
101 :     my %genomes;
102 :     foreach my $gen (@{$fig->subsystem_genomes($subsys)}) {$genomes{$gen->[0]}=$gen->[1]}
103 :    
104 : redwards 1.2 # start a new row for this data
105 :     $table .= "\n<tr>\n";
106 :    
107 : redwards 1.1 # get the classification if required
108 :     if ($cgi->param('levels')) {
109 : redwards 1.2 # get the classification and make sure there are now 2 columns as andrei doesn't like #3.
110 : redwards 1.1 my $class=$fig->subsystem_classification($subsys);
111 : redwards 1.2 unless ($class) {@$class=(' &nbsp; ',' &nbsp; ')}
112 :     unless ($$class[0]) {$$class[0] = " &nbsp; "}
113 :     unless ($$class[1]) {$$class[1] = " &nbsp; "}
114 :     # remove anything more than $$class[1];
115 :     @$class=($$class[0], $$class[1]); # could have done this with splice. Ech.
116 :    
117 :     $table .= "\n\t<td rowspan='$rows'>" . (join "</td>\n\t<td rowspan='$rows'>", (@$class)) . "</td>";
118 : redwards 1.1 }
119 :    
120 : redwards 1.2 # add the subsystem to the table
121 :     $table .= "\n\t<td><strong>$subsys<strong></td>";
122 :    
123 : redwards 1.1 # add the genomes in the subsystem
124 : redwards 1.2 if ($cgi->param('genomes') && $cgi->param('stats')) {$table .= "\n\t<td rowspan='$rows'>" . (scalar keys %genomes) . " </td>"}
125 :     elsif ($cgi->param('genomes')) {$table .= "\n\t<td rowspan='$rows'> &nbsp; " . (join "<br>\n", sort {$a cmp $b} values %genomes) . "</td>"}
126 :    
127 :     if ($cgi->param('stats')) {
128 :     my $pegcount=0;
129 :     $table .= "\n\t<td>" . (scalar @roles) . "</td>"; #number of roles in the subsystem
130 :     my $pegcount; my $totalpegs;
131 :     # there should be a quicker way of getting this ... ?
132 :     foreach my $role (@roles) {
133 :     foreach my $genome (keys %genomes) {
134 :     my $count = scalar ($fig->pegs_in_subsystem_cell($subsys, $genome, $role));
135 :     $pegcount->{$genome} += $count;
136 :     $totalpegs += $count;
137 :     }
138 :     }
139 :    
140 :     $table .= "\n\t<td>$totalpegs</td>"; # all the pegs in the subsystem
141 :     foreach my $w (@wants) {
142 :     $table .= "\n\t<td>$pegcount->{$w}</td>"; # pegs for each of the chosen genomes
143 :     }
144 :     $table .= "</tr>\n";
145 :     }
146 :     elsif ($cgi->param('roles')) {
147 : redwards 1.1 # now add the roles
148 :     my $first=1;
149 :     foreach my $role (@roles) {
150 :     my $genomeroles;
151 :     foreach my $gen (@wants) {
152 : redwards 1.2 my $cell = ' &nbsp; ';
153 : redwards 1.1 if ($genomes{$gen}) {
154 :     foreach my $peg ($fig->pegs_in_subsystem_cell($subsys, $gen, $role)) {
155 :     $cell .= &HTML::fid_link($cgi,$peg) . "; ";
156 :     }
157 :     }
158 : redwards 1.2 $genomeroles .= "\n\t<td>$cell</td>";
159 : redwards 1.1 }
160 :     # because I am using rowspan to make long columns, we don't want the tr on the first of these.
161 :     if ($first) {$table .= "\n\t<td>$role</td>" . $genomeroles . "</tr>\n"; $first=0}
162 :     else {$table .= "\n\t<tr><td>$role</td>" . $genomeroles . "</tr>\n"}
163 :     }
164 :     }
165 :     else {$table .= "</tr>\n"}
166 :     }
167 :     push @$html, ("\n<table border=1>" . $tableheader . $table . "</table>\n");
168 :     }
169 :    
170 :    
171 :    
172 :    
173 :    
174 :    
175 :    
176 :    
177 :    
178 :    
179 :     sub show_initial {
180 :     #############
181 :     #
182 :     # Stolen from index.cgi
183 :     #
184 :     #
185 :    
186 :     my @display = ( 'All', 'Archaea', 'Bacteria', 'Eucarya', 'Viruses', 'Environmental samples' );
187 :    
188 :     #
189 :     # Canonical names must match the keywords used in the DBMS. They are
190 :     # defined in compute_genome_counts.pl
191 :     #
192 :     my %canonical = (
193 :     'All' => undef,
194 :     'Archaea' => 'Archaea',
195 :     'Bacteria' => 'Bacteria',
196 :     'Eucarya' => 'Eukaryota',
197 :     'Viruses' => 'Virus',
198 :     'Environmental samples' => 'Environmental Sample'
199 :     );
200 :    
201 :     my $req_dom = $cgi->param( 'domain' ) || 'All';
202 :     my @domains = $cgi->radio_group( -name => 'domain',
203 :     -default => $req_dom,
204 :     -override => 1,
205 :     -values => [ @display ]
206 :     );
207 :    
208 :     my $n_domain = 0;
209 :     my %dom_num = map { ( $_, $n_domain++ ) } @display;
210 :     my $req_dom_num = $dom_num{ $req_dom } || 0;
211 :    
212 :     #
213 :     # Viruses and Environmental samples must have completeness = All (that is
214 :     # how they are in the database). Otherwise, default is Only "complete".
215 :     #
216 :     my $req_comp = ( $req_dom_num > $dom_num{ 'Eucarya' } ) ? 'All'
217 :     : $cgi->param( 'complete' ) || 'Only "complete"';
218 :     my @complete = $cgi->radio_group( -name => 'complete',
219 :     -default => $req_comp,
220 :     -override => 1,
221 :     -values => [ 'All', 'Only "complete"' ]
222 :     );
223 :     #
224 :     # Use $fig->genomes( complete, restricted, domain ) to get org list:
225 :     #
226 :     my $complete = ( $req_comp =~ /^all$/i ) ? undef : "complete";
227 :    
228 :     my @orgs = sort map { my $org = $_; my $gs = $fig->genus_species($org); my $gc=scalar $fig->all_contigs($org); "$gs ($org) [$gc contigs]" }
229 :     $fig->genomes( $complete, undef, $canonical{ $req_dom } );
230 :    
231 :     my $n_genomes = @orgs;
232 :    
233 :     push @$html, $cgi->start_form,
234 :     $cgi->h2("Please choose one or more organisms from the list below to see in the subsystems table"),
235 :     "<TABLE>\n",
236 :     " <TR>\n",
237 :     " <TD>",
238 :     $cgi->scrolling_list( -name => 'korgs',
239 :     -size => 10,
240 :     -multiple => 1,
241 :     -values => \@orgs,
242 :     ),
243 :     $cgi->br,
244 :     "$n_genomes genomes shown ",
245 :     $cgi->submit( 'Update List' ), $cgi->reset, $cgi->submit('submit', 'Summarize Subsystems'),
246 :     "</TD>",
247 :     " <TD>",
248 :     join( "<br>", "<b>Domain(s) to show:</b>", @domains), "<br>\n",
249 :     join( "<br>", "<b>Completeness?</b>", @complete), "\n",
250 :     "</TD>",
251 :     " </TR>\n",
252 :     "</TABLE>\n",
253 :     $cgi->p,
254 : redwards 1.2 $cgi->checkbox(-name=>"stats", -label=>"Only show statistics", -checked=>'on'), $cgi->p,
255 : redwards 1.1 $cgi->checkbox(-name=>"levels", -label=>"Show subsystem classification", -checked=>'on'), $cgi->p,
256 :     $cgi->checkbox(-name=>"genomes", -label=>"Show genomes in subsystem", -checked=>'on'), $cgi->p,
257 :     $cgi->checkbox(-name=>"roles", -label=>"Show roles in subsystem", -checked=>'on'), $cgi->p,
258 :     $cgi->end_form,
259 :    
260 :     }

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3