Parent Directory
|
Revision Log
Revision 1.3 - (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 : | redwards | 1.3 | elsif ($cgi->param('korgs')) {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 : | # figure out how many roles we have, as this will determine the number of rows in the table | ||
93 : | my @roles=$fig->subsystem_to_roles($subsys); | ||
94 : | my $rows=1; | ||
95 : | redwards | 1.3 | if (!$cgi->param('stats') && $cgi->param('korgs')) {$rows=scalar @roles} |
96 : | redwards | 1.1 | |
97 : | # figure out which genomes are in this subsystem | ||
98 : | my %genomes; | ||
99 : | foreach my $gen (@{$fig->subsystem_genomes($subsys)}) {$genomes{$gen->[0]}=$gen->[1]} | ||
100 : | |||
101 : | redwards | 1.2 | # start a new row for this data |
102 : | redwards | 1.3 | # tablerows is a refence to an array. |
103 : | # each element is an array of tablecells with the following values colspan rowspan value | ||
104 : | my $tablerows; | ||
105 : | redwards | 1.2 | |
106 : | redwards | 1.1 | # get the classification if required |
107 : | if ($cgi->param('levels')) { | ||
108 : | redwards | 1.2 | # get the classification and make sure there are now 2 columns as andrei doesn't like #3. |
109 : | redwards | 1.1 | my $class=$fig->subsystem_classification($subsys); |
110 : | redwards | 1.2 | unless ($class) {@$class=(' ',' ')} |
111 : | unless ($$class[0]) {$$class[0] = " "} | ||
112 : | unless ($$class[1]) {$$class[1] = " "} | ||
113 : | # remove anything more than $$class[1]; | ||
114 : | @$class=($$class[0], $$class[1]); # could have done this with splice. Ech. | ||
115 : | |||
116 : | redwards | 1.3 | foreach my $c (@$class) { |
117 : | push @$tablerows, ['1', $rows, $c]; | ||
118 : | } | ||
119 : | redwards | 1.1 | } |
120 : | |||
121 : | redwards | 1.2 | # add the subsystem to the table |
122 : | redwards | 1.3 | push @$tablerows, ['1', $rows, "<strong>$subsys<strong>"]; |
123 : | redwards | 1.2 | |
124 : | redwards | 1.1 | # add the genomes in the subsystem |
125 : | redwards | 1.3 | if ($cgi->param('genomes') && $cgi->param('stats')) {push @$tablerows, ['1', $rows, (scalar keys %genomes)]} |
126 : | elsif ($cgi->param('genomes')) { | ||
127 : | my $c=join "<br>\n", sort {$a cmp $b} values %genomes; | ||
128 : | push @$tablerows, ['1', $rows, $c]; | ||
129 : | } | ||
130 : | redwards | 1.2 | |
131 : | redwards | 1.3 | |
132 : | # | ||
133 : | # This is convolvuted because we may want to skip some empty cells, but we won't know whether | ||
134 : | # we want to skip them. Also, we are using rowspan/colspan to determine the size of the cells | ||
135 : | # so we need everything defined | ||
136 : | # | ||
137 : | # I store the table initially in @$tablerows, and then push it into @$table. Later on we | ||
138 : | # reconstruct @$table with <td> etc.... | ||
139 : | # | ||
140 : | # Now I am going to store the rows in @$toadd, and if we want them I will add them to @$table. | ||
141 : | # | ||
142 : | # For stats, there is only one row in @$toadd, but for other data there are several because | ||
143 : | # of the use of rowspan | ||
144 : | |||
145 : | my $pegcount; | ||
146 : | my $toadd; #this is what we will add if we need to | ||
147 : | redwards | 1.2 | if ($cgi->param('stats')) { |
148 : | redwards | 1.3 | push @$tablerows, ['1', $rows, (scalar @roles)]; |
149 : | my $totalpegs; | ||
150 : | redwards | 1.2 | # there should be a quicker way of getting this ... ? |
151 : | foreach my $role (@roles) { | ||
152 : | foreach my $genome (keys %genomes) { | ||
153 : | my $count = scalar ($fig->pegs_in_subsystem_cell($subsys, $genome, $role)); | ||
154 : | $pegcount->{$genome} += $count; | ||
155 : | $totalpegs += $count; | ||
156 : | } | ||
157 : | } | ||
158 : | redwards | 1.3 | |
159 : | push @$tablerows, ['1', $rows, $totalpegs]; | ||
160 : | redwards | 1.2 | foreach my $w (@wants) { |
161 : | redwards | 1.3 | push @$tablerows, ['1', $rows, $pegcount->{$w}]; # pegs for each of the chosen genomes |
162 : | redwards | 1.2 | } |
163 : | redwards | 1.3 | push @$toadd, $tablerows; |
164 : | redwards | 1.2 | } |
165 : | redwards | 1.3 | elsif ($cgi->param('korgs')) { |
166 : | redwards | 1.1 | # now add the roles |
167 : | my $first=1; | ||
168 : | foreach my $role (@roles) { | ||
169 : | my $genomeroles; | ||
170 : | foreach my $gen (@wants) { | ||
171 : | redwards | 1.2 | my $cell = ' '; |
172 : | redwards | 1.1 | if ($genomes{$gen}) { |
173 : | foreach my $peg ($fig->pegs_in_subsystem_cell($subsys, $gen, $role)) { | ||
174 : | $cell .= &HTML::fid_link($cgi,$peg) . "; "; | ||
175 : | } | ||
176 : | } | ||
177 : | redwards | 1.3 | push @$genomeroles, [1, 1, $cell]; |
178 : | redwards | 1.1 | } |
179 : | # because I am using rowspan to make long columns, we don't want the tr on the first of these. | ||
180 : | redwards | 1.3 | if ($first) { |
181 : | push @$tablerows, (['1', '1', $role], @$genomeroles); | ||
182 : | push @$toadd, $tablerows; | ||
183 : | } | ||
184 : | else { | ||
185 : | my $tr=[('1', '1', $role), @$genomeroles]; | ||
186 : | push @$toadd, $tr; | ||
187 : | } | ||
188 : | redwards | 1.1 | } |
189 : | } | ||
190 : | redwards | 1.3 | unless ($toadd) {$toadd=$tablerows} # in case we didn't define it |
191 : | # now decide if we want the table | ||
192 : | if ($cgi->param('orgpegs')) { | ||
193 : | my $mustadd; | ||
194 : | foreach my $org (@wants) {if ($pegcount->{$org}) {$mustadd=1}} # we'll add it if one of the orgs has a role | ||
195 : | if ($mustadd) {push @$table, @$toadd} | ||
196 : | } | ||
197 : | elsif ($cgi->param("haveroles")) { | ||
198 : | if (scalar(@roles)) {push @$table, @$toadd} | ||
199 : | } | ||
200 : | else { | ||
201 : | push @$table, @$toadd; | ||
202 : | } | ||
203 : | } | ||
204 : | |||
205 : | # now convert $table into a table | ||
206 : | |||
207 : | my $tab; | ||
208 : | foreach my $row (@$table) { | ||
209 : | $tab .= "\n<tr>"; | ||
210 : | foreach my $cell (@$row) { | ||
211 : | $tab .= "\n\t<td colspan=$cell->[0] rowspan=$cell->[1]>$cell->[2]</td>"; | ||
212 : | } | ||
213 : | $tab .= "\n</tr>\n"; | ||
214 : | redwards | 1.1 | } |
215 : | redwards | 1.3 | |
216 : | push @$html, ("\n<table border=1>" . $tableheader . $tab . "</table>\n"); | ||
217 : | redwards | 1.1 | } |
218 : | |||
219 : | |||
220 : | |||
221 : | |||
222 : | |||
223 : | |||
224 : | |||
225 : | |||
226 : | |||
227 : | |||
228 : | sub show_initial { | ||
229 : | ############# | ||
230 : | # | ||
231 : | # Stolen from index.cgi | ||
232 : | # | ||
233 : | # | ||
234 : | |||
235 : | my @display = ( 'All', 'Archaea', 'Bacteria', 'Eucarya', 'Viruses', 'Environmental samples' ); | ||
236 : | |||
237 : | # | ||
238 : | # Canonical names must match the keywords used in the DBMS. They are | ||
239 : | # defined in compute_genome_counts.pl | ||
240 : | # | ||
241 : | my %canonical = ( | ||
242 : | 'All' => undef, | ||
243 : | 'Archaea' => 'Archaea', | ||
244 : | 'Bacteria' => 'Bacteria', | ||
245 : | 'Eucarya' => 'Eukaryota', | ||
246 : | 'Viruses' => 'Virus', | ||
247 : | 'Environmental samples' => 'Environmental Sample' | ||
248 : | ); | ||
249 : | |||
250 : | my $req_dom = $cgi->param( 'domain' ) || 'All'; | ||
251 : | my @domains = $cgi->radio_group( -name => 'domain', | ||
252 : | -default => $req_dom, | ||
253 : | -override => 1, | ||
254 : | -values => [ @display ] | ||
255 : | ); | ||
256 : | |||
257 : | my $n_domain = 0; | ||
258 : | my %dom_num = map { ( $_, $n_domain++ ) } @display; | ||
259 : | my $req_dom_num = $dom_num{ $req_dom } || 0; | ||
260 : | |||
261 : | # | ||
262 : | # Viruses and Environmental samples must have completeness = All (that is | ||
263 : | # how they are in the database). Otherwise, default is Only "complete". | ||
264 : | # | ||
265 : | my $req_comp = ( $req_dom_num > $dom_num{ 'Eucarya' } ) ? 'All' | ||
266 : | : $cgi->param( 'complete' ) || 'Only "complete"'; | ||
267 : | my @complete = $cgi->radio_group( -name => 'complete', | ||
268 : | -default => $req_comp, | ||
269 : | -override => 1, | ||
270 : | -values => [ 'All', 'Only "complete"' ] | ||
271 : | ); | ||
272 : | # | ||
273 : | # Use $fig->genomes( complete, restricted, domain ) to get org list: | ||
274 : | # | ||
275 : | my $complete = ( $req_comp =~ /^all$/i ) ? undef : "complete"; | ||
276 : | |||
277 : | my @orgs = sort map { my $org = $_; my $gs = $fig->genus_species($org); my $gc=scalar $fig->all_contigs($org); "$gs ($org) [$gc contigs]" } | ||
278 : | $fig->genomes( $complete, undef, $canonical{ $req_dom } ); | ||
279 : | |||
280 : | my $n_genomes = @orgs; | ||
281 : | |||
282 : | push @$html, $cgi->start_form, | ||
283 : | $cgi->h2("Please choose one or more organisms from the list below to see in the subsystems table"), | ||
284 : | "<TABLE>\n", | ||
285 : | " <TR>\n", | ||
286 : | " <TD>", | ||
287 : | $cgi->scrolling_list( -name => 'korgs', | ||
288 : | -size => 10, | ||
289 : | -multiple => 1, | ||
290 : | -values => \@orgs, | ||
291 : | ), | ||
292 : | $cgi->br, | ||
293 : | "$n_genomes genomes shown ", | ||
294 : | $cgi->submit( 'Update List' ), $cgi->reset, $cgi->submit('submit', 'Summarize Subsystems'), | ||
295 : | "</TD>", | ||
296 : | " <TD>", | ||
297 : | join( "<br>", "<b>Domain(s) to show:</b>", @domains), "<br>\n", | ||
298 : | join( "<br>", "<b>Completeness?</b>", @complete), "\n", | ||
299 : | "</TD>", | ||
300 : | " </TR>\n", | ||
301 : | "</TABLE>\n", | ||
302 : | $cgi->p, | ||
303 : | redwards | 1.2 | $cgi->checkbox(-name=>"stats", -label=>"Only show statistics", -checked=>'on'), $cgi->p, |
304 : | redwards | 1.1 | $cgi->checkbox(-name=>"levels", -label=>"Show subsystem classification", -checked=>'on'), $cgi->p, |
305 : | $cgi->checkbox(-name=>"genomes", -label=>"Show genomes in subsystem", -checked=>'on'), $cgi->p, | ||
306 : | redwards | 1.3 | $cgi->checkbox(-name=>"haveroles", -label=>"Show only subsystems that have roles defined", -checked=>'on'), $cgi->p, |
307 : | $cgi->checkbox(-name=>"orgpegs", -label=>"Show only subsystems that have roles in the organism(s) you have chosen", -checked=>'on'), $cgi->p, | ||
308 : | |||
309 : | redwards | 1.1 | $cgi->end_form, |
310 : | |||
311 : | } |
MCS Webmaster | ViewVC Help |
Powered by ViewVC 1.0.3 |