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, $cookie, $script, @html );
45 $script = Maasha::Common::get_scriptname();
46 $cookie = cookie_default( $cgi );;
48 push @html, Maasha::XHTML::html_header(
50 title => "KISS Genome Browser",
51 css_file => "kiss.css",
52 author => "Martin A. Hansen, mail\@maasha.dk",
53 description => "Biopieces bacterial genome browser - KISS",
54 keywords => [ qw( KISS Biopieces biopiece genome browser viewer bacterium bacteria prokaryote prokaryotes ) ],
58 push @html, Maasha::XHTML::h1( txt => "KISS Genome Browser", class => 'center' );
59 push @html, Maasha::XHTML::form_beg( action => $script, method => "get", enctype => "multipart/form-data" );
61 push @html, sec_navigate( $cookie );
62 push @html, sec_browse( $cookie );
64 push @html, Maasha::XHTML::form_end;
65 push @html, Maasha::XHTML::body_end;
66 push @html, Maasha::XHTML::html_end;
68 print "$_\n" foreach @html;
71 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
76 my ( $cgi, # CGI object
85 $cookie->{ 'DATA_DIR' } = "Data";
87 cookie_cgi( $cookie, $cgi );
88 cookie_user( $cookie );
89 cookie_clade( $cookie );
90 cookie_genome( $cookie );
91 cookie_assembly( $cookie );
92 cookie_contig( $cookie );
93 cookie_start( $cookie );
94 cookie_end( $cookie );
95 cookie_zoom( $cookie );
96 cookie_move( $cookie );
98 # print STDERR Dumper( $cookie );
100 return wantarray ? %{ $cookie } : $cookie;
112 $cookie->{ 'DEF_CLADE' } = $cgi->param( 'nav_clade' );
113 $cookie->{ 'DEF_GENOME' } = $cgi->param( 'nav_genome' );
114 $cookie->{ 'DEF_ASSEMBLY' } = $cgi->param( 'nav_assembly' );
115 $cookie->{ 'DEF_CONTIG' } = $cgi->param( 'nav_contig' );
116 $cookie->{ 'NAV_START' } = $cgi->param( 'nav_start' );
117 $cookie->{ 'NAV_END' } = $cgi->param( 'nav_end' );
118 $cookie->{ 'ZOOM_IN1' } = $cgi->param( 'zoom_in1' );
119 $cookie->{ 'ZOOM_IN2' } = $cgi->param( 'zoom_in2' );
120 $cookie->{ 'ZOOM_IN3' } = $cgi->param( 'zoom_in3' );
121 $cookie->{ 'ZOOM_OUT1' } = $cgi->param( 'zoom_out1' );
122 $cookie->{ 'ZOOM_OUT2' } = $cgi->param( 'zoom_out2' );
123 $cookie->{ 'ZOOM_OUT3' } = $cgi->param( 'zoom_out3' );
124 $cookie->{ 'MOVE_LEFT1' } = $cgi->param( 'move_left1' );
125 $cookie->{ 'MOVE_LEFT2' } = $cgi->param( 'move_left2' );
126 $cookie->{ 'MOVE_LEFT3' } = $cgi->param( 'move_left3' );
127 $cookie->{ 'MOVE_RIGHT1' } = $cgi->param( 'move_right1' );
128 $cookie->{ 'MOVE_RIGHT2' } = $cgi->param( 'move_right2' );
129 $cookie->{ 'MOVE_RIGHT3' } = $cgi->param( 'move_right3' );
142 @dirs = Maasha::Filesys::ls_dirs( "$cookie->{ 'DATA_DIR' }/Users" );
144 foreach $dir ( @dirs )
146 next if $dir =~ /\/\.\.?$/;
148 push @{ $cookie->{ 'LIST_USER' } }, ( split "/", $dir )[ -1 ];
151 $cookie->{ 'DEF_USER' } = $cookie->{ 'LIST_USER' }->[ 0 ];
162 my ( $user, @dirs, $dir );
164 $user = $cookie->{ 'DEF_USER' };
166 @dirs = Maasha::Filesys::ls_dirs( "$cookie->{ 'DATA_DIR' }/Users/$user" );
168 foreach $dir ( @dirs )
170 next if $dir =~ /\/\.\.?$/;
172 push @{ $cookie->{ 'LIST_CLADE' } }, ( split "/", $dir )[ -1 ];
175 if ( not defined $cookie->{ 'DEF_CLADE' } ) {
176 $cookie->{ 'DEF_CLADE' } = $cookie->{ 'LIST_CLADE' }->[ 1 ];
188 my ( $user, $clade, @dirs, $dir );
190 $user = $cookie->{ 'DEF_USER' };
191 $clade = $cookie->{ 'DEF_CLADE' };
193 @dirs = Maasha::Filesys::ls_dirs( "$cookie->{ 'DATA_DIR' }/Users/$user/$clade" );
195 foreach $dir ( @dirs )
197 next if $dir =~ /\/\.\.?$/;
199 push @{ $cookie->{ 'LIST_GENOME' } }, ( split "/", $dir )[ -1 ];
202 if ( not defined $cookie->{ 'DEF_GENOME' } ) {
203 $cookie->{ 'DEF_GENOME' } = $cookie->{ 'LIST_GENOME' }->[ 0 ];
215 my ( $user, $clade, $genome, @dirs, $dir );
217 $user = $cookie->{ 'DEF_USER' };
218 $clade = $cookie->{ 'DEF_CLADE' };
219 $genome = $cookie->{ 'DEF_GENOME' };
221 @dirs = Maasha::Filesys::ls_dirs( "$cookie->{ 'DATA_DIR' }/Users/$user/$clade/$genome" );
223 foreach $dir ( @dirs )
225 next if $dir =~ /\/\.\.?$/;
227 push @{ $cookie->{ 'LIST_ASSEMBLY' } }, ( split "/", $dir )[ -1 ];
230 if ( not defined $cookie->{ 'DEF_ASSEMBLY' } ) {
231 $cookie->{ 'DEF_ASSEMBLY' } = $cookie->{ 'LIST_ASSEMBLY' }->[ 0 ];
243 my ( $user, $clade, $genome, $assembly, @dirs, $dir );
245 $user = $cookie->{ 'DEF_USER' };
246 $clade = $cookie->{ 'DEF_CLADE' };
247 $genome = $cookie->{ 'DEF_GENOME' };
248 $assembly = $cookie->{ 'DEF_ASSEMBLY' };
250 @dirs = Maasha::Filesys::ls_dirs( "$cookie->{ 'DATA_DIR' }/Users/$user/$clade/$genome/$assembly" );
252 foreach $dir ( @dirs )
254 next if $dir =~ /\/\.\.?$/;
256 push @{ $cookie->{ 'LIST_CONTIG' } }, ( split "/", $dir )[ -1 ];
259 if ( not defined $cookie->{ 'DEF_CONTIG' } ) {
260 $cookie->{ 'DEF_CONTIG' } = $cookie->{ 'LIST_CONTIG' }->[ 0 ];
272 if ( defined $cookie->{ 'NAV_START' } )
274 $cookie->{ 'NAV_START' } =~ tr/,//d;
275 $cookie->{ 'NAV_START' } = 1 if $cookie->{ 'NAV_START' } <= 0;
279 $cookie->{ 'NAV_START' } = 1;
293 $max = Maasha::Filesys::file_size( Maasha::KISS::Track::path_seq( $cookie ) );
295 if ( defined $cookie->{ 'NAV_END' } )
297 $cookie->{ 'NAV_END' } =~ tr/,//d;
298 $cookie->{ 'NAV_END' } = $max if $cookie->{ 'NAV_END' } > $max;
302 $cookie->{ 'NAV_END' } = $max;
314 my ( $max, $dist, $new_dist, $dist_diff );
316 $max = Maasha::Filesys::file_size( Maasha::KISS::Track::path_seq( $cookie ) );
318 $dist = $cookie->{ 'NAV_END' } - $cookie->{ 'NAV_START' };
320 if ( defined $cookie->{ 'ZOOM_IN1' } ) {
321 $new_dist = $dist / 1.5;
322 } elsif ( defined $cookie->{ 'ZOOM_IN2' } ) {
323 $new_dist = $dist / 3;
324 } elsif ( defined $cookie->{ 'ZOOM_IN3' } ) {
325 $new_dist = $dist / 10;
326 } elsif ( defined $cookie->{ 'ZOOM_OUT1' } ) {
327 $new_dist = $dist * 1.5;
328 } elsif ( defined $cookie->{ 'ZOOM_OUT2' } ) {
329 $new_dist = $dist * 3;
330 } elsif ( defined $cookie->{ 'ZOOM_OUT3' } ) {
331 $new_dist = $dist * 10;
336 $dist_diff = $dist - $new_dist;
338 $cookie->{ 'NAV_START' } = int( $cookie->{ 'NAV_START' } + ( $dist_diff / 2 ) );
339 $cookie->{ 'NAV_END' } = int( $cookie->{ 'NAV_END' } - ( $dist_diff / 2 ) );
341 $cookie->{ 'NAV_START' } = 1 if $cookie->{ 'NAV_START' } <= 0;
342 $cookie->{ 'NAV_END' } = $max if $cookie->{ 'NAV_END' } > $max;
352 my ( $max, $dist, $shift, $new_start, $new_end );
354 $max = Maasha::Filesys::file_size( Maasha::KISS::Track::path_seq( $cookie ) );
356 $dist = $cookie->{ 'NAV_END' } - $cookie->{ 'NAV_START' };
358 if ( defined $cookie->{ 'MOVE_LEFT1' } ) {
359 $shift = -1 * $dist * 0.10;
360 } elsif ( defined $cookie->{ 'MOVE_LEFT2' } ) {
361 $shift = -1 * $dist * 0.475;
362 } elsif ( defined $cookie->{ 'MOVE_LEFT3' } ) {
363 $shift = -1 * $dist * 0.95;
364 } elsif ( defined $cookie->{ 'MOVE_RIGHT1' } ) {
365 $shift = $dist * 0.10;
366 } elsif ( defined $cookie->{ 'MOVE_RIGHT2' } ) {
367 $shift = $dist * 0.475;
368 } elsif ( defined $cookie->{ 'MOVE_RIGHT3' } ) {
369 $shift = $dist * 0.95;
374 $new_start = int( $cookie->{ 'NAV_START' } + $shift );
375 $new_end = int( $cookie->{ 'NAV_END' } + $shift );
377 if ( $new_start > 0 and $new_end < $max )
379 $cookie->{ 'NAV_START' } = $new_start;
380 $cookie->{ 'NAV_END' } = $new_end;
395 push @html, Maasha::XHTML::table_beg( summary => "Navigation table", align => 'center' );
396 push @html, Maasha::XHTML::table_row_simple( tr => [ qw( Clade Genome Assembly Contig Start End ) ], align => 'center' );
397 push @html, Maasha::XHTML::table_row_simple( tr => [
398 Maasha::XHTML::menu( name => "nav_clade", options => $cookie->{ 'LIST_CLADE' }, selected => $cookie->{ 'DEF_CLADE' } ),
399 Maasha::XHTML::menu( name => "nav_genome", options => $cookie->{ 'LIST_GENOME' }, selected => $cookie->{ 'DEF_GENOME' } ),
400 Maasha::XHTML::menu( name => "nav_assembly", options => $cookie->{ 'LIST_ASSEMBLY' }, selected => $cookie->{ 'DEF_ASSEMBLY' } ),
401 Maasha::XHTML::menu( name => "nav_contig", options => $cookie->{ 'LIST_CONTIG' }, selected => $cookie->{ 'DEF_CONTIG' } ),
402 Maasha::XHTML::text( name => "nav_start", value => Maasha::Calc::commify( $cookie->{ 'NAV_START' } ), size => 20 ),
403 Maasha::XHTML::text( name => "nav_end", value => Maasha::Calc::commify( $cookie->{ 'NAV_END' } ), size => 20 ),
404 Maasha::XHTML::submit( name => "nav_submit", value => "Submit" ),
406 push @html, Maasha::XHTML::table_end;
408 push @html, Maasha::XHTML::table_beg( summary => "Zoom table", align => 'center' );
409 push @html, Maasha::XHTML::table_row_simple( tr => [
410 Maasha::XHTML::p( txt => 'Move:' ),
411 Maasha::XHTML::submit( name => "move_left3", value => "<<<", title => "move 95% to the left" ),
412 Maasha::XHTML::submit( name => "move_left2", value => "<<", title => "move 47.5% to the left" ),
413 Maasha::XHTML::submit( name => "move_left1", value => "<", title => "move 10% to the left" ),
414 Maasha::XHTML::submit( name => "move_right1", value => ">", title => "move 10% to the rigth" ),
415 Maasha::XHTML::submit( name => "move_right2", value => ">>", title => "move 47.5% to the rigth" ),
416 Maasha::XHTML::submit( name => "move_right3", value => ">>>", title => "move 95% to the right" ),
417 Maasha::XHTML::p( txt => 'Zoom in:' ),
418 Maasha::XHTML::submit( name => "zoom_in1", value => "1.5x" ),
419 Maasha::XHTML::submit( name => "zoom_in2", value => "3x" ),
420 Maasha::XHTML::submit( name => "zoom_in3", value => "10x" ),
421 Maasha::XHTML::p( txt => 'Zoom out:' ),
422 Maasha::XHTML::submit( name => "zoom_out1", value => "1.5x" ),
423 Maasha::XHTML::submit( name => "zoom_out2", value => "3x" ),
424 Maasha::XHTML::submit( name => "zoom_out3", value => "10x" ),
426 push @html, Maasha::XHTML::table_end;
428 @html = Maasha::XHTML::div( txt => join( "\n", @html ), class => 'navigate' );
430 return wantarray ? @html : \@html;
441 my ( $draw_metrics, @tracks, @features, $feat, $elem, $file, $surface, $cr, @html, @img );
448 RULER_FONT_SIZE => 10,
449 RULER_COLOR => 'black',
451 SEQ_COLOR => 'black',
455 push @features, [ Maasha::KISS::Track::track_ruler( $draw_metrics, $cookie ) ];
456 push @features, [ Maasha::KISS::Track::track_seq( $draw_metrics, $cookie ) ];
458 @tracks = Maasha::KISS::Track::path_tracks( $cookie );
460 map { push @features, [ Maasha::KISS::Track::track_feature( $_, $draw_metrics, $cookie ) ] } @tracks;
464 $surface = Cairo::ImageSurface->create( 'argb32', $draw_metrics->{ 'IMG_WIDTH' }, $draw_metrics->{ 'TRACK_OFFSET' } );
465 $cr = Cairo::Context->create( $surface );
467 foreach $feat ( @features ) {
468 Maasha::KISS::Draw::draw_feature( $cr, $feat ) if $feat;
471 Maasha::KISS::Draw::file_png( $surface, $file );
473 push @img, Maasha::XHTML::img(
475 alt => "Browser Tracks",
476 height => $draw_metrics->{ 'TRACK_OFFSET' },
477 width => $draw_metrics->{ 'IMG_WIDTH' },
479 usemap => "#browser_map"
482 push @img, Maasha::XHTML::map_beg( name => "browser_map", id => "browser_map" );
484 foreach $feat ( @features )
486 foreach $elem ( @{ $feat } )
488 next if not $elem->{ 'type' } eq 'line';
490 push @img, Maasha::XHTML::area(
491 href => "www.dmi.dk",
493 coords => "$elem->{ x1 }, $elem->{ y1 }, $elem->{ x2 }, $elem->{ y2 }", title => "$elem->{ 'title' }",
498 push @img, Maasha::XHTML::map_end();
500 push @html, Maasha::XHTML::p( txt => join( "\n", @img ) );
502 @html = Maasha::XHTML::div( txt => join( "\n", @html ), class => 'browse' );
504 return wantarray ? @html : \@html;
508 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
513 # push @html, Maasha::KISS::Draw::hdump( $entries );
514 # push @html, Maasha::KISS::Draw::hdump( $features );
516 $t0 = Time::HiRes::gettimeofday();
517 $t1 = Time::HiRes::gettimeofday();