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' };
37 use Maasha::BGB::Session;
38 use Maasha::BGB::Track;
39 use Maasha::BGB::Draw;
41 my ( $cgi, $cookie, @html );
44 $cookie = cookie_default( $cgi );;
46 push @html, Maasha::XHTML::html_header(
48 title => 'Biopieces Genome Browser',
49 css_file => 'bgb.css',
50 author => 'Martin A. Hansen, mail@maasha.dk',
51 description => 'Biopieces Genome Browser',
52 keywords => [ qw( Biopieces biopiece genome browser viewer bacterium bacteria prokaryote prokaryotes ) ],
56 push @html, Maasha::XHTML::h1( txt => "Biopieces Genome Browser", class => 'center' );
57 push @html, Maasha::XHTML::form_beg( action => $cookie->{ 'SCRIPT' }, method => "post", enctype => "multipart/form-data" );
59 push @html, page( $cookie );
61 push @html, Maasha::XHTML::form_end;
62 push @html, Maasha::XHTML::body_end;
63 push @html, Maasha::XHTML::html_end;
65 # push @html, Maasha::XHTML::hdump( [ $cgi->Vars ] ); # DEBUG
66 # push @html, Maasha::XHTML::hdump( \%ENV ); # DEBUG
67 # push @html, Maasha::XHTML::hdump( $cookie ); # DEBUG
69 print "$_\n" foreach @html;
72 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> SUBROUTINES <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
75 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> COOKIE <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
80 # Martin A. Hansen, November 2009.
82 # Set a cookie with values from the CGI object or defaults.
84 my ( $cgi, # CGI object
89 my ( $cookie, $path );
93 if ( $cgi->param( 'nav_search' ) )
95 if ( $cgi->param( 'nav_search' ) =~ /([0-9,]+)[ -]([0-9,]+)/ )
97 $cookie->{ 'NAV_START' } = $1;
98 $cookie->{ 'NAV_END' } = $2;
102 $cookie->{ 'SEARCH' } = $cgi->param( 'nav_search' );
104 $cgi->param( 'page', 'search' );
108 $cookie->{ 'SCRIPT' } = Maasha::Common::get_scriptname();
109 $cookie->{ 'DATA_DIR' } = "Data";
110 $cookie->{ 'SESSION_DIR' } = "Sessions";
111 $cookie->{ 'LIST_PAGES' } = [ qw( clade genome assembly contig browse ) ];
113 $cookie->{ 'USER' } = $cgi->param( 'user' ) || '';
114 $cookie->{ 'PASSWORD' } = $cgi->param( 'password' );
115 $cookie->{ 'SESSION_ID' } = $cgi->param( 'session_id' );
117 cookie_session( $cookie );
118 cookie_login( $cookie );
120 $cookie->{ 'PAGE' } ||= $cgi->param( 'page' ) || 'login';
121 $cookie->{ 'CLADE' } = $cgi->param( 'clade' ) || '';
122 $cookie->{ 'GENOME' } = $cgi->param( 'genome' ) || '';
123 $cookie->{ 'ASSEMBLY' } = $cgi->param( 'assembly' ) || '';
124 $cookie->{ 'CONTIG' } = $cgi->param( 'contig' ) || '';
125 $cookie->{ 'Q_ID' } = $cgi->param( 'q_id' );
126 $cookie->{ 'NAV_START' } ||= $cgi->param( 'nav_start' ) || $cgi->param( 's_beg' ); # FIXME this is ugly!
127 $cookie->{ 'NAV_END' } ||= $cgi->param( 'nav_end' ) || $cgi->param( 's_end' );
128 $cookie->{ 'NAV_CENTER' } = $cgi->param( 'nav_center' );
129 $cookie->{ 'S_BEG' } = $cgi->param( 's_beg' );
130 $cookie->{ 'S_END' } = $cgi->param( 's_end' );
131 $cookie->{ 'STRAND' } = $cgi->param( 'strand' );
132 $cookie->{ 'ZOOM_IN1' } = $cgi->param( 'zoom_in1' );
133 $cookie->{ 'ZOOM_IN2' } = $cgi->param( 'zoom_in2' );
134 $cookie->{ 'ZOOM_IN3' } = $cgi->param( 'zoom_in3' );
135 $cookie->{ 'ZOOM_OUT1' } = $cgi->param( 'zoom_out1' );
136 $cookie->{ 'ZOOM_OUT2' } = $cgi->param( 'zoom_out2' );
137 $cookie->{ 'ZOOM_OUT3' } = $cgi->param( 'zoom_out3' );
138 $cookie->{ 'MOVE_LEFT1' } = $cgi->param( 'move_left1' );
139 $cookie->{ 'MOVE_LEFT2' } = $cgi->param( 'move_left2' );
140 $cookie->{ 'MOVE_LEFT3' } = $cgi->param( 'move_left3' );
141 $cookie->{ 'MOVE_RIGHT1' } = $cgi->param( 'move_right1' );
142 $cookie->{ 'MOVE_RIGHT2' } = $cgi->param( 'move_right2' );
143 $cookie->{ 'MOVE_RIGHT3' } = $cgi->param( 'move_right3' );
145 $cookie->{ 'IMG_WIDTH' } = 1200;
146 $cookie->{ 'IMG_HEIGHT' } = 800;
147 $cookie->{ 'TRACK_OFFSET' } = 20;
148 $cookie->{ 'TRACK_SPACE' } = 20;
149 $cookie->{ 'RULER_FONT_SIZE' } = 10;
150 $cookie->{ 'RULER_COLOR' } = [ 0, 0, 0 ];
151 $cookie->{ 'SEQ_FONT_SIZE' } = 10;
152 $cookie->{ 'SEQ_COLOR' } = [ 0, 0, 0, ];
153 $cookie->{ 'FEAT_WIDTH' } = 5;
154 $cookie->{ 'FEAT_COLOR' } = [ 0, 0, 0 ];
155 $cookie->{ 'FEAT_MAX' } = 5000;
157 $path = "$cookie->{ 'DATA_DIR' }/Users";
159 $cookie->{ 'LIST_USER' } = Maasha::Filesys::ls_dirs_base( $path ) if -d $path;
161 $path .= "/$cookie->{ 'USER' }";
163 $cookie->{ 'LIST_CLADE' } = Maasha::Filesys::ls_dirs_base( $path ) if -d $path;
165 $path .= "/$cookie->{ 'CLADE' }";
167 $cookie->{ 'LIST_GENOME' } = Maasha::Filesys::ls_dirs_base( $path ) if -d $path;
169 $path .= "/$cookie->{ 'GENOME' }";
171 $cookie->{ 'LIST_ASSEMBLY' } = Maasha::Filesys::ls_dirs_base( $path ) if -d $path;
173 $path .= "/$cookie->{ 'ASSEMBLY' }";
175 $cookie->{ 'LIST_CONTIG' } = Maasha::Filesys::ls_dirs_base( $path ) if -d $path;
177 if ( $cookie->{ 'CONTIG' } )
179 cookie_start( $cookie );
180 cookie_end( $cookie );
181 cookie_zoom( $cookie );
182 cookie_move( $cookie );
183 cookie_center( $cookie );
186 $cookie->{ 'STRAND' } = '+' if defined $cookie->{ 'STRAND' } and $cookie->{ 'STRAND' } eq ' '; # FIXME ugly HTML fix
188 return wantarray ? %{ $cookie } : $cookie;
194 # Martin A. Hansen, December 2009.
196 # Check cookie information against session information.
198 my ( $cookie, # cookie hash
205 $session = Maasha::BGB::Session::session_restore( "$cookie->{ 'SESSION_DIR' }/sessions.txt" );
207 # if ( $cookie->{ 'SESSION_ID' } )
209 # if ( $cookie->{ 'SESSION_ID' } ne $ENV{ 'SSL_SESSION_ID' } ) {
210 # $cookie->{ 'PAGE' } = 'login';
211 # print STDERR "HER1"; # DEBUG
216 # $cookie->{ 'PAGE' } = 'login';
218 # print STDERR "HER2"; # DEBUG
221 if ( exists $session->{ $cookie->{ 'USER' } } and $cookie->{ 'SESSION_ID' } )
223 if ( $session->{ $cookie->{ 'USER' } }->{ 'SESSION_ID' } ne $cookie->{ 'SESSION_ID' } ) {
224 $cookie->{ 'PAGE' } = 'login';
225 print STDERR "HER3"; # DEBUG
230 $cookie->{ 'PAGE' } = 'login';
231 print STDERR "HER4"; # DEBUG
232 print STDERR "NO COOKIE SESSION ID\n" if not $cookie->{ 'SESSION_ID' }; # DEBUG
233 print STDERR "NO COOKIE USER\n" if not $cookie->{ 'USER' }; # DEBUG
234 print STDERR "NO SESSION USER\n" if not exists $session->{ $cookie->{ 'USER' } }; # DEBUG
241 # Martin A. Hansen, December 2009.
243 # Check a user and password from CGI against the password file and
244 # set the session ID, if found, in the cookie.
246 my ( $cookie, # cookie hash
253 if ( $cookie->{ 'USER' } and $cookie->{ 'PASSWORD' } )
255 $session = Maasha::BGB::Session::session_restore( "$cookie->{ 'SESSION_DIR' }/sessions.txt" );
257 if ( exists $session->{ $cookie->{ 'USER' } } and
258 $session->{ $cookie->{ 'USER' } }->{ 'PASSWORD' } eq Digest::MD5::md5_hex( $cookie->{ 'PASSWORD' } ) )
260 $session->{ $cookie->{ 'USER' } }->{ 'SESSION_ID' } ||= Maasha::BGB::Session::session_new();
261 # $session->{ $cookie->{ 'USER' } }->{ 'SESSION_ID' } = $ENV{ 'SSL_SESSION_ID' };
262 $session->{ $cookie->{ 'USER' } }->{ 'TIME' } = Maasha::Common::time_stamp();
264 $cookie->{ 'SESSION_ID' } = $session->{ $cookie->{ 'USER' } }->{ 'SESSION_ID' };
265 $cookie->{ 'LOGIN' } = "OK";
266 $cookie->{ 'PAGE' } = 'clade';
268 Maasha::BGB::Session::session_store( "$cookie->{ 'SESSION_DIR' }/sessions.txt", $session );
272 $cookie->{ 'LOGIN' } = "ERROR";
280 # Martin A. Hansen, November 2009.
282 # Decommify the cookie value for NAV_START and adjust it to
283 # to prevent negative values.
285 my ( $cookie, # cookie hash
290 if ( defined $cookie->{ 'NAV_START' } )
292 $cookie->{ 'NAV_START' } =~ tr/,//d;
293 $cookie->{ 'NAV_START' } = 0 if $cookie->{ 'NAV_START' } < 0;
297 $cookie->{ 'NAV_START' } = 0;
304 # Martin A. Hansen, November 2009.
306 # Decommify the cookie value for NAV_END and adjust it to prevent
307 # overshooting the max value for the contig size as determined
310 my ( $cookie, # cookie hash
317 $max = Maasha::Filesys::file_size( Maasha::BGB::Track::path_seq( $cookie ) );
319 if ( defined $cookie->{ 'NAV_END' } )
321 $cookie->{ 'NAV_END' } =~ tr/,//d;
322 $cookie->{ 'NAV_END' } = $max if $cookie->{ 'NAV_END' } > $max;
326 $cookie->{ 'NAV_END' } = $max;
333 # Martin A. Hansen, November 2009.
335 # Adjust the cookie values for NAV_START and NAV_END based
336 # on cookie ZOOM values.
338 my ( $cookie, # cookie hash
343 my ( $max, $dist, $new_dist, $dist_diff );
345 $max = Maasha::Filesys::file_size( Maasha::BGB::Track::path_seq( $cookie ) );
347 $dist = $cookie->{ 'NAV_END' } - $cookie->{ 'NAV_START' };
349 if ( defined $cookie->{ 'ZOOM_IN1' } ) {
350 $new_dist = $dist / 1.5;
351 } elsif ( defined $cookie->{ 'ZOOM_IN2' } ) {
352 $new_dist = $dist / 3;
353 } elsif ( defined $cookie->{ 'ZOOM_IN3' } ) {
354 $new_dist = $dist / 10;
355 } elsif ( defined $cookie->{ 'ZOOM_OUT1' } ) {
356 $new_dist = $dist * 1.5;
357 } elsif ( defined $cookie->{ 'ZOOM_OUT2' } ) {
358 $new_dist = $dist * 3;
359 } elsif ( defined $cookie->{ 'ZOOM_OUT3' } ) {
360 $new_dist = $dist * 10;
365 $dist_diff = $dist - $new_dist;
367 $cookie->{ 'NAV_START' } = int( $cookie->{ 'NAV_START' } + ( $dist_diff / 2 ) );
368 $cookie->{ 'NAV_END' } = int( $cookie->{ 'NAV_END' } - ( $dist_diff / 2 ) );
370 $cookie->{ 'NAV_START' } = 0 if $cookie->{ 'NAV_START' } < 0;
371 $cookie->{ 'NAV_END' } = $max if $cookie->{ 'NAV_END' } > $max;
378 # Martin A. Hansen, November 2009.
380 # Adjust the cookie values for NAV_START and NAV_END based
381 # on cookie MOVE values.
383 my ( $cookie, # cookie hash
388 my ( $max, $dist, $shift, $new_start, $new_end );
390 $max = Maasha::Filesys::file_size( Maasha::BGB::Track::path_seq( $cookie ) );
392 $dist = $cookie->{ 'NAV_END' } - $cookie->{ 'NAV_START' };
394 if ( defined $cookie->{ 'MOVE_LEFT1' } ) {
395 $shift = -1 * $dist * 0.10;
396 } elsif ( defined $cookie->{ 'MOVE_LEFT2' } ) {
397 $shift = -1 * $dist * 0.475;
398 } elsif ( defined $cookie->{ 'MOVE_LEFT3' } ) {
399 $shift = -1 * $dist * 0.95;
400 } elsif ( defined $cookie->{ 'MOVE_RIGHT1' } ) {
401 $shift = $dist * 0.10;
402 } elsif ( defined $cookie->{ 'MOVE_RIGHT2' } ) {
403 $shift = $dist * 0.475;
404 } elsif ( defined $cookie->{ 'MOVE_RIGHT3' } ) {
405 $shift = $dist * 0.95;
410 $new_start = int( $cookie->{ 'NAV_START' } + $shift );
411 $new_end = int( $cookie->{ 'NAV_END' } + $shift );
413 if ( $new_start > 0 and $new_end < $max )
415 $cookie->{ 'NAV_START' } = $new_start;
416 $cookie->{ 'NAV_END' } = $new_end;
424 # Martin A. Hansen, March 2010
426 # Adjust the cookie values for NAV_START and NAV_END based
427 # on cookie CENTER value if defined.
429 my ( $cookie, # cookie hash
434 my ( $l_dist, $r_dist );
436 if ( defined $cookie->{ 'NAV_CENTER' } )
438 $l_dist = $cookie->{ 'NAV_CENTER' } - $cookie->{ 'NAV_START' };
439 $r_dist = $cookie->{ 'NAV_END' } - $cookie->{ 'NAV_CENTER' };
441 if ( $l_dist > $r_dist ) {
442 $cookie->{ 'NAV_START' } = $cookie->{ 'NAV_END' } - 2 * $r_dist;
444 $cookie->{ 'NAV_END' } = $cookie->{ 'NAV_START' } + 2 * $l_dist;
452 # Martin A. Hansen, November 2009.
454 # Returns the href for a taxonomy path terminated at a given
455 # page using information stored in a cookie.
457 my ( $cookie, # cookie hash
463 my ( @href_list, %href_hash, $href );
465 $href_hash{ "user" } = $cookie->{ 'USER' } if $cookie->{ 'USER' };
469 $href_hash{ "clade" } = $cookie->{ 'CLADE' } if $cookie->{ 'CLADE' };
470 last if $page eq 'clade';
471 $href_hash{ "genome" } = $cookie->{ 'GENOME' } if $cookie->{ 'GENOME' };
472 last if $page eq 'genome';
473 $href_hash{ "assembly" } = $cookie->{ 'ASSEMBLY' } if $cookie->{ 'ASSEMBLY' };
474 last if $page eq 'assembly';
475 $href_hash{ "contig" } = $cookie->{ 'CONTIG' } if $cookie->{ 'CONTIG' };
476 last if $page eq 'contig';
480 if ( defined $cookie->{ 'NAV_START' } and defined $cookie->{ 'NAV_END' } and $page !~ /clade|genome|assembly|contig|browse/ ) {
481 $href_hash{ "nav_search" } = "$cookie->{ 'NAV_START' }-$cookie->{ 'NAV_END' }";
484 $href_hash{ "q_id" } = URI::Escape::uri_escape( $cookie->{ 'Q_ID' } ) if defined $cookie->{ 'Q_ID' };
485 $href_hash{ "s_beg" } = $cookie->{ 'S_BEG' } if defined $cookie->{ 'S_BEG' };
486 $href_hash{ "s_end" } = $cookie->{ 'S_END' } if defined $cookie->{ 'S_END' };
487 $href_hash{ "strand" } = $cookie->{ 'STRAND' } if defined $cookie->{ 'STRAND' };
488 $href_hash{ "session_id" } = $cookie->{ 'SESSION_ID' } if defined $cookie->{ 'SESSION_ID' };
490 push @href_list, "$cookie->{ 'SCRIPT' }?page=$page";
492 foreach $href ( keys %href_hash ) {
493 push @href_list, "$href=$href_hash{ $href }";
496 return join "&", @href_list;
502 # Martin A. Hansen, November 2009.
504 # Returns the next page in the taxonomy path.
506 my ( $cookie, # cookie hash
513 for ( $i = 0; $i < @{ $cookie->{ 'LIST_PAGES' } }; $i++ ) {
514 last if $cookie->{ 'PAGE' } eq $cookie->{ 'LIST_PAGES' }->[ $i ];
517 return $cookie->{ 'LIST_PAGES' }->[ $i + 1 ];
521 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> PAGES <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
526 # Martin A. Hansen, November 2009.
528 # Determines what page to render based on
529 # the cookie's PAGE setting.
531 my ( $cookie, # cookie hash
538 if ( $cookie->{ 'PAGE' } eq 'login' ) {
539 push @html, page_login( $cookie );
540 } elsif ( $cookie->{ 'PAGE' } eq 'search' ) {
541 push @html, page_search( $cookie );
542 } elsif ( $cookie->{ 'PAGE' } eq 'browse' ) {
543 push @html, page_browse( $cookie );
544 } elsif ( $cookie->{ 'PAGE' } eq 'dna' ) {
545 push @html, page_dna( $cookie );
546 } elsif ( $cookie->{ 'PAGE' } eq 'export' ) {
547 push @html, page_export( $cookie );
549 push @html, page_taxonomy( $cookie );
552 if ( $cookie->{ 'SESSION_ID' } ) {
553 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "session_id", value => $cookie->{ 'SESSION_ID' } ) );
556 return wantarray ? @html : \@html;
562 # Martin A. Hansen, December 2009.
564 # Renders the login page.
573 push @html, section_login( $cookie );
575 return wantarray ? @html : \@html;
581 # Martin A. Hansen, December 2009.
583 # Renders the search page.
592 push @html, section_taxonomy_table( $cookie );
593 push @html, section_search( $cookie );
595 return wantarray ? @html : \@html;
601 # Martin A. Hansen, November 2009.
603 # Renders the browse page.
612 push @html, section_taxonomy_table( $cookie );
613 push @html, section_navigate( $cookie );
614 push @html, section_browse( $cookie );
616 return wantarray ? @html : \@html;
622 # Martin A. Hansen, November 2009.
624 # Renders the DNA page.
633 push @html, section_taxonomy_table( $cookie );
634 push @html, section_dna( $cookie );
636 return wantarray ? @html : \@html;
642 # Martin A. Hansen, November 2009.
644 # Renders the export page.
653 push @html, section_taxonomy_table( $cookie );
654 push @html, section_export( $cookie );
656 return wantarray ? @html : \@html;
662 # Martin A. Hansen, November 2009.
664 # Renders the browse page.
666 my ( $cookie, # cookie hash
673 push @html, section_taxonomy_table( $cookie );
674 push @html, section_taxonomy_select( $cookie );
676 return wantarray ? @html : \@html;
680 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> SECTIONS <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
685 # Martin A. Hansen, December 2009.
687 # Returns a HTML section with a login menu.
689 my ( $cookie, # cookie hash
694 my ( $user, $password, $login, @html );
696 $user = Maasha::XHTML::text( name => "user", value => "", size => 20 );
697 $password = Maasha::XHTML::password( name => "password", value => "", size => 20 );
698 $login = Maasha::XHTML::submit( name => "login_submit", value => "Login" );
700 push @html, Maasha::XHTML::h2( txt => "Login", class => 'center' );
702 push @html, Maasha::XHTML::table_beg( summary => "Login table", align => 'center' );
703 push @html, Maasha::XHTML::table_row_simple( tr => [ "User:", $user ] );
704 push @html, Maasha::XHTML::table_row_simple( tr => [ "Password:", $password ] );
705 push @html, Maasha::XHTML::table_row_simple( tr => [ "", $login ] );
706 push @html, Maasha::XHTML::table_end;
708 if ( $cookie->{ 'LOGIN' } and $cookie->{ 'LOGIN' } eq 'ERROR' ) {
709 push @html, Maasha::XHTML::h3( txt => "Bad user or password - please retry", class => 'error' );
712 return wantarray ? @html : \@html;
716 sub section_taxonomy_table
718 # Martin A. Hansen, November 2009.
720 # Returns a HTML section with a taxonomy table
721 # showing the location in the taxonomy and with
722 # links to browse the taxonomy.
724 my ( $cookie, # cookie hash
729 my ( $page, @row, @html, $href, $txt );
731 foreach $page ( @{ $cookie->{ 'LIST_PAGES' } } )
733 last if $page eq $cookie->{ 'PAGE' } or $page eq 'browse';
735 $href = cookie_href( $cookie, $page );
737 $txt = ": $cookie->{ uc $page }";
739 push @row, Maasha::XHTML::ln( txt => $page, href => $href, class => 'inline' );
740 push @row, Maasha::XHTML::p( txt => $txt, class => 'inline' );
743 push @html, Maasha::XHTML::table_beg( summary => "Taxonomy table", align => 'center', cellpadding => '5px' );
744 push @html, Maasha::XHTML::table_row_simple( tr => [ join( "\n", @row ) ], align => 'center' );
745 push @html, Maasha::XHTML::table_end;
747 return wantarray ? @html : \@html;
751 sub section_taxonomy_select
753 # Martin A. Hansen, November 2009.
755 # Returns a HTML section with selection choices
756 # for navigating the taxonomy tree.
758 my ( $cookie, # cookie hash
763 my ( $list, @html, $item, $href );
765 $list = "LIST_" . uc $cookie->{ 'PAGE' };
767 push @html, Maasha::XHTML::h2( txt => "Select $cookie->{ 'PAGE' }", class => 'center' );
769 push @html, Maasha::XHTML::table_beg( summary => "Taxonomy select table", align => 'center', cellpadding => '5px' );
771 foreach $item ( @{ $cookie->{ $list } } )
773 $cookie->{ uc $cookie->{ 'PAGE' } } = $item;
775 $href = cookie_href( $cookie, cookie_page_next( $cookie ) );
777 push @html, Maasha::XHTML::table_row_simple( tr => [ Maasha::XHTML::ln( txt => $item, href => $href ) ] );
780 push @html, Maasha::XHTML::table_end;
782 return wantarray ? @html : \@html;
788 # Martin A. Hansen, November 2009.
790 # Returns a HTML section for navigating in the browser window.
792 my ( $cookie, # cookie hash
797 my ( @html, $nav_val );
799 $nav_val = Maasha::Calc::commify( $cookie->{ 'NAV_START' } ) . "-" . Maasha::Calc::commify( $cookie->{ 'NAV_END' } );
801 push @html, Maasha::XHTML::table_beg( summary => "Navigation table", align => 'center' );
802 push @html, Maasha::XHTML::table_row_simple( tr => [
803 "Position or search term:",
804 Maasha::XHTML::text( name => "nav_search", value => $nav_val, size => 30 ),
805 Maasha::XHTML::submit( name => "nav_submit", value => "Submit" ),
807 push @html, Maasha::XHTML::table_end;
809 push @html, Maasha::XHTML::table_beg( summary => "Zoom table", align => 'center' );
810 push @html, Maasha::XHTML::table_row_simple( tr => [
811 Maasha::XHTML::p( txt => 'Move:' ),
812 Maasha::XHTML::submit( name => "move_left3", value => "<<<", title => "move 95% to the left" ),
813 Maasha::XHTML::submit( name => "move_left2", value => "<<", title => "move 47.5% to the left" ),
814 Maasha::XHTML::submit( name => "move_left1", value => "<", title => "move 10% to the left" ),
815 Maasha::XHTML::submit( name => "move_right1", value => ">", title => "move 10% to the rigth" ),
816 Maasha::XHTML::submit( name => "move_right2", value => ">>", title => "move 47.5% to the rigth" ),
817 Maasha::XHTML::submit( name => "move_right3", value => ">>>", title => "move 95% to the right" ),
818 Maasha::XHTML::p( txt => 'Zoom in:' ),
819 Maasha::XHTML::submit( name => "zoom_in1", value => "1.5x" ),
820 Maasha::XHTML::submit( name => "zoom_in2", value => "3x" ),
821 Maasha::XHTML::submit( name => "zoom_in3", value => "10x" ),
822 Maasha::XHTML::p( txt => 'Zoom out:' ),
823 Maasha::XHTML::submit( name => "zoom_out1", value => "1.5x" ),
824 Maasha::XHTML::submit( name => "zoom_out2", value => "3x" ),
825 Maasha::XHTML::submit( name => "zoom_out3", value => "10x" ),
827 push @html, Maasha::XHTML::table_end;
829 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "page", value => "browse" ) );
830 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "user", value => $cookie->{ 'USER' } ) );
831 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "clade", value => $cookie->{ 'CLADE' } ) );
832 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "genome", value => $cookie->{ 'GENOME' } ) );
833 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "assembly", value => $cookie->{ 'ASSEMBLY' } ) );
834 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "contig", value => $cookie->{ 'CONTIG' } ) );
836 return wantarray ? @html : \@html;
847 my ( @tracks, $i, @features, $feat, $elem, $surface, $cr, $png_data, @html, @img, $x1, $y1, $x2, $y2, $factor, $center );
849 push @features, [ Maasha::BGB::Track::track_ruler( $cookie ) ];
850 push @features, [ Maasha::BGB::Track::track_seq( $cookie ) ];
852 @tracks = Maasha::BGB::Track::path_tracks( $cookie );
854 for ( $i = 0; $i < @tracks; $i++ )
856 $cookie->{ 'FEAT_COLOR' } = Maasha::BGB::Draw::palette( $i );
858 push @features, [ Maasha::BGB::Track::track_feature( $tracks[ $i ], $cookie ) ];
861 $surface = Cairo::ImageSurface->create( 'argb32', $cookie->{ 'IMG_WIDTH' }, $cookie->{ 'TRACK_OFFSET' } );
862 $cr = Cairo::Context->create( $surface );
864 $cr->rectangle ( 0, 0, $cookie->{ 'IMG_WIDTH' }, $cookie->{ 'TRACK_OFFSET' } );
865 $cr->set_source_rgb ( 1, 1, 1 );
868 foreach $feat ( @features ) {
869 Maasha::BGB::Draw::draw_feature( $cr, $feat ) if $feat;
872 $png_data = Maasha::BGB::Draw::base64_png( $surface );
874 push @img, Maasha::XHTML::img(
875 src => "data:image/png;base64,$png_data",
876 alt => "Browser Tracks",
877 height => $cookie->{ 'TRACK_OFFSET' },
878 width => $cookie->{ 'IMG_WIDTH' },
880 usemap => "#browser_map"
883 push @img, Maasha::XHTML::map_beg( name => "browser_map", id => "browser_map" );
885 foreach $feat ( @features )
887 foreach $elem ( @{ $feat } )
889 next if $elem->{ 'type' } eq 'text';
890 next if $elem->{ 'type' } eq 'wiggle';
892 #$elem->{ 'strand' } = '+' if $elem->{ 'strand' } eq '+';
894 $cookie->{ 'Q_ID' } = $elem->{ 'q_id' };
895 $cookie->{ 'S_BEG' } = $elem->{ 's_beg' };
896 $cookie->{ 'S_END' } = $elem->{ 's_end' };
897 $cookie->{ 'STRAND' } = $elem->{ 'strand' };
899 push @img, Maasha::XHTML::area(
900 href => cookie_href( $cookie, "export" ),
901 # href => cookie_href( $cookie, "export" ) . "&q_id=$elem->{ 'q_id' }&s_beg=$elem->{ 's_beg' }&s_end=$elem->{ 's_end' }&strand=$elem->{ 'strand' }",
903 coords => "$elem->{ x1 }, $elem->{ y1 }, $elem->{ x2 }, $elem->{ y2 }",
904 title => "$elem->{ 'title' }",
909 $factor = $cookie->{ 'IMG_WIDTH' } / ( $cookie->{ 'NAV_END' } - $cookie->{ 'NAV_START' } + 1 );
910 $factor = ( $cookie->{ 'NAV_END' } - $cookie->{ 'NAV_START' } + 1 ) / $cookie->{ 'IMG_WIDTH' };
912 for ( $i = 0; $i < $cookie->{ 'IMG_WIDTH' }; $i += 5 )
919 $center = int( $cookie->{ 'NAV_START' } + $factor * $i );
921 push @img, Maasha::XHTML::area(
922 # href => cookie_href( $cookie, "browse" ) . "&nav_start=$cookie->{ 'NAV_START' }&nav_end=$cookie->{ 'NAV_END' }&nav_center=$center",
923 href => join( "&", "$cookie->{ 'SCRIPT' }?page=browse",
924 "session_id=$cookie->{ 'SESSION_ID' }",
925 "user=$cookie->{ 'USER' }",
926 "clade=$cookie->{ 'CLADE' }",
927 "genome=$cookie->{ 'GENOME' }",
928 "contig=$cookie->{ 'CONTIG' }",
929 "assembly=$cookie->{ 'ASSEMBLY' }",
930 "nav_start=$cookie->{ 'NAV_START' }",
931 "nav_end=$cookie->{ 'NAV_END' }",
932 "nav_center=$center",
935 coords => "$x1, $y1, $x2, $y2",
936 title => "Center on " . Maasha::Calc::commify( $center ),
940 push @img, Maasha::XHTML::map_end();
942 push @html, Maasha::XHTML::p( txt => join( "\n", @img ) );
944 @html = Maasha::XHTML::div( txt => join( "\n", @html ), class => 'browse' );
946 return wantarray ? @html : \@html;
952 # Martin A. Hansen, November 2009.
954 # Returns a HTML section with export table.
956 my ( $cookie, # cookie hash
961 my ( @row_dna_contig, @html );
963 push @row_dna_contig, Maasha::XHTML::p( txt => qq(Export Feature: "$cookie->{ 'Q_ID' }" DNA from Contig: ), class => 'inline' );
964 push @row_dna_contig, Maasha::XHTML::p( txt => "$cookie->{ 'CONTIG' } Start: ", class => 'inline' );
965 push @row_dna_contig, Maasha::XHTML::text( name => "s_beg", value => Maasha::Calc::commify( $cookie->{ 'S_BEG' } ), size => 15 );
966 push @row_dna_contig, Maasha::XHTML::p( txt => "End: ", class => 'inline' );
967 push @row_dna_contig, Maasha::XHTML::text( name => "s_end", value => Maasha::Calc::commify( $cookie->{ 'S_END' } ), size => 15 );
968 push @row_dna_contig, Maasha::XHTML::p( txt => "Strand: ", class => 'inline' );
969 push @row_dna_contig, Maasha::XHTML::menu( name => "strand", options => [ qw( + - ) ], selected => $cookie->{ 'STRAND' } );
970 push @row_dna_contig, Maasha::XHTML::submit( name => "export", value => "Export", title => "Fetch DNA from this region" );
972 push @html, Maasha::XHTML::h2( txt => "Export", class => 'center' );
973 push @html, Maasha::XHTML::table_beg( summary => "Taxonomy select table", align => 'center' );
974 push @html, Maasha::XHTML::table_row_simple( tr => \@row_dna_contig );
975 push @html, Maasha::XHTML::table_end;
977 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "page", value => "dna" ) );
978 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "user", value => $cookie->{ 'USER' } ) );
979 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "clade", value => $cookie->{ 'CLADE' } ) );
980 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "genome", value => $cookie->{ 'GENOME' } ) );
981 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "assembly", value => $cookie->{ 'ASSEMBLY' } ) );
982 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "contig", value => $cookie->{ 'CONTIG' } ) );
984 return wantarray ? @html : \@html;
990 # Martin A. Hansen, November 2009.
992 # Returns a HTML section with export table.
994 my ( $cookie, # cookie hash
999 my ( $results, $result, $count, @html, $export, $browse );
1001 $results = Maasha::BGB::Track::search_tracks( $cookie );
1003 $count = scalar @{ $results };
1005 push @html, Maasha::XHTML::h2( txt => "Search", class => 'center' );
1006 push @html, Maasha::XHTML::p( txt => qq(Results for "$cookie->{ 'SEARCH' }": $count), class => 'center' );
1010 push @html, Maasha::XHTML::table_beg( summary => "Search table", align => 'center', cellpadding => '5px' );
1011 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) ] );
1013 foreach $result ( @{ $results } )
1015 $result = Maasha::KISS::kiss2biopiece( $result );
1017 $cookie->{ 'CONTIG' } = $result->{ 'S_ID' };
1018 $cookie->{ 'NAV_START' } = $result->{ 'S_BEG' };
1019 $cookie->{ 'NAV_END' } = $result->{ 'S_END' };
1020 $cookie->{ 'S_BEG' } = $result->{ 'S_BEG' };
1021 $cookie->{ 'S_END' } = $result->{ 'S_END' };
1022 $cookie->{ 'STRAND' } = $result->{ 'STRAND' };
1023 $cookie->{ 'Q_ID' } = $result->{ 'Q_ID' };
1025 $browse = Maasha::XHTML::ln( txt => "browse", href => cookie_href( $cookie, "browse" ) );
1026 $export = Maasha::XHTML::ln( txt => "export", href => cookie_href( $cookie, "export" ) );
1028 push @html, Maasha::XHTML::table_row_advanced(
1029 tr => [ { td => $result->{ 'S_ID' } },
1030 { td => $result->{ 'S_BEG' }, align => 'right' },
1031 { td => $result->{ 'S_END' }, align => 'right' },
1032 { td => $result->{ 'Q_ID' } },
1033 { td => $result->{ 'SCORE' }, align => 'right' },
1034 { td => $result->{ 'STRAND' } },
1035 { td => $result->{ 'HITS' }, align => 'right' },
1036 { td => $result->{ 'ALIGN' } },
1037 { td => $result->{ 'BLOCK_COUNT' }, align => 'right' },
1038 { td => $result->{ 'BLOCK_BEGS' } },
1039 { td => $result->{ 'BLOCK_LENS' } },
1040 { td => $result->{ 'BLOCK_TYPE' } },
1043 ], class => "monospace"
1047 push @html, Maasha::XHTML::table_end;
1050 return wantarray ? @html : \@html;
1056 # Martin A. Hansen, November 2009.
1058 # Returns a HTML section with extracted DNA.
1060 my ( $cookie, # cookie hash
1065 my ( @html, $beg, $end, $seq );
1067 $beg = $cookie->{ 'S_BEG' };
1068 $end = $cookie->{ 'S_END' };
1072 $seq = join ";", ">$cookie->{ 'GENOME' }", $cookie->{ 'ASSEMBLY' }, $cookie->{ 'CONTIG' }, $beg, $end, "$cookie->{ 'STRAND' }\n";
1073 $seq .= Maasha::BGB::Track::dna_get( $cookie );
1075 push @html, Maasha::XHTML::h2( txt => "DNA", class => 'center' );
1076 push @html, Maasha::XHTML::pre( txt => $seq );
1078 return wantarray ? @html : \@html;
1082 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<