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

Annotation of /FigWebServices/genomebrowser.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.6 - (view) (download)

1 : redwards 1.1 # -*- perl -*-
2 : olson 1.6 #
3 :     # Copyright (c) 2003-2006 University of Chicago and Fellowship
4 :     # for Interpretations of Genomes. All Rights Reserved.
5 :     #
6 :     # This file is part of the SEED Toolkit.
7 :     #
8 :     # The SEED Toolkit is free software. You can redistribute
9 :     # it and/or modify it under the terms of the SEED Toolkit
10 :     # Public License.
11 :     #
12 :     # You should have received a copy of the SEED Toolkit Public License
13 :     # along with this program; if not write to the University of Chicago
14 :     # at info@ci.uchicago.edu or the Fellowship for Interpretation of
15 :     # Genomes at veronika@thefig.info or download a copy from
16 :     # http://www.theseed.org/LICENSE.TXT.
17 :     #
18 :    
19 : redwards 1.1
20 :     =pod
21 :    
22 :     =head1
23 :    
24 :     A genome browser to view different things in genomes
25 :    
26 :     =cut
27 :    
28 :     use strict;
29 :     use FIG;
30 :     use HTML;
31 :     use raedraw;
32 :     use CGI;
33 :     my $cgi=new CGI;
34 :     my $fig;
35 :     eval {
36 :     $fig = new FIG;
37 :     };
38 :    
39 :     if ($@ ne "")
40 :     {
41 :     my $err = $@;
42 :    
43 :     my(@html);
44 :    
45 :     push(@html, $cgi->p("Error connecting to SEED database."));
46 :     if ($err =~ /Could not connect to DBI:.*could not connect to server/)
47 :     {
48 :     push(@html, $cgi->p("Could not connect to relational database of type $FIG_Config::dbms named $FIG_Config::db on port $FIG_Config::dbport."));
49 :     }
50 :     else
51 :     {
52 :     push(@html, $cgi->pre($err));
53 :     }
54 :     &HTML::show_page($cgi, \@html, 1);
55 :     exit;
56 :     }
57 :    
58 :    
59 :     $ENV{"PATH"} = "$FIG_Config::bin:$FIG_Config::ext_bin:" . $ENV{"PATH"};
60 :    
61 :     my $html = [];
62 :     my $user = $cgi->param('user');
63 :     my $err;
64 :    
65 : redwards 1.5
66 :     foreach (@ARGV) {
67 :     my ($k, $v)=split /\=/;
68 :     if ($k eq "compare_to") {my @arr=split /\,/, $v; $v=\@arr}
69 :     $cgi->param(-name=>$k, -value=>$v);
70 :     }
71 :    
72 : redwards 1.1 if ($cgi->param('genome')) {
73 :     # draw the image
74 : redwards 1.2 unshift @$html, "<TITLE>The SEED - Genome Browser </TITLE>\n";
75 : redwards 1.1
76 :     my %imagefns;
77 :     foreach my $kw
78 : redwards 1.5 (qw[width margin top_marg bottom_marg box_height rows box_no_score box_score show_function tick_mark_height genome_lines abbrev stopshort
79 :     maxn maxp bluescale stopshort user])
80 : redwards 1.1 {
81 :     $imagefns{"-".$kw}=$cgi->param($kw);
82 :     }
83 :    
84 :     $cgi->param('genome') =~ /\((\d+\.\d+)\)/; $imagefns{'-genome'}=$1;
85 :     # this should be an array!!!
86 :    
87 :     foreach my $ct ($cgi->param('compare_to')) {
88 :     $ct =~ /\((\d+\.\d+)\)/;
89 :     push @{$imagefns{'-compare_to'}}, $1;
90 :     }
91 : redwards 1.5 if ($cgi->param('subsystems')) {push @{$imagefns{'-compare_to'}}, "subsystems"}
92 : redwards 1.3 if ($cgi->param('pirsf')) {push @{$imagefns{'-compare_to'}}, ['tagvalue', 'pirsf']}
93 :     #
94 :     # remember that we also need to pass in scalefactor here if we have one. This should be a tuple of 'pirsf' and the factor
95 :    
96 : redwards 1.5 if ($ARGV[0]) {
97 :     print STDERR "These are the compare to's: \n", join "\n", @{$imagefns{'-compare_to'}}, '';
98 :     }
99 : redwards 1.1
100 :     my $image=raedraw->new(%imagefns);
101 : redwards 1.3
102 :    
103 : redwards 1.1 my $filename = "$FIG_Config::temp/genomebrowser_$$.svg";
104 :     my $url = &FIG::temp_url . "/genomebrowser_$$.svg";
105 :    
106 :    
107 : redwards 1.2 my ($width, $height)=$image->write_image($filename);
108 : redwards 1.1
109 : redwards 1.5
110 : redwards 1.2 push @$html, $cgi->div({class=>"image"}, $cgi->object({class=>"genomebrowser", data=>"$url", width=>"$width", height=>"$height",
111 : redwards 1.1 standby=>"Loading genome browser image, please be patient"},
112 :     "There should have been an SVG graphic comparing the genomes that you have chosen here, however, you probably need to download ",
113 :     "the SVG viewer from <a href=\"http://www.adobe.com/svg/viewer/install/main.html\">Adobe</a> (yes, it is free)."),"\n",);
114 :     }
115 :    
116 :    
117 :    
118 :    
119 :     else {
120 : redwards 1.2 unshift @$html, "<TITLE>The SEED - Genome Browser </TITLE>\n";
121 : redwards 1.1 &show_initial($fig,$cgi,$html);
122 :     }
123 :    
124 : redwards 1.5 push @$err, "Computing this image took " . int((time-$^T)/0.6)/100 . " minutes\n";
125 : redwards 1.3 push @$html, $cgi->div({class=>"errors", style=>"font-size: smaller"}, $cgi->h3("Errors/Diagnoses we caught:"), @$err);
126 : redwards 1.1 &HTML::show_page($cgi,$html,1);
127 :     exit;
128 :    
129 :    
130 :    
131 :    
132 :    
133 :     sub show_initial {
134 :     my ($fig,$cgi,$html)=@_;
135 :     # generate a blank page
136 :     # we want a list of all functions that have >= 1 peg unless we want all
137 :    
138 :     push (@$html, $cgi->start_form(-action => "genomebrowser.cgi"),
139 :     $cgi->h2("Please choose some factors for your image"),
140 :     "First, please enter a username: ", $cgi->textfield(-name=>"user"), $cgi->p,
141 :     $cgi->h2("Please choose a <strong>single</strong> genome as the baseline:"), $cgi->p,
142 :     &genome_lists("domain1", "complete1", "genome", 0), $cgi->p,
143 :     $cgi->h2("Please choose one or more genomes as the comparators:"), $cgi->p,
144 :     &genome_lists("domain2", "complete2", "compare_to", 'true'), $cgi->p,
145 :     $cgi->submit(-label=>"Draw Genomes"), $cgi->reset);
146 :    
147 :    
148 :     my %options=(
149 :     width => [800, 'width'],
150 :     margin => [100, 'margin'],
151 :     top_marg => [20, 'top margin'],
152 :     bottom_marg => [20, 'bottom margin'],
153 :     box_height => [10, 'height of the boxes around the pegs'],
154 : redwards 1.4 rows => [10, 'split the image into rows'],
155 : redwards 1.1 show_function=> [3, 'show function every n pegs'],
156 :     tick_mark_height=> [3, 'height of the tick marks on the genome line'],
157 : redwards 1.5 maxn => [5, "Max sims"],
158 : redwards 1.3 maxp => [1e-5, "Max E-val"],
159 : redwards 1.5 stopshort => [500, "Stop after drawing this many pegs"],
160 : redwards 1.1 );
161 :    
162 :     my %checkbox=(
163 :     box_no_score => [0, "draw boxes around empty cells"],
164 :     box_score => [1, "draw boxes around cells with content"],
165 : redwards 1.3 bluescale => [1, "make the darkest color blue (if checked) or red (if not checked)"],
166 : redwards 1.1 genome_lines => [1, "draw lines where the genomes are"],
167 :     abbrev => [1, "abbreviate genome names"],
168 :     );
169 :    
170 :     my $advanced;
171 :     foreach my $opt (sort {$a cmp $b} keys %options) {
172 :     $advanced .= "\n" . $cgi->Tr($cgi->td([$options{$opt}->[1]. ":", $cgi->textfield(-name=>$opt, -default=>$options{$opt}->[0], -size=>4)]));
173 :     }
174 :     foreach my $opt (sort {$a cmp $b} keys %checkbox) {
175 :     $advanced .= "\n" . $cgi->Tr($cgi->td([$checkbox{$opt}->[1], $cgi->checkbox(-name=>$opt, -label=>'', -checked=>$checkbox{$opt}->[0])]));
176 :     }
177 :    
178 : redwards 1.3 push @$html, "\n" , $cgi->p, $cgi->div({class=>"advanced"}, $cgi->table($advanced));
179 : redwards 1.5
180 :     push @$html, $cgi->h3("Subsystems"), $cgi->table($cgi->Tr(
181 :     $cgi->td([$cgi->checkbox(-name=>'subsystems', -label=>'') . " &nbsp; highlight PEGs in subsystems"])));
182 : redwards 1.3
183 :     # now add the table for tag value pairs:
184 :     push @$html, $cgi->h3("Tag value pairs"), $cgi->table($cgi->Tr(
185 :     $cgi->td([$cgi->checkbox(-name=>'pirsf', -label=>'') . " &nbsp; PIR superfamilies", ''])));
186 :    
187 :     push @$html, $cgi->submit(-label=>"Draw Genomes"), $cgi->reset, $cgi->end_form;
188 :    
189 : redwards 1.1 }
190 :    
191 :    
192 :    
193 :    
194 :    
195 :    
196 :    
197 :    
198 :    
199 :    
200 :    
201 :     # generate the genome lists as needed.
202 :    
203 :     sub genome_lists {
204 :     my ($domain,$complete, $listname, $multiple)=@_;
205 :    
206 :     #############
207 :     #
208 :     # Stolen from index.cgi
209 :     #
210 :     #
211 :    
212 :     my @display = ( 'All', 'Archaea', 'Bacteria', 'Eucarya', 'Viruses', 'Environmental samples' );
213 :    
214 :     #
215 :     # Canonical names must match the keywords used in the DBMS. They are
216 :     # defined in compute_genome_counts.pl
217 :     #
218 :     my %canonical = (
219 :     'All' => undef,
220 :     'Archaea' => 'Archaea',
221 :     'Bacteria' => 'Bacteria',
222 :     'Eucarya' => 'Eukaryota',
223 :     'Viruses' => 'Virus',
224 :     'Environmental samples' => 'Environmental Sample'
225 :     );
226 :    
227 :     my $req_dom = $cgi->param( $domain ) || 'All';
228 :     my @domains = $cgi->radio_group( -name => $domain,
229 :     -default => $req_dom,
230 :     -override => 1,
231 :     -values => [ @display ]
232 :     );
233 :    
234 :     my $n_domain = 0;
235 :     my %dom_num = map { ( $_, $n_domain++ ) } @display;
236 :     my $req_dom_num = $dom_num{ $req_dom } || 0;
237 :    
238 :     #
239 :     # Viruses and Environmental samples must have completeness = All (that is
240 :     # how they are in the database). Otherwise, default is Only "complete".
241 :     #
242 :     my $req_comp = ( $req_dom_num > $dom_num{ 'Eucarya' } ) ? 'All'
243 :     : $cgi->param( 'complete' ) || 'Only "complete"';
244 :     my @complete = $cgi->radio_group( -name => $complete,
245 :     -default => $req_comp,
246 :     -override => 1,
247 :     -values => [ 'All', 'Only "complete"' ]
248 :     );
249 :     #
250 :     # Use $fig->genomes( complete, restricted, domain ) to get org list:
251 :     #
252 :     my $complete = ( $req_comp =~ /^all$/i ) ? undef : "complete";
253 :    
254 :     my @orgs = sort map { my $org = $_; my $gs = $fig->genus_species($org); my $gc=scalar $fig->all_contigs($org); "$gs ($org) [$gc contigs]" }
255 :     $fig->genomes( $complete, undef, $canonical{ $req_dom } );
256 :    
257 :     my $n_genomes = @orgs;
258 :    
259 :     return "<TABLE>\n",
260 :     " <TR>\n",
261 :     " <TD>",
262 :     $cgi->scrolling_list( -name => $listname,
263 :     -size => 10,
264 :     -multiple => $multiple,
265 :     -values => \@orgs,
266 :     ),
267 :     $cgi->br,
268 :     "$n_genomes genomes shown ",
269 :     $cgi->submit( 'Update List' ), $cgi->reset,
270 :     "</TD>",
271 :     " <TD>",
272 :     join( "<br>", "<b>Domain(s) to show:</b>", @domains), "<br>\n",
273 :     join( "<br>", "<b>Completeness?</b>", @complete), "\n",
274 :     "</TD>",
275 :     " </TR>\n",
276 :     "</TABLE>\n",
277 :     $cgi->br,
278 :    
279 :     }

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3