3 # Copyright (C) 2006-2009 Martin A. Hansen.
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 # http://www.gnu.org/copyleft/gpl.html
21 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
26 use lib "/Users/maasha/biopieces/code_perl/";
37 use Maasha::Biopieces;
39 use Maasha::KISS::Track;
40 use Maasha::KISS::Draw;
42 my ( $cgi, $database, $user, $password, $dbh, $script, @html );
46 $database = 'S_aur_COL';
47 $user = Maasha::Biopieces::biopiecesrc( "MYSQL_USER" );
48 $password = Maasha::Biopieces::biopiecesrc( "MYSQL_PASSWORD" );
50 $dbh = Maasha::SQL::connect( $database, $user, $password );
52 $script = Maasha::Common::get_scriptname();
54 push @html, Maasha::XHTML::html_header(
56 title => "KISS Genome Browser",
57 # css_file => "test.css",
58 author => "Martin A. Hansen, mail\@maasha.dk",
59 description => "Biopieces bacterial genome browser - KISS",
60 keywords => [ qw( KISS Biopieces biopiece genome browser viewer bacterium bacteria prokaryote prokaryotes ) ],
64 push @html, Maasha::XHTML::h1( txt => "KISS Genome Browser", class => "center" );
65 push @html, Maasha::XHTML::form_beg( action => $script, method => "get", enctype => "multipart/form-data" );
67 push @html, sec_navigate( $cgi );
68 push @html, sec_browse( $dbh, $cgi->param( 'nav_start' ), $cgi->param( 'nav_end' ) );
70 push @html, Maasha::XHTML::form_end;
71 push @html, Maasha::XHTML::body_end;
72 push @html, Maasha::XHTML::html_end;
74 print "$_\n" foreach @html;
77 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
82 my ( $cgi, # CGI object
87 my ( $list_clade, $list_genome, $list_assembly, $list_contig, $def_clade, $def_genome, $def_assembly, $def_contig, $def_start, $def_end, @html );
89 $list_clade = nav_list_clade();
90 $list_genome = nav_list_genome();
91 $list_assembly = nav_list_assembly();
92 $list_contig = nav_list_contig();
95 nav_move( $cgi, 2_800_000 ); # FIXME
97 $def_clade = nav_def_clade( $cgi );
98 $def_genome = nav_def_genome( $cgi );
99 $def_assembly = nav_def_assembly( $cgi );
100 $def_contig = nav_def_contig( $cgi );
101 $def_start = nav_def_start( $cgi );
102 $def_end = nav_def_end( $cgi );
104 push @html, Maasha::XHTML::table_beg( summary => "Navigation table" );
105 push @html, Maasha::XHTML::table_row_simple( tr => [ qw( Clade Genome Assembly Contig Start End ) ], align => 'center' );
106 push @html, Maasha::XHTML::table_row_simple( tr => [
107 Maasha::XHTML::menu( name => "nav_clade", options => $list_clade, selected => $def_clade ),
108 Maasha::XHTML::menu( name => "nav_genome", options => $list_genome, selected => $def_genome ),
109 Maasha::XHTML::menu( name => "nav_assembly", options => $list_assembly, selected => $def_assembly ),
110 Maasha::XHTML::menu( name => "nav_contig", options => $list_contig, selected => $def_contig ),
111 Maasha::XHTML::text( name => "nav_start", value => Maasha::Calc::commify( $def_start ), size => 20 ),
112 Maasha::XHTML::text( name => "nav_end", value => Maasha::Calc::commify( $def_end ), size => 20 ),
113 Maasha::XHTML::submit( name => "nav_submit", value => "Submit" ),
115 push @html, Maasha::XHTML::table_end;
117 push @html, Maasha::XHTML::table_beg( summary => "Zoom table" );
118 push @html, Maasha::XHTML::table_row_simple( tr => [
119 Maasha::XHTML::p( txt => 'Move:' ),
120 Maasha::XHTML::submit( name => "move_left3", value => "<<<", title => "move 95% to the left" ),
121 Maasha::XHTML::submit( name => "move_left2", value => "<<", title => "move 47.5% to the left" ),
122 Maasha::XHTML::submit( name => "move_left1", value => "<", title => "move 10% to the left" ),
123 Maasha::XHTML::submit( name => "move_right1", value => ">", title => "move 10% to the rigth" ),
124 Maasha::XHTML::submit( name => "move_right2", value => ">>", title => "move 47.5% to the rigth" ),
125 Maasha::XHTML::submit( name => "move_right3", value => ">>>", title => "move 95% to the right" ),
126 Maasha::XHTML::p( txt => 'Zoom in:' ),
127 Maasha::XHTML::submit( name => "zoom_in1", value => "1.5x" ),
128 Maasha::XHTML::submit( name => "zoom_in2", value => "3x" ),
129 Maasha::XHTML::submit( name => "zoom_in3", value => "10x" ),
130 Maasha::XHTML::p( txt => 'Zoom out:' ),
131 Maasha::XHTML::submit( name => "zoom_out1", value => "1.5x" ),
132 Maasha::XHTML::submit( name => "zoom_out2", value => "3x" ),
133 Maasha::XHTML::submit( name => "zoom_out3", value => "10x" ),
135 push @html, Maasha::XHTML::table_end;
137 return wantarray ? @html : \@html;
143 my ( $dbh, # Database handle
144 $start, # Browse start position
145 $end, # Browse end position
150 my ( $t0, $t1, $ruler, $index, $index_beg, $index_len, $fh, $seq, $dna, $table, $entries, $features, $surface, $cr, $file, @html );
152 $ruler = Maasha::KISS::Track::track_ruler( 1200, 25, $start, $end );
154 $index = Maasha::Fasta::index_retrieve( "$ENV{ 'BP_DATA' }/genomes/S_aur_COL/fasta/S_aur_COL.index" );
156 ( $index_beg, $index_len ) = @{ $index->{ 'S_aur_COL' } };
158 $fh = Maasha::Filesys::file_read_open( "$ENV{ 'BP_DATA' }/genomes/S_aur_COL/fasta/S_aur_COL.fna" );
160 $seq = Maasha::Filesys::file_read( $fh, $index_beg + $start, $end - $start + 1 );
164 $dna = Maasha::KISS::Track::track_seq( 1200, 50, $seq ) if length $seq <= 220;
168 $t0 = Time::HiRes::gettimeofday();
169 $entries = Maasha::KISS::IO::kiss_sql_get( $dbh, $table, $start, $end );
170 $t1 = Time::HiRes::gettimeofday();
172 push @html, Maasha::XHTML::p( txt => "Feature count: " . Maasha::Calc::commify( scalar @$entries ) );
174 push @html, Maasha::XHTML::p( txt => "Time SQL: " . ( $t1 - $t0 ) );
176 $t0 = Time::HiRes::gettimeofday();
178 my $MAX = 4000; # FIXME should depend on height of track as well
180 if ( @$entries > $MAX ) {
181 $features = Maasha::KISS::Track::track_histogram( 1200, 75, $start, $end, $entries );
183 $features = Maasha::KISS::Track::track_feature( 1200, 75, $start, $end, $entries );
186 $t1 = Time::HiRes::gettimeofday();
188 # push @html, Maasha::KISS::Draw::hdump( $entries );
189 # push @html, Maasha::KISS::Draw::hdump( $features );
191 push @html, Maasha::XHTML::p( txt => "Time Track: " . ( $t1 - $t0 ) );
195 $surface = Cairo::ImageSurface->create( 'argb32', 1200, 800 );
196 $cr = Cairo::Context->create( $surface );
198 $t0 = Time::HiRes::gettimeofday();
200 Maasha::KISS::Draw::track_text( $cr, $ruler, "red" ) if $ruler;
201 Maasha::KISS::Draw::track_text( $cr, $dna, "red" ) if $dna;
203 Maasha::KISS::Draw::track_feature( $cr, $features, 'green' ) if $features;
205 Maasha::KISS::Draw::file_png( $surface, $file );
207 $t1 = Time::HiRes::gettimeofday();
209 push @html, Maasha::XHTML::p( txt => "Time Draw: " . ( $t1 - $t0 ) );
211 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::img( src => $file, alt => "Browser Tracks", height => 800, width => 1200, class => "foo", id => "pix_id", usemap => "map" ) );
213 return wantarray ? @html : \@html;
221 $list_clade = [ qw( Eukaryote Bacillus Fish ) ];
223 return wantarray ? @{ $list_clade } : $list_clade;
231 $list_genome = [ qw( S.aur_COL E.col B.sub ) ];
233 return wantarray ? @{ $list_genome } : $list_genome;
237 sub nav_list_assembly
239 my ( $list_assembly );
241 $list_assembly = [ qw( 2008-02-21 2009-01-23 ) ];
243 return wantarray ? @{ $list_assembly } : $list_assembly;
251 $list_contig = [ qw( chr1 chr2 ) ];
253 return wantarray ? @{ $list_contig } : $list_contig;
259 my ( $cgi, # CGI object
262 my ( $start, $end, $dist, $new_dist, $dist_diff, $new_start, $new_end );
264 if ( defined $cgi->param( 'nav_start' ) and $cgi->param( 'nav_end' ) )
266 $start = $cgi->param( 'nav_start' );
267 $end = $cgi->param( 'nav_end' );
272 $dist = $end - $start;
274 if ( defined $cgi->param( 'zoom_in1' ) ) {
275 $new_dist = $dist / 1.5;
276 } elsif ( defined $cgi->param( 'zoom_in2' ) ) {
277 $new_dist = $dist / 3;
278 } elsif ( defined $cgi->param( 'zoom_in3' ) ) {
279 $new_dist = $dist / 10;
280 } elsif ( defined $cgi->param( 'zoom_out1' ) ) {
281 $new_dist = $dist * 1.5;
282 } elsif ( defined $cgi->param( 'zoom_out2' ) ) {
283 $new_dist = $dist * 3;
284 } elsif ( defined $cgi->param( 'zoom_out3' ) ) {
285 $new_dist = $dist * 10;
290 $dist_diff = $dist - $new_dist;
291 $new_start = int( $start + ( $dist_diff / 2 ) );
292 $new_end = int( $end - ( $dist_diff / 2 ) );
294 $cgi->param( 'nav_start', $new_start );
295 $cgi->param( 'nav_end', $new_end );
303 my ( $cgi, # CGI object
304 $max, # Max end position
307 my ( $start, $end, $dist, $shift, $new_start, $new_end );
309 if ( defined $cgi->param( 'nav_start' ) and $cgi->param( 'nav_end' ) )
311 $start = $cgi->param( 'nav_start' );
312 $end = $cgi->param( 'nav_end' );
317 $dist = $end - $start;
319 if ( defined $cgi->param( 'move_left1' ) ) {
320 $shift = -1 * $dist * 0.10;
321 } elsif ( defined $cgi->param( 'move_left2' ) ) {
322 $shift = -1 * $dist * 0.475;
323 } elsif ( defined $cgi->param( 'move_left3' ) ) {
324 $shift = -1 * $dist * 0.95;
325 } elsif ( defined $cgi->param( 'move_right1' ) ) {
326 $shift = $dist * 0.10;
327 } elsif ( defined $cgi->param( 'move_right2' ) ) {
328 $shift = $dist * 0.475;
329 } elsif ( defined $cgi->param( 'move_right3' ) ) {
330 $shift = $dist * 0.95;
335 $new_start = int( $start + $shift );
336 $new_end = int( $end + $shift );
338 print "HERRRR: shift: $shift start: $new_start end: $new_end\n";
340 if ( $new_start > 0 and $new_end < $max )
342 $cgi->param( 'nav_start', $new_start );
343 $cgi->param( 'nav_end', $new_end );
352 my ( $cgi, # CGI object
357 if ( defined $cgi->param( 'nav_clade' ) )
359 $def_clade = $cgi->param( 'nav_clade' );
363 $def_clade = "Bacteria";
372 my ( $cgi, # CGI object
377 if ( defined $cgi->param( 'nav_genome' ) )
379 $def_genome = $cgi->param( 'nav_genome' );
383 $def_genome = "S.aur_COL";
392 my ( $cgi, # CGI object
395 my ( $def_assembly );
397 if ( defined $cgi->param( 'nav_assembly' ) )
399 $def_assembly = $cgi->param( 'nav_assembly' );
403 $def_assembly = "2009-01-23";
406 return $def_assembly;
412 my ( $cgi, # CGI object
417 if ( defined $cgi->param( 'nav_contig' ) )
419 $def_contig = $cgi->param( 'nav_contig' );
423 $def_contig = "chr1";
432 my ( $cgi, # CGI object
437 if ( defined $cgi->param( 'nav_start' ) ) {
438 $def_start = $cgi->param( 'nav_start' );
443 $def_start =~ tr/,//d;
445 if ( $def_start <= 0 ) {
449 $cgi->param( 'nav_start', $def_start );
457 my ( $cgi, # CGI object
462 if ( defined $cgi->param( 'nav_end' ) ) {
463 $def_end = $cgi->param( 'nav_end' );
471 if ( $def_end > 2809422 ) {
475 $cgi->param( 'nav_end', $def_end );
481 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
486 Maasha::SQL::disconnect( $dbh ) if $dbh;