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

Annotation of /FigWebServices/genomebrowser.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
6 :    
7 :     A genome browser to view different things in genomes
8 :    
9 :     =cut
10 :    
11 :     use strict;
12 :     use FIG;
13 :     use HTML;
14 :     use raedraw;
15 :     use CGI;
16 :     my $cgi=new CGI;
17 :     my $fig;
18 :     eval {
19 :     $fig = new FIG;
20 :     };
21 :    
22 :     if ($@ ne "")
23 :     {
24 :     my $err = $@;
25 :    
26 :     my(@html);
27 :    
28 :     push(@html, $cgi->p("Error connecting to SEED database."));
29 :     if ($err =~ /Could not connect to DBI:.*could not connect to server/)
30 :     {
31 :     push(@html, $cgi->p("Could not connect to relational database of type $FIG_Config::dbms named $FIG_Config::db on port $FIG_Config::dbport."));
32 :     }
33 :     else
34 :     {
35 :     push(@html, $cgi->pre($err));
36 :     }
37 :     &HTML::show_page($cgi, \@html, 1);
38 :     exit;
39 :     }
40 :    
41 :    
42 :     $ENV{"PATH"} = "$FIG_Config::bin:$FIG_Config::ext_bin:" . $ENV{"PATH"};
43 :    
44 :     my $html = [];
45 :     my $user = $cgi->param('user');
46 :     my $err;
47 :    
48 :     if ($cgi->param('genome')) {
49 :     # draw the image
50 : redwards 1.2 unshift @$html, "<TITLE>The SEED - Genome Browser </TITLE>\n";
51 : redwards 1.1
52 :     my %imagefns;
53 :     foreach my $kw
54 :     (qw[width margin top_marg bottom_marg box_height rows box_no_score box_score show_function tick_mark_height genome_lines abrrev stopshort])
55 :     {
56 :     $imagefns{"-".$kw}=$cgi->param($kw);
57 :     }
58 :    
59 :     $cgi->param('genome') =~ /\((\d+\.\d+)\)/; $imagefns{'-genome'}=$1;
60 :     # this should be an array!!!
61 :    
62 :     foreach my $ct ($cgi->param('compare_to')) {
63 :     $ct =~ /\((\d+\.\d+)\)/;
64 :     push @{$imagefns{'-compare_to'}}, $1;
65 :     print STDERR "Added $1\n";
66 :     }
67 :    
68 :    
69 :     my $image=raedraw->new(%imagefns);
70 :     my $filename = "$FIG_Config::temp/genomebrowser_$$.svg";
71 :     my $url = &FIG::temp_url . "/genomebrowser_$$.svg";
72 :    
73 :    
74 : redwards 1.2 my ($width, $height)=$image->write_image($filename);
75 : redwards 1.1
76 : redwards 1.2 push @$html, $cgi->div({class=>"image"}, $cgi->object({class=>"genomebrowser", data=>"$url", width=>"$width", height=>"$height",
77 : redwards 1.1 standby=>"Loading genome browser image, please be patient"},
78 :     "There should have been an SVG graphic comparing the genomes that you have chosen here, however, you probably need to download ",
79 :     "the SVG viewer from <a href=\"http://www.adobe.com/svg/viewer/install/main.html\">Adobe</a> (yes, it is free)."),"\n",);
80 :     }
81 :    
82 :    
83 :    
84 :    
85 :     else {
86 : redwards 1.2 unshift @$html, "<TITLE>The SEED - Genome Browser </TITLE>\n";
87 : redwards 1.1 &show_initial($fig,$cgi,$html);
88 :     }
89 :    
90 :     push @$html, $cgi->div({class=>"errors", style=>"font-size: smaller"}, @$err);
91 :     &HTML::show_page($cgi,$html,1);
92 :     exit;
93 :    
94 :    
95 :    
96 :    
97 :    
98 :     sub show_initial {
99 :     my ($fig,$cgi,$html)=@_;
100 :     # generate a blank page
101 :     # we want a list of all functions that have >= 1 peg unless we want all
102 :    
103 :     push (@$html, $cgi->start_form(-action => "genomebrowser.cgi"),
104 :     $cgi->h2("Please choose some factors for your image"),
105 :     "First, please enter a username: ", $cgi->textfield(-name=>"user"), $cgi->p,
106 :     $cgi->h2("Please choose a <strong>single</strong> genome as the baseline:"), $cgi->p,
107 :     &genome_lists("domain1", "complete1", "genome", 0), $cgi->p,
108 :     $cgi->h2("Please choose one or more genomes as the comparators:"), $cgi->p,
109 :     &genome_lists("domain2", "complete2", "compare_to", 'true'), $cgi->p,
110 :     $cgi->submit(-label=>"Draw Genomes"), $cgi->reset);
111 :    
112 :    
113 :     my %options=(
114 :     width => [800, 'width'],
115 :     margin => [100, 'margin'],
116 :     top_marg => [20, 'top margin'],
117 :     bottom_marg => [20, 'bottom margin'],
118 :     box_height => [10, 'height of the boxes around the pegs'],
119 :     rows => [2, 'rows to split the image into'],
120 :     show_function=> [3, 'show function every n pegs'],
121 :     tick_mark_height=> [3, 'height of the tick marks on the genome line'],
122 :     );
123 :    
124 :     my %checkbox=(
125 :     box_no_score => [0, "draw boxes around empty cells"],
126 :     box_score => [1, "draw boxes around cells with content"],
127 :     genome_lines => [1, "draw lines where the genomes are"],
128 :     abbrev => [1, "abbreviate genome names"],
129 :     );
130 :    
131 :     my $advanced;
132 :     foreach my $opt (sort {$a cmp $b} keys %options) {
133 :     $advanced .= "\n" . $cgi->Tr($cgi->td([$options{$opt}->[1]. ":", $cgi->textfield(-name=>$opt, -default=>$options{$opt}->[0], -size=>4)]));
134 :     }
135 :     foreach my $opt (sort {$a cmp $b} keys %checkbox) {
136 :     $advanced .= "\n" . $cgi->Tr($cgi->td([$checkbox{$opt}->[1], $cgi->checkbox(-name=>$opt, -label=>'', -checked=>$checkbox{$opt}->[0])]));
137 :     }
138 :    
139 :     push @$html, "\n" , $cgi->p, $cgi->div({class=>"advanced"},
140 :     $cgi->table($advanced), $cgi->submit(-label=>"Draw Genomes"), $cgi->reset, $cgi->end_form);
141 :     }
142 :    
143 :    
144 :    
145 :    
146 :    
147 :    
148 :    
149 :    
150 :    
151 :    
152 :    
153 :     # generate the genome lists as needed.
154 :    
155 :     sub genome_lists {
156 :     my ($domain,$complete, $listname, $multiple)=@_;
157 :    
158 :     #############
159 :     #
160 :     # Stolen from index.cgi
161 :     #
162 :     #
163 :    
164 :     my @display = ( 'All', 'Archaea', 'Bacteria', 'Eucarya', 'Viruses', 'Environmental samples' );
165 :    
166 :     #
167 :     # Canonical names must match the keywords used in the DBMS. They are
168 :     # defined in compute_genome_counts.pl
169 :     #
170 :     my %canonical = (
171 :     'All' => undef,
172 :     'Archaea' => 'Archaea',
173 :     'Bacteria' => 'Bacteria',
174 :     'Eucarya' => 'Eukaryota',
175 :     'Viruses' => 'Virus',
176 :     'Environmental samples' => 'Environmental Sample'
177 :     );
178 :    
179 :     my $req_dom = $cgi->param( $domain ) || 'All';
180 :     my @domains = $cgi->radio_group( -name => $domain,
181 :     -default => $req_dom,
182 :     -override => 1,
183 :     -values => [ @display ]
184 :     );
185 :    
186 :     my $n_domain = 0;
187 :     my %dom_num = map { ( $_, $n_domain++ ) } @display;
188 :     my $req_dom_num = $dom_num{ $req_dom } || 0;
189 :    
190 :     #
191 :     # Viruses and Environmental samples must have completeness = All (that is
192 :     # how they are in the database). Otherwise, default is Only "complete".
193 :     #
194 :     my $req_comp = ( $req_dom_num > $dom_num{ 'Eucarya' } ) ? 'All'
195 :     : $cgi->param( 'complete' ) || 'Only "complete"';
196 :     my @complete = $cgi->radio_group( -name => $complete,
197 :     -default => $req_comp,
198 :     -override => 1,
199 :     -values => [ 'All', 'Only "complete"' ]
200 :     );
201 :     #
202 :     # Use $fig->genomes( complete, restricted, domain ) to get org list:
203 :     #
204 :     my $complete = ( $req_comp =~ /^all$/i ) ? undef : "complete";
205 :    
206 :     my @orgs = sort map { my $org = $_; my $gs = $fig->genus_species($org); my $gc=scalar $fig->all_contigs($org); "$gs ($org) [$gc contigs]" }
207 :     $fig->genomes( $complete, undef, $canonical{ $req_dom } );
208 :    
209 :     my $n_genomes = @orgs;
210 :    
211 :     return "<TABLE>\n",
212 :     " <TR>\n",
213 :     " <TD>",
214 :     $cgi->scrolling_list( -name => $listname,
215 :     -size => 10,
216 :     -multiple => $multiple,
217 :     -values => \@orgs,
218 :     ),
219 :     $cgi->br,
220 :     "$n_genomes genomes shown ",
221 :     $cgi->submit( 'Update List' ), $cgi->reset,
222 :     "</TD>",
223 :     " <TD>",
224 :     join( "<br>", "<b>Domain(s) to show:</b>", @domains), "<br>\n",
225 :     join( "<br>", "<b>Completeness?</b>", @complete), "\n",
226 :     "</TD>",
227 :     " </TR>\n",
228 :     "</TABLE>\n",
229 :     $cgi->br,
230 :    
231 :     }

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3