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';
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 $cookie->{ 'LIST_USER' } = Maasha::BGB::Track::list_users();
157 $cookie->{ 'LIST_CLADE' } = Maasha::BGB::Track::list_clades( $cookie->{ 'USER' } );
158 $cookie->{ 'LIST_GENOME' } = Maasha::BGB::Track::list_genomes( $cookie->{ 'USER' }, $cookie->{ 'CLADE' } );
159 $cookie->{ 'LIST_ASSEMBLY' } = Maasha::BGB::Track::list_assemblies( $cookie->{ 'USER' }, $cookie->{ 'CLADE' }, $cookie->{ 'GENOME' } );
160 $cookie->{ 'LIST_CONTIG' } = Maasha::BGB::Track::list_contigs( $cookie->{ 'USER' }, $cookie->{ 'CLADE' }, $cookie->{ 'GENOME' }, $cookie->{ 'ASSEMBLY' } );
162 if ( $cookie->{ 'CONTIG' } )
164 cookie_start( $cookie );
165 cookie_end( $cookie );
166 cookie_zoom( $cookie );
167 cookie_move( $cookie );
168 cookie_center( $cookie );
171 $cookie->{ 'STRAND' } = '+' if defined $cookie->{ 'STRAND' } and $cookie->{ 'STRAND' } eq ' '; # FIXME ugly HTML fix
173 return wantarray ? %{ $cookie } : $cookie;
179 # Martin A. Hansen, December 2009.
181 # Check cookie information against session information.
183 my ( $cookie, # cookie hash
190 $session = Maasha::BGB::Session::session_restore( "$cookie->{ 'SESSION_DIR' }/sessions.txt" );
192 # if ( $cookie->{ 'SESSION_ID' } )
194 # if ( $cookie->{ 'SESSION_ID' } ne $ENV{ 'SSL_SESSION_ID' } ) {
195 # $cookie->{ 'PAGE' } = 'login';
196 # print STDERR "HER1"; # DEBUG
201 # $cookie->{ 'PAGE' } = 'login';
203 # print STDERR "HER2"; # DEBUG
206 if ( exists $session->{ $cookie->{ 'USER' } } and $cookie->{ 'SESSION_ID' } )
208 if ( $session->{ $cookie->{ 'USER' } }->{ 'SESSION_ID' } ne $cookie->{ 'SESSION_ID' } ) {
209 $cookie->{ 'PAGE' } = 'login';
210 print STDERR "HER3"; # DEBUG
215 $cookie->{ 'PAGE' } = 'login';
216 print STDERR "HER4"; # DEBUG
217 print STDERR "NO COOKIE SESSION ID\n" if not $cookie->{ 'SESSION_ID' }; # DEBUG
218 print STDERR "NO COOKIE USER\n" if not $cookie->{ 'USER' }; # DEBUG
219 print STDERR "NO SESSION USER\n" if not exists $session->{ $cookie->{ 'USER' } }; # DEBUG
226 # Martin A. Hansen, December 2009.
228 # Check a user and password from CGI against the password file and
229 # set the session ID, if found, in the cookie.
231 my ( $cookie, # cookie hash
238 if ( $cookie->{ 'USER' } and $cookie->{ 'PASSWORD' } )
240 $session = Maasha::BGB::Session::session_restore( "$cookie->{ 'SESSION_DIR' }/sessions.txt" );
242 if ( exists $session->{ $cookie->{ 'USER' } } and
243 $session->{ $cookie->{ 'USER' } }->{ 'PASSWORD' } eq Digest::MD5::md5_hex( $cookie->{ 'PASSWORD' } ) )
245 $session->{ $cookie->{ 'USER' } }->{ 'SESSION_ID' } ||= Maasha::BGB::Session::session_new();
246 # $session->{ $cookie->{ 'USER' } }->{ 'SESSION_ID' } = $ENV{ 'SSL_SESSION_ID' };
247 $session->{ $cookie->{ 'USER' } }->{ 'TIME' } = Maasha::Common::time_stamp();
249 $cookie->{ 'SESSION_ID' } = $session->{ $cookie->{ 'USER' } }->{ 'SESSION_ID' };
250 $cookie->{ 'LOGIN' } = "OK";
251 $cookie->{ 'PAGE' } = 'clade';
253 Maasha::BGB::Session::session_store( "$cookie->{ 'SESSION_DIR' }/sessions.txt", $session );
257 $cookie->{ 'LOGIN' } = "ERROR";
265 # Martin A. Hansen, November 2009.
267 # Decommify the cookie value for NAV_START and adjust it to
268 # to prevent negative values.
270 my ( $cookie, # cookie hash
275 if ( defined $cookie->{ 'NAV_START' } )
277 $cookie->{ 'NAV_START' } =~ tr/,//d;
278 $cookie->{ 'NAV_START' } = 0 if $cookie->{ 'NAV_START' } < 0;
282 $cookie->{ 'NAV_START' } = 0;
289 # Martin A. Hansen, November 2009.
291 # Decommify the cookie value for NAV_END and adjust it to prevent
292 # overshooting the max value for the contig size as determined
295 my ( $cookie, # cookie hash
302 $max = Maasha::Filesys::file_size( Maasha::BGB::Track::path_seq( $cookie ) );
304 if ( defined $cookie->{ 'NAV_END' } )
306 $cookie->{ 'NAV_END' } =~ tr/,//d;
307 $cookie->{ 'NAV_END' } = $max if $cookie->{ 'NAV_END' } > $max;
311 $cookie->{ 'NAV_END' } = $max;
318 # Martin A. Hansen, November 2009.
320 # Adjust the cookie values for NAV_START and NAV_END based
321 # on cookie ZOOM values.
323 my ( $cookie, # cookie hash
328 my ( $max, $dist, $new_dist, $dist_diff );
330 $max = Maasha::Filesys::file_size( Maasha::BGB::Track::path_seq( $cookie ) );
332 $dist = $cookie->{ 'NAV_END' } - $cookie->{ 'NAV_START' };
334 if ( defined $cookie->{ 'ZOOM_IN1' } ) {
335 $new_dist = $dist / 1.5;
336 } elsif ( defined $cookie->{ 'ZOOM_IN2' } ) {
337 $new_dist = $dist / 3;
338 } elsif ( defined $cookie->{ 'ZOOM_IN3' } ) {
339 $new_dist = $dist / 10;
340 } elsif ( defined $cookie->{ 'ZOOM_OUT1' } ) {
341 $new_dist = $dist * 1.5;
342 } elsif ( defined $cookie->{ 'ZOOM_OUT2' } ) {
343 $new_dist = $dist * 3;
344 } elsif ( defined $cookie->{ 'ZOOM_OUT3' } ) {
345 $new_dist = $dist * 10;
350 $dist_diff = $dist - $new_dist;
352 $cookie->{ 'NAV_START' } = int( $cookie->{ 'NAV_START' } + ( $dist_diff / 2 ) );
353 $cookie->{ 'NAV_END' } = int( $cookie->{ 'NAV_END' } - ( $dist_diff / 2 ) );
355 $cookie->{ 'NAV_START' } = 0 if $cookie->{ 'NAV_START' } < 0;
356 $cookie->{ 'NAV_END' } = $max if $cookie->{ 'NAV_END' } > $max;
363 # Martin A. Hansen, November 2009.
365 # Adjust the cookie values for NAV_START and NAV_END based
366 # on cookie MOVE values.
368 my ( $cookie, # cookie hash
373 my ( $max, $dist, $shift, $new_start, $new_end );
375 $max = Maasha::Filesys::file_size( Maasha::BGB::Track::path_seq( $cookie ) );
377 $dist = $cookie->{ 'NAV_END' } - $cookie->{ 'NAV_START' };
379 if ( defined $cookie->{ 'MOVE_LEFT1' } ) {
380 $shift = -1 * $dist * 0.10;
381 } elsif ( defined $cookie->{ 'MOVE_LEFT2' } ) {
382 $shift = -1 * $dist * 0.475;
383 } elsif ( defined $cookie->{ 'MOVE_LEFT3' } ) {
384 $shift = -1 * $dist * 0.95;
385 } elsif ( defined $cookie->{ 'MOVE_RIGHT1' } ) {
386 $shift = $dist * 0.10;
387 } elsif ( defined $cookie->{ 'MOVE_RIGHT2' } ) {
388 $shift = $dist * 0.475;
389 } elsif ( defined $cookie->{ 'MOVE_RIGHT3' } ) {
390 $shift = $dist * 0.95;
395 $new_start = int( $cookie->{ 'NAV_START' } + $shift );
396 $new_end = int( $cookie->{ 'NAV_END' } + $shift );
398 if ( $new_start > 0 and $new_end < $max )
400 $cookie->{ 'NAV_START' } = $new_start;
401 $cookie->{ 'NAV_END' } = $new_end;
409 # Martin A. Hansen, March 2010
411 # Adjust the cookie values for NAV_START and NAV_END based
412 # on cookie CENTER value if defined.
414 my ( $cookie, # cookie hash
419 my ( $l_dist, $r_dist );
421 if ( defined $cookie->{ 'NAV_CENTER' } )
423 $l_dist = $cookie->{ 'NAV_CENTER' } - $cookie->{ 'NAV_START' };
424 $r_dist = $cookie->{ 'NAV_END' } - $cookie->{ 'NAV_CENTER' };
426 if ( $l_dist > $r_dist ) {
427 $cookie->{ 'NAV_START' } = $cookie->{ 'NAV_END' } - 2 * $r_dist;
429 $cookie->{ 'NAV_END' } = $cookie->{ 'NAV_START' } + 2 * $l_dist;
437 # Martin A. Hansen, November 2009.
439 # Returns the next page in the taxonomy path.
441 my ( $cookie, # cookie hash
448 for ( $i = 0; $i < @{ $cookie->{ 'LIST_PAGES' } }; $i++ ) {
449 last if $cookie->{ 'PAGE' } eq $cookie->{ 'LIST_PAGES' }->[ $i ];
452 return $cookie->{ 'LIST_PAGES' }->[ $i + 1 ];
456 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> PAGES <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
461 # Martin A. Hansen, November 2009.
463 # Determines what page to render based on
464 # the cookie's PAGE setting.
466 my ( $cookie, # cookie hash
473 if ( $cookie->{ 'SESSION_ID' } ) {
474 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "session_id", value => $cookie->{ 'SESSION_ID' } ) );
477 if ( $cookie->{ 'PAGE' } eq 'login' ) {
478 push @html, page_login( $cookie );
479 } elsif ( $cookie->{ 'PAGE' } eq 'search' ) {
480 push @html, page_search( $cookie );
481 } elsif ( $cookie->{ 'PAGE' } eq 'browse' ) {
482 push @html, page_browse( $cookie );
483 } elsif ( $cookie->{ 'PAGE' } eq 'dna' ) {
484 push @html, page_dna( $cookie );
485 } elsif ( $cookie->{ 'PAGE' } eq 'export' ) {
486 push @html, page_export( $cookie );
488 push @html, page_taxonomy( $cookie );
491 return wantarray ? @html : \@html;
497 # Martin A. Hansen, December 2009.
499 # Renders the login page.
508 push @html, section_login( $cookie );
510 return wantarray ? @html : \@html;
516 # Martin A. Hansen, December 2009.
518 # Renders the search page.
527 push @html, section_taxonomy_table( $cookie );
528 push @html, section_search( $cookie );
530 return wantarray ? @html : \@html;
536 # Martin A. Hansen, November 2009.
538 # Renders the browse page.
547 push @html, section_taxonomy_table( $cookie );
548 push @html, section_navigate( $cookie );
549 push @html, section_browse( $cookie );
551 return wantarray ? @html : \@html;
557 # Martin A. Hansen, November 2009.
559 # Renders the DNA page.
568 push @html, section_taxonomy_table( $cookie );
569 push @html, section_dna( $cookie );
571 return wantarray ? @html : \@html;
577 # Martin A. Hansen, November 2009.
579 # Renders the export page.
588 push @html, section_taxonomy_table( $cookie );
589 push @html, section_export( $cookie );
591 return wantarray ? @html : \@html;
597 # Martin A. Hansen, November 2009.
599 # Renders the browse page.
601 my ( $cookie, # cookie hash
608 push @html, section_taxonomy_table( $cookie );
609 push @html, section_taxonomy_select( $cookie );
611 return wantarray ? @html : \@html;
615 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> SECTIONS <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
620 # Martin A. Hansen, December 2009.
622 # Returns a HTML section with a login menu.
624 my ( $cookie, # cookie hash
629 my ( $user, $password, $login, @html );
631 $user = Maasha::XHTML::text( name => "user", value => "", size => 20 );
632 $password = Maasha::XHTML::password( name => "password", value => "", size => 20 );
633 $login = Maasha::XHTML::submit( name => "login_submit", value => "Login" );
635 push @html, Maasha::XHTML::h2( txt => "Login", class => 'center' );
637 push @html, Maasha::XHTML::table_beg( summary => "Login table", align => 'center' );
638 push @html, Maasha::XHTML::table_row_simple( tr => [ "User:", $user ] );
639 push @html, Maasha::XHTML::table_row_simple( tr => [ "Password:", $password ] );
640 push @html, Maasha::XHTML::table_row_simple( tr => [ "", $login ] );
641 push @html, Maasha::XHTML::table_end;
643 if ( $cookie->{ 'LOGIN' } and $cookie->{ 'LOGIN' } eq 'ERROR' ) {
644 push @html, Maasha::XHTML::h3( txt => "Bad user or password - please retry", class => 'error' );
647 return wantarray ? @html : \@html;
651 sub section_taxonomy_table
653 # Martin A. Hansen, November 2009.
655 # Returns a HTML section with a taxonomy table
656 # showing the location in the taxonomy and with
657 # links to browse the taxonomy.
659 my ( $cookie, # cookie hash
664 my ( $page, @row, @html, $href, $txt );
666 foreach $page ( @{ $cookie->{ 'LIST_PAGES' } } )
668 last if $page eq $cookie->{ 'PAGE' } or $page eq 'browse';
670 $href = "$cookie->{ 'SCRIPT' }?page=$page";
671 $href .= "&session_id=$cookie->{ 'SESSION_ID' }";
672 $href .= "&user=$cookie->{ 'USER' }";
673 $href .= "&clade=$cookie->{ 'CLADE' }" if $page !~ /clade/;
674 $href .= "&genome=$cookie->{ 'GENOME' }" if $page !~ /clade|genome/;
675 $href .= "&assembly=$cookie->{ 'ASSEMBLY' }" if $page !~ /clade|genome|assembly/;
676 $href .= "&contig=$cookie->{ 'CONTIG' }" if $page !~ /clade|genome|assembly|contig/;
678 $txt = ": $cookie->{ uc $page }";
680 push @row, Maasha::XHTML::ln( txt => $page, href => $href, class => 'inline' );
681 push @row, Maasha::XHTML::p( txt => $txt, class => 'inline' );
684 push @html, Maasha::XHTML::table_beg( summary => "Taxonomy table", align => 'center', cellpadding => '5px' );
685 push @html, Maasha::XHTML::table_row_simple( tr => [ join( "\n", @row ) ], align => 'center' );
686 push @html, Maasha::XHTML::table_end;
688 return wantarray ? @html : \@html;
692 sub section_taxonomy_select
694 # Martin A. Hansen, November 2009.
696 # Returns a HTML section with selection choices
697 # for navigating the taxonomy tree.
699 my ( $cookie, # cookie hash
704 my ( $list, @html, $item, $href );
706 $list = "LIST_" . uc $cookie->{ 'PAGE' };
708 push @html, Maasha::XHTML::h2( txt => "Select $cookie->{ 'PAGE' }", class => 'center' );
710 push @html, Maasha::XHTML::table_beg( summary => "Taxonomy select table", align => 'center', cellpadding => '5px' );
712 foreach $item ( @{ $cookie->{ $list } } )
714 $cookie->{ uc $cookie->{ 'PAGE' } } = $item;
716 $href = "$cookie->{ 'SCRIPT' }?page=" . cookie_page_next( $cookie );
717 $href .= "&session_id=$cookie->{ 'SESSION_ID' }";
718 $href .= "&user=$cookie->{ 'USER' }";
719 $href .= "&clade=$cookie->{ 'CLADE' }";
720 $href .= "&genome=$cookie->{ 'GENOME' }" if $cookie->{ 'GENOME' };
721 $href .= "&assembly=$cookie->{ 'ASSEMBLY' }" if $cookie->{ 'ASSEMBLY' };
722 $href .= "&contig=$cookie->{ 'CONTIG' }" if $cookie->{ 'CONTIG' };
724 push @html, Maasha::XHTML::table_row_simple( tr => [ Maasha::XHTML::ln( txt => $item, href => $href ) ] );
727 push @html, Maasha::XHTML::table_end;
729 return wantarray ? @html : \@html;
735 # Martin A. Hansen, November 2009.
737 # Returns a HTML section for navigating in the browser window.
739 my ( $cookie, # cookie hash
744 my ( @html, $nav_val );
746 $nav_val = Maasha::Calc::commify( $cookie->{ 'NAV_START' } ) . "-" . Maasha::Calc::commify( $cookie->{ 'NAV_END' } );
748 push @html, Maasha::XHTML::table_beg( summary => "Navigation table", align => 'center' );
749 push @html, Maasha::XHTML::table_row_simple( tr => [
750 "Position or search term:",
751 Maasha::XHTML::text( name => "nav_search", value => $nav_val, size => 30 ),
752 Maasha::XHTML::submit( name => "nav_submit", value => "Submit" ),
754 push @html, Maasha::XHTML::table_end;
756 push @html, Maasha::XHTML::table_beg( summary => "Zoom table", align => 'center' );
757 push @html, Maasha::XHTML::table_row_simple( tr => [
758 Maasha::XHTML::p( txt => 'Move:' ),
759 Maasha::XHTML::submit( name => "move_left3", value => "<<<", title => "move 95% to the left" ),
760 Maasha::XHTML::submit( name => "move_left2", value => "<<", title => "move 47.5% to the left" ),
761 Maasha::XHTML::submit( name => "move_left1", value => "<", title => "move 10% to the left" ),
762 Maasha::XHTML::submit( name => "move_right1", value => ">", title => "move 10% to the rigth" ),
763 Maasha::XHTML::submit( name => "move_right2", value => ">>", title => "move 47.5% to the rigth" ),
764 Maasha::XHTML::submit( name => "move_right3", value => ">>>", title => "move 95% to the right" ),
765 Maasha::XHTML::p( txt => 'Zoom in:' ),
766 Maasha::XHTML::submit( name => "zoom_in1", value => "1.5x" ),
767 Maasha::XHTML::submit( name => "zoom_in2", value => "3x" ),
768 Maasha::XHTML::submit( name => "zoom_in3", value => "10x" ),
769 Maasha::XHTML::p( txt => 'Zoom out:' ),
770 Maasha::XHTML::submit( name => "zoom_out1", value => "1.5x" ),
771 Maasha::XHTML::submit( name => "zoom_out2", value => "3x" ),
772 Maasha::XHTML::submit( name => "zoom_out3", value => "10x" ),
774 push @html, Maasha::XHTML::table_end;
776 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "page", value => "browse" ) );
777 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "user", value => $cookie->{ 'USER' } ) );
778 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "clade", value => $cookie->{ 'CLADE' } ) );
779 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "genome", value => $cookie->{ 'GENOME' } ) );
780 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "assembly", value => $cookie->{ 'ASSEMBLY' } ) );
781 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "contig", value => $cookie->{ 'CONTIG' } ) );
783 return wantarray ? @html : \@html;
794 my ( @tracks, $i, @features, $feat, $elem, $surface, $cr, $png_data, @html, @img, $x1, $y1, $x2, $y2, $factor, $center );
796 push @features, [ Maasha::BGB::Track::track_ruler( $cookie ) ];
797 push @features, [ Maasha::BGB::Track::track_seq( $cookie ) ];
799 @tracks = Maasha::BGB::Track::path_tracks( $cookie );
801 for ( $i = 0; $i < @tracks; $i++ )
803 $cookie->{ 'FEAT_COLOR' } = Maasha::BGB::Draw::palette( $i );
805 push @features, [ Maasha::BGB::Track::track_feature( $tracks[ $i ], $cookie ) ];
808 $surface = Cairo::ImageSurface->create( 'argb32', $cookie->{ 'IMG_WIDTH' }, $cookie->{ 'TRACK_OFFSET' } );
809 $cr = Cairo::Context->create( $surface );
811 $cr->rectangle ( 0, 0, $cookie->{ 'IMG_WIDTH' }, $cookie->{ 'TRACK_OFFSET' } );
812 $cr->set_source_rgb ( 1, 1, 1 );
815 foreach $feat ( @features ) {
816 Maasha::BGB::Draw::draw_feature( $cr, $feat ) if $feat;
819 $png_data = Maasha::BGB::Draw::base64_png( $surface );
821 push @img, Maasha::XHTML::img(
822 src => "data:image/png;base64,$png_data",
823 alt => "Browser Tracks",
824 height => $cookie->{ 'TRACK_OFFSET' },
825 width => $cookie->{ 'IMG_WIDTH' },
827 usemap => "#browser_map"
830 push @img, Maasha::XHTML::map_beg( name => "browser_map", id => "browser_map" );
832 $factor = ( $cookie->{ 'NAV_END' } - $cookie->{ 'NAV_START' } + 1 ) / $cookie->{ 'IMG_WIDTH' };
834 for ( $i = 0; $i < $cookie->{ 'IMG_WIDTH' }; $i += 5 )
841 $center = int( $cookie->{ 'NAV_START' } + $factor * $i );
843 push @img, Maasha::XHTML::area(
844 href => join( "&", "$cookie->{ 'SCRIPT' }?page=browse",
845 "session_id=$cookie->{ 'SESSION_ID' }",
846 "user=$cookie->{ 'USER' }",
847 "clade=$cookie->{ 'CLADE' }",
848 "genome=$cookie->{ 'GENOME' }",
849 "contig=$cookie->{ 'CONTIG' }",
850 "assembly=$cookie->{ 'ASSEMBLY' }",
851 "nav_start=$cookie->{ 'NAV_START' }",
852 "nav_end=$cookie->{ 'NAV_END' }",
853 "nav_center=$center",
856 coords => "$x1, $y1, $x2, $y2",
857 title => "Center on " . Maasha::Calc::commify( $center ),
861 foreach $feat ( @features )
863 foreach $elem ( @{ $feat } )
865 next if $elem->{ 'type' } eq 'text';
866 next if $elem->{ 'type' } eq 'wiggle';
868 #$elem->{ 'strand' } = '+' if $elem->{ 'strand' } eq '+';
870 $cookie->{ 'Q_ID' } = $elem->{ 'q_id' };
871 $cookie->{ 'S_BEG' } = $elem->{ 's_beg' };
872 $cookie->{ 'S_END' } = $elem->{ 's_end' };
873 $cookie->{ 'STRAND' } = $elem->{ 'strand' };
875 push @img, Maasha::XHTML::area(
876 href => join( "&", "$cookie->{ 'SCRIPT' }?page=export",
877 "session_id=$cookie->{ 'SESSION_ID' }",
878 "user=$cookie->{ 'USER' }",
879 "clade=$cookie->{ 'CLADE' }",
880 "genome=$cookie->{ 'GENOME' }",
881 "contig=$cookie->{ 'CONTIG' }",
882 "assembly=$cookie->{ 'ASSEMBLY' }",
883 "s_beg=$cookie->{ 'S_BEG' }",
884 "s_end=$cookie->{ 'S_END' }",
885 "strand=$cookie->{ 'STRAND' }",
888 coords => "$elem->{ x1 }, $elem->{ y1 }, $elem->{ x2 }, $elem->{ y2 }",
889 title => "$elem->{ 'title' }",
894 push @img, Maasha::XHTML::map_end();
896 push @html, Maasha::XHTML::p( txt => join( "\n", @img ) );
898 @html = Maasha::XHTML::div( txt => join( "\n", @html ), class => 'browse' );
900 return wantarray ? @html : \@html;
906 # Martin A. Hansen, November 2009.
908 # Returns a HTML section with export table.
910 my ( $cookie, # cookie hash
915 my ( $feat, @row_dna_contig, @html );
917 $feat = $cookie->{ 'Q_ID' } || "[no name]";
919 push @row_dna_contig, Maasha::XHTML::p( txt => qq(Export Feature: "$feat" DNA from Contig: ), class => 'inline' );
920 push @row_dna_contig, Maasha::XHTML::p( txt => "$cookie->{ 'CONTIG' } Start: ", class => 'inline' );
921 push @row_dna_contig, Maasha::XHTML::text( name => "s_beg", value => Maasha::Calc::commify( $cookie->{ 'S_BEG' } ), size => 15 );
922 push @row_dna_contig, Maasha::XHTML::p( txt => "End: ", class => 'inline' );
923 push @row_dna_contig, Maasha::XHTML::text( name => "s_end", value => Maasha::Calc::commify( $cookie->{ 'S_END' } ), size => 15 );
924 push @row_dna_contig, Maasha::XHTML::p( txt => "Strand: ", class => 'inline' );
925 push @row_dna_contig, Maasha::XHTML::menu( name => "strand", options => [ qw( + - ) ], selected => $cookie->{ 'STRAND' } );
926 push @row_dna_contig, Maasha::XHTML::submit( name => "export", value => "Export", title => "Fetch DNA from this region" );
928 push @html, Maasha::XHTML::h2( txt => "Export", class => 'center' );
929 push @html, Maasha::XHTML::table_beg( summary => "Taxonomy select table", align => 'center' );
930 push @html, Maasha::XHTML::table_row_simple( tr => \@row_dna_contig );
931 push @html, Maasha::XHTML::table_end;
933 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "page", value => "dna" ) );
934 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "user", value => $cookie->{ 'USER' } ) );
935 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "clade", value => $cookie->{ 'CLADE' } ) );
936 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "genome", value => $cookie->{ 'GENOME' } ) );
937 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "assembly", value => $cookie->{ 'ASSEMBLY' } ) );
938 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "contig", value => $cookie->{ 'CONTIG' } ) );
940 return wantarray ? @html : \@html;
946 # Martin A. Hansen, November 2009.
948 # Returns a HTML section with export table.
950 my ( $cookie, # cookie hash
955 my ( $results, $result, $count, @html, $export, $browse );
957 $results = Maasha::BGB::Track::search_tracks( $cookie );
959 $count = scalar @{ $results };
961 push @html, Maasha::XHTML::h2( txt => "Search", class => 'center' );
962 push @html, Maasha::XHTML::p( txt => qq(Results for "$cookie->{ 'SEARCH' }": $count), class => 'center' );
966 push @html, Maasha::XHTML::table_beg( summary => "Search table", align => 'center', cellpadding => '5px' );
967 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) ] );
969 foreach $result ( @{ $results } )
971 $cookie->{ 'CONTIG' } = $result->{ 'S_ID' };
972 $cookie->{ 'NAV_START' } = $result->{ 'S_BEG' };
973 $cookie->{ 'NAV_END' } = $result->{ 'S_END' };
974 $cookie->{ 'S_BEG' } = $result->{ 'S_BEG' };
975 $cookie->{ 'S_END' } = $result->{ 'S_END' };
976 $cookie->{ 'STRAND' } = $result->{ 'STRAND' };
977 $cookie->{ 'Q_ID' } = $result->{ 'Q_ID' };
979 $browse = Maasha::XHTML::ln(
981 href => join( "&", "$cookie->{ 'SCRIPT' }?page=browse",
982 "session_id=$cookie->{ 'SESSION_ID' }",
983 "user=$cookie->{ 'USER' }",
984 "clade=$cookie->{ 'CLADE' }",
985 "genome=$cookie->{ 'GENOME' }",
986 "contig=$cookie->{ 'CONTIG' }",
987 "assembly=$cookie->{ 'ASSEMBLY' }",
988 "nav_start=$cookie->{ 'NAV_START' }",
989 "nav_end=$cookie->{ 'NAV_END' }",
994 $export = Maasha::XHTML::ln(
996 href => join( "&", "$cookie->{ 'SCRIPT' }?page=export",
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 "s_beg=$cookie->{ 'S_BEG' }",
1004 "s_end=$cookie->{ 'S_END' }",
1005 "strand=$cookie->{ 'STRAND' }",
1009 push @html, Maasha::XHTML::table_row_advanced(
1010 tr => [ { td => $result->{ 'S_ID' } },
1011 { td => $result->{ 'S_BEG' }, align => 'right' },
1012 { td => $result->{ 'S_END' }, align => 'right' },
1013 { td => $result->{ 'Q_ID' } },
1014 { td => $result->{ 'SCORE' }, align => 'right' },
1015 { td => $result->{ 'STRAND' } },
1016 { td => $result->{ 'HITS' }, align => 'right' },
1017 { td => $result->{ 'ALIGN' } },
1018 { td => $result->{ 'BLOCK_COUNT' }, align => 'right' },
1019 { td => $result->{ 'BLOCK_BEGS' } },
1020 { td => $result->{ 'BLOCK_LENS' } },
1021 { td => $result->{ 'BLOCK_TYPE' } },
1024 ], class => "monospace"
1028 push @html, Maasha::XHTML::table_end;
1031 return wantarray ? @html : \@html;
1037 # Martin A. Hansen, November 2009.
1039 # Returns a HTML section with extracted DNA.
1041 my ( $cookie, # cookie hash
1046 my ( @html, $beg, $end, $seq );
1048 $beg = $cookie->{ 'S_BEG' };
1049 $end = $cookie->{ 'S_END' };
1053 $seq = join ";", ">$cookie->{ 'GENOME' }", $cookie->{ 'ASSEMBLY' }, $cookie->{ 'CONTIG' }, $beg, $end, "$cookie->{ 'STRAND' }\n";
1054 $seq .= Maasha::BGB::Track::dna_get( $cookie );
1056 push @html, Maasha::XHTML::h2( txt => "DNA", class => 'center' );
1057 push @html, Maasha::XHTML::pre( txt => $seq );
1059 return wantarray ? @html : \@html;
1063 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<