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

Annotation of /FigWebServices/genomebrowser.cgi

Parent Directory Parent Directory | Revision Log Revision Log


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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3