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

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3