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

Annotation of /FigWebServices/genomebrowser.cgi

Parent Directory Parent Directory | Revision Log Revision Log


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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3