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( $cookie ); # DEBUG
66 # push @html, Maasha::XHTML::hdump( \%ENV ); # 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, $session );
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 ) ];
111 $cookie->{ 'USER' } = $cgi->param( 'user' );
112 $cookie->{ 'PASSWORD' } = $cgi->param( 'password' );
113 $cookie->{ 'SESSION_ID' } = $cgi->param( 'session_id' );
115 $session = session_restore( $cookie );
117 cookie_login( $cookie );
119 # session_id_check( $cookie, $session );
121 if ( $cookie->{ 'LOGIN_ERROR' } or $cookie->{ 'SESSION_ERROR' } )
123 $cookie->{ 'PAGE' } = 'login';
125 elsif ( $cookie->{ 'LOGIN' } )
127 if ( $cgi->param( 'genome' ) ) {
128 $cookie->{ 'PAGE' } = 'browse';
130 $cookie->{ 'PAGE' } = $session->{ 'PAGE' } || 'clade';
133 elsif ( not defined $cookie->{ 'USER' } )
135 $cookie->{ 'PAGE' } = 'login';
139 $cookie->{ 'PAGE' } = $cgi->param( 'page' ) || 'login';
142 $cookie->{ 'CLADE' } = $cgi->param( 'clade' ) || $session->{ 'CLADE' };
143 $cookie->{ 'GENOME' } = $cgi->param( 'genome' ) || $session->{ 'GENOME' };
144 $cookie->{ 'ASSEMBLY' } = $cgi->param( 'assembly' ) || $session->{ 'ASSEMBLY' };
145 $cookie->{ 'CONTIG' } = $cgi->param( 'contig' ) || $session->{ 'CONTIG' };
146 $cookie->{ 'Q_ID' } = $cgi->param( 'q_id' ) || $session->{ 'Q_ID' };
147 $cookie->{ 'NAV_START' } = defined $cgi->param( 'nav_start' ) ? $cgi->param( 'nav_start' ) : $session->{ 'NAV_START' };
148 $cookie->{ 'NAV_END' } = $cgi->param( 'nav_end' ) || $session->{ 'NAV_END' };
149 $cookie->{ 'NAV_CENTER' } = $cgi->param( 'nav_center' );
150 $cookie->{ 'S_BEG' } = $cgi->param( 's_beg' ) || $session->{ 'S_BEG' };
151 $cookie->{ 'S_END' } = $cgi->param( 's_end' ) || $session->{ 'S_END' };
152 $cookie->{ 'STRAND' } = $cgi->param( 'strand' ) || $session->{ 'STRAND' };
153 $cookie->{ 'ZOOM_IN1' } = $cgi->param( 'zoom_in1' );
154 $cookie->{ 'ZOOM_IN2' } = $cgi->param( 'zoom_in2' );
155 $cookie->{ 'ZOOM_IN3' } = $cgi->param( 'zoom_in3' );
156 $cookie->{ 'ZOOM_OUT1' } = $cgi->param( 'zoom_out1' );
157 $cookie->{ 'ZOOM_OUT2' } = $cgi->param( 'zoom_out2' );
158 $cookie->{ 'ZOOM_OUT3' } = $cgi->param( 'zoom_out3' );
159 $cookie->{ 'MOVE_LEFT1' } = $cgi->param( 'move_left1' );
160 $cookie->{ 'MOVE_LEFT2' } = $cgi->param( 'move_left2' );
161 $cookie->{ 'MOVE_LEFT3' } = $cgi->param( 'move_left3' );
162 $cookie->{ 'MOVE_RIGHT1' } = $cgi->param( 'move_right1' );
163 $cookie->{ 'MOVE_RIGHT2' } = $cgi->param( 'move_right2' );
164 $cookie->{ 'MOVE_RIGHT3' } = $cgi->param( 'move_right3' );
166 $cookie->{ 'IMG_WIDTH' } = 1200; # Width of browser image in pixels
167 $cookie->{ 'IMG_HEIGHT' } = 800; # Height of browser image in pixels
168 $cookie->{ 'WIGGLE_HEIGHT' } = 75; # Height of Wiggle tracks in pixels
169 $cookie->{ 'TRACK_OFFSET' } = 20;
170 $cookie->{ 'TRACK_SPACE' } = 20;
171 $cookie->{ 'RULER_FONT_SIZE' } = 10; # Size of ruler font in pixels
172 $cookie->{ 'RULER_COLOR' } = [ 0, 0, 0 ];
173 $cookie->{ 'SEQ_FONT_SIZE' } = 10;
174 $cookie->{ 'SEQ_COLOR' } = [ 0, 0, 0, ];
175 $cookie->{ 'FEAT_WIDTH' } = 5;
176 $cookie->{ 'FEAT_COLOR' } = [ 0, 0, 0 ];
177 $cookie->{ 'FEAT_MAX' } = 5000; # TODO: Reduntant?
179 # $cookie->{ 'LIST_USER' } = Maasha::BGB::Track::list_users(); # TODO: Redundant?
181 if ( $cookie->{ 'USER' } and not $cookie->{ 'LOGIN_ERROR' } )
183 $cookie->{ 'LIST_CLADE' } = Maasha::BGB::Track::list_clades( $cookie->{ 'USER' } );
184 $cookie->{ 'LIST_GENOME' } = Maasha::BGB::Track::list_genomes( $cookie->{ 'USER' }, $cookie->{ 'CLADE' } );
185 $cookie->{ 'LIST_ASSEMBLY' } = Maasha::BGB::Track::list_assemblies( $cookie->{ 'USER' }, $cookie->{ 'CLADE' }, $cookie->{ 'GENOME' } );
186 $cookie->{ 'LIST_CONTIG' } = Maasha::BGB::Track::list_contigs( $cookie->{ 'USER' }, $cookie->{ 'CLADE' }, $cookie->{ 'GENOME' }, $cookie->{ 'ASSEMBLY' } );
188 if ( $cookie->{ 'CONTIG' } )
190 cookie_start( $cookie );
191 cookie_end( $cookie );
192 cookie_zoom( $cookie );
193 cookie_move( $cookie );
194 cookie_center( $cookie );
198 $cookie->{ 'STRAND' } = '+' if defined $cookie->{ 'STRAND' } and $cookie->{ 'STRAND' } eq ' '; # FIXME ugly HTML fix
200 session_store( $cookie, $session );
202 return wantarray ? %{ $cookie } : $cookie;
208 # Martin A. Hansen, March 2010.
210 # Restores session and returns this.
212 my ( $cookie, # cookie hash
219 if ( defined $cookie->{ 'USER' } and -d "$cookie->{ 'SESSION_DIR' }/$cookie->{ 'USER' }" ) {
220 $session = Maasha::BGB::Session::session_restore( "$cookie->{ 'SESSION_DIR' }/$cookie->{ 'USER' }/session.json" );
223 return wantarray ? %{ $session } : $session;
229 # Martin A. Hansen, March 2010.
231 # Store a session updated with cookie information to session file.
233 my ( $cookie, # cookie hash
234 $session, # session hash
239 if ( defined $cookie->{ 'USER' } and $cookie->{ 'USER' } ne '' and -d "$cookie->{ 'SESSION_DIR' }/$cookie->{ 'USER' }" )
241 $session->{ 'TIME' } = Maasha::Common::time_stamp();
242 $session->{ 'PAGE' } = $cookie->{ 'PAGE' };
243 $session->{ 'CLADE' } = $cookie->{ 'CLADE' };
244 $session->{ 'GENOME' } = $cookie->{ 'GENOME' };
245 $session->{ 'ASSEMBLY' } = $cookie->{ 'ASSEMBLY' };
246 $session->{ 'CONTIG' } = $cookie->{ 'CONTIG' };
247 $session->{ 'Q_ID' } = $cookie->{ 'Q_ID' };
248 $session->{ 'S_BEG' } = $cookie->{ 'S_BEG' };
249 $session->{ 'S_END' } = $cookie->{ 'S_END' };
250 $session->{ 'STRAND' } = $cookie->{ 'STRAND' };
251 $session->{ 'NAV_START' } = $cookie->{ 'PAGE' } eq 'browse' ? $cookie->{ 'NAV_START' } : undef;
252 $session->{ 'NAV_END' } = $cookie->{ 'PAGE' } eq 'browse' ? $cookie->{ 'NAV_END' } : undef;
254 Maasha::BGB::Session::session_store( "$cookie->{ 'SESSION_DIR' }/$cookie->{ 'USER' }/session.json", $session );
261 # Martin A. Hansen, March 2010.
263 # Check that the session id in the cookie and session match.
264 # Sets SESSION_ERROR flag in cookie if not matching.
266 my ( $cookie, # cookie hash
267 $session, # session hash
272 if ( defined $cookie->{ 'SESSION_ID' } and defined $session->{ 'SESSION_ID' } )
274 if ( $cookie->{ 'SESSION_ID' } ne $session->{ 'SESSION_ID' } ) {
275 $cookie->{ 'SESSION_ERROR' } = 1;
277 $cookie->{ 'SESSION_ERROR' } = 0;
285 # Martin A. Hansen, December 2009.
287 # Check a user and password from CGI against the password file and
288 # set the session ID, if found, in the cookie.
290 my ( $cookie, # cookie hash
297 if ( defined $cookie->{ 'PASSWORD' } )
299 if ( defined $cookie->{ 'USER' } and -d "$cookie->{ 'SESSION_DIR' }/$cookie->{ 'USER' }" )
301 $session = Maasha::BGB::Session::session_restore( "$cookie->{ 'SESSION_DIR' }/$cookie->{ 'USER' }/session.json" );
303 if ( $session->{ 'PASSWORD' } eq Digest::MD5::md5_hex( $cookie->{ 'PASSWORD' } ) )
305 $cookie->{ 'TIME' } = Maasha::Common::time_stamp();
306 $cookie->{ 'SESSION_ID' } ||= Maasha::BGB::Session::session_new();
307 $cookie->{ 'LOGIN' } = 1;
308 $cookie->{ 'LOGIN_ERROR' } = 0;
312 $cookie->{ 'LOGIN_ERROR' } = 1;
317 $cookie->{ 'LOGIN_ERROR' } = 1;
325 # Martin A. Hansen, November 2009.
327 # Decommify the cookie value for NAV_START and adjust it to
328 # to prevent negative values.
330 my ( $cookie, # cookie hash
335 if ( defined $cookie->{ 'NAV_START' } )
337 $cookie->{ 'NAV_START' } =~ tr/,//d;
338 $cookie->{ 'NAV_START' } = 0 if $cookie->{ 'NAV_START' } < 0;
342 $cookie->{ 'NAV_START' } = 0;
349 # Martin A. Hansen, November 2009.
351 # Decommify the cookie value for NAV_END and adjust it to prevent
352 # overshooting the max value for the contig size as determined
355 my ( $cookie, # cookie hash
362 $max = Maasha::Filesys::file_size( Maasha::BGB::Track::path_seq( $cookie ) );
364 if ( defined $cookie->{ 'NAV_END' } )
366 $cookie->{ 'NAV_END' } =~ tr/,//d;
367 $cookie->{ 'NAV_END' } = $max if $cookie->{ 'NAV_END' } > $max;
371 $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 ZOOM values.
383 my ( $cookie, # cookie hash
388 my ( $max, $dist, $new_dist, $dist_diff );
390 $max = Maasha::Filesys::file_size( Maasha::BGB::Track::path_seq( $cookie ) );
392 $dist = $cookie->{ 'NAV_END' } - $cookie->{ 'NAV_START' };
394 if ( defined $cookie->{ 'ZOOM_IN1' } ) {
395 $new_dist = $dist / 1.5;
396 } elsif ( defined $cookie->{ 'ZOOM_IN2' } ) {
397 $new_dist = $dist / 3;
398 } elsif ( defined $cookie->{ 'ZOOM_IN3' } ) {
399 $new_dist = $dist / 10;
400 } elsif ( defined $cookie->{ 'ZOOM_OUT1' } ) {
401 $new_dist = $dist * 1.5;
402 } elsif ( defined $cookie->{ 'ZOOM_OUT2' } ) {
403 $new_dist = $dist * 3;
404 } elsif ( defined $cookie->{ 'ZOOM_OUT3' } ) {
405 $new_dist = $dist * 10;
410 $dist_diff = $dist - $new_dist;
412 $cookie->{ 'NAV_START' } = int( $cookie->{ 'NAV_START' } + ( $dist_diff / 2 ) );
413 $cookie->{ 'NAV_END' } = int( $cookie->{ 'NAV_END' } - ( $dist_diff / 2 ) );
415 $cookie->{ 'NAV_START' } = 0 if $cookie->{ 'NAV_START' } < 0;
416 $cookie->{ 'NAV_END' } = $max if $cookie->{ 'NAV_END' } > $max;
423 # Martin A. Hansen, November 2009.
425 # Adjust the cookie values for NAV_START and NAV_END based
426 # on cookie MOVE values.
428 my ( $cookie, # cookie hash
433 my ( $max, $dist, $shift, $new_start, $new_end );
435 $max = Maasha::Filesys::file_size( Maasha::BGB::Track::path_seq( $cookie ) );
437 $dist = $cookie->{ 'NAV_END' } - $cookie->{ 'NAV_START' };
439 if ( defined $cookie->{ 'MOVE_LEFT1' } ) {
440 $shift = -1 * $dist * 0.10;
441 } elsif ( defined $cookie->{ 'MOVE_LEFT2' } ) {
442 $shift = -1 * $dist * 0.475;
443 } elsif ( defined $cookie->{ 'MOVE_LEFT3' } ) {
444 $shift = -1 * $dist * 0.95;
445 } elsif ( defined $cookie->{ 'MOVE_RIGHT1' } ) {
446 $shift = $dist * 0.10;
447 } elsif ( defined $cookie->{ 'MOVE_RIGHT2' } ) {
448 $shift = $dist * 0.475;
449 } elsif ( defined $cookie->{ 'MOVE_RIGHT3' } ) {
450 $shift = $dist * 0.95;
455 $new_start = int( $cookie->{ 'NAV_START' } + $shift );
456 $new_end = int( $cookie->{ 'NAV_END' } + $shift );
458 if ( $new_start > 0 and $new_end < $max )
460 $cookie->{ 'NAV_START' } = $new_start;
461 $cookie->{ 'NAV_END' } = $new_end;
469 # Martin A. Hansen, March 2010
471 # Adjust the cookie values for NAV_START and NAV_END based
472 # on cookie CENTER value if defined.
474 my ( $cookie, # cookie hash
479 my ( $l_dist, $r_dist );
481 if ( defined $cookie->{ 'NAV_CENTER' } )
483 $l_dist = $cookie->{ 'NAV_CENTER' } - $cookie->{ 'NAV_START' };
484 $r_dist = $cookie->{ 'NAV_END' } - $cookie->{ 'NAV_CENTER' };
486 if ( $l_dist > $r_dist ) {
487 $cookie->{ 'NAV_START' } = $cookie->{ 'NAV_END' } - 2 * $r_dist;
489 $cookie->{ 'NAV_END' } = $cookie->{ 'NAV_START' } + 2 * $l_dist;
497 # Martin A. Hansen, November 2009.
499 # Returns the next page in the taxonomy path.
501 my ( $cookie, # cookie hash
508 for ( $i = 0; $i < @{ $cookie->{ 'LIST_PAGES' } }; $i++ ) {
509 last if $cookie->{ 'PAGE' } eq $cookie->{ 'LIST_PAGES' }->[ $i ];
512 return $cookie->{ 'LIST_PAGES' }->[ $i + 1 ];
516 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> PAGES <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
521 # Martin A. Hansen, November 2009.
523 # Determines what page to render based on
524 # the cookie's PAGE setting.
526 my ( $cookie, # cookie hash
533 if ( $cookie->{ 'SESSION_ID' } ) {
534 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "session_id", value => $cookie->{ 'SESSION_ID' } ) );
537 if ( $cookie->{ 'PAGE' } eq 'login' ) {
538 push @html, page_login( $cookie );
539 } elsif ( $cookie->{ 'PAGE' } eq 'search' ) {
540 push @html, page_search( $cookie );
541 } elsif ( $cookie->{ 'PAGE' } eq 'browse' ) {
542 push @html, page_browse( $cookie );
543 } elsif ( $cookie->{ 'PAGE' } eq 'dna' ) {
544 push @html, page_dna( $cookie );
545 } elsif ( $cookie->{ 'PAGE' } eq 'export' ) {
546 push @html, page_export( $cookie );
548 push @html, page_taxonomy( $cookie );
551 return wantarray ? @html : \@html;
557 # Martin A. Hansen, December 2009.
559 # Renders the login page.
568 push @html, section_login( $cookie );
570 return wantarray ? @html : \@html;
576 # Martin A. Hansen, December 2009.
578 # Renders the search page.
587 push @html, section_taxonomy_table( $cookie );
588 push @html, section_search( $cookie );
590 return wantarray ? @html : \@html;
596 # Martin A. Hansen, November 2009.
598 # Renders the browse page.
607 push @html, section_taxonomy_table( $cookie );
608 push @html, section_navigate( $cookie );
609 push @html, section_browse( $cookie );
610 push @html, section_linkout( $cookie );
612 return wantarray ? @html : \@html;
618 # Martin A. Hansen, November 2009.
620 # Renders the DNA page.
629 push @html, section_taxonomy_table( $cookie );
630 push @html, section_dna( $cookie );
632 return wantarray ? @html : \@html;
638 # Martin A. Hansen, November 2009.
640 # Renders the export page.
649 push @html, section_taxonomy_table( $cookie );
650 push @html, section_export( $cookie );
652 return wantarray ? @html : \@html;
658 # Martin A. Hansen, November 2009.
660 # Renders the browse page.
662 my ( $cookie, # cookie hash
669 push @html, section_taxonomy_table( $cookie );
670 push @html, section_taxonomy_select( $cookie );
672 return wantarray ? @html : \@html;
676 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> SECTIONS <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
681 # Martin A. Hansen, December 2009.
683 # Returns a HTML section with a login menu.
685 my ( $cookie, # cookie hash
690 my ( $user, $password, $login, @html );
692 $user = Maasha::XHTML::text( name => "user", value => "", size => 20 );
693 $password = Maasha::XHTML::password( name => "password", value => "", size => 20 );
694 $login = Maasha::XHTML::submit( name => "login_submit", value => "Login" );
696 push @html, Maasha::XHTML::h2( txt => "Login", class => 'center' );
698 push @html, Maasha::XHTML::table_beg( summary => "Login table", align => 'center' );
699 push @html, Maasha::XHTML::table_row_simple( tr => [ "User:", $user ] );
700 push @html, Maasha::XHTML::table_row_simple( tr => [ "Password:", $password ] );
701 push @html, Maasha::XHTML::table_row_simple( tr => [ "", $login ] );
702 push @html, Maasha::XHTML::table_end;
704 if ( defined $cookie->{ 'CLADE' } and
705 defined $cookie->{ 'GENOME' } and
706 defined $cookie->{ 'ASSEMBLY' } and
707 defined $cookie->{ 'CONTIG' } and
708 defined $cookie->{ 'NAV_START' } and
709 defined $cookie->{ 'NAV_END' }
712 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "clade", value => $cookie->{ 'CLADE' } ) );
713 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "genome", value => $cookie->{ 'GENOME' } ) );
714 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "assembly", value => $cookie->{ 'ASSEMBLY' } ) );
715 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "contig", value => $cookie->{ 'CONTIG' } ) );
716 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "nav_start", value => $cookie->{ 'NAV_START' } ) );
717 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "nav_end", value => $cookie->{ 'NAV_END' } ) );
720 if ( $cookie->{ 'LOGIN_ERROR' } ) {
721 push @html, Maasha::XHTML::h3( txt => "Bad user or password - please retry", class => 'error' );
724 return wantarray ? @html : \@html;
728 sub section_taxonomy_table
730 # Martin A. Hansen, November 2009.
732 # Returns a HTML section with a taxonomy table
733 # showing the location in the taxonomy and with
734 # links to browse the taxonomy.
736 my ( $cookie, # cookie hash
741 my ( $page, @row, @html, $href, $txt );
743 foreach $page ( @{ $cookie->{ 'LIST_PAGES' } } )
745 last if $page eq $cookie->{ 'PAGE' } or $page eq 'browse';
747 $href = "$cookie->{ 'SCRIPT' }?page=$page";
748 $href .= "&session_id=$cookie->{ 'SESSION_ID' }";
749 $href .= "&user=$cookie->{ 'USER' }";
750 $href .= "&clade=$cookie->{ 'CLADE' }" if $page !~ /clade/;
751 $href .= "&genome=$cookie->{ 'GENOME' }" if $page !~ /clade|genome/;
752 $href .= "&assembly=$cookie->{ 'ASSEMBLY' }" if $page !~ /clade|genome|assembly/;
753 $href .= "&contig=$cookie->{ 'CONTIG' }" if $page !~ /clade|genome|assembly|contig/;
755 $txt = ": $cookie->{ uc $page }";
757 push @row, Maasha::XHTML::ln( txt => $page, href => $href, class => 'inline' );
758 push @row, Maasha::XHTML::p( txt => $txt, class => 'inline' );
761 push @html, Maasha::XHTML::table_beg( summary => "Taxonomy table", align => 'center', cellpadding => '5px' );
762 push @html, Maasha::XHTML::table_row_simple( tr => [ join( "\n", @row ) ], align => 'center' );
763 push @html, Maasha::XHTML::table_end;
765 return wantarray ? @html : \@html;
769 sub section_taxonomy_select
771 # Martin A. Hansen, November 2009.
773 # Returns a HTML section with selection choices
774 # for navigating the taxonomy tree.
776 my ( $cookie, # cookie hash
781 my ( $list, @html, $item, $href );
783 $list = "LIST_" . uc $cookie->{ 'PAGE' };
785 push @html, Maasha::XHTML::h2( txt => "Select $cookie->{ 'PAGE' }", class => 'center' );
787 push @html, Maasha::XHTML::table_beg( summary => "Taxonomy select table", align => 'center', cellpadding => '5px' );
789 foreach $item ( @{ $cookie->{ $list } } )
791 $cookie->{ uc $cookie->{ 'PAGE' } } = $item;
793 $href = "$cookie->{ 'SCRIPT' }?page=" . cookie_page_next( $cookie );
794 $href .= "&session_id=$cookie->{ 'SESSION_ID' }";
795 $href .= "&user=$cookie->{ 'USER' }";
796 $href .= "&clade=$cookie->{ 'CLADE' }";
797 $href .= "&genome=$cookie->{ 'GENOME' }" if $cookie->{ 'GENOME' };
798 $href .= "&assembly=$cookie->{ 'ASSEMBLY' }" if $cookie->{ 'ASSEMBLY' };
799 $href .= "&contig=$cookie->{ 'CONTIG' }" if $cookie->{ 'CONTIG' };
801 push @html, Maasha::XHTML::table_row_simple( tr => [ Maasha::XHTML::ln( txt => $item, href => $href ) ] );
804 push @html, Maasha::XHTML::table_end;
806 return wantarray ? @html : \@html;
812 # Martin A. Hansen, November 2009.
814 # Returns a HTML section for navigating in the browser window.
816 my ( $cookie, # cookie hash
821 my ( @html, $nav_val );
823 $nav_val = Maasha::Calc::commify( $cookie->{ 'NAV_START' } ) . "-" . Maasha::Calc::commify( $cookie->{ 'NAV_END' } );
825 push @html, Maasha::XHTML::table_beg( summary => "Navigation table", align => 'center' );
826 push @html, Maasha::XHTML::table_row_simple( tr => [
827 "Position or search term:",
828 Maasha::XHTML::text( name => "nav_search", value => $nav_val, size => 30 ),
829 Maasha::XHTML::submit( name => "nav_submit", value => "Submit" ),
831 push @html, Maasha::XHTML::table_end;
833 push @html, Maasha::XHTML::table_beg( summary => "Zoom table", align => 'center' );
834 push @html, Maasha::XHTML::table_row_simple( tr => [
835 Maasha::XHTML::p( txt => 'Move:' ),
836 Maasha::XHTML::submit( name => "move_left3", value => "<<<", title => "move 95% to the left" ),
837 Maasha::XHTML::submit( name => "move_left2", value => "<<", title => "move 47.5% to the left" ),
838 Maasha::XHTML::submit( name => "move_left1", value => "<", title => "move 10% to the left" ),
839 Maasha::XHTML::submit( name => "move_right1", value => ">", title => "move 10% to the rigth" ),
840 Maasha::XHTML::submit( name => "move_right2", value => ">>", title => "move 47.5% to the rigth" ),
841 Maasha::XHTML::submit( name => "move_right3", value => ">>>", title => "move 95% to the right" ),
842 Maasha::XHTML::p( txt => 'Zoom in:' ),
843 Maasha::XHTML::submit( name => "zoom_in1", value => "1.5x" ),
844 Maasha::XHTML::submit( name => "zoom_in2", value => "3x" ),
845 Maasha::XHTML::submit( name => "zoom_in3", value => "10x" ),
846 Maasha::XHTML::p( txt => 'Zoom out:' ),
847 Maasha::XHTML::submit( name => "zoom_out1", value => "1.5x" ),
848 Maasha::XHTML::submit( name => "zoom_out2", value => "3x" ),
849 Maasha::XHTML::submit( name => "zoom_out3", value => "10x" ),
851 push @html, Maasha::XHTML::table_end;
853 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "page", value => "browse" ) );
854 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "user", value => $cookie->{ 'USER' } ) );
855 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "clade", value => $cookie->{ 'CLADE' } ) );
856 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "genome", value => $cookie->{ 'GENOME' } ) );
857 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "assembly", value => $cookie->{ 'ASSEMBLY' } ) );
858 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "contig", value => $cookie->{ 'CONTIG' } ) );
860 return wantarray ? @html : \@html;
866 # Martin A. Hansen, March 2010.
868 # Returns a HTML section for a static link based on information in the cookie.
870 my ( $cookie, # cookie hash
877 $link = Maasha::XHTML::ln(
879 href => join( "&", "$cookie->{ 'SCRIPT' }?page=browse",
880 "clade=$cookie->{ 'CLADE' }",
881 "genome=$cookie->{ 'GENOME' }",
882 "assembly=$cookie->{ 'ASSEMBLY' }",
883 "contig=$cookie->{ 'CONTIG' }",
884 "nav_start=$cookie->{ 'NAV_START' }",
885 "nav_end=$cookie->{ 'NAV_END' }",
887 title => "Static link to this view",
890 push @html, Maasha::XHTML::p( txt => $link, class => 'center' );
892 return wantarray ? @html : \@html;
903 my ( @tracks, $i, @features, $feat, $elem, $surface, $cr, $png_data, @html, @img, $x1, $y1, $x2, $y2, $factor, $center );
905 push @features, [ Maasha::BGB::Track::track_ruler( $cookie ) ];
906 push @features, [ Maasha::BGB::Track::track_seq( $cookie ) ];
908 @tracks = Maasha::BGB::Track::path_tracks( $cookie );
910 for ( $i = 0; $i < @tracks; $i++ )
912 $cookie->{ 'FEAT_COLOR' } = Maasha::BGB::Draw::palette( $i );
914 push @features, [ Maasha::BGB::Track::track_feature( $tracks[ $i ], $cookie ) ];
917 $surface = Cairo::ImageSurface->create( 'argb32', $cookie->{ 'IMG_WIDTH' }, $cookie->{ 'TRACK_OFFSET' } );
918 $cr = Cairo::Context->create( $surface );
920 $cr->rectangle ( 0, 0, $cookie->{ 'IMG_WIDTH' }, $cookie->{ 'TRACK_OFFSET' } );
921 $cr->set_source_rgb ( 1, 1, 1 );
924 foreach $feat ( @features ) {
925 Maasha::BGB::Draw::draw_feature( $cr, $feat ) if $feat;
928 $png_data = Maasha::BGB::Draw::base64_png( $surface );
930 push @img, Maasha::XHTML::img(
931 src => "data:image/png;base64,$png_data",
932 alt => "Browser Tracks",
933 height => $cookie->{ 'TRACK_OFFSET' },
934 width => $cookie->{ 'IMG_WIDTH' },
936 usemap => "#browser_map"
939 push @img, Maasha::XHTML::map_beg( name => "browser_map", id => "browser_map" );
941 $factor = ( $cookie->{ 'NAV_END' } - $cookie->{ 'NAV_START' } + 1 ) / $cookie->{ 'IMG_WIDTH' };
943 for ( $i = 0; $i < $cookie->{ 'IMG_WIDTH' }; $i += 5 )
950 $center = int( $cookie->{ 'NAV_START' } + $factor * $i );
952 push @img, Maasha::XHTML::area(
953 href => join( "&", "$cookie->{ 'SCRIPT' }?page=browse",
954 "session_id=$cookie->{ 'SESSION_ID' }",
955 "user=$cookie->{ 'USER' }",
956 "clade=$cookie->{ 'CLADE' }",
957 "genome=$cookie->{ 'GENOME' }",
958 "assembly=$cookie->{ 'ASSEMBLY' }",
959 "contig=$cookie->{ 'CONTIG' }",
960 "nav_start=$cookie->{ 'NAV_START' }",
961 "nav_end=$cookie->{ 'NAV_END' }",
962 "nav_center=$center",
965 coords => "$x1, $y1, $x2, $y2",
966 title => "Center on " . Maasha::Calc::commify( $center ),
970 foreach $feat ( @features )
972 foreach $elem ( @{ $feat } )
974 next if $elem->{ 'type' } eq 'text';
975 next if $elem->{ 'type' } eq 'wiggle';
977 #$elem->{ 'strand' } = '+' if $elem->{ 'strand' } eq '+';
979 $cookie->{ 'Q_ID' } = $elem->{ 'q_id' };
980 $cookie->{ 'S_BEG' } = $elem->{ 's_beg' };
981 $cookie->{ 'S_END' } = $elem->{ 's_end' };
982 $cookie->{ 'STRAND' } = $elem->{ 'strand' };
984 push @img, Maasha::XHTML::area(
985 href => join( "&", "$cookie->{ 'SCRIPT' }?page=export",
986 "session_id=$cookie->{ 'SESSION_ID' }",
987 "user=$cookie->{ 'USER' }",
988 "clade=$cookie->{ 'CLADE' }",
989 "genome=$cookie->{ 'GENOME' }",
990 "assembly=$cookie->{ 'ASSEMBLY' }",
991 "contig=$cookie->{ 'CONTIG' }",
992 "s_beg=$cookie->{ 'S_BEG' }",
993 "s_end=$cookie->{ 'S_END' }",
994 "strand=$cookie->{ 'STRAND' }",
997 coords => "$elem->{ x1 }, $elem->{ y1 }, $elem->{ x2 }, $elem->{ y2 }",
998 title => "$elem->{ 'title' }",
1003 push @img, Maasha::XHTML::map_end();
1005 push @html, Maasha::XHTML::p( txt => join( "\n", @img ) );
1007 @html = Maasha::XHTML::div( txt => join( "\n", @html ), class => 'browse' );
1009 return wantarray ? @html : \@html;
1015 # Martin A. Hansen, November 2009.
1017 # Returns a HTML section with export table.
1019 my ( $cookie, # cookie hash
1024 my ( $feat, @row_dna_contig, @html );
1026 $feat = $cookie->{ 'Q_ID' } || "[no name]";
1028 push @row_dna_contig, Maasha::XHTML::p( txt => qq(Export Feature: "$feat" DNA from Contig: ), class => 'inline' );
1029 push @row_dna_contig, Maasha::XHTML::p( txt => "$cookie->{ 'CONTIG' } Start: ", class => 'inline' );
1030 push @row_dna_contig, Maasha::XHTML::text( name => "s_beg", value => Maasha::Calc::commify( $cookie->{ 'S_BEG' } ), size => 15 );
1031 push @row_dna_contig, Maasha::XHTML::p( txt => "End: ", class => 'inline' );
1032 push @row_dna_contig, Maasha::XHTML::text( name => "s_end", value => Maasha::Calc::commify( $cookie->{ 'S_END' } ), size => 15 );
1033 push @row_dna_contig, Maasha::XHTML::p( txt => "Strand: ", class => 'inline' );
1034 push @row_dna_contig, Maasha::XHTML::menu( name => "strand", options => [ qw( + - ) ], selected => $cookie->{ 'STRAND' } );
1035 push @row_dna_contig, Maasha::XHTML::submit( name => "export", value => "Export", title => "Fetch DNA from this region" );
1037 push @html, Maasha::XHTML::h2( txt => "Export", class => 'center' );
1038 push @html, Maasha::XHTML::table_beg( summary => "Taxonomy select table", align => 'center' );
1039 push @html, Maasha::XHTML::table_row_simple( tr => \@row_dna_contig );
1040 push @html, Maasha::XHTML::table_end;
1042 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "page", value => "dna" ) );
1043 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "user", value => $cookie->{ 'USER' } ) );
1044 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "clade", value => $cookie->{ 'CLADE' } ) );
1045 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "genome", value => $cookie->{ 'GENOME' } ) );
1046 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "assembly", value => $cookie->{ 'ASSEMBLY' } ) );
1047 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "contig", value => $cookie->{ 'CONTIG' } ) );
1049 return wantarray ? @html : \@html;
1055 # Martin A. Hansen, November 2009.
1057 # Returns a HTML section with export table.
1059 my ( $cookie, # cookie hash
1064 my ( $results, $result, $count, @html, $export, $browse );
1066 $results = Maasha::BGB::Track::search_tracks( $cookie );
1068 $count = scalar @{ $results };
1070 push @html, Maasha::XHTML::h2( txt => "Search", class => 'center' );
1071 push @html, Maasha::XHTML::p( txt => qq(Results for "$cookie->{ 'SEARCH' }": $count), class => 'center' );
1075 push @html, Maasha::XHTML::table_beg( summary => "Search table", align => 'center', cellpadding => '5px' );
1076 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) ] );
1078 foreach $result ( @{ $results } )
1080 $cookie->{ 'CONTIG' } = $result->{ 'S_ID' };
1081 $cookie->{ 'NAV_START' } = $result->{ 'S_BEG' };
1082 $cookie->{ 'NAV_END' } = $result->{ 'S_END' };
1083 $cookie->{ 'S_BEG' } = $result->{ 'S_BEG' };
1084 $cookie->{ 'S_END' } = $result->{ 'S_END' };
1085 $cookie->{ 'STRAND' } = $result->{ 'STRAND' };
1086 $cookie->{ 'Q_ID' } = $result->{ 'Q_ID' };
1088 $browse = Maasha::XHTML::ln(
1090 href => join( "&", "$cookie->{ 'SCRIPT' }?page=browse",
1091 "session_id=$cookie->{ 'SESSION_ID' }",
1092 "user=$cookie->{ 'USER' }",
1093 "clade=$cookie->{ 'CLADE' }",
1094 "genome=$cookie->{ 'GENOME' }",
1095 "assembly=$cookie->{ 'ASSEMBLY' }",
1096 "contig=$cookie->{ 'CONTIG' }",
1097 "nav_start=$cookie->{ 'NAV_START' }",
1098 "nav_end=$cookie->{ 'NAV_END' }",
1103 $export = Maasha::XHTML::ln(
1105 href => join( "&", "$cookie->{ 'SCRIPT' }?page=export",
1106 "session_id=$cookie->{ 'SESSION_ID' }",
1107 "user=$cookie->{ 'USER' }",
1108 "clade=$cookie->{ 'CLADE' }",
1109 "genome=$cookie->{ 'GENOME' }",
1110 "assembly=$cookie->{ 'ASSEMBLY' }",
1111 "contig=$cookie->{ 'CONTIG' }",
1112 "s_beg=$cookie->{ 'S_BEG' }",
1113 "s_end=$cookie->{ 'S_END' }",
1114 "strand=$cookie->{ 'STRAND' }",
1118 push @html, Maasha::XHTML::table_row_advanced(
1119 tr => [ { td => $result->{ 'S_ID' } },
1120 { td => $result->{ 'S_BEG' }, align => 'right' },
1121 { td => $result->{ 'S_END' }, align => 'right' },
1122 { td => $result->{ 'Q_ID' } },
1123 { td => $result->{ 'SCORE' }, align => 'right' },
1124 { td => $result->{ 'STRAND' } },
1125 { td => $result->{ 'HITS' }, align => 'right' },
1126 { td => $result->{ 'ALIGN' } },
1127 { td => $result->{ 'BLOCK_COUNT' }, align => 'right' },
1128 { td => $result->{ 'BLOCK_BEGS' } },
1129 { td => $result->{ 'BLOCK_LENS' } },
1130 { td => $result->{ 'BLOCK_TYPE' } },
1133 ], class => "monospace"
1137 push @html, Maasha::XHTML::table_end;
1140 return wantarray ? @html : \@html;
1146 # Martin A. Hansen, November 2009.
1148 # Returns a HTML section with extracted DNA.
1150 my ( $cookie, # cookie hash
1155 my ( @html, $beg, $end, $seq );
1157 $beg = $cookie->{ 'S_BEG' };
1158 $end = $cookie->{ 'S_END' };
1162 $seq = join ";", ">$cookie->{ 'GENOME' }", $cookie->{ 'ASSEMBLY' }, $cookie->{ 'CONTIG' }, $beg, $end, "$cookie->{ 'STRAND' }\n";
1163 $seq .= Maasha::BGB::Track::dna_get( $cookie );
1165 push @html, Maasha::XHTML::h2( txt => "DNA", class => 'center' );
1166 push @html, Maasha::XHTML::pre( txt => $seq );
1168 return wantarray ? @html : \@html;
1172 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<