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

Annotation of /FigWebServices/genomebrowser.cgi

Parent Directory Parent Directory | Revision Log Revision Log


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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3