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

Annotation of /FigWebServices/genomebrowser.cgi

Parent Directory Parent Directory | Revision Log Revision Log


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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3