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

Annotation of /FigWebServices/subsys_vectors.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (view) (download)

1 : redwards 1.1 # -*- perl -*-
2 :    
3 :     =pod
4 :    
5 :     =head1 subsys_vectors.cgi
6 :    
7 :     Subsystem vectors is a page for displaying information about the functional variants for different subsystems in different genomes. The basic idea is to present a spreadsheet where the rows are organisms and the columns are subsystems. The cells will be variant codes.
8 :    
9 :     We will add the ability to sort the table by any individual subsystem, genus species information, or taxonomy.
10 :    
11 :     Coloring will be done by css with some css code somewhere (not sure where yet). Each cell will be given a class equal to subsysname."_".functionalvariant. If you set the value of $color{subsysname."_".functionalvariant} it will be set the color of the cell using css. hopefully.
12 :    
13 :     =cut
14 :    
15 :     use strict;
16 :     use FIG;
17 :     use HTML;
18 :     use raelib;
19 :     my $raelib=new raelib;
20 :     use CGI;
21 :     my $cgi=new CGI;
22 :    
23 :     my $fig;
24 :     eval {
25 :     $fig = new FIG;
26 :     };
27 :    
28 :     if ($@ ne "")
29 :     {
30 :     my $err = $@;
31 :    
32 :     my(@html);
33 :    
34 :     push(@html, $cgi->p("Error connecting to SEED database."));
35 :     if ($err =~ /Could not connect to DBI:.*could not connect to server/)
36 :     {
37 :     push(@html, $cgi->p("Could not connect to relational database of type $FIG_Config::dbms named $FIG_Config::db on port $FIG_Config::dbport."));
38 :     }
39 :     else
40 :     {
41 :     push(@html, $cgi->pre($err));
42 :     }
43 :     &HTML::show_page($cgi, \@html, 1);
44 :     exit;
45 :     }
46 :    
47 :     my $html = [];
48 :     my $user = $cgi->param('user');
49 :    
50 :     unshift(@$html, "<TITLE>The SEED - Subsystem Vectors</TITLE>\n");
51 :    
52 :    
53 :    
54 :     if ($cgi->param('korgs') && $cgi->param('subsystems'))
55 :     {
56 :     &show_table($fig,$cgi,$html);
57 :     }
58 :     else
59 :     {
60 :     &show_initial($fig,$cgi,$html);
61 :     }
62 :    
63 :     &HTML::show_page($cgi,$html,1);
64 :     exit;
65 :    
66 :    
67 :     sub show_initial {
68 :     my ($fig,$cgi,$html)=@_;
69 :     # generate a blank page
70 :     push @$html,
71 :     $cgi->start_form(),
72 :     $cgi->p("Please enter your username: &nbsp; ", $cgi->textfield("user")),
73 :     $cgi->p("Please choose some organisms from the list. You can choose more than one organism:"),
74 :     $raelib->scrolling_org_list($cgi, 1),
75 :     $cgi->p("Please choose some subsystems from the list. You can choose more than one subsystem."),
76 :     $raelib->scrolling_subsys_list($cgi, 1),
77 :     $cgi->p,
78 :     $cgi->submit, $cgi->reset, $cgi->end_form;
79 :     return $html;
80 :     }
81 :    
82 :     sub show_table {
83 :     my ($fig,$cgi,$html)=@_;
84 :     # what genomes are we interested in?
85 :     my @genomes=$cgi->param('korgs');
86 :     # and subsystems
87 :     my @ss=$cgi->param('subsystems');
88 :     # go through the subsystems and get the variant codes
89 :     # we do this first because we can load a subsystem and then get all vcs for it. Then when we do the table, we buuild it
90 :     # genome by genome and not col by col
91 :     my $vc;
92 :     foreach my $ss (@ss) {
93 :     my $subsystem=$fig->get_subsystem($ss);
94 :     foreach my $gen (@genomes) {
95 :     if ($subsystem->get_variant_code_for_genome($gen)) {$vc->{$ss}->{$gen}=$subsystem->get_variant_code_for_genome($gen)}
96 :     else {$vc->{$ss}->{$gen}=" &nbsp; "}
97 :     }
98 :     }
99 :    
100 :    
101 :     # now generate the table header
102 :     my $selfurl=$cgi->self_url;
103 :     $selfurl =~ s/(;?&?)sortby=.*?;?&?/$1/g;
104 :    
105 :     my $col_hdrs=[
106 :     "<a href='$selfurl;sortby=0'>Genome ID</a>",
107 :     "<a href='$selfurl;sortby=1'>Organism</a>"
108 :     ];
109 :    
110 :     my @labels=$raelib->subsys_names_for_display(@ss);
111 :     for (my $i=2; $i<=(scalar(@ss)+2); $i++) {
112 :     push @$col_hdrs, "<a href='$selfurl;sortby=$i'>".$labels[$i-2]."</a>";
113 :     }
114 :    
115 :     my $tab=[];
116 :     foreach my $gen (@genomes) {
117 :     my $row=[
118 :     [$gen, "td class='genomeid'"],
119 :     [$fig->genus_species($gen), "td class='genus_species'"]
120 :     ];
121 :     foreach my $ss (@ss) {
122 :     push @$row, [$vc->{$ss}->{$gen}, "td class='".${ss}."_".$vc->{$ss}->{$gen}."' style='text-align: center'"];
123 :     }
124 :     push @$tab, $row;
125 :     }
126 :    
127 :     my $sort=$cgi->param('sortby');
128 :     print STDERR "Sorting by $sort\n";
129 :     if ($sort =~ /^\d+$/) {
130 :     # sort by a column number
131 :     # all columns are refs to arrays, so we sort on the first element in the ref that defines the cell.
132 :     # we sort on the $sort value which is the name of the column.
133 :     # and we sort the rows of the table as $a and $b
134 :     @$tab=sort {$a->[$sort]->[0] cmp $b->[$sort]->[0]} @$tab;
135 :     }
136 :     elsif ($sort eq "by_phylo")
137 :     {
138 :     # stolen from subsys.cgi
139 :     $tab = [map { $_->[0] }
140 :     sort { ($a->[1] cmp $b->[1]) or ($a->[0]->[1] cmp $b->[0]->[1]) }
141 :     map { [$_, $fig->taxonomy_of($_->[0]->[0])] }
142 :     @$tab];
143 :     }
144 :     elsif ($sort eq "by_tax_id")
145 :     {
146 :     $tab = [sort { $a->[0] <=> $b->[0] } @$tab];
147 :     }
148 :    
149 :    
150 :    
151 :     push @$html,
152 :     "<center><h2>Subsystem Vectors</h2></center>",
153 : redwards 1.2 $cgi->start_form, $cgi->hidden('user'),
154 :     &HTML::make_table($col_hdrs, $tab, "Subsystem Version Codes"), "\n",
155 : redwards 1.1 $cgi->p("You may sort by an individual column by clicking on that column header, or you may sort by one of these options",
156 :     $cgi->popup_menu(-name => 'sortby', -value => ['','by_phylo','by_tax_id'], -labels => {"by_phylo"=>"Phylogeny", "by_tax_id"=>"Taxonomic ID"}, -default=>'')),
157 :     $cgi->p("You can modify your selected genomes:<br>", $raelib->scrolling_org_list($cgi, 1)),
158 :     $cgi->p("You can modify your selected subsystems:<br>", $raelib->scrolling_subsys_list($cgi, 1)),
159 :     $cgi->p, $cgi->submit, $cgi->reset,
160 :     $cgi->end_form;
161 :     }

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3