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

Diff of /FigWebServices/subsys_summary.cgi

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2, Sat Feb 12 19:28:04 2005 UTC revision 1.15, Sat Feb 12 23:36:21 2005 UTC
# Line 76  Line 76 
76   }   }
77    
78    
79     my @wantheaders;
80     foreach my $gen (@wants) {push @wantheaders, $fig->abbrev($fig->genus_species($gen))}
81    
82   my @th;   my @th;
83   if ($cgi->param('levels')) {push @th, ('Level 1', 'Level 2')}   if ($cgi->param('levels')) {push @th, ('Level 1', 'Level 2')}
84   push @th, 'Subsystem'; # we should have this, at least   push @th, 'Subsystem'; # we should have this, at least
85   if ($cgi->param('genomes')) {push @th, ('Organisms')}   if ($cgi->param('genomes')) {push @th, ('Organisms')}
86   if ($cgi->param('stats')) {push @th, ('Roles', 'Total Pegs', @wants)}   if ($cgi->param('stats')) {push @th, ('Non-zero variants', 'Roles', 'Total Pegs', @wantheaders)}
87   elsif ($cgi->param('roles')) {push @th, ('Roles', @wants)}   elsif ($cgi->param('korgs')) {push @th, ('Roles', @wantheaders)}
88    
89   my $tableheader="<tr><th>". (join "</th><th>", @th) . "</th></tr>\n\n";   my $tableheader="<tr><th>". (join "</th><th>", @th) . "</th></tr>\n\n";
90    
# Line 89  Line 92 
92   my $table;   my $table;
93   foreach my $subsys ($fig->all_subsystems) {   foreach my $subsys ($fig->all_subsystems) {
94    
   # add a header  
   unless ($cgi->param('stats')) {$table .= "<tr><td colspan=$cols align=center><strong>Subsystem: $subsys</strong></td></tr>\n"}  
   
95    # figure out how many roles we have, as this will determine the number of rows in the table    # 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);    my @roles=$fig->subsystem_to_roles($subsys);
97    my $rows=1;    my $rows=1;
98    if (!$cgi->param('stats') && $cgi->param('roles')) {$rows=scalar @roles}    if (!$cgi->param('stats') && $cgi->param('korgs')) {$rows=scalar @roles}
99    
100    # figure out which genomes are in this subsystem    # figure out which genomes are in this subsystem
101    my %genomes;    my %genomes;
102    foreach my $gen (@{$fig->subsystem_genomes($subsys)}) {$genomes{$gen->[0]}=$gen->[1]}    foreach my $gen ($fig->get_subsystem($subsys)->get_genomes()) {$genomes{$gen}=$fig->genus_species($gen)}
103    
104    # start a new row for this data    # start a new row for this data
105    $table .= "\n<tr>\n";    # tablerows is a refence to an array.
106      # each element is an array of tablecells with the following values value colspan rowspan width
107      # if colspan or rowspan are undef they are believed to be 1
108      # if width is ommitted it is ignored
109    
110      my $tablerows;
111    # get the classification if required    # get the classification if required
112    if ($cgi->param('levels')) {    if ($cgi->param('levels')) {
113     # get the classification and make sure there are now 2 columns as andrei doesn't like #3.     # get the classification and make sure there are now 2 columns as andrei doesn't like #3.
# Line 114  Line 118 
118     # remove anything more than $$class[1];     # remove anything more than $$class[1];
119     @$class=($$class[0], $$class[1]); # could have done this with splice. Ech.     @$class=($$class[0], $$class[1]); # could have done this with splice. Ech.
120    
121     $table .= "\n\t<td rowspan='$rows'>" . (join "</td>\n\t<td rowspan='$rows'>", (@$class)) . "</td>";     foreach my $c (@$class) {
122        push @$tablerows, [$c, 1, $rows, 20];
123       }
124    }    }
125    
126    # add the subsystem to the table    # add the subsystem to the table
127    $table .= "\n\t<td><strong>$subsys<strong></td>";    my $link=&HTML::sub_link($cgi,$subsys);
128      push @$tablerows, [$link, '1', $rows];
129    
130    # add the genomes in the subsystem    # add the genomes in the subsystem
131    if ($cgi->param('genomes') && $cgi->param('stats')) {$table .= "\n\t<td rowspan='$rows'>" . (scalar keys %genomes) . " </td>"}    if ($cgi->param('genomes') && $cgi->param('stats')) {push @$tablerows, [(scalar keys %genomes), '1', $rows]}
132    elsif ($cgi->param('genomes')) {$table .= "\n\t<td rowspan='$rows'> &nbsp; " . (join "<br>\n", sort {$a cmp $b} values %genomes) . "</td>"}    elsif ($cgi->param('genomes')) {
133       my $c=join "<br>\n", sort {$a cmp $b} values %genomes;
134       push @$tablerows, [$c, 1, $rows];
135      }
136    
137      #
138      # This is convolvuted because we may want to skip some empty cells, but we won't know whether
139      # we want to skip them. Also, we are using rowspan/colspan to determine the size of the cells
140      # so we need everything defined
141      #
142      # I store the table initially in @$tablerows, and then push it into @$table. Later on we
143      # reconstruct @$table with <td> etc....
144      #
145      # Now I am going to store the rows in @$toadd, and if we want them I will add them to @$table.
146      #
147      # For stats, there is only one row in @$toadd, but for other data there are several because
148      # of the use of rowspan
149    
150      my $pegcount;
151      my $toadd; #this is what we will add if we need to
152    if ($cgi->param('stats')) {    if ($cgi->param('stats')) {
153     my $pegcount=0;     my $totalpegs;
154     $table .= "\n\t<td>" . (scalar @roles) . "</td>"; #number of roles in the subsystem     my $nzv=0; # non-zero variant codes
    my $pegcount; my $totalpegs;  
155     # there should be a quicker way of getting this ... ?     # there should be a quicker way of getting this ... ?
156     foreach my $role (@roles) {     foreach my $role (@roles) {
157      foreach my $genome (keys %genomes) {      foreach my $genome (keys %genomes) {
158       my $count = scalar ($fig->pegs_in_subsystem_cell($subsys, $genome, $role));       my $count = scalar ($fig->pegs_in_subsystem_cell($subsys, $genome, $role));
159       $pegcount->{$genome} += $count;       $pegcount->{$genome} += $count;
160       $totalpegs += $count;       $totalpegs += $count;
161         my $vc=$fig->get_subsystem($subsys)->get_variant_code_for_genome($genome);
162         unless ($vc == 0) {$nzv++}
163      }      }
164     }     }
165    
166     $table .= "\n\t<td>$totalpegs</td>"; # all the pegs in the subsystem     # add non-zero variant codes
167       push @$tablerows, [$nzv, 1, $rows];
168       # add roles
169       push @$tablerows, [(scalar @roles), '1', $rows];
170       # add total pegs
171       push @$tablerows, [$totalpegs, '1', $rows];
172     foreach my $w (@wants) {     foreach my $w (@wants) {
173      $table .= "\n\t<td>$pegcount->{$w}</td>"; # pegs for each of the chosen genomes      push @$tablerows, [$pegcount->{$w}, '1', $rows]; # pegs for each of the chosen genomes
174     }     }
175     $table .= "</tr>\n";     push @$toadd, $tablerows;
176    }    }
177    elsif ($cgi->param('roles')) {    elsif ($cgi->param('korgs')) {
    # now add the roles  
178     my $first=1;     my $first=1;
179     foreach my $role (@roles) {     foreach my $role (@roles) {
180      my $genomeroles;      my $genomeroles;
# Line 152  Line 182 
182       my $cell = ' &nbsp; ';       my $cell = ' &nbsp; ';
183       if ($genomes{$gen}) {       if ($genomes{$gen}) {
184        foreach my $peg ($fig->pegs_in_subsystem_cell($subsys, $gen, $role)) {        foreach my $peg ($fig->pegs_in_subsystem_cell($subsys, $gen, $role)) {
185         $cell .= &HTML::fid_link($cgi,$peg) . "; ";         $cell .= &HTML::fid_link($cgi,$peg, 'local') . "; ";
186        }        }
187       }       }
188       $genomeroles .= "\n\t<td>$cell</td>";       push @$genomeroles, [$cell, 1, 1];
189      }      }
190      # because I am using rowspan to make long columns, we don't want the tr on the first of these.      # because I am using rowspan to make long columns, we don't want the tr on the first of these.
191      if ($first) {$table .= "\n\t<td>$role</td>" . $genomeroles . "</tr>\n"; $first=0}      if ($first) {
192      else {$table .= "\n\t<tr><td>$role</td>" . $genomeroles . "</tr>\n"}       push @$tablerows, [$role, 1, 1], @$genomeroles;
193         push @$toadd, $tablerows;
194         undef $first;
195        }
196        else {
197         my @tr=([$role, 1, 1], @$genomeroles);
198         push @$toadd, \@tr;
199        }
200       }
201      }
202    
203      unless ($toadd) {
204       push @$toadd, $tablerows;
205      } # in case we didn't define it
206    
207    
208      # now decide if we want the table
209      if ($cgi->param('orgpegs')) {
210       my $mustadd;
211       foreach my $org (@wants) {if ($pegcount->{$org}) {$mustadd=1}} # we'll add it if one of the orgs has a role
212       if ($mustadd) {push @$table, @$toadd}
213      }
214      elsif ($cgi->param("haveroles")) {
215       if (scalar(@roles)) {push @$table, @$toadd}
216      }
217      else {
218       push @$table, @$toadd;
219      }
220     }
221    
222     # now convert $table into a table
223    
224     # sort the table
225     # if we have levels we want to sort on level 1 and then level 2 and then subsysname
226     # if not, we just sort on subsys name
227     if ($cgi->param("levels")) {
228      @$table = sort {
229       $a->[0]->[0] cmp $b->[0]->[0]
230                    ||
231       $a->[1]->[0] cmp $b->[1]->[0]
232                    ||
233       $a->[2]->[0] cmp $b->[2]->[0]
234      } @$table;
235     }     }
236     else {
237      @$table = sort {
238       $a->[0]->[0] cmp $b->[0]->[0]
239      } @$table;
240    }    }
241    else {$table .= "</tr>\n"}  
242    
243     my $tab;
244     foreach my $row (@$table) {
245      $tab .= "\n<tr>";
246      foreach my $cell (@$row) {
247       my $width='';
248       if ($cell->[3]) {$width="width=" . $cell->[3]}
249       $tab .= "\n\t<td valign=top $width colspan=$cell->[1] rowspan=$cell->[2]>$cell->[0]</td>";
250   }   }
251   push @$html, ("\n<table border=1>" . $tableheader . $table . "</table>\n");    $tab .= "\n</tr>\n";
252     }
253    
254     push @$html, ("\n<table border=1>" . $tableheader . $tab . "</table>\n");
255  }  }
256    
257    
# Line 183  Line 270 
270      #      #
271      #      #
272    
273    
274      my @display = ( 'All', 'Archaea', 'Bacteria', 'Eucarya', 'Viruses', 'Environmental samples' );      my @display = ( 'All', 'Archaea', 'Bacteria', 'Eucarya', 'Viruses', 'Environmental samples' );
275    
276      #      #
# Line 251  Line 339 
339                    "   </TR>\n",                    "   </TR>\n",
340                    "</TABLE>\n",                    "</TABLE>\n",
341                    $cgi->p,                    $cgi->p,
342                      "Enter user: ", $cgi->textfield(-name=>'user', size=>20), $cgi->p,
343                    $cgi->checkbox(-name=>"stats", -label=>"Only show statistics", -checked=>'on'), $cgi->p,                    $cgi->checkbox(-name=>"stats", -label=>"Only show statistics", -checked=>'on'), $cgi->p,
344                    $cgi->checkbox(-name=>"levels", -label=>"Show subsystem classification", -checked=>'on'), $cgi->p,                    $cgi->checkbox(-name=>"levels", -label=>"Show subsystem classification", -checked=>'on'), $cgi->p,
345                    $cgi->checkbox(-name=>"genomes", -label=>"Show genomes in subsystem", -checked=>'on'), $cgi->p,                    $cgi->checkbox(-name=>"genomes", -label=>"Show genomes in subsystem", -checked=>'on'), $cgi->p,
346                    $cgi->checkbox(-name=>"roles", -label=>"Show roles in subsystem", -checked=>'on'), $cgi->p,                    $cgi->checkbox(-name=>"haveroles", -label=>"Show only subsystems that have roles defined"), $cgi->p,
347                      $cgi->checkbox(-name=>"orgpegs", -label=>"Show only subsystems that have roles in the organism(s) you have chosen"), $cgi->p,
348    
349                    $cgi->end_form,                    $cgi->end_form,
350    
351  }  }

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.15

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3