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' );
126 $cookie->{ 'NAV_END' } ||= $cgi->param( 'nav_end' );
127 $cookie->{ 'NAV_CENTER' } = $cgi->param( 'nav_center' );
128 $cookie->{ 'S_BEG' } = $cgi->param( 's_beg' );
129 $cookie->{ 'S_END' } = $cgi->param( 's_end' );
130 $cookie->{ 'STRAND' } = $cgi->param( 'strand' );
131 $cookie->{ 'ZOOM_IN1' } = $cgi->param( 'zoom_in1' );
132 $cookie->{ 'ZOOM_IN2' } = $cgi->param( 'zoom_in2' );
133 $cookie->{ 'ZOOM_IN3' } = $cgi->param( 'zoom_in3' );
134 $cookie->{ 'ZOOM_OUT1' } = $cgi->param( 'zoom_out1' );
135 $cookie->{ 'ZOOM_OUT2' } = $cgi->param( 'zoom_out2' );
136 $cookie->{ 'ZOOM_OUT3' } = $cgi->param( 'zoom_out3' );
137 $cookie->{ 'MOVE_LEFT1' } = $cgi->param( 'move_left1' );
138 $cookie->{ 'MOVE_LEFT2' } = $cgi->param( 'move_left2' );
139 $cookie->{ 'MOVE_LEFT3' } = $cgi->param( 'move_left3' );
140 $cookie->{ 'MOVE_RIGHT1' } = $cgi->param( 'move_right1' );
141 $cookie->{ 'MOVE_RIGHT2' } = $cgi->param( 'move_right2' );
142 $cookie->{ 'MOVE_RIGHT3' } = $cgi->param( 'move_right3' );
144 $cookie->{ 'IMG_WIDTH' } = 1200;
145 $cookie->{ 'IMG_HEIGHT' } = 800;
146 $cookie->{ 'TRACK_OFFSET' } = 20;
147 $cookie->{ 'TRACK_SPACE' } = 20;
148 $cookie->{ 'RULER_FONT_SIZE' } = 10;
149 $cookie->{ 'RULER_COLOR' } = [ 0, 0, 0 ];
150 $cookie->{ 'SEQ_FONT_SIZE' } = 10;
151 $cookie->{ 'SEQ_COLOR' } = [ 0, 0, 0, ];
152 $cookie->{ 'FEAT_WIDTH' } = 5;
153 $cookie->{ 'FEAT_COLOR' } = [ 0, 0, 0 ];
154 $cookie->{ 'FEAT_MAX' } = 5000;
156 $path = "$cookie->{ 'DATA_DIR' }/Users";
158 $cookie->{ 'LIST_USER' } = Maasha::Filesys::ls_dirs_base( $path ) if -d $path;
160 $path .= "/$cookie->{ 'USER' }";
162 $cookie->{ 'LIST_CLADE' } = Maasha::Filesys::ls_dirs_base( $path ) if -d $path;
164 $path .= "/$cookie->{ 'CLADE' }";
166 $cookie->{ 'LIST_GENOME' } = Maasha::Filesys::ls_dirs_base( $path ) if -d $path;
168 $path .= "/$cookie->{ 'GENOME' }";
170 $cookie->{ 'LIST_ASSEMBLY' } = Maasha::Filesys::ls_dirs_base( $path ) if -d $path;
172 $path .= "/$cookie->{ 'ASSEMBLY' }";
174 $cookie->{ 'LIST_CONTIG' } = Maasha::Filesys::ls_dirs_base( $path ) if -d $path;
176 if ( $cookie->{ 'CONTIG' } )
178 cookie_start( $cookie );
179 cookie_end( $cookie );
180 cookie_zoom( $cookie );
181 cookie_move( $cookie );
182 cookie_center( $cookie );
185 $cookie->{ 'STRAND' } = '+' if defined $cookie->{ 'STRAND' } and $cookie->{ 'STRAND' } eq ' '; # FIXME ugly HTML fix
187 return wantarray ? %{ $cookie } : $cookie;
193 # Martin A. Hansen, December 2009.
195 # Check cookie information against session information.
197 my ( $cookie, # cookie hash
204 $session = Maasha::BGB::Session::session_restore( "$cookie->{ 'SESSION_DIR' }/sessions.txt" );
206 # if ( $cookie->{ 'SESSION_ID' } )
208 # if ( $cookie->{ 'SESSION_ID' } ne $ENV{ 'SSL_SESSION_ID' } ) {
209 # $cookie->{ 'PAGE' } = 'login';
210 # print STDERR "HER1"; # DEBUG
215 # $cookie->{ 'PAGE' } = 'login';
217 # print STDERR "HER2"; # DEBUG
220 if ( exists $session->{ $cookie->{ 'USER' } } and $cookie->{ 'SESSION_ID' } )
222 if ( $session->{ $cookie->{ 'USER' } }->{ 'SESSION_ID' } ne $cookie->{ 'SESSION_ID' } ) {
223 $cookie->{ 'PAGE' } = 'login';
224 print STDERR "HER3"; # DEBUG
229 $cookie->{ 'PAGE' } = 'login';
230 print STDERR "HER4"; # DEBUG
231 print STDERR "NO COOKIE SESSION ID\n" if not $cookie->{ 'SESSION_ID' }; # DEBUG
232 print STDERR "NO COOKIE USER\n" if not $cookie->{ 'USER' }; # DEBUG
233 print STDERR "NO SESSION USER\n" if not exists $session->{ $cookie->{ 'USER' } }; # DEBUG
240 # Martin A. Hansen, December 2009.
242 # Check a user and password from CGI against the password file and
243 # set the session ID, if found, in the cookie.
245 my ( $cookie, # cookie hash
252 if ( $cookie->{ 'USER' } and $cookie->{ 'PASSWORD' } )
254 $session = Maasha::BGB::Session::session_restore( "$cookie->{ 'SESSION_DIR' }/sessions.txt" );
256 if ( exists $session->{ $cookie->{ 'USER' } } and
257 $session->{ $cookie->{ 'USER' } }->{ 'PASSWORD' } eq Digest::MD5::md5_hex( $cookie->{ 'PASSWORD' } ) )
259 $session->{ $cookie->{ 'USER' } }->{ 'SESSION_ID' } ||= Maasha::BGB::Session::session_new();
260 # $session->{ $cookie->{ 'USER' } }->{ 'SESSION_ID' } = $ENV{ 'SSL_SESSION_ID' };
261 $session->{ $cookie->{ 'USER' } }->{ 'TIME' } = Maasha::Common::time_stamp();
263 $cookie->{ 'SESSION_ID' } = $session->{ $cookie->{ 'USER' } }->{ 'SESSION_ID' };
264 $cookie->{ 'LOGIN' } = "OK";
265 $cookie->{ 'PAGE' } = 'clade';
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 );
565 return wantarray ? @html : \@html;
571 # Martin A. Hansen, November 2009.
573 # Renders the DNA page.
582 push @html, section_taxonomy_table( $cookie );
583 push @html, section_dna( $cookie );
585 return wantarray ? @html : \@html;
591 # Martin A. Hansen, November 2009.
593 # Renders the export page.
602 push @html, section_taxonomy_table( $cookie );
603 push @html, section_export( $cookie );
605 return wantarray ? @html : \@html;
611 # Martin A. Hansen, November 2009.
613 # Renders the browse page.
615 my ( $cookie, # cookie hash
622 push @html, section_taxonomy_table( $cookie );
623 push @html, section_taxonomy_select( $cookie );
625 return wantarray ? @html : \@html;
629 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> SECTIONS <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
634 # Martin A. Hansen, December 2009.
636 # Returns a HTML section with a login menu.
638 my ( $cookie, # cookie hash
643 my ( $user, $password, $login, @html );
645 $user = Maasha::XHTML::text( name => "user", value => "", size => 20 );
646 $password = Maasha::XHTML::password( name => "password", value => "", size => 20 );
647 $login = Maasha::XHTML::submit( name => "login_submit", value => "Login" );
649 push @html, Maasha::XHTML::h2( txt => "Login", class => 'center' );
651 push @html, Maasha::XHTML::table_beg( summary => "Login table", align => 'center' );
652 push @html, Maasha::XHTML::table_row_simple( tr => [ "User:", $user ] );
653 push @html, Maasha::XHTML::table_row_simple( tr => [ "Password:", $password ] );
654 push @html, Maasha::XHTML::table_row_simple( tr => [ "", $login ] );
655 push @html, Maasha::XHTML::table_end;
657 if ( $cookie->{ 'LOGIN' } and $cookie->{ 'LOGIN' } eq 'ERROR' ) {
658 push @html, Maasha::XHTML::h3( txt => "Bad user or password - please retry", class => 'error' );
661 return wantarray ? @html : \@html;
665 sub section_taxonomy_table
667 # Martin A. Hansen, November 2009.
669 # Returns a HTML section with a taxonomy table
670 # showing the location in the taxonomy and with
671 # links to browse the taxonomy.
673 my ( $cookie, # cookie hash
678 my ( $page, @row, @html, $href, $txt );
680 foreach $page ( @{ $cookie->{ 'LIST_PAGES' } } )
682 last if $page eq $cookie->{ 'PAGE' } or $page eq 'browse';
684 $href = "$cookie->{ 'SCRIPT' }?page=$page";
685 $href .= "&session_id=$cookie->{ 'SESSION_ID' }";
686 $href .= "&user=$cookie->{ 'USER' }";
687 $href .= "&clade=$cookie->{ 'CLADE' }" if $page !~ /clade/;
688 $href .= "&genome=$cookie->{ 'GENOME' }" if $page !~ /clade|genome/;
689 $href .= "&assembly=$cookie->{ 'ASSEMBLY' }" if $page !~ /clade|genome|assembly/;
690 $href .= "&contig=$cookie->{ 'CONTIG' }" if $page !~ /clade|genome|assembly|contig/;
692 $txt = ": $cookie->{ uc $page }";
694 push @row, Maasha::XHTML::ln( txt => $page, href => $href, class => 'inline' );
695 push @row, Maasha::XHTML::p( txt => $txt, class => 'inline' );
698 push @html, Maasha::XHTML::table_beg( summary => "Taxonomy table", align => 'center', cellpadding => '5px' );
699 push @html, Maasha::XHTML::table_row_simple( tr => [ join( "\n", @row ) ], align => 'center' );
700 push @html, Maasha::XHTML::table_end;
702 return wantarray ? @html : \@html;
706 sub section_taxonomy_select
708 # Martin A. Hansen, November 2009.
710 # Returns a HTML section with selection choices
711 # for navigating the taxonomy tree.
713 my ( $cookie, # cookie hash
718 my ( $list, @html, $item, $href );
720 $list = "LIST_" . uc $cookie->{ 'PAGE' };
722 push @html, Maasha::XHTML::h2( txt => "Select $cookie->{ 'PAGE' }", class => 'center' );
724 push @html, Maasha::XHTML::table_beg( summary => "Taxonomy select table", align => 'center', cellpadding => '5px' );
726 foreach $item ( @{ $cookie->{ $list } } )
728 $cookie->{ uc $cookie->{ 'PAGE' } } = $item;
730 $href = "$cookie->{ 'SCRIPT' }?page=" . cookie_page_next( $cookie );
731 $href .= "&session_id=$cookie->{ 'SESSION_ID' }";
732 $href .= "&user=$cookie->{ 'USER' }";
733 $href .= "&clade=$cookie->{ 'CLADE' }";
734 $href .= "&genome=$cookie->{ 'GENOME' }" if $cookie->{ 'GENOME' };
735 $href .= "&assembly=$cookie->{ 'ASSEMBLY' }" if $cookie->{ 'ASSEMBLY' };
736 $href .= "&contig=$cookie->{ 'CONTIG' }" if $cookie->{ 'CONTIG' };
738 push @html, Maasha::XHTML::table_row_simple( tr => [ Maasha::XHTML::ln( txt => $item, href => $href ) ] );
741 push @html, Maasha::XHTML::table_end;
743 return wantarray ? @html : \@html;
749 # Martin A. Hansen, November 2009.
751 # Returns a HTML section for navigating in the browser window.
753 my ( $cookie, # cookie hash
758 my ( @html, $nav_val );
760 $nav_val = Maasha::Calc::commify( $cookie->{ 'NAV_START' } ) . "-" . Maasha::Calc::commify( $cookie->{ 'NAV_END' } );
762 push @html, Maasha::XHTML::table_beg( summary => "Navigation table", align => 'center' );
763 push @html, Maasha::XHTML::table_row_simple( tr => [
764 "Position or search term:",
765 Maasha::XHTML::text( name => "nav_search", value => $nav_val, size => 30 ),
766 Maasha::XHTML::submit( name => "nav_submit", value => "Submit" ),
768 push @html, Maasha::XHTML::table_end;
770 push @html, Maasha::XHTML::table_beg( summary => "Zoom table", align => 'center' );
771 push @html, Maasha::XHTML::table_row_simple( tr => [
772 Maasha::XHTML::p( txt => 'Move:' ),
773 Maasha::XHTML::submit( name => "move_left3", value => "<<<", title => "move 95% to the left" ),
774 Maasha::XHTML::submit( name => "move_left2", value => "<<", title => "move 47.5% to the left" ),
775 Maasha::XHTML::submit( name => "move_left1", value => "<", title => "move 10% to the left" ),
776 Maasha::XHTML::submit( name => "move_right1", value => ">", title => "move 10% to the rigth" ),
777 Maasha::XHTML::submit( name => "move_right2", value => ">>", title => "move 47.5% to the rigth" ),
778 Maasha::XHTML::submit( name => "move_right3", value => ">>>", title => "move 95% to the right" ),
779 Maasha::XHTML::p( txt => 'Zoom in:' ),
780 Maasha::XHTML::submit( name => "zoom_in1", value => "1.5x" ),
781 Maasha::XHTML::submit( name => "zoom_in2", value => "3x" ),
782 Maasha::XHTML::submit( name => "zoom_in3", value => "10x" ),
783 Maasha::XHTML::p( txt => 'Zoom out:' ),
784 Maasha::XHTML::submit( name => "zoom_out1", value => "1.5x" ),
785 Maasha::XHTML::submit( name => "zoom_out2", value => "3x" ),
786 Maasha::XHTML::submit( name => "zoom_out3", value => "10x" ),
788 push @html, Maasha::XHTML::table_end;
790 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "page", value => "browse" ) );
791 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "user", value => $cookie->{ 'USER' } ) );
792 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "clade", value => $cookie->{ 'CLADE' } ) );
793 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "genome", value => $cookie->{ 'GENOME' } ) );
794 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "assembly", value => $cookie->{ 'ASSEMBLY' } ) );
795 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "contig", value => $cookie->{ 'CONTIG' } ) );
797 return wantarray ? @html : \@html;
808 my ( @tracks, $i, @features, $feat, $elem, $surface, $cr, $png_data, @html, @img, $x1, $y1, $x2, $y2, $factor, $center );
810 push @features, [ Maasha::BGB::Track::track_ruler( $cookie ) ];
811 push @features, [ Maasha::BGB::Track::track_seq( $cookie ) ];
813 @tracks = Maasha::BGB::Track::path_tracks( $cookie );
815 for ( $i = 0; $i < @tracks; $i++ )
817 $cookie->{ 'FEAT_COLOR' } = Maasha::BGB::Draw::palette( $i );
819 push @features, [ Maasha::BGB::Track::track_feature( $tracks[ $i ], $cookie ) ];
822 $surface = Cairo::ImageSurface->create( 'argb32', $cookie->{ 'IMG_WIDTH' }, $cookie->{ 'TRACK_OFFSET' } );
823 $cr = Cairo::Context->create( $surface );
825 $cr->rectangle ( 0, 0, $cookie->{ 'IMG_WIDTH' }, $cookie->{ 'TRACK_OFFSET' } );
826 $cr->set_source_rgb ( 1, 1, 1 );
829 foreach $feat ( @features ) {
830 Maasha::BGB::Draw::draw_feature( $cr, $feat ) if $feat;
833 $png_data = Maasha::BGB::Draw::base64_png( $surface );
835 push @img, Maasha::XHTML::img(
836 src => "data:image/png;base64,$png_data",
837 alt => "Browser Tracks",
838 height => $cookie->{ 'TRACK_OFFSET' },
839 width => $cookie->{ 'IMG_WIDTH' },
841 usemap => "#browser_map"
844 push @img, Maasha::XHTML::map_beg( name => "browser_map", id => "browser_map" );
846 $factor = ( $cookie->{ 'NAV_END' } - $cookie->{ 'NAV_START' } + 1 ) / $cookie->{ 'IMG_WIDTH' };
848 for ( $i = 0; $i < $cookie->{ 'IMG_WIDTH' }; $i += 5 )
855 $center = int( $cookie->{ 'NAV_START' } + $factor * $i );
857 push @img, Maasha::XHTML::area(
858 href => join( "&", "$cookie->{ 'SCRIPT' }?page=browse",
859 "session_id=$cookie->{ 'SESSION_ID' }",
860 "user=$cookie->{ 'USER' }",
861 "clade=$cookie->{ 'CLADE' }",
862 "genome=$cookie->{ 'GENOME' }",
863 "contig=$cookie->{ 'CONTIG' }",
864 "assembly=$cookie->{ 'ASSEMBLY' }",
865 "nav_start=$cookie->{ 'NAV_START' }",
866 "nav_end=$cookie->{ 'NAV_END' }",
867 "nav_center=$center",
870 coords => "$x1, $y1, $x2, $y2",
871 title => "Center on " . Maasha::Calc::commify( $center ),
875 foreach $feat ( @features )
877 foreach $elem ( @{ $feat } )
879 next if $elem->{ 'type' } eq 'text';
880 next if $elem->{ 'type' } eq 'wiggle';
882 #$elem->{ 'strand' } = '+' if $elem->{ 'strand' } eq '+';
884 $cookie->{ 'Q_ID' } = $elem->{ 'q_id' };
885 $cookie->{ 'S_BEG' } = $elem->{ 's_beg' };
886 $cookie->{ 'S_END' } = $elem->{ 's_end' };
887 $cookie->{ 'STRAND' } = $elem->{ 'strand' };
889 push @img, Maasha::XHTML::area(
890 href => join( "&", "$cookie->{ 'SCRIPT' }?page=export",
891 "session_id=$cookie->{ 'SESSION_ID' }",
892 "user=$cookie->{ 'USER' }",
893 "clade=$cookie->{ 'CLADE' }",
894 "genome=$cookie->{ 'GENOME' }",
895 "contig=$cookie->{ 'CONTIG' }",
896 "assembly=$cookie->{ 'ASSEMBLY' }",
897 "s_beg=$cookie->{ 'S_BEG' }",
898 "s_end=$cookie->{ 'S_END' }",
899 "strand=$cookie->{ 'STRAND' }",
902 coords => "$elem->{ x1 }, $elem->{ y1 }, $elem->{ x2 }, $elem->{ y2 }",
903 title => "$elem->{ 'title' }",
908 push @img, Maasha::XHTML::map_end();
910 push @html, Maasha::XHTML::p( txt => join( "\n", @img ) );
912 @html = Maasha::XHTML::div( txt => join( "\n", @html ), class => 'browse' );
914 return wantarray ? @html : \@html;
920 # Martin A. Hansen, November 2009.
922 # Returns a HTML section with export table.
924 my ( $cookie, # cookie hash
929 my ( @row_dna_contig, @html );
931 push @row_dna_contig, Maasha::XHTML::p( txt => qq(Export Feature: "$cookie->{ 'Q_ID' }" DNA from Contig: ), class => 'inline' );
932 push @row_dna_contig, Maasha::XHTML::p( txt => "$cookie->{ 'CONTIG' } Start: ", class => 'inline' );
933 push @row_dna_contig, Maasha::XHTML::text( name => "s_beg", value => Maasha::Calc::commify( $cookie->{ 'S_BEG' } ), size => 15 );
934 push @row_dna_contig, Maasha::XHTML::p( txt => "End: ", class => 'inline' );
935 push @row_dna_contig, Maasha::XHTML::text( name => "s_end", value => Maasha::Calc::commify( $cookie->{ 'S_END' } ), size => 15 );
936 push @row_dna_contig, Maasha::XHTML::p( txt => "Strand: ", class => 'inline' );
937 push @row_dna_contig, Maasha::XHTML::menu( name => "strand", options => [ qw( + - ) ], selected => $cookie->{ 'STRAND' } );
938 push @row_dna_contig, Maasha::XHTML::submit( name => "export", value => "Export", title => "Fetch DNA from this region" );
940 push @html, Maasha::XHTML::h2( txt => "Export", class => 'center' );
941 push @html, Maasha::XHTML::table_beg( summary => "Taxonomy select table", align => 'center' );
942 push @html, Maasha::XHTML::table_row_simple( tr => \@row_dna_contig );
943 push @html, Maasha::XHTML::table_end;
945 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "page", value => "dna" ) );
946 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "user", value => $cookie->{ 'USER' } ) );
947 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "clade", value => $cookie->{ 'CLADE' } ) );
948 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "genome", value => $cookie->{ 'GENOME' } ) );
949 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "assembly", value => $cookie->{ 'ASSEMBLY' } ) );
950 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "contig", value => $cookie->{ 'CONTIG' } ) );
952 return wantarray ? @html : \@html;
958 # Martin A. Hansen, November 2009.
960 # Returns a HTML section with export table.
962 my ( $cookie, # cookie hash
967 my ( $results, $result, $count, @html, $export, $browse );
969 $results = Maasha::BGB::Track::search_tracks( $cookie );
971 $count = scalar @{ $results };
973 push @html, Maasha::XHTML::h2( txt => "Search", class => 'center' );
974 push @html, Maasha::XHTML::p( txt => qq(Results for "$cookie->{ 'SEARCH' }": $count), class => 'center' );
978 push @html, Maasha::XHTML::table_beg( summary => "Search table", align => 'center', cellpadding => '5px' );
979 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) ] );
981 foreach $result ( @{ $results } )
983 $cookie->{ 'CONTIG' } = $result->{ 'S_ID' };
984 $cookie->{ 'NAV_START' } = $result->{ 'S_BEG' };
985 $cookie->{ 'NAV_END' } = $result->{ 'S_END' };
986 $cookie->{ 'S_BEG' } = $result->{ 'S_BEG' };
987 $cookie->{ 'S_END' } = $result->{ 'S_END' };
988 $cookie->{ 'STRAND' } = $result->{ 'STRAND' };
989 $cookie->{ 'Q_ID' } = $result->{ 'Q_ID' };
991 $browse = Maasha::XHTML::ln(
993 href => join( "&", "$cookie->{ 'SCRIPT' }?page=browse",
994 "session_id=$cookie->{ 'SESSION_ID' }",
995 "user=$cookie->{ 'USER' }",
996 "clade=$cookie->{ 'CLADE' }",
997 "genome=$cookie->{ 'GENOME' }",
998 "contig=$cookie->{ 'CONTIG' }",
999 "assembly=$cookie->{ 'ASSEMBLY' }",
1000 "nav_start=$cookie->{ 'NAV_START' }",
1001 "nav_end=$cookie->{ 'NAV_END' }",
1006 $export = Maasha::XHTML::ln(
1008 href => join( "&", "$cookie->{ 'SCRIPT' }?page=export",
1009 "session_id=$cookie->{ 'SESSION_ID' }",
1010 "user=$cookie->{ 'USER' }",
1011 "clade=$cookie->{ 'CLADE' }",
1012 "genome=$cookie->{ 'GENOME' }",
1013 "contig=$cookie->{ 'CONTIG' }",
1014 "assembly=$cookie->{ 'ASSEMBLY' }",
1015 "s_beg=$cookie->{ 'S_BEG' }",
1016 "s_end=$cookie->{ 'S_END' }",
1017 "strand=$cookie->{ 'STRAND' }",
1021 push @html, Maasha::XHTML::table_row_advanced(
1022 tr => [ { td => $result->{ 'S_ID' } },
1023 { td => $result->{ 'S_BEG' }, align => 'right' },
1024 { td => $result->{ 'S_END' }, align => 'right' },
1025 { td => $result->{ 'Q_ID' } },
1026 { td => $result->{ 'SCORE' }, align => 'right' },
1027 { td => $result->{ 'STRAND' } },
1028 { td => $result->{ 'HITS' }, align => 'right' },
1029 { td => $result->{ 'ALIGN' } },
1030 { td => $result->{ 'BLOCK_COUNT' }, align => 'right' },
1031 { td => $result->{ 'BLOCK_BEGS' } },
1032 { td => $result->{ 'BLOCK_LENS' } },
1033 { td => $result->{ 'BLOCK_TYPE' } },
1036 ], class => "monospace"
1040 push @html, Maasha::XHTML::table_end;
1043 return wantarray ? @html : \@html;
1049 # Martin A. Hansen, November 2009.
1051 # Returns a HTML section with extracted DNA.
1053 my ( $cookie, # cookie hash
1058 my ( @html, $beg, $end, $seq );
1060 $beg = $cookie->{ 'S_BEG' };
1061 $end = $cookie->{ 'S_END' };
1065 $seq = join ";", ">$cookie->{ 'GENOME' }", $cookie->{ 'ASSEMBLY' }, $cookie->{ 'CONTIG' }, $beg, $end, "$cookie->{ 'STRAND' }\n";
1066 $seq .= Maasha::BGB::Track::dna_get( $cookie );
1068 push @html, Maasha::XHTML::h2( txt => "DNA", class => 'center' );
1069 push @html, Maasha::XHTML::pre( txt => $seq );
1071 return wantarray ? @html : \@html;
1075 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<