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 next page in the taxonomy path.
456 my ( $cookie, # cookie hash
463 for ( $i = 0; $i < @{ $cookie->{ 'LIST_PAGES' } }; $i++ ) {
464 last if $cookie->{ 'PAGE' } eq $cookie->{ 'LIST_PAGES' }->[ $i ];
467 return $cookie->{ 'LIST_PAGES' }->[ $i + 1 ];
471 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> PAGES <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
476 # Martin A. Hansen, November 2009.
478 # Determines what page to render based on
479 # the cookie's PAGE setting.
481 my ( $cookie, # cookie hash
488 if ( $cookie->{ 'PAGE' } eq 'login' ) {
489 push @html, page_login( $cookie );
490 } elsif ( $cookie->{ 'PAGE' } eq 'search' ) {
491 push @html, page_search( $cookie );
492 } elsif ( $cookie->{ 'PAGE' } eq 'browse' ) {
493 push @html, page_browse( $cookie );
494 } elsif ( $cookie->{ 'PAGE' } eq 'dna' ) {
495 push @html, page_dna( $cookie );
496 } elsif ( $cookie->{ 'PAGE' } eq 'export' ) {
497 push @html, page_export( $cookie );
499 push @html, page_taxonomy( $cookie );
502 if ( $cookie->{ 'SESSION_ID' } ) {
503 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "session_id", value => $cookie->{ 'SESSION_ID' } ) );
506 return wantarray ? @html : \@html;
512 # Martin A. Hansen, December 2009.
514 # Renders the login page.
523 push @html, section_login( $cookie );
525 return wantarray ? @html : \@html;
531 # Martin A. Hansen, December 2009.
533 # Renders the search page.
542 push @html, section_taxonomy_table( $cookie );
543 push @html, section_search( $cookie );
545 return wantarray ? @html : \@html;
551 # Martin A. Hansen, November 2009.
553 # Renders the browse page.
562 push @html, section_taxonomy_table( $cookie );
563 push @html, section_navigate( $cookie );
564 push @html, section_browse( $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 ( $cookie->{ 'LOGIN' } and $cookie->{ 'LOGIN' } eq 'ERROR' ) {
659 push @html, Maasha::XHTML::h3( txt => "Bad user or password - please retry", class => 'error' );
662 return wantarray ? @html : \@html;
666 sub section_taxonomy_table
668 # Martin A. Hansen, November 2009.
670 # Returns a HTML section with a taxonomy table
671 # showing the location in the taxonomy and with
672 # links to browse the taxonomy.
674 my ( $cookie, # cookie hash
679 my ( $page, @row, @html, $href, $txt );
681 foreach $page ( @{ $cookie->{ 'LIST_PAGES' } } )
683 last if $page eq $cookie->{ 'PAGE' } or $page eq 'browse';
685 $href = "$cookie->{ 'SCRIPT' }?page=$page";
686 $href .= "&session_id=$cookie->{ 'SESSION_ID' }";
687 $href .= "&user=$cookie->{ 'USER' }";
688 $href .= "&clade=$cookie->{ 'CLADE' }" if $page !~ /clade/;
689 $href .= "&genome=$cookie->{ 'GENOME' }" if $page !~ /clade|genome/;
690 $href .= "&assembly=$cookie->{ 'ASSEMBLY' }" if $page !~ /clade|genome|assembly/;
691 $href .= "&contig=$cookie->{ 'CONTIG' }" if $page !~ /clade|genome|assembly|contig/;
693 $txt = ": $cookie->{ uc $page }";
695 push @row, Maasha::XHTML::ln( txt => $page, href => $href, class => 'inline' );
696 push @row, Maasha::XHTML::p( txt => $txt, class => 'inline' );
699 push @html, Maasha::XHTML::table_beg( summary => "Taxonomy table", align => 'center', cellpadding => '5px' );
700 push @html, Maasha::XHTML::table_row_simple( tr => [ join( "\n", @row ) ], align => 'center' );
701 push @html, Maasha::XHTML::table_end;
703 return wantarray ? @html : \@html;
707 sub section_taxonomy_select
709 # Martin A. Hansen, November 2009.
711 # Returns a HTML section with selection choices
712 # for navigating the taxonomy tree.
714 my ( $cookie, # cookie hash
719 my ( $list, @html, $item, $href );
721 $list = "LIST_" . uc $cookie->{ 'PAGE' };
723 push @html, Maasha::XHTML::h2( txt => "Select $cookie->{ 'PAGE' }", class => 'center' );
725 push @html, Maasha::XHTML::table_beg( summary => "Taxonomy select table", align => 'center', cellpadding => '5px' );
727 foreach $item ( @{ $cookie->{ $list } } )
729 $cookie->{ uc $cookie->{ 'PAGE' } } = $item;
731 $href = "$cookie->{ 'SCRIPT' }?page=" . cookie_page_next( $cookie );
732 $href .= "&session_id=$cookie->{ 'SESSION_ID' }";
733 $href .= "&user=$cookie->{ 'USER' }";
734 $href .= "&clade=$cookie->{ 'CLADE' }";
735 $href .= "&genome=$cookie->{ 'GENOME' }" if $cookie->{ 'GENOME' };
736 $href .= "&assembly=$cookie->{ 'ASSEMBLY' }" if $cookie->{ 'ASSEMBLY' };
737 $href .= "&contig=$cookie->{ 'CONTIG' }" if $cookie->{ 'CONTIG' };
739 push @html, Maasha::XHTML::table_row_simple( tr => [ Maasha::XHTML::ln( txt => $item, href => $href ) ] );
742 push @html, Maasha::XHTML::table_end;
744 return wantarray ? @html : \@html;
750 # Martin A. Hansen, November 2009.
752 # Returns a HTML section for navigating in the browser window.
754 my ( $cookie, # cookie hash
759 my ( @html, $nav_val );
761 $nav_val = Maasha::Calc::commify( $cookie->{ 'NAV_START' } ) . "-" . Maasha::Calc::commify( $cookie->{ 'NAV_END' } );
763 push @html, Maasha::XHTML::table_beg( summary => "Navigation table", align => 'center' );
764 push @html, Maasha::XHTML::table_row_simple( tr => [
765 "Position or search term:",
766 Maasha::XHTML::text( name => "nav_search", value => $nav_val, size => 30 ),
767 Maasha::XHTML::submit( name => "nav_submit", value => "Submit" ),
769 push @html, Maasha::XHTML::table_end;
771 push @html, Maasha::XHTML::table_beg( summary => "Zoom table", align => 'center' );
772 push @html, Maasha::XHTML::table_row_simple( tr => [
773 Maasha::XHTML::p( txt => 'Move:' ),
774 Maasha::XHTML::submit( name => "move_left3", value => "<<<", title => "move 95% to the left" ),
775 Maasha::XHTML::submit( name => "move_left2", value => "<<", title => "move 47.5% to the left" ),
776 Maasha::XHTML::submit( name => "move_left1", value => "<", title => "move 10% to the left" ),
777 Maasha::XHTML::submit( name => "move_right1", value => ">", title => "move 10% to the rigth" ),
778 Maasha::XHTML::submit( name => "move_right2", value => ">>", title => "move 47.5% to the rigth" ),
779 Maasha::XHTML::submit( name => "move_right3", value => ">>>", title => "move 95% to the right" ),
780 Maasha::XHTML::p( txt => 'Zoom in:' ),
781 Maasha::XHTML::submit( name => "zoom_in1", value => "1.5x" ),
782 Maasha::XHTML::submit( name => "zoom_in2", value => "3x" ),
783 Maasha::XHTML::submit( name => "zoom_in3", value => "10x" ),
784 Maasha::XHTML::p( txt => 'Zoom out:' ),
785 Maasha::XHTML::submit( name => "zoom_out1", value => "1.5x" ),
786 Maasha::XHTML::submit( name => "zoom_out2", value => "3x" ),
787 Maasha::XHTML::submit( name => "zoom_out3", value => "10x" ),
789 push @html, Maasha::XHTML::table_end;
791 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "page", value => "browse" ) );
792 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "user", value => $cookie->{ 'USER' } ) );
793 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "clade", value => $cookie->{ 'CLADE' } ) );
794 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "genome", value => $cookie->{ 'GENOME' } ) );
795 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "assembly", value => $cookie->{ 'ASSEMBLY' } ) );
796 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "contig", value => $cookie->{ 'CONTIG' } ) );
798 return wantarray ? @html : \@html;
809 my ( @tracks, $i, @features, $feat, $elem, $surface, $cr, $png_data, @html, @img, $x1, $y1, $x2, $y2, $factor, $center );
811 push @features, [ Maasha::BGB::Track::track_ruler( $cookie ) ];
812 push @features, [ Maasha::BGB::Track::track_seq( $cookie ) ];
814 @tracks = Maasha::BGB::Track::path_tracks( $cookie );
816 for ( $i = 0; $i < @tracks; $i++ )
818 $cookie->{ 'FEAT_COLOR' } = Maasha::BGB::Draw::palette( $i );
820 push @features, [ Maasha::BGB::Track::track_feature( $tracks[ $i ], $cookie ) ];
823 $surface = Cairo::ImageSurface->create( 'argb32', $cookie->{ 'IMG_WIDTH' }, $cookie->{ 'TRACK_OFFSET' } );
824 $cr = Cairo::Context->create( $surface );
826 $cr->rectangle ( 0, 0, $cookie->{ 'IMG_WIDTH' }, $cookie->{ 'TRACK_OFFSET' } );
827 $cr->set_source_rgb ( 1, 1, 1 );
830 foreach $feat ( @features ) {
831 Maasha::BGB::Draw::draw_feature( $cr, $feat ) if $feat;
834 $png_data = Maasha::BGB::Draw::base64_png( $surface );
836 push @img, Maasha::XHTML::img(
837 src => "data:image/png;base64,$png_data",
838 alt => "Browser Tracks",
839 height => $cookie->{ 'TRACK_OFFSET' },
840 width => $cookie->{ 'IMG_WIDTH' },
842 usemap => "#browser_map"
845 push @img, Maasha::XHTML::map_beg( name => "browser_map", id => "browser_map" );
847 $factor = ( $cookie->{ 'NAV_END' } - $cookie->{ 'NAV_START' } + 1 ) / $cookie->{ 'IMG_WIDTH' };
849 for ( $i = 0; $i < $cookie->{ 'IMG_WIDTH' }; $i += 5 )
856 $center = int( $cookie->{ 'NAV_START' } + $factor * $i );
858 push @img, Maasha::XHTML::area(
859 href => join( "&", "$cookie->{ 'SCRIPT' }?page=browse",
860 "session_id=$cookie->{ 'SESSION_ID' }",
861 "user=$cookie->{ 'USER' }",
862 "clade=$cookie->{ 'CLADE' }",
863 "genome=$cookie->{ 'GENOME' }",
864 "contig=$cookie->{ 'CONTIG' }",
865 "assembly=$cookie->{ 'ASSEMBLY' }",
866 "nav_start=$cookie->{ 'NAV_START' }",
867 "nav_end=$cookie->{ 'NAV_END' }",
868 "nav_center=$center",
871 coords => "$x1, $y1, $x2, $y2",
872 title => "Center on " . Maasha::Calc::commify( $center ),
876 foreach $feat ( @features )
878 foreach $elem ( @{ $feat } )
880 next if $elem->{ 'type' } eq 'text';
881 next if $elem->{ 'type' } eq 'wiggle';
883 #$elem->{ 'strand' } = '+' if $elem->{ 'strand' } eq '+';
885 $cookie->{ 'Q_ID' } = $elem->{ 'q_id' };
886 $cookie->{ 'S_BEG' } = $elem->{ 's_beg' };
887 $cookie->{ 'S_END' } = $elem->{ 's_end' };
888 $cookie->{ 'STRAND' } = $elem->{ 'strand' };
890 push @img, Maasha::XHTML::area(
891 href => join( "&", "$cookie->{ 'SCRIPT' }?page=export",
892 "session_id=$cookie->{ 'SESSION_ID' }",
893 "user=$cookie->{ 'USER' }",
894 "clade=$cookie->{ 'CLADE' }",
895 "genome=$cookie->{ 'GENOME' }",
896 "contig=$cookie->{ 'CONTIG' }",
897 "assembly=$cookie->{ 'ASSEMBLY' }",
898 "s_beg=$cookie->{ 'S_BEG' }",
899 "s_end=$cookie->{ 'S_END' }",
900 "strand=$cookie->{ 'STRAND' }",
903 coords => "$elem->{ x1 }, $elem->{ y1 }, $elem->{ x2 }, $elem->{ y2 }",
904 title => "$elem->{ 'title' }",
909 push @img, Maasha::XHTML::map_end();
911 push @html, Maasha::XHTML::p( txt => join( "\n", @img ) );
913 @html = Maasha::XHTML::div( txt => join( "\n", @html ), class => 'browse' );
915 return wantarray ? @html : \@html;
921 # Martin A. Hansen, November 2009.
923 # Returns a HTML section with export table.
925 my ( $cookie, # cookie hash
930 my ( @row_dna_contig, @html );
932 push @row_dna_contig, Maasha::XHTML::p( txt => qq(Export Feature: "$cookie->{ 'Q_ID' }" DNA from Contig: ), class => 'inline' );
933 push @row_dna_contig, Maasha::XHTML::p( txt => "$cookie->{ 'CONTIG' } Start: ", class => 'inline' );
934 push @row_dna_contig, Maasha::XHTML::text( name => "s_beg", value => Maasha::Calc::commify( $cookie->{ 'S_BEG' } ), size => 15 );
935 push @row_dna_contig, Maasha::XHTML::p( txt => "End: ", class => 'inline' );
936 push @row_dna_contig, Maasha::XHTML::text( name => "s_end", value => Maasha::Calc::commify( $cookie->{ 'S_END' } ), size => 15 );
937 push @row_dna_contig, Maasha::XHTML::p( txt => "Strand: ", class => 'inline' );
938 push @row_dna_contig, Maasha::XHTML::menu( name => "strand", options => [ qw( + - ) ], selected => $cookie->{ 'STRAND' } );
939 push @row_dna_contig, Maasha::XHTML::submit( name => "export", value => "Export", title => "Fetch DNA from this region" );
941 push @html, Maasha::XHTML::h2( txt => "Export", class => 'center' );
942 push @html, Maasha::XHTML::table_beg( summary => "Taxonomy select table", align => 'center' );
943 push @html, Maasha::XHTML::table_row_simple( tr => \@row_dna_contig );
944 push @html, Maasha::XHTML::table_end;
946 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "page", value => "dna" ) );
947 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "user", value => $cookie->{ 'USER' } ) );
948 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "clade", value => $cookie->{ 'CLADE' } ) );
949 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "genome", value => $cookie->{ 'GENOME' } ) );
950 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "assembly", value => $cookie->{ 'ASSEMBLY' } ) );
951 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "contig", value => $cookie->{ 'CONTIG' } ) );
953 return wantarray ? @html : \@html;
959 # Martin A. Hansen, November 2009.
961 # Returns a HTML section with export table.
963 my ( $cookie, # cookie hash
968 my ( $results, $result, $count, @html, $export, $browse );
970 $results = Maasha::BGB::Track::search_tracks( $cookie );
972 $count = scalar @{ $results };
974 push @html, Maasha::XHTML::h2( txt => "Search", class => 'center' );
975 push @html, Maasha::XHTML::p( txt => qq(Results for "$cookie->{ 'SEARCH' }": $count), class => 'center' );
979 push @html, Maasha::XHTML::table_beg( summary => "Search table", align => 'center', cellpadding => '5px' );
980 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) ] );
982 foreach $result ( @{ $results } )
984 $result = Maasha::KISS::kiss2biopiece( $result );
986 $cookie->{ 'CONTIG' } = $result->{ 'S_ID' };
987 $cookie->{ 'NAV_START' } = $result->{ 'S_BEG' };
988 $cookie->{ 'NAV_END' } = $result->{ 'S_END' };
989 $cookie->{ 'S_BEG' } = $result->{ 'S_BEG' };
990 $cookie->{ 'S_END' } = $result->{ 'S_END' };
991 $cookie->{ 'STRAND' } = $result->{ 'STRAND' };
992 $cookie->{ 'Q_ID' } = $result->{ 'Q_ID' };
994 $browse = Maasha::XHTML::ln(
996 href => join( "&", "$cookie->{ 'SCRIPT' }?page=browse",
997 "session_id=$cookie->{ 'SESSION_ID' }",
998 "user=$cookie->{ 'USER' }",
999 "clade=$cookie->{ 'CLADE' }",
1000 "genome=$cookie->{ 'GENOME' }",
1001 "contig=$cookie->{ 'CONTIG' }",
1002 "assembly=$cookie->{ 'ASSEMBLY' }",
1003 "nav_start=$cookie->{ 'NAV_START' }",
1004 "nav_end=$cookie->{ 'NAV_END' }",
1009 $export = Maasha::XHTML::ln(
1011 href => join( "&", "$cookie->{ 'SCRIPT' }?page=export",
1012 "session_id=$cookie->{ 'SESSION_ID' }",
1013 "user=$cookie->{ 'USER' }",
1014 "clade=$cookie->{ 'CLADE' }",
1015 "genome=$cookie->{ 'GENOME' }",
1016 "contig=$cookie->{ 'CONTIG' }",
1017 "assembly=$cookie->{ 'ASSEMBLY' }",
1018 "s_beg=$cookie->{ 'S_BEG' }",
1019 "s_end=$cookie->{ 'S_END' }",
1020 "strand=$cookie->{ 'STRAND' }",
1024 push @html, Maasha::XHTML::table_row_advanced(
1025 tr => [ { td => $result->{ 'S_ID' } },
1026 { td => $result->{ 'S_BEG' }, align => 'right' },
1027 { td => $result->{ 'S_END' }, align => 'right' },
1028 { td => $result->{ 'Q_ID' } },
1029 { td => $result->{ 'SCORE' }, align => 'right' },
1030 { td => $result->{ 'STRAND' } },
1031 { td => $result->{ 'HITS' }, align => 'right' },
1032 { td => $result->{ 'ALIGN' } },
1033 { td => $result->{ 'BLOCK_COUNT' }, align => 'right' },
1034 { td => $result->{ 'BLOCK_BEGS' } },
1035 { td => $result->{ 'BLOCK_LENS' } },
1036 { td => $result->{ 'BLOCK_TYPE' } },
1039 ], class => "monospace"
1043 push @html, Maasha::XHTML::table_end;
1046 return wantarray ? @html : \@html;
1052 # Martin A. Hansen, November 2009.
1054 # Returns a HTML section with extracted DNA.
1056 my ( $cookie, # cookie hash
1061 my ( @html, $beg, $end, $seq );
1063 $beg = $cookie->{ 'S_BEG' };
1064 $end = $cookie->{ 'S_END' };
1068 $seq = join ";", ">$cookie->{ 'GENOME' }", $cookie->{ 'ASSEMBLY' }, $cookie->{ 'CONTIG' }, $beg, $end, "$cookie->{ 'STRAND' }\n";
1069 $seq .= Maasha::BGB::Track::dna_get( $cookie );
1071 push @html, Maasha::XHTML::h2( txt => "DNA", class => 'center' );
1072 push @html, Maasha::XHTML::pre( txt => $seq );
1074 return wantarray ? @html : \@html;
1078 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<