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 $ENV{ 'BP_PERL' };
36 use Maasha::BGB::Session;
37 use Maasha::BGB::Track;
38 use Maasha::BGB::Draw;
40 my ( $cgi, $cookie, @html );
43 $cookie = cookie_default( $cgi );;
45 push @html, Maasha::XHTML::html_header(
47 title => "Biopieces Genome Browser",
48 css_file => "bgb.css",
49 author => "Martin A. Hansen, mail\@maasha.dk",
50 description => "Biopieces Genome Browser",
51 keywords => [ qw( Biopieces biopiece genome browser viewer bacterium bacteria prokaryote prokaryotes ) ],
55 push @html, Maasha::XHTML::h1( txt => "Biopieces Genome Browser", class => 'center' );
56 push @html, Maasha::XHTML::form_beg( action => $cookie->{ 'SCRIPT' }, method => "post", enctype => "multipart/form-data" );
58 push @html, page( $cookie );
60 push @html, Maasha::XHTML::form_end;
61 push @html, Maasha::XHTML::body_end;
62 push @html, Maasha::XHTML::html_end;
64 # push @html, Maasha::XHTML::hdump( [ $cgi->Vars ] ); # DEBUG
65 # push @html, Maasha::XHTML::hdump( \%ENV ); # DEBUG
66 # push @html, Maasha::XHTML::hdump( $cookie ); # DEBUG
68 print "$_\n" foreach @html;
71 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> SUBROUTINES <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
74 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> COOKIE <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
79 # Martin A. Hansen, November 2009.
81 # Set a cookie with values from the CGI object or defaults.
83 my ( $cgi, # CGI object
88 my ( $cookie, $path );
92 if ( $cgi->param( 'nav_search' ) )
94 if ( $cgi->param( 'nav_search' ) =~ /([0-9,]+)[ -]([0-9,]+)/ )
96 $cookie->{ 'NAV_START' } = $1;
97 $cookie->{ 'NAV_END' } = $2;
101 $cookie->{ 'SEARCH' } = $cgi->param( 'nav_search' );
103 $cgi->param( 'page', 'search' );
107 $cookie->{ 'SCRIPT' } = Maasha::Common::get_scriptname();
108 $cookie->{ 'DATA_DIR' } = "Data";
109 $cookie->{ 'SESSION_DIR' } = "Sessions";
110 $cookie->{ 'LIST_PAGES' } = [ qw( clade genome assembly contig browse ) ];
112 $cookie->{ 'USER' } = $cgi->param( 'user' ) || '';
113 $cookie->{ 'PASSWORD' } = $cgi->param( 'password' );
114 $cookie->{ 'SESSION_ID' } = $cgi->param( 'session_id' );
116 cookie_session( $cookie );
117 cookie_login( $cookie );
119 $cookie->{ 'PAGE' } ||= $cgi->param( 'page' ) || 'login';
120 $cookie->{ 'CLADE' } = $cgi->param( 'clade' ) || '';
121 $cookie->{ 'GENOME' } = $cgi->param( 'genome' ) || '';
122 $cookie->{ 'ASSEMBLY' } = $cgi->param( 'assembly' ) || '';
123 $cookie->{ 'CONTIG' } = $cgi->param( 'contig' ) || '';
124 $cookie->{ 'Q_ID' } = $cgi->param( 'q_id' );
125 $cookie->{ 'NAV_START' } ||= $cgi->param( 'nav_start' ) || $cgi->param( 's_beg' ); # FIXME this is ugly!
126 $cookie->{ 'NAV_END' } ||= $cgi->param( 'nav_end' ) || $cgi->param( 's_end' );
127 $cookie->{ 'S_BEG' } = $cgi->param( 's_beg' );
128 $cookie->{ 'S_END' } = $cgi->param( 's_end' );
129 $cookie->{ 'STRAND' } = $cgi->param( 'strand' );
130 $cookie->{ 'ZOOM_IN1' } = $cgi->param( 'zoom_in1' );
131 $cookie->{ 'ZOOM_IN2' } = $cgi->param( 'zoom_in2' );
132 $cookie->{ 'ZOOM_IN3' } = $cgi->param( 'zoom_in3' );
133 $cookie->{ 'ZOOM_OUT1' } = $cgi->param( 'zoom_out1' );
134 $cookie->{ 'ZOOM_OUT2' } = $cgi->param( 'zoom_out2' );
135 $cookie->{ 'ZOOM_OUT3' } = $cgi->param( 'zoom_out3' );
136 $cookie->{ 'MOVE_LEFT1' } = $cgi->param( 'move_left1' );
137 $cookie->{ 'MOVE_LEFT2' } = $cgi->param( 'move_left2' );
138 $cookie->{ 'MOVE_LEFT3' } = $cgi->param( 'move_left3' );
139 $cookie->{ 'MOVE_RIGHT1' } = $cgi->param( 'move_right1' );
140 $cookie->{ 'MOVE_RIGHT2' } = $cgi->param( 'move_right2' );
141 $cookie->{ 'MOVE_RIGHT3' } = $cgi->param( 'move_right3' );
143 $cookie->{ 'IMG_WIDTH' } = 1200;
144 $cookie->{ 'IMG_HEIGHT' } = 800;
145 $cookie->{ 'TRACK_OFFSET' } = 20;
146 $cookie->{ 'TRACK_SPACE' } = 20;
147 $cookie->{ 'RULER_FONT_SIZE' } = 10;
148 $cookie->{ 'RULER_COLOR' } = [ 0, 0, 0 ];
149 $cookie->{ 'SEQ_FONT_SIZE' } = 10;
150 $cookie->{ 'SEQ_COLOR' } = [ 0, 0, 0, ];
151 $cookie->{ 'FEAT_WIDTH' } = 5;
152 $cookie->{ 'FEAT_COLOR' } = [ 0, 0, 0 ];
153 $cookie->{ 'FEAT_MAX' } = 5000;
155 $path = "$cookie->{ 'DATA_DIR' }/Users";
157 $cookie->{ 'LIST_USER' } = Maasha::Filesys::ls_dirs_base( $path ) if -d $path;
159 $path .= "/$cookie->{ 'USER' }";
161 $cookie->{ 'LIST_CLADE' } = Maasha::Filesys::ls_dirs_base( $path ) if -d $path;
163 $path .= "/$cookie->{ 'CLADE' }";
165 $cookie->{ 'LIST_GENOME' } = Maasha::Filesys::ls_dirs_base( $path ) if -d $path;
167 $path .= "/$cookie->{ 'GENOME' }";
169 $cookie->{ 'LIST_ASSEMBLY' } = Maasha::Filesys::ls_dirs_base( $path ) if -d $path;
171 $path .= "/$cookie->{ 'ASSEMBLY' }";
173 $cookie->{ 'LIST_CONTIG' } = Maasha::Filesys::ls_dirs_base( $path ) if -d $path;
175 if ( $cookie->{ 'CONTIG' } )
177 cookie_start( $cookie );
178 cookie_end( $cookie );
179 cookie_zoom( $cookie );
180 cookie_move( $cookie );
183 $cookie->{ 'STRAND' } = '+' if defined $cookie->{ 'STRAND' } and $cookie->{ 'STRAND' } eq ' '; # FIXME ugly HTML fix
185 return wantarray ? %{ $cookie } : $cookie;
191 # Martin A. Hansen, December 2009.
193 # Check cookie information against session information.
195 my ( $cookie, # cookie hash
202 $session = Maasha::BGB::Session::session_restore( "$cookie->{ 'SESSION_DIR' }/sessions.txt" );
204 # if ( $cookie->{ 'SESSION_ID' } )
206 # if ( $cookie->{ 'SESSION_ID' } ne $ENV{ 'SSL_SESSION_ID' } ) {
207 # $cookie->{ 'PAGE' } = 'login';
208 # print STDERR "HER1"; # DEBUG
213 # $cookie->{ 'PAGE' } = 'login';
215 # print STDERR "HER2"; # DEBUG
218 if ( exists $session->{ $cookie->{ 'USER' } } and $cookie->{ 'SESSION_ID' } )
220 if ( $session->{ $cookie->{ 'USER' } }->{ 'SESSION_ID' } ne $cookie->{ 'SESSION_ID' } ) {
221 $cookie->{ 'PAGE' } = 'login';
222 print STDERR "HER3"; # DEBUG
227 $cookie->{ 'PAGE' } = 'login';
228 print STDERR "HER4"; # DEBUG
229 print STDERR "NO COOKIE SESSION ID\n" if not $cookie->{ 'SESSION_ID' }; # DEBUG
230 print STDERR "NO COOKIE SESSION ID\n" if not $cookie->{ 'USER' }; # DEBUG
231 print STDERR "NO SESSION USER\n" if not exists $session->{ $cookie->{ 'USER' } }; # DEBUG
238 # Martin A. Hansen, December 2009.
240 # Check a user and password from CGI against the password file and
241 # set the session ID, if found, in the cookie.
243 my ( $cookie, # cookie hash
250 if ( $cookie->{ 'USER' } and $cookie->{ 'PASSWORD' } )
252 $session = Maasha::BGB::Session::session_restore( "$cookie->{ 'SESSION_DIR' }/sessions.txt" );
254 if ( exists $session->{ $cookie->{ 'USER' } } and
255 $session->{ $cookie->{ 'USER' } }->{ 'PASSWORD' } eq Digest::MD5::md5_hex( $cookie->{ 'PASSWORD' } ) )
257 $session->{ $cookie->{ 'USER' } }->{ 'SESSION_ID' } ||= Maasha::BGB::Session::session_new();
258 # $session->{ $cookie->{ 'USER' } }->{ 'SESSION_ID' } = $ENV{ 'SSL_SESSION_ID' };
259 $session->{ $cookie->{ 'USER' } }->{ 'TIME' } = Maasha::Common::time_stamp();
261 $cookie->{ 'SESSION_ID' } = $session->{ $cookie->{ 'USER' } }->{ 'SESSION_ID' };
262 $cookie->{ 'LOGIN' } = "OK";
263 $cookie->{ 'PAGE' } = 'clade';
265 Maasha::BGB::Session::session_store( "$cookie->{ 'SESSION_DIR' }/sessions.txt", $session );
269 $cookie->{ 'LOGIN' } = "ERROR";
277 # Martin A. Hansen, November 2009.
279 # Decommify the cookie value for NAV_START and adjust it to
280 # to prevent negative values.
282 my ( $cookie, # cookie hash
287 if ( defined $cookie->{ 'NAV_START' } )
289 $cookie->{ 'NAV_START' } =~ tr/,//d;
290 $cookie->{ 'NAV_START' } = 0 if $cookie->{ 'NAV_START' } < 0;
294 $cookie->{ 'NAV_START' } = 0;
301 # Martin A. Hansen, November 2009.
303 # Decommify the cookie value for NAV_END and adjust it to prevent
304 # overshooting the max value for the contig size as determined
307 my ( $cookie, # cookie hash
314 $max = Maasha::Filesys::file_size( Maasha::BGB::Track::path_seq( $cookie ) );
316 if ( defined $cookie->{ 'NAV_END' } )
318 $cookie->{ 'NAV_END' } =~ tr/,//d;
319 $cookie->{ 'NAV_END' } = $max if $cookie->{ 'NAV_END' } > $max;
323 $cookie->{ 'NAV_END' } = $max;
330 # Martin A. Hansen, November 2009.
332 # Adjust the cookie values for NAV_START and NAV_END based
333 # on cookie ZOOM values.
335 my ( $cookie, # cookie hash
340 my ( $max, $dist, $new_dist, $dist_diff );
342 $max = Maasha::Filesys::file_size( Maasha::BGB::Track::path_seq( $cookie ) );
344 $dist = $cookie->{ 'NAV_END' } - $cookie->{ 'NAV_START' };
346 if ( defined $cookie->{ 'ZOOM_IN1' } ) {
347 $new_dist = $dist / 1.5;
348 } elsif ( defined $cookie->{ 'ZOOM_IN2' } ) {
349 $new_dist = $dist / 3;
350 } elsif ( defined $cookie->{ 'ZOOM_IN3' } ) {
351 $new_dist = $dist / 10;
352 } elsif ( defined $cookie->{ 'ZOOM_OUT1' } ) {
353 $new_dist = $dist * 1.5;
354 } elsif ( defined $cookie->{ 'ZOOM_OUT2' } ) {
355 $new_dist = $dist * 3;
356 } elsif ( defined $cookie->{ 'ZOOM_OUT3' } ) {
357 $new_dist = $dist * 10;
362 $dist_diff = $dist - $new_dist;
364 $cookie->{ 'NAV_START' } = int( $cookie->{ 'NAV_START' } + ( $dist_diff / 2 ) );
365 $cookie->{ 'NAV_END' } = int( $cookie->{ 'NAV_END' } - ( $dist_diff / 2 ) );
367 $cookie->{ 'NAV_START' } = 0 if $cookie->{ 'NAV_START' } < 0;
368 $cookie->{ 'NAV_END' } = $max if $cookie->{ 'NAV_END' } > $max;
375 # Martin A. Hansen, November 2009.
377 # Adjust the cookie values for NAV_START and NAV_END based
378 # on cookie MOVE values.
380 my ( $cookie, # cookie hash
383 my ( $max, $dist, $shift, $new_start, $new_end );
385 $max = Maasha::Filesys::file_size( Maasha::BGB::Track::path_seq( $cookie ) );
387 $dist = $cookie->{ 'NAV_END' } - $cookie->{ 'NAV_START' };
389 if ( defined $cookie->{ 'MOVE_LEFT1' } ) {
390 $shift = -1 * $dist * 0.10;
391 } elsif ( defined $cookie->{ 'MOVE_LEFT2' } ) {
392 $shift = -1 * $dist * 0.475;
393 } elsif ( defined $cookie->{ 'MOVE_LEFT3' } ) {
394 $shift = -1 * $dist * 0.95;
395 } elsif ( defined $cookie->{ 'MOVE_RIGHT1' } ) {
396 $shift = $dist * 0.10;
397 } elsif ( defined $cookie->{ 'MOVE_RIGHT2' } ) {
398 $shift = $dist * 0.475;
399 } elsif ( defined $cookie->{ 'MOVE_RIGHT3' } ) {
400 $shift = $dist * 0.95;
405 $new_start = int( $cookie->{ 'NAV_START' } + $shift );
406 $new_end = int( $cookie->{ 'NAV_END' } + $shift );
408 if ( $new_start > 0 and $new_end < $max )
410 $cookie->{ 'NAV_START' } = $new_start;
411 $cookie->{ 'NAV_END' } = $new_end;
419 # Martin A. Hansen, November 2009.
421 # Returns the href for a taxonomy path terminated at a given
422 # page using information stored in a cookie.
424 my ( $cookie, # cookie hash
430 my ( @href_list, %href_hash, $href );
432 $href_hash{ "user" } = $cookie->{ 'USER' } if $cookie->{ 'USER' };
436 $href_hash{ "clade" } = $cookie->{ 'CLADE' } if $cookie->{ 'CLADE' };
437 last if $page eq 'clade';
438 $href_hash{ "genome" } = $cookie->{ 'GENOME' } if $cookie->{ 'GENOME' };
439 last if $page eq 'genome';
440 $href_hash{ "assembly" } = $cookie->{ 'ASSEMBLY' } if $cookie->{ 'ASSEMBLY' };
441 last if $page eq 'assembly';
442 $href_hash{ "contig" } = $cookie->{ 'CONTIG' } if $cookie->{ 'CONTIG' };
443 last if $page eq 'contig';
447 if ( defined $cookie->{ 'NAV_START' } and defined $cookie->{ 'NAV_END' } and $page !~ /clade|genome|assembly|contig|browse/ ) {
448 $href_hash{ "nav_search" } = "$cookie->{ 'NAV_START' }-$cookie->{ 'NAV_END' }";
451 $href_hash{ "s_beg" } = $cookie->{ 'S_BEG' } if defined $cookie->{ 'S_BEG' };
452 $href_hash{ "s_end" } = $cookie->{ 'S_END' } if defined $cookie->{ 'S_END' };
453 $href_hash{ "q_id" } = $cookie->{ 'Q_ID' } if defined $cookie->{ 'Q_ID' };
454 $href_hash{ "strand" } = $cookie->{ 'STRAND' } if defined $cookie->{ 'STRAND' };
455 $href_hash{ "session_id" } = $cookie->{ 'SESSION_ID' } if defined $cookie->{ 'SESSION_ID' };
457 push @href_list, "$cookie->{ 'SCRIPT' }?page=$page";
459 foreach $href ( keys %href_hash ) {
460 push @href_list, "$href=$href_hash{ $href }";
463 return join "&", @href_list;
469 # Martin A. Hansen, November 2009.
471 # Returns the next page in the taxonomy path.
473 my ( $cookie, # cookie hash
480 for ( $i = 0; $i < @{ $cookie->{ 'LIST_PAGES' } }; $i++ ) {
481 last if $cookie->{ 'PAGE' } eq $cookie->{ 'LIST_PAGES' }->[ $i ];
484 return $cookie->{ 'LIST_PAGES' }->[ $i + 1 ];
488 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> PAGES <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
493 # Martin A. Hansen, November 2009.
495 # Determines what page to render based on
496 # the cookie's PAGE setting.
498 my ( $cookie, # cookie hash
505 if ( $cookie->{ 'PAGE' } eq 'login' ) {
506 push @html, page_login( $cookie );
507 } elsif ( $cookie->{ 'PAGE' } eq 'search' ) {
508 push @html, page_search( $cookie );
509 } elsif ( $cookie->{ 'PAGE' } eq 'browse' ) {
510 push @html, page_browse( $cookie );
511 } elsif ( $cookie->{ 'PAGE' } eq 'dna' ) {
512 push @html, page_dna( $cookie );
513 } elsif ( $cookie->{ 'PAGE' } eq 'export' ) {
514 push @html, page_export( $cookie );
516 push @html, page_taxonomy( $cookie );
519 if ( $cookie->{ 'SESSION_ID' } ) {
520 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "session_id", value => $cookie->{ 'SESSION_ID' } ) );
523 return wantarray ? @html : \@html;
529 # Martin A. Hansen, December 2009.
531 # Renders the login page.
540 push @html, section_login( $cookie );
542 return wantarray ? @html : \@html;
548 # Martin A. Hansen, December 2009.
550 # Renders the search page.
559 push @html, section_taxonomy_table( $cookie );
560 push @html, section_search( $cookie );
562 return wantarray ? @html : \@html;
568 # Martin A. Hansen, November 2009.
570 # Renders the browse page.
579 push @html, section_taxonomy_table( $cookie );
580 push @html, section_navigate( $cookie );
581 push @html, section_browse( $cookie );
583 return wantarray ? @html : \@html;
589 # Martin A. Hansen, November 2009.
591 # Renders the DNA page.
600 push @html, section_taxonomy_table( $cookie );
601 push @html, section_dna( $cookie );
603 return wantarray ? @html : \@html;
609 # Martin A. Hansen, November 2009.
611 # Renders the export page.
620 push @html, section_taxonomy_table( $cookie );
621 push @html, section_export( $cookie );
623 return wantarray ? @html : \@html;
629 # Martin A. Hansen, November 2009.
631 # Renders the browse page.
633 my ( $cookie, # cookie hash
640 push @html, section_taxonomy_table( $cookie );
641 push @html, section_taxonomy_select( $cookie );
643 return wantarray ? @html : \@html;
647 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> SECTIONS <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
652 # Martin A. Hansen, December 2009.
654 # Returns a HTML section with a login menu.
656 my ( $cookie, # cookie hash
661 my ( $user, $password, $login, @html );
663 $user = Maasha::XHTML::text( name => "user", value => "", size => 20 );
664 $password = Maasha::XHTML::password( name => "password", value => "", size => 20 );
665 $login = Maasha::XHTML::submit( name => "login_submit", value => "Login" );
667 push @html, Maasha::XHTML::h2( txt => "Login", class => 'center' );
669 push @html, Maasha::XHTML::table_beg( summary => "Login table", align => 'center' );
670 push @html, Maasha::XHTML::table_row_simple( tr => [ "User:", $user ] );
671 push @html, Maasha::XHTML::table_row_simple( tr => [ "Password:", $password ] );
672 push @html, Maasha::XHTML::table_row_simple( tr => [ "", $login ] );
673 push @html, Maasha::XHTML::table_end;
675 if ( $cookie->{ 'LOGIN' } and $cookie->{ 'LOGIN' } eq 'ERROR' ) {
676 push @html, Maasha::XHTML::h3( txt => "Bad user or password - please retry", class => 'error' );
679 return wantarray ? @html : \@html;
683 sub section_taxonomy_table
685 # Martin A. Hansen, November 2009.
687 # Returns a HTML section with a taxonomy table
688 # showing the location in the taxonomy and with
689 # links to browse the taxonomy.
691 my ( $cookie, # cookie hash
696 my ( $page, @row, @html, $href, $txt );
698 foreach $page ( @{ $cookie->{ 'LIST_PAGES' } } )
700 last if $page eq $cookie->{ 'PAGE' } or $page eq 'browse';
702 $href = cookie_href( $cookie, $page );
704 $txt = ": $cookie->{ uc $page }";
706 push @row, Maasha::XHTML::ln( txt => $page, href => $href, class => 'inline' );
707 push @row, Maasha::XHTML::p( txt => $txt, class => 'inline' );
710 push @html, Maasha::XHTML::table_beg( summary => "Taxonomy table", align => 'center', cellpadding => '5px' );
711 push @html, Maasha::XHTML::table_row_simple( tr => [ join( "\n", @row ) ], align => 'center' );
712 push @html, Maasha::XHTML::table_end;
714 return wantarray ? @html : \@html;
718 sub section_taxonomy_select
720 # Martin A. Hansen, November 2009.
722 # Returns a HTML section with selection choices
723 # for navigating the taxonomy tree.
725 my ( $cookie, # cookie hash
730 my ( $list, @html, $item, $href );
732 $list = "LIST_" . uc $cookie->{ 'PAGE' };
734 push @html, Maasha::XHTML::h2( txt => "Select $cookie->{ 'PAGE' }", class => 'center' );
736 push @html, Maasha::XHTML::table_beg( summary => "Taxonomy select table", align => 'center', cellpadding => '5px' );
738 foreach $item ( @{ $cookie->{ $list } } )
740 $cookie->{ uc $cookie->{ 'PAGE' } } = $item;
742 $href = cookie_href( $cookie, cookie_page_next( $cookie ) );
744 push @html, Maasha::XHTML::table_row_simple( tr => [ Maasha::XHTML::ln( txt => $item, href => $href ) ] );
747 push @html, Maasha::XHTML::table_end;
749 return wantarray ? @html : \@html;
755 # Martin A. Hansen, November 2009.
757 # Returns a HTML section for navigating in the browser window.
759 my ( $cookie, # cookie hash
764 my ( @html, $nav_val );
766 $nav_val = Maasha::Calc::commify( $cookie->{ 'NAV_START' } ) . "-" . Maasha::Calc::commify( $cookie->{ 'NAV_END' } );
768 push @html, Maasha::XHTML::table_beg( summary => "Navigation table", align => 'center' );
769 push @html, Maasha::XHTML::table_row_simple( tr => [
770 "Position or search term:",
771 Maasha::XHTML::text( name => "nav_search", value => $nav_val, size => 30 ),
772 Maasha::XHTML::submit( name => "nav_submit", value => "Submit" ),
774 push @html, Maasha::XHTML::table_end;
776 push @html, Maasha::XHTML::table_beg( summary => "Zoom table", align => 'center' );
777 push @html, Maasha::XHTML::table_row_simple( tr => [
778 Maasha::XHTML::p( txt => 'Move:' ),
779 Maasha::XHTML::submit( name => "move_left3", value => "<<<", title => "move 95% to the left" ),
780 Maasha::XHTML::submit( name => "move_left2", value => "<<", title => "move 47.5% to the left" ),
781 Maasha::XHTML::submit( name => "move_left1", value => "<", title => "move 10% to the left" ),
782 Maasha::XHTML::submit( name => "move_right1", value => ">", title => "move 10% to the rigth" ),
783 Maasha::XHTML::submit( name => "move_right2", value => ">>", title => "move 47.5% to the rigth" ),
784 Maasha::XHTML::submit( name => "move_right3", value => ">>>", title => "move 95% to the right" ),
785 Maasha::XHTML::p( txt => 'Zoom in:' ),
786 Maasha::XHTML::submit( name => "zoom_in1", value => "1.5x" ),
787 Maasha::XHTML::submit( name => "zoom_in2", value => "3x" ),
788 Maasha::XHTML::submit( name => "zoom_in3", value => "10x" ),
789 Maasha::XHTML::p( txt => 'Zoom out:' ),
790 Maasha::XHTML::submit( name => "zoom_out1", value => "1.5x" ),
791 Maasha::XHTML::submit( name => "zoom_out2", value => "3x" ),
792 Maasha::XHTML::submit( name => "zoom_out3", value => "10x" ),
794 push @html, Maasha::XHTML::table_end;
796 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "page", value => "browse" ) );
797 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "user", value => $cookie->{ 'USER' } ) );
798 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "clade", value => $cookie->{ 'CLADE' } ) );
799 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "genome", value => $cookie->{ 'GENOME' } ) );
800 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "assembly", value => $cookie->{ 'ASSEMBLY' } ) );
801 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "contig", value => $cookie->{ 'CONTIG' } ) );
803 return wantarray ? @html : \@html;
814 my ( @tracks, $i, @features, $feat, $elem, $surface, $cr, $png_data, @html, @img );
816 push @features, [ Maasha::BGB::Track::track_ruler( $cookie ) ];
817 push @features, [ Maasha::BGB::Track::track_seq( $cookie ) ];
819 @tracks = Maasha::BGB::Track::path_tracks( $cookie );
821 for ( $i = 0; $i < @tracks; $i++ )
823 $cookie->{ 'FEAT_COLOR' } = Maasha::BGB::Draw::palette( $i );
825 push @features, [ Maasha::BGB::Track::track_feature( $tracks[ $i ], $cookie ) ];
828 $surface = Cairo::ImageSurface->create( 'argb32', $cookie->{ 'IMG_WIDTH' }, $cookie->{ 'TRACK_OFFSET' } );
829 $cr = Cairo::Context->create( $surface );
831 $cr->rectangle ( 0, 0, $cookie->{ 'IMG_WIDTH' }, $cookie->{ 'TRACK_OFFSET' } );
832 $cr->set_source_rgb ( 1, 1, 1 );
835 foreach $feat ( @features ) {
836 Maasha::BGB::Draw::draw_feature( $cr, $feat ) if $feat;
839 $png_data = Maasha::BGB::Draw::base64_png( $surface );
841 push @img, Maasha::XHTML::img(
842 src => "data:image/png;base64,$png_data",
843 alt => "Browser Tracks",
844 height => $cookie->{ 'TRACK_OFFSET' },
845 width => $cookie->{ 'IMG_WIDTH' },
847 usemap => "#browser_map"
850 push @img, Maasha::XHTML::map_beg( name => "browser_map", id => "browser_map" );
852 foreach $feat ( @features )
854 foreach $elem ( @{ $feat } )
856 next if $elem->{ 'type' } eq 'text';
858 #$elem->{ 'strand' } = '+' if $elem->{ 'strand' } eq '+';
860 $cookie->{ 'Q_ID' } = $elem->{ 'q_id' };
861 $cookie->{ 'S_BEG' } = $elem->{ 's_beg' };
862 $cookie->{ 'S_END' } = $elem->{ 's_end' };
863 $cookie->{ 'STRAND' } = $elem->{ 'strand' };
865 push @img, Maasha::XHTML::area(
866 href => cookie_href( $cookie, "export" ),
867 # href => cookie_href( $cookie, "export" ) . "&q_id=$elem->{ 'q_id' }&s_beg=$elem->{ 's_beg' }&s_end=$elem->{ 's_end' }&strand=$elem->{ 'strand' }",
869 coords => "$elem->{ x1 }, $elem->{ y1 }, $elem->{ x2 }, $elem->{ y2 }", title => "$elem->{ 'title' }",
874 push @img, Maasha::XHTML::map_end();
876 push @html, Maasha::XHTML::p( txt => join( "\n", @img ) );
878 @html = Maasha::XHTML::div( txt => join( "\n", @html ), class => 'browse' );
880 return wantarray ? @html : \@html;
886 # Martin A. Hansen, November 2009.
888 # Returns a HTML section with export table.
890 my ( $cookie, # cookie hash
895 my ( @row_dna_contig, @html );
897 push @row_dna_contig, Maasha::XHTML::p( txt => qq(Export Feature: "$cookie->{ 'Q_ID' }" DNA from Contig: ), class => 'inline' );
898 push @row_dna_contig, Maasha::XHTML::p( txt => "$cookie->{ 'CONTIG' } Start: ", class => 'inline' );
899 push @row_dna_contig, Maasha::XHTML::text( name => "s_beg", value => Maasha::Calc::commify( $cookie->{ 'S_BEG' } ), size => 15 );
900 push @row_dna_contig, Maasha::XHTML::p( txt => "End: ", class => 'inline' );
901 push @row_dna_contig, Maasha::XHTML::text( name => "s_end", value => Maasha::Calc::commify( $cookie->{ 'S_END' } ), size => 15 );
902 push @row_dna_contig, Maasha::XHTML::p( txt => "Strand: ", class => 'inline' );
903 push @row_dna_contig, Maasha::XHTML::menu( name => "strand", options => [ qw( + - ) ], selected => $cookie->{ 'STRAND' } );
904 push @row_dna_contig, Maasha::XHTML::submit( name => "export", value => "Export", title => "Fetch DNA from this region" );
906 push @html, Maasha::XHTML::h2( txt => "Export", class => 'center' );
907 push @html, Maasha::XHTML::table_beg( summary => "Taxonomy select table", align => 'center' );
908 push @html, Maasha::XHTML::table_row_simple( tr => \@row_dna_contig );
909 push @html, Maasha::XHTML::table_end;
911 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "page", value => "dna" ) );
912 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "user", value => $cookie->{ 'USER' } ) );
913 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "clade", value => $cookie->{ 'CLADE' } ) );
914 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "genome", value => $cookie->{ 'GENOME' } ) );
915 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "assembly", value => $cookie->{ 'ASSEMBLY' } ) );
916 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "contig", value => $cookie->{ 'CONTIG' } ) );
918 return wantarray ? @html : \@html;
924 # Martin A. Hansen, November 2009.
926 # Returns a HTML section with export table.
928 my ( $cookie, # cookie hash
933 my ( $results, $result, $count, @html, $export, $browse );
935 $results = Maasha::BGB::Track::search_tracks( $cookie );
937 $count = scalar @{ $results };
939 push @html, Maasha::XHTML::h2( txt => "Search", class => 'center' );
940 push @html, Maasha::XHTML::p( txt => qq(Results for "$cookie->{ 'SEARCH' }": $count), class => 'center' );
944 push @html, Maasha::XHTML::table_beg( summary => "Search table", align => 'center', cellpadding => '5px' );
945 push @html, Maasha::XHTML::table_row_simple( tr => [ qw( S_ID S_BEG S_END Q_ID SCORE STRAND HITS ALIGN BLOCK_COUNT BLOCK_BEGS BLOCK_LENS BLOCK_TYPE) ] );
947 foreach $result ( @{ $results } )
949 $cookie->{ 'CONTIG' } = $result->{ 'S_ID' };
950 $cookie->{ 'NAV_START' } = $result->{ 'S_BEG' };
951 $cookie->{ 'NAV_END' } = $result->{ 'S_END' };
952 $cookie->{ 'S_BEG' } = $result->{ 'S_BEG' };
953 $cookie->{ 'S_END' } = $result->{ 'S_END' };
954 $cookie->{ 'STRAND' } = $result->{ 'STRAND' };
955 $cookie->{ 'Q_ID' } = $result->{ 'Q_ID' };
957 $browse = Maasha::XHTML::ln( txt => "browse", href => cookie_href( $cookie, "browse" ) );
958 $export = Maasha::XHTML::ln( txt => "export", href => cookie_href( $cookie, "export" ) );
960 push @html, Maasha::XHTML::table_row_advanced(
961 tr => [ { td => $result->{ 'S_ID' } },
962 { td => $result->{ 'S_BEG' }, align => 'right' },
963 { td => $result->{ 'S_END' }, align => 'right' },
964 { td => $result->{ 'Q_ID' } },
965 { td => $result->{ 'SCORE' }, align => 'right' },
966 { td => $result->{ 'STRAND' } },
967 { td => $result->{ 'HITS' }, align => 'right' },
968 { td => $result->{ 'ALIGN' } },
969 { td => $result->{ 'BLOCK_COUNT' }, align => 'right' },
970 { td => $result->{ 'BLOCK_BEGS' } },
971 { td => $result->{ 'BLOCK_LENS' } },
972 { td => $result->{ 'BLOCK_TYPE' } },
975 ], class => "monospace"
979 push @html, Maasha::XHTML::table_end;
982 return wantarray ? @html : \@html;
988 # Martin A. Hansen, November 2009.
990 # Returns a HTML section with extracted DNA.
992 my ( $cookie, # cookie hash
997 my ( @html, $beg, $end, $seq );
999 $beg = $cookie->{ 'S_BEG' };
1000 $end = $cookie->{ 'S_END' };
1004 $seq = join ";", ">$cookie->{ 'GENOME' }", $cookie->{ 'ASSEMBLY' }, $cookie->{ 'CONTIG' }, $beg, $end, "$cookie->{ 'STRAND' }\n";
1005 $seq .= Maasha::BGB::Track::dna_get( $cookie );
1007 push @html, Maasha::XHTML::h2( txt => "DNA", class => 'center' );
1008 push @html, Maasha::XHTML::pre( txt => $seq );
1010 return wantarray ? @html : \@html;
1014 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<