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
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';
121 if ( $cookie->{ 'LOGIN' } eq 'OK' )
123 if ( $cgi->param( 'genome' ) ) {
124 $cookie->{ 'PAGE' } = 'browse';
126 $cookie->{ 'PAGE' } = 'clade';
130 $cookie->{ 'CLADE' } = $cgi->param( 'clade' ) || '';
131 $cookie->{ 'GENOME' } = $cgi->param( 'genome' ) || '';
132 $cookie->{ 'ASSEMBLY' } = $cgi->param( 'assembly' ) || '';
133 $cookie->{ 'CONTIG' } = $cgi->param( 'contig' ) || '';
134 $cookie->{ 'Q_ID' } = $cgi->param( 'q_id' );
135 $cookie->{ 'NAV_START' } ||= $cgi->param( 'nav_start' );
136 $cookie->{ 'NAV_END' } ||= $cgi->param( 'nav_end' );
137 $cookie->{ 'NAV_CENTER' } = $cgi->param( 'nav_center' );
138 $cookie->{ 'S_BEG' } = $cgi->param( 's_beg' );
139 $cookie->{ 'S_END' } = $cgi->param( 's_end' );
140 $cookie->{ 'STRAND' } = $cgi->param( 'strand' );
141 $cookie->{ 'ZOOM_IN1' } = $cgi->param( 'zoom_in1' );
142 $cookie->{ 'ZOOM_IN2' } = $cgi->param( 'zoom_in2' );
143 $cookie->{ 'ZOOM_IN3' } = $cgi->param( 'zoom_in3' );
144 $cookie->{ 'ZOOM_OUT1' } = $cgi->param( 'zoom_out1' );
145 $cookie->{ 'ZOOM_OUT2' } = $cgi->param( 'zoom_out2' );
146 $cookie->{ 'ZOOM_OUT3' } = $cgi->param( 'zoom_out3' );
147 $cookie->{ 'MOVE_LEFT1' } = $cgi->param( 'move_left1' );
148 $cookie->{ 'MOVE_LEFT2' } = $cgi->param( 'move_left2' );
149 $cookie->{ 'MOVE_LEFT3' } = $cgi->param( 'move_left3' );
150 $cookie->{ 'MOVE_RIGHT1' } = $cgi->param( 'move_right1' );
151 $cookie->{ 'MOVE_RIGHT2' } = $cgi->param( 'move_right2' );
152 $cookie->{ 'MOVE_RIGHT3' } = $cgi->param( 'move_right3' );
154 $cookie->{ 'IMG_WIDTH' } = 1200; # Width of browser image in pixels
155 $cookie->{ 'IMG_HEIGHT' } = 800; # Height of browser image in pixels
156 $cookie->{ 'WIGGLE_HEIGHT' } = 75; # Height of Wiggle tracks in pixels
157 $cookie->{ 'TRACK_OFFSET' } = 20;
158 $cookie->{ 'TRACK_SPACE' } = 20;
159 $cookie->{ 'RULER_FONT_SIZE' } = 10; # Size of ruler font in pixels
160 $cookie->{ 'RULER_COLOR' } = [ 0, 0, 0 ];
161 $cookie->{ 'SEQ_FONT_SIZE' } = 10;
162 $cookie->{ 'SEQ_COLOR' } = [ 0, 0, 0, ];
163 $cookie->{ 'FEAT_WIDTH' } = 5;
164 $cookie->{ 'FEAT_COLOR' } = [ 0, 0, 0 ];
165 $cookie->{ 'FEAT_MAX' } = 5000; # TODO: Reduntant?
167 $cookie->{ 'LIST_USER' } = Maasha::BGB::Track::list_users();
169 if ( $cookie->{ 'USER' } )
171 $cookie->{ 'LIST_CLADE' } = Maasha::BGB::Track::list_clades( $cookie->{ 'USER' } );
172 $cookie->{ 'LIST_GENOME' } = Maasha::BGB::Track::list_genomes( $cookie->{ 'USER' }, $cookie->{ 'CLADE' } );
173 $cookie->{ 'LIST_ASSEMBLY' } = Maasha::BGB::Track::list_assemblies( $cookie->{ 'USER' }, $cookie->{ 'CLADE' }, $cookie->{ 'GENOME' } );
174 $cookie->{ 'LIST_CONTIG' } = Maasha::BGB::Track::list_contigs( $cookie->{ 'USER' }, $cookie->{ 'CLADE' }, $cookie->{ 'GENOME' }, $cookie->{ 'ASSEMBLY' } );
176 if ( $cookie->{ 'CONTIG' } )
178 cookie_start( $cookie );
179 cookie_end( $cookie );
180 cookie_zoom( $cookie );
181 cookie_move( $cookie );
182 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\n"; # DEBUG
216 # $cookie->{ 'PAGE' } = 'login';
218 # print STDERR "HER2\n"; # 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\n"; # DEBUG
230 $cookie->{ 'PAGE' } = 'login';
231 print STDERR "HER4\n"; # 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";
267 Maasha::BGB::Session::session_store( "$cookie->{ 'SESSION_DIR' }/sessions.txt", $session );
271 $cookie->{ 'LOGIN' } = "ERROR";
279 # Martin A. Hansen, November 2009.
281 # Decommify the cookie value for NAV_START and adjust it to
282 # to prevent negative values.
284 my ( $cookie, # cookie hash
289 if ( defined $cookie->{ 'NAV_START' } )
291 $cookie->{ 'NAV_START' } =~ tr/,//d;
292 $cookie->{ 'NAV_START' } = 0 if $cookie->{ 'NAV_START' } < 0;
296 $cookie->{ 'NAV_START' } = 0;
303 # Martin A. Hansen, November 2009.
305 # Decommify the cookie value for NAV_END and adjust it to prevent
306 # overshooting the max value for the contig size as determined
309 my ( $cookie, # cookie hash
316 $max = Maasha::Filesys::file_size( Maasha::BGB::Track::path_seq( $cookie ) );
318 if ( defined $cookie->{ 'NAV_END' } )
320 $cookie->{ 'NAV_END' } =~ tr/,//d;
321 $cookie->{ 'NAV_END' } = $max if $cookie->{ 'NAV_END' } > $max;
325 $cookie->{ 'NAV_END' } = $max;
332 # Martin A. Hansen, November 2009.
334 # Adjust the cookie values for NAV_START and NAV_END based
335 # on cookie ZOOM values.
337 my ( $cookie, # cookie hash
342 my ( $max, $dist, $new_dist, $dist_diff );
344 $max = Maasha::Filesys::file_size( Maasha::BGB::Track::path_seq( $cookie ) );
346 $dist = $cookie->{ 'NAV_END' } - $cookie->{ 'NAV_START' };
348 if ( defined $cookie->{ 'ZOOM_IN1' } ) {
349 $new_dist = $dist / 1.5;
350 } elsif ( defined $cookie->{ 'ZOOM_IN2' } ) {
351 $new_dist = $dist / 3;
352 } elsif ( defined $cookie->{ 'ZOOM_IN3' } ) {
353 $new_dist = $dist / 10;
354 } elsif ( defined $cookie->{ 'ZOOM_OUT1' } ) {
355 $new_dist = $dist * 1.5;
356 } elsif ( defined $cookie->{ 'ZOOM_OUT2' } ) {
357 $new_dist = $dist * 3;
358 } elsif ( defined $cookie->{ 'ZOOM_OUT3' } ) {
359 $new_dist = $dist * 10;
364 $dist_diff = $dist - $new_dist;
366 $cookie->{ 'NAV_START' } = int( $cookie->{ 'NAV_START' } + ( $dist_diff / 2 ) );
367 $cookie->{ 'NAV_END' } = int( $cookie->{ 'NAV_END' } - ( $dist_diff / 2 ) );
369 $cookie->{ 'NAV_START' } = 0 if $cookie->{ 'NAV_START' } < 0;
370 $cookie->{ 'NAV_END' } = $max if $cookie->{ 'NAV_END' } > $max;
377 # Martin A. Hansen, November 2009.
379 # Adjust the cookie values for NAV_START and NAV_END based
380 # on cookie MOVE values.
382 my ( $cookie, # cookie hash
387 my ( $max, $dist, $shift, $new_start, $new_end );
389 $max = Maasha::Filesys::file_size( Maasha::BGB::Track::path_seq( $cookie ) );
391 $dist = $cookie->{ 'NAV_END' } - $cookie->{ 'NAV_START' };
393 if ( defined $cookie->{ 'MOVE_LEFT1' } ) {
394 $shift = -1 * $dist * 0.10;
395 } elsif ( defined $cookie->{ 'MOVE_LEFT2' } ) {
396 $shift = -1 * $dist * 0.475;
397 } elsif ( defined $cookie->{ 'MOVE_LEFT3' } ) {
398 $shift = -1 * $dist * 0.95;
399 } elsif ( defined $cookie->{ 'MOVE_RIGHT1' } ) {
400 $shift = $dist * 0.10;
401 } elsif ( defined $cookie->{ 'MOVE_RIGHT2' } ) {
402 $shift = $dist * 0.475;
403 } elsif ( defined $cookie->{ 'MOVE_RIGHT3' } ) {
404 $shift = $dist * 0.95;
409 $new_start = int( $cookie->{ 'NAV_START' } + $shift );
410 $new_end = int( $cookie->{ 'NAV_END' } + $shift );
412 if ( $new_start > 0 and $new_end < $max )
414 $cookie->{ 'NAV_START' } = $new_start;
415 $cookie->{ 'NAV_END' } = $new_end;
423 # Martin A. Hansen, March 2010
425 # Adjust the cookie values for NAV_START and NAV_END based
426 # on cookie CENTER value if defined.
428 my ( $cookie, # cookie hash
433 my ( $l_dist, $r_dist );
435 if ( defined $cookie->{ 'NAV_CENTER' } )
437 $l_dist = $cookie->{ 'NAV_CENTER' } - $cookie->{ 'NAV_START' };
438 $r_dist = $cookie->{ 'NAV_END' } - $cookie->{ 'NAV_CENTER' };
440 if ( $l_dist > $r_dist ) {
441 $cookie->{ 'NAV_START' } = $cookie->{ 'NAV_END' } - 2 * $r_dist;
443 $cookie->{ 'NAV_END' } = $cookie->{ 'NAV_START' } + 2 * $l_dist;
451 # Martin A. Hansen, November 2009.
453 # Returns the next page in the taxonomy path.
455 my ( $cookie, # cookie hash
462 for ( $i = 0; $i < @{ $cookie->{ 'LIST_PAGES' } }; $i++ ) {
463 last if $cookie->{ 'PAGE' } eq $cookie->{ 'LIST_PAGES' }->[ $i ];
466 return $cookie->{ 'LIST_PAGES' }->[ $i + 1 ];
470 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> PAGES <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
475 # Martin A. Hansen, November 2009.
477 # Determines what page to render based on
478 # the cookie's PAGE setting.
480 my ( $cookie, # cookie hash
487 if ( $cookie->{ 'SESSION_ID' } ) {
488 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "session_id", value => $cookie->{ 'SESSION_ID' } ) );
491 if ( $cookie->{ 'PAGE' } eq 'login' ) {
492 push @html, page_login( $cookie );
493 } elsif ( $cookie->{ 'PAGE' } eq 'search' ) {
494 push @html, page_search( $cookie );
495 } elsif ( $cookie->{ 'PAGE' } eq 'browse' ) {
496 push @html, page_browse( $cookie );
497 } elsif ( $cookie->{ 'PAGE' } eq 'dna' ) {
498 push @html, page_dna( $cookie );
499 } elsif ( $cookie->{ 'PAGE' } eq 'export' ) {
500 push @html, page_export( $cookie );
502 push @html, page_taxonomy( $cookie );
505 return wantarray ? @html : \@html;
511 # Martin A. Hansen, December 2009.
513 # Renders the login page.
522 push @html, section_login( $cookie );
524 return wantarray ? @html : \@html;
530 # Martin A. Hansen, December 2009.
532 # Renders the search page.
541 push @html, section_taxonomy_table( $cookie );
542 push @html, section_search( $cookie );
544 return wantarray ? @html : \@html;
550 # Martin A. Hansen, November 2009.
552 # Renders the browse page.
561 push @html, section_taxonomy_table( $cookie );
562 push @html, section_navigate( $cookie );
563 push @html, section_browse( $cookie );
564 push @html, section_linkout( $cookie );
566 return wantarray ? @html : \@html;
572 # Martin A. Hansen, November 2009.
574 # Renders the DNA page.
583 push @html, section_taxonomy_table( $cookie );
584 push @html, section_dna( $cookie );
586 return wantarray ? @html : \@html;
592 # Martin A. Hansen, November 2009.
594 # Renders the export page.
603 push @html, section_taxonomy_table( $cookie );
604 push @html, section_export( $cookie );
606 return wantarray ? @html : \@html;
612 # Martin A. Hansen, November 2009.
614 # Renders the browse page.
616 my ( $cookie, # cookie hash
623 push @html, section_taxonomy_table( $cookie );
624 push @html, section_taxonomy_select( $cookie );
626 return wantarray ? @html : \@html;
630 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> SECTIONS <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
635 # Martin A. Hansen, December 2009.
637 # Returns a HTML section with a login menu.
639 my ( $cookie, # cookie hash
644 my ( $user, $password, $login, @html );
646 $user = Maasha::XHTML::text( name => "user", value => "", size => 20 );
647 $password = Maasha::XHTML::password( name => "password", value => "", size => 20 );
648 $login = Maasha::XHTML::submit( name => "login_submit", value => "Login" );
650 push @html, Maasha::XHTML::h2( txt => "Login", class => 'center' );
652 push @html, Maasha::XHTML::table_beg( summary => "Login table", align => 'center' );
653 push @html, Maasha::XHTML::table_row_simple( tr => [ "User:", $user ] );
654 push @html, Maasha::XHTML::table_row_simple( tr => [ "Password:", $password ] );
655 push @html, Maasha::XHTML::table_row_simple( tr => [ "", $login ] );
656 push @html, Maasha::XHTML::table_end;
658 if ( defined $cookie->{ 'CLADE' } and
659 defined $cookie->{ 'GENOME' } and
660 defined $cookie->{ 'ASSEMBLY' } and
661 defined $cookie->{ 'CONTIG' } and
662 defined $cookie->{ 'NAV_START' } and
663 defined $cookie->{ 'NAV_END' }
666 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "clade", value => $cookie->{ 'CLADE' } ) );
667 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "genome", value => $cookie->{ 'GENOME' } ) );
668 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "assembly", value => $cookie->{ 'ASSEMBLY' } ) );
669 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "contig", value => $cookie->{ 'CONTIG' } ) );
670 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "nav_start", value => $cookie->{ 'NAV_START' } ) );
671 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "nav_end", value => $cookie->{ 'NAV_END' } ) );
674 if ( $cookie->{ 'LOGIN' } and $cookie->{ 'LOGIN' } eq 'ERROR' ) {
675 push @html, Maasha::XHTML::h3( txt => "Bad user or password - please retry", class => 'error' );
678 return wantarray ? @html : \@html;
682 sub section_taxonomy_table
684 # Martin A. Hansen, November 2009.
686 # Returns a HTML section with a taxonomy table
687 # showing the location in the taxonomy and with
688 # links to browse the taxonomy.
690 my ( $cookie, # cookie hash
695 my ( $page, @row, @html, $href, $txt );
697 foreach $page ( @{ $cookie->{ 'LIST_PAGES' } } )
699 last if $page eq $cookie->{ 'PAGE' } or $page eq 'browse';
701 $href = "$cookie->{ 'SCRIPT' }?page=$page";
702 $href .= "&session_id=$cookie->{ 'SESSION_ID' }";
703 $href .= "&user=$cookie->{ 'USER' }";
704 $href .= "&clade=$cookie->{ 'CLADE' }" if $page !~ /clade/;
705 $href .= "&genome=$cookie->{ 'GENOME' }" if $page !~ /clade|genome/;
706 $href .= "&assembly=$cookie->{ 'ASSEMBLY' }" if $page !~ /clade|genome|assembly/;
707 $href .= "&contig=$cookie->{ 'CONTIG' }" if $page !~ /clade|genome|assembly|contig/;
709 $txt = ": $cookie->{ uc $page }";
711 push @row, Maasha::XHTML::ln( txt => $page, href => $href, class => 'inline' );
712 push @row, Maasha::XHTML::p( txt => $txt, class => 'inline' );
715 push @html, Maasha::XHTML::table_beg( summary => "Taxonomy table", align => 'center', cellpadding => '5px' );
716 push @html, Maasha::XHTML::table_row_simple( tr => [ join( "\n", @row ) ], align => 'center' );
717 push @html, Maasha::XHTML::table_end;
719 return wantarray ? @html : \@html;
723 sub section_taxonomy_select
725 # Martin A. Hansen, November 2009.
727 # Returns a HTML section with selection choices
728 # for navigating the taxonomy tree.
730 my ( $cookie, # cookie hash
735 my ( $list, @html, $item, $href );
737 $list = "LIST_" . uc $cookie->{ 'PAGE' };
739 push @html, Maasha::XHTML::h2( txt => "Select $cookie->{ 'PAGE' }", class => 'center' );
741 push @html, Maasha::XHTML::table_beg( summary => "Taxonomy select table", align => 'center', cellpadding => '5px' );
743 foreach $item ( @{ $cookie->{ $list } } )
745 $cookie->{ uc $cookie->{ 'PAGE' } } = $item;
747 $href = "$cookie->{ 'SCRIPT' }?page=" . cookie_page_next( $cookie );
748 $href .= "&session_id=$cookie->{ 'SESSION_ID' }";
749 $href .= "&user=$cookie->{ 'USER' }";
750 $href .= "&clade=$cookie->{ 'CLADE' }";
751 $href .= "&genome=$cookie->{ 'GENOME' }" if $cookie->{ 'GENOME' };
752 $href .= "&assembly=$cookie->{ 'ASSEMBLY' }" if $cookie->{ 'ASSEMBLY' };
753 $href .= "&contig=$cookie->{ 'CONTIG' }" if $cookie->{ 'CONTIG' };
755 push @html, Maasha::XHTML::table_row_simple( tr => [ Maasha::XHTML::ln( txt => $item, href => $href ) ] );
758 push @html, Maasha::XHTML::table_end;
760 return wantarray ? @html : \@html;
766 # Martin A. Hansen, November 2009.
768 # Returns a HTML section for navigating in the browser window.
770 my ( $cookie, # cookie hash
775 my ( @html, $nav_val );
777 $nav_val = Maasha::Calc::commify( $cookie->{ 'NAV_START' } ) . "-" . Maasha::Calc::commify( $cookie->{ 'NAV_END' } );
779 push @html, Maasha::XHTML::table_beg( summary => "Navigation table", align => 'center' );
780 push @html, Maasha::XHTML::table_row_simple( tr => [
781 "Position or search term:",
782 Maasha::XHTML::text( name => "nav_search", value => $nav_val, size => 30 ),
783 Maasha::XHTML::submit( name => "nav_submit", value => "Submit" ),
785 push @html, Maasha::XHTML::table_end;
787 push @html, Maasha::XHTML::table_beg( summary => "Zoom table", align => 'center' );
788 push @html, Maasha::XHTML::table_row_simple( tr => [
789 Maasha::XHTML::p( txt => 'Move:' ),
790 Maasha::XHTML::submit( name => "move_left3", value => "<<<", title => "move 95% to the left" ),
791 Maasha::XHTML::submit( name => "move_left2", value => "<<", title => "move 47.5% to the left" ),
792 Maasha::XHTML::submit( name => "move_left1", value => "<", title => "move 10% to the left" ),
793 Maasha::XHTML::submit( name => "move_right1", value => ">", title => "move 10% to the rigth" ),
794 Maasha::XHTML::submit( name => "move_right2", value => ">>", title => "move 47.5% to the rigth" ),
795 Maasha::XHTML::submit( name => "move_right3", value => ">>>", title => "move 95% to the right" ),
796 Maasha::XHTML::p( txt => 'Zoom in:' ),
797 Maasha::XHTML::submit( name => "zoom_in1", value => "1.5x" ),
798 Maasha::XHTML::submit( name => "zoom_in2", value => "3x" ),
799 Maasha::XHTML::submit( name => "zoom_in3", value => "10x" ),
800 Maasha::XHTML::p( txt => 'Zoom out:' ),
801 Maasha::XHTML::submit( name => "zoom_out1", value => "1.5x" ),
802 Maasha::XHTML::submit( name => "zoom_out2", value => "3x" ),
803 Maasha::XHTML::submit( name => "zoom_out3", value => "10x" ),
805 push @html, Maasha::XHTML::table_end;
807 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "page", value => "browse" ) );
808 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "user", value => $cookie->{ 'USER' } ) );
809 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "clade", value => $cookie->{ 'CLADE' } ) );
810 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "genome", value => $cookie->{ 'GENOME' } ) );
811 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "assembly", value => $cookie->{ 'ASSEMBLY' } ) );
812 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "contig", value => $cookie->{ 'CONTIG' } ) );
814 return wantarray ? @html : \@html;
820 # Martin A. Hansen, March 2010.
822 # Returns a HTML section for a static link based on information in the cookie.
824 my ( $cookie, # cookie hash
831 $link = Maasha::XHTML::ln(
833 href => join( "&", "$cookie->{ 'SCRIPT' }?page=browse",
834 "clade=$cookie->{ 'CLADE' }",
835 "genome=$cookie->{ 'GENOME' }",
836 "assembly=$cookie->{ 'ASSEMBLY' }",
837 "contig=$cookie->{ 'CONTIG' }",
838 "nav_start=$cookie->{ 'NAV_START' }",
839 "nav_end=$cookie->{ 'NAV_END' }",
841 title => "Static link to this view",
844 push @html, Maasha::XHTML::p( txt => $link, class => 'center' );
846 return wantarray ? @html : \@html;
857 my ( @tracks, $i, @features, $feat, $elem, $surface, $cr, $png_data, @html, @img, $x1, $y1, $x2, $y2, $factor, $center );
859 push @features, [ Maasha::BGB::Track::track_ruler( $cookie ) ];
860 push @features, [ Maasha::BGB::Track::track_seq( $cookie ) ];
862 @tracks = Maasha::BGB::Track::path_tracks( $cookie );
864 for ( $i = 0; $i < @tracks; $i++ )
866 $cookie->{ 'FEAT_COLOR' } = Maasha::BGB::Draw::palette( $i );
868 push @features, [ Maasha::BGB::Track::track_feature( $tracks[ $i ], $cookie ) ];
871 $surface = Cairo::ImageSurface->create( 'argb32', $cookie->{ 'IMG_WIDTH' }, $cookie->{ 'TRACK_OFFSET' } );
872 $cr = Cairo::Context->create( $surface );
874 $cr->rectangle ( 0, 0, $cookie->{ 'IMG_WIDTH' }, $cookie->{ 'TRACK_OFFSET' } );
875 $cr->set_source_rgb ( 1, 1, 1 );
878 foreach $feat ( @features ) {
879 Maasha::BGB::Draw::draw_feature( $cr, $feat ) if $feat;
882 $png_data = Maasha::BGB::Draw::base64_png( $surface );
884 push @img, Maasha::XHTML::img(
885 src => "data:image/png;base64,$png_data",
886 alt => "Browser Tracks",
887 height => $cookie->{ 'TRACK_OFFSET' },
888 width => $cookie->{ 'IMG_WIDTH' },
890 usemap => "#browser_map"
893 push @img, Maasha::XHTML::map_beg( name => "browser_map", id => "browser_map" );
895 $factor = ( $cookie->{ 'NAV_END' } - $cookie->{ 'NAV_START' } + 1 ) / $cookie->{ 'IMG_WIDTH' };
897 for ( $i = 0; $i < $cookie->{ 'IMG_WIDTH' }; $i += 5 )
904 $center = int( $cookie->{ 'NAV_START' } + $factor * $i );
906 push @img, Maasha::XHTML::area(
907 href => join( "&", "$cookie->{ 'SCRIPT' }?page=browse",
908 "session_id=$cookie->{ 'SESSION_ID' }",
909 "user=$cookie->{ 'USER' }",
910 "clade=$cookie->{ 'CLADE' }",
911 "genome=$cookie->{ 'GENOME' }",
912 "assembly=$cookie->{ 'ASSEMBLY' }",
913 "contig=$cookie->{ 'CONTIG' }",
914 "nav_start=$cookie->{ 'NAV_START' }",
915 "nav_end=$cookie->{ 'NAV_END' }",
916 "nav_center=$center",
919 coords => "$x1, $y1, $x2, $y2",
920 title => "Center on " . Maasha::Calc::commify( $center ),
924 foreach $feat ( @features )
926 foreach $elem ( @{ $feat } )
928 next if $elem->{ 'type' } eq 'text';
929 next if $elem->{ 'type' } eq 'wiggle';
931 #$elem->{ 'strand' } = '+' if $elem->{ 'strand' } eq '+';
933 $cookie->{ 'Q_ID' } = $elem->{ 'q_id' };
934 $cookie->{ 'S_BEG' } = $elem->{ 's_beg' };
935 $cookie->{ 'S_END' } = $elem->{ 's_end' };
936 $cookie->{ 'STRAND' } = $elem->{ 'strand' };
938 push @img, Maasha::XHTML::area(
939 href => join( "&", "$cookie->{ 'SCRIPT' }?page=export",
940 "session_id=$cookie->{ 'SESSION_ID' }",
941 "user=$cookie->{ 'USER' }",
942 "clade=$cookie->{ 'CLADE' }",
943 "genome=$cookie->{ 'GENOME' }",
944 "assembly=$cookie->{ 'ASSEMBLY' }",
945 "contig=$cookie->{ 'CONTIG' }",
946 "s_beg=$cookie->{ 'S_BEG' }",
947 "s_end=$cookie->{ 'S_END' }",
948 "strand=$cookie->{ 'STRAND' }",
951 coords => "$elem->{ x1 }, $elem->{ y1 }, $elem->{ x2 }, $elem->{ y2 }",
952 title => "$elem->{ 'title' }",
957 push @img, Maasha::XHTML::map_end();
959 push @html, Maasha::XHTML::p( txt => join( "\n", @img ) );
961 @html = Maasha::XHTML::div( txt => join( "\n", @html ), class => 'browse' );
963 return wantarray ? @html : \@html;
969 # Martin A. Hansen, November 2009.
971 # Returns a HTML section with export table.
973 my ( $cookie, # cookie hash
978 my ( $feat, @row_dna_contig, @html );
980 $feat = $cookie->{ 'Q_ID' } || "[no name]";
982 push @row_dna_contig, Maasha::XHTML::p( txt => qq(Export Feature: "$feat" DNA from Contig: ), class => 'inline' );
983 push @row_dna_contig, Maasha::XHTML::p( txt => "$cookie->{ 'CONTIG' } Start: ", class => 'inline' );
984 push @row_dna_contig, Maasha::XHTML::text( name => "s_beg", value => Maasha::Calc::commify( $cookie->{ 'S_BEG' } ), size => 15 );
985 push @row_dna_contig, Maasha::XHTML::p( txt => "End: ", class => 'inline' );
986 push @row_dna_contig, Maasha::XHTML::text( name => "s_end", value => Maasha::Calc::commify( $cookie->{ 'S_END' } ), size => 15 );
987 push @row_dna_contig, Maasha::XHTML::p( txt => "Strand: ", class => 'inline' );
988 push @row_dna_contig, Maasha::XHTML::menu( name => "strand", options => [ qw( + - ) ], selected => $cookie->{ 'STRAND' } );
989 push @row_dna_contig, Maasha::XHTML::submit( name => "export", value => "Export", title => "Fetch DNA from this region" );
991 push @html, Maasha::XHTML::h2( txt => "Export", class => 'center' );
992 push @html, Maasha::XHTML::table_beg( summary => "Taxonomy select table", align => 'center' );
993 push @html, Maasha::XHTML::table_row_simple( tr => \@row_dna_contig );
994 push @html, Maasha::XHTML::table_end;
996 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "page", value => "dna" ) );
997 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "user", value => $cookie->{ 'USER' } ) );
998 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "clade", value => $cookie->{ 'CLADE' } ) );
999 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "genome", value => $cookie->{ 'GENOME' } ) );
1000 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "assembly", value => $cookie->{ 'ASSEMBLY' } ) );
1001 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "contig", value => $cookie->{ 'CONTIG' } ) );
1003 return wantarray ? @html : \@html;
1009 # Martin A. Hansen, November 2009.
1011 # Returns a HTML section with export table.
1013 my ( $cookie, # cookie hash
1018 my ( $results, $result, $count, @html, $export, $browse );
1020 $results = Maasha::BGB::Track::search_tracks( $cookie );
1022 $count = scalar @{ $results };
1024 push @html, Maasha::XHTML::h2( txt => "Search", class => 'center' );
1025 push @html, Maasha::XHTML::p( txt => qq(Results for "$cookie->{ 'SEARCH' }": $count), class => 'center' );
1029 push @html, Maasha::XHTML::table_beg( summary => "Search table", align => 'center', cellpadding => '5px' );
1030 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) ] );
1032 foreach $result ( @{ $results } )
1034 $cookie->{ 'CONTIG' } = $result->{ 'S_ID' };
1035 $cookie->{ 'NAV_START' } = $result->{ 'S_BEG' };
1036 $cookie->{ 'NAV_END' } = $result->{ 'S_END' };
1037 $cookie->{ 'S_BEG' } = $result->{ 'S_BEG' };
1038 $cookie->{ 'S_END' } = $result->{ 'S_END' };
1039 $cookie->{ 'STRAND' } = $result->{ 'STRAND' };
1040 $cookie->{ 'Q_ID' } = $result->{ 'Q_ID' };
1042 $browse = Maasha::XHTML::ln(
1044 href => join( "&", "$cookie->{ 'SCRIPT' }?page=browse",
1045 "session_id=$cookie->{ 'SESSION_ID' }",
1046 "user=$cookie->{ 'USER' }",
1047 "clade=$cookie->{ 'CLADE' }",
1048 "genome=$cookie->{ 'GENOME' }",
1049 "assembly=$cookie->{ 'ASSEMBLY' }",
1050 "contig=$cookie->{ 'CONTIG' }",
1051 "nav_start=$cookie->{ 'NAV_START' }",
1052 "nav_end=$cookie->{ 'NAV_END' }",
1057 $export = Maasha::XHTML::ln(
1059 href => join( "&", "$cookie->{ 'SCRIPT' }?page=export",
1060 "session_id=$cookie->{ 'SESSION_ID' }",
1061 "user=$cookie->{ 'USER' }",
1062 "clade=$cookie->{ 'CLADE' }",
1063 "genome=$cookie->{ 'GENOME' }",
1064 "assembly=$cookie->{ 'ASSEMBLY' }",
1065 "contig=$cookie->{ 'CONTIG' }",
1066 "s_beg=$cookie->{ 'S_BEG' }",
1067 "s_end=$cookie->{ 'S_END' }",
1068 "strand=$cookie->{ 'STRAND' }",
1072 push @html, Maasha::XHTML::table_row_advanced(
1073 tr => [ { td => $result->{ 'S_ID' } },
1074 { td => $result->{ 'S_BEG' }, align => 'right' },
1075 { td => $result->{ 'S_END' }, align => 'right' },
1076 { td => $result->{ 'Q_ID' } },
1077 { td => $result->{ 'SCORE' }, align => 'right' },
1078 { td => $result->{ 'STRAND' } },
1079 { td => $result->{ 'HITS' }, align => 'right' },
1080 { td => $result->{ 'ALIGN' } },
1081 { td => $result->{ 'BLOCK_COUNT' }, align => 'right' },
1082 { td => $result->{ 'BLOCK_BEGS' } },
1083 { td => $result->{ 'BLOCK_LENS' } },
1084 { td => $result->{ 'BLOCK_TYPE' } },
1087 ], class => "monospace"
1091 push @html, Maasha::XHTML::table_end;
1094 return wantarray ? @html : \@html;
1100 # Martin A. Hansen, November 2009.
1102 # Returns a HTML section with extracted DNA.
1104 my ( $cookie, # cookie hash
1109 my ( @html, $beg, $end, $seq );
1111 $beg = $cookie->{ 'S_BEG' };
1112 $end = $cookie->{ 'S_END' };
1116 $seq = join ";", ">$cookie->{ 'GENOME' }", $cookie->{ 'ASSEMBLY' }, $cookie->{ 'CONTIG' }, $beg, $end, "$cookie->{ 'STRAND' }\n";
1117 $seq .= Maasha::BGB::Track::dna_get( $cookie );
1119 push @html, Maasha::XHTML::h2( txt => "DNA", class => 'center' );
1120 push @html, Maasha::XHTML::pre( txt => $seq );
1122 return wantarray ? @html : \@html;
1126 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<