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
241 if ( defined $cookie->{ 'USER' } and $cookie->{ 'USER' } ne '' and -d "$cookie->{ 'SESSION_DIR' }/$cookie->{ 'USER' }" )
243 $new_session->{ 'PASSWORD' } = $session->{ 'PASSWORD' };
244 $new_session->{ 'SESSION_ID' } = $session->{ 'SESSION_ID' };
245 $new_session->{ 'TIME' } = Maasha::Common::time_stamp();
246 $new_session->{ 'PAGE' } = $cookie->{ 'PAGE' };
248 if ( $cookie->{ 'PAGE' } eq 'browse' )
250 $new_session->{ 'CLADE' } = $cookie->{ 'CLADE' };
251 $new_session->{ 'GENOME' } = $cookie->{ 'GENOME' };
252 $new_session->{ 'ASSEMBLY' } = $cookie->{ 'ASSEMBLY' };
253 $new_session->{ 'CONTIG' } = $cookie->{ 'CONTIG' };
254 $new_session->{ 'NAV_START' } = $cookie->{ 'NAV_START' };
255 $new_session->{ 'NAV_END' } = $cookie->{ 'NAV_END' };
257 elsif ( $cookie->{ 'PAGE' } eq 'contig' )
259 $new_session->{ 'CLADE' } = $cookie->{ 'CLADE' };
260 $new_session->{ 'GENOME' } = $cookie->{ 'GENOME' };
261 $new_session->{ 'ASSEMBLY' } = $cookie->{ 'ASSEMBLY' };
263 elsif ( $cookie->{ 'PAGE' } eq 'assembly' )
265 $new_session->{ 'CLADE' } = $cookie->{ 'CLADE' };
266 $new_session->{ 'GENOME' } = $cookie->{ 'GENOME' };
268 elsif ( $cookie->{ 'PAGE' } eq 'genome' )
270 $new_session->{ 'CLADE' } = $cookie->{ 'CLADE' };
272 elsif ( $cookie->{ 'PAGE' } eq 'export' )
274 $new_session->{ 'CLADE' } = $cookie->{ 'CLADE' };
275 $new_session->{ 'GENOME' } = $cookie->{ 'GENOME' };
276 $new_session->{ 'ASSEMBLY' } = $cookie->{ 'ASSEMBLY' };
277 $new_session->{ 'CONTIG' } = $cookie->{ 'CONTIG' };
278 $new_session->{ 'Q_ID' } = $cookie->{ 'Q_ID' };
279 $new_session->{ 'S_BEG' } = $cookie->{ 'S_BEG' };
280 $new_session->{ 'S_END' } = $cookie->{ 'S_END' };
281 $new_session->{ 'STRAND' } = $cookie->{ 'STRAND' };
284 Maasha::BGB::Session::session_store( "$cookie->{ 'SESSION_DIR' }/$cookie->{ 'USER' }/session.json", $new_session );
291 # Martin A. Hansen, March 2010.
293 # Check that the session id in the cookie and session match.
294 # Sets SESSION_ERROR flag in cookie if not matching.
296 my ( $cookie, # cookie hash
297 $session, # session hash
302 if ( defined $cookie->{ 'SESSION_ID' } and defined $session->{ 'SESSION_ID' } )
304 if ( $cookie->{ 'SESSION_ID' } ne $session->{ 'SESSION_ID' } ) {
305 $cookie->{ 'SESSION_ERROR' } = 1;
307 $cookie->{ 'SESSION_ERROR' } = 0;
315 # Martin A. Hansen, December 2009.
317 # Check a user and password from CGI against the password file and
318 # set the session ID, if found, in the cookie.
320 my ( $cookie, # cookie hash
327 if ( defined $cookie->{ 'PASSWORD' } )
329 if ( defined $cookie->{ 'USER' } and -d "$cookie->{ 'SESSION_DIR' }/$cookie->{ 'USER' }" )
331 $session = Maasha::BGB::Session::session_restore( "$cookie->{ 'SESSION_DIR' }/$cookie->{ 'USER' }/session.json" );
333 if ( $session->{ 'PASSWORD' } eq Digest::MD5::md5_hex( $cookie->{ 'PASSWORD' } ) )
335 $cookie->{ 'TIME' } = Maasha::Common::time_stamp();
336 $cookie->{ 'SESSION_ID' } ||= Maasha::BGB::Session::session_new();
337 $cookie->{ 'LOGIN' } = 1;
338 $cookie->{ 'LOGIN_ERROR' } = 0;
342 $cookie->{ 'LOGIN_ERROR' } = 1;
347 $cookie->{ 'LOGIN_ERROR' } = 1;
355 # Martin A. Hansen, November 2009.
357 # Decommify the cookie value for NAV_START and adjust it to
358 # to prevent negative values.
360 my ( $cookie, # cookie hash
365 if ( defined $cookie->{ 'NAV_START' } )
367 $cookie->{ 'NAV_START' } =~ tr/,//d;
368 $cookie->{ 'NAV_START' } = 0 if $cookie->{ 'NAV_START' } < 0;
372 $cookie->{ 'NAV_START' } = 0;
379 # Martin A. Hansen, November 2009.
381 # Decommify the cookie value for NAV_END and adjust it to prevent
382 # overshooting the max value for the contig size as determined
385 my ( $cookie, # cookie hash
392 $max = Maasha::Filesys::file_size( Maasha::BGB::Track::path_seq( $cookie ) );
394 if ( defined $cookie->{ 'NAV_END' } )
396 $cookie->{ 'NAV_END' } =~ tr/,//d;
397 $cookie->{ 'NAV_END' } = $max if $cookie->{ 'NAV_END' } > $max;
401 $cookie->{ 'NAV_END' } = $max;
408 # Martin A. Hansen, November 2009.
410 # Adjust the cookie values for NAV_START and NAV_END based
411 # on cookie ZOOM values.
413 my ( $cookie, # cookie hash
418 my ( $max, $dist, $new_dist, $dist_diff );
420 $max = Maasha::Filesys::file_size( Maasha::BGB::Track::path_seq( $cookie ) );
422 $dist = $cookie->{ 'NAV_END' } - $cookie->{ 'NAV_START' };
424 if ( defined $cookie->{ 'ZOOM_IN1' } ) {
425 $new_dist = $dist / 1.5;
426 } elsif ( defined $cookie->{ 'ZOOM_IN2' } ) {
427 $new_dist = $dist / 3;
428 } elsif ( defined $cookie->{ 'ZOOM_IN3' } ) {
429 $new_dist = $dist / 10;
430 } elsif ( defined $cookie->{ 'ZOOM_OUT1' } ) {
431 $new_dist = $dist * 1.5;
432 } elsif ( defined $cookie->{ 'ZOOM_OUT2' } ) {
433 $new_dist = $dist * 3;
434 } elsif ( defined $cookie->{ 'ZOOM_OUT3' } ) {
435 $new_dist = $dist * 10;
440 $dist_diff = $dist - $new_dist;
442 $cookie->{ 'NAV_START' } = int( $cookie->{ 'NAV_START' } + ( $dist_diff / 2 ) );
443 $cookie->{ 'NAV_END' } = int( $cookie->{ 'NAV_END' } - ( $dist_diff / 2 ) );
445 $cookie->{ 'NAV_START' } = 0 if $cookie->{ 'NAV_START' } < 0;
446 $cookie->{ 'NAV_END' } = $max if $cookie->{ 'NAV_END' } > $max;
453 # Martin A. Hansen, November 2009.
455 # Adjust the cookie values for NAV_START and NAV_END based
456 # on cookie MOVE values.
458 my ( $cookie, # cookie hash
463 my ( $max, $dist, $shift, $new_start, $new_end );
465 $max = Maasha::Filesys::file_size( Maasha::BGB::Track::path_seq( $cookie ) );
467 $dist = $cookie->{ 'NAV_END' } - $cookie->{ 'NAV_START' };
469 if ( defined $cookie->{ 'MOVE_LEFT1' } ) {
470 $shift = -1 * $dist * 0.10;
471 } elsif ( defined $cookie->{ 'MOVE_LEFT2' } ) {
472 $shift = -1 * $dist * 0.475;
473 } elsif ( defined $cookie->{ 'MOVE_LEFT3' } ) {
474 $shift = -1 * $dist * 0.95;
475 } elsif ( defined $cookie->{ 'MOVE_RIGHT1' } ) {
476 $shift = $dist * 0.10;
477 } elsif ( defined $cookie->{ 'MOVE_RIGHT2' } ) {
478 $shift = $dist * 0.475;
479 } elsif ( defined $cookie->{ 'MOVE_RIGHT3' } ) {
480 $shift = $dist * 0.95;
485 $new_start = int( $cookie->{ 'NAV_START' } + $shift );
486 $new_end = int( $cookie->{ 'NAV_END' } + $shift );
488 if ( $new_start > 0 and $new_end < $max )
490 $cookie->{ 'NAV_START' } = $new_start;
491 $cookie->{ 'NAV_END' } = $new_end;
499 # Martin A. Hansen, March 2010
501 # Adjust the cookie values for NAV_START and NAV_END based
502 # on cookie CENTER value if defined.
504 my ( $cookie, # cookie hash
509 my ( $l_dist, $r_dist );
511 if ( defined $cookie->{ 'NAV_CENTER' } )
513 $l_dist = $cookie->{ 'NAV_CENTER' } - $cookie->{ 'NAV_START' };
514 $r_dist = $cookie->{ 'NAV_END' } - $cookie->{ 'NAV_CENTER' };
516 if ( $l_dist > $r_dist ) {
517 $cookie->{ 'NAV_START' } = $cookie->{ 'NAV_END' } - 2 * $r_dist;
519 $cookie->{ 'NAV_END' } = $cookie->{ 'NAV_START' } + 2 * $l_dist;
525 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> PAGES <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
530 # Martin A. Hansen, November 2009.
532 # Determines what page to render based on
533 # the cookie's PAGE setting.
535 my ( $cookie, # cookie hash
542 if ( $cookie->{ 'SESSION_ID' } ) {
543 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "session_id", value => $cookie->{ 'SESSION_ID' } ) );
546 if ( $cookie->{ 'PAGE' } eq 'login' ) {
547 push @html, page_login( $cookie );
548 } elsif ( $cookie->{ 'PAGE' } eq 'search' ) {
549 push @html, page_search( $cookie );
550 } elsif ( $cookie->{ 'PAGE' } eq 'browse' ) {
551 push @html, page_browse( $cookie );
552 } elsif ( $cookie->{ 'PAGE' } eq 'dna' ) {
553 push @html, page_dna( $cookie );
554 } elsif ( $cookie->{ 'PAGE' } eq 'export' ) {
555 push @html, page_export( $cookie );
556 } elsif ( $cookie->{ 'PAGE' } eq 'clade' ) {
557 push @html, page_clade( $cookie );
558 } elsif ( $cookie->{ 'PAGE' } eq 'genome' ) {
559 push @html, page_genome( $cookie );
560 } elsif ( $cookie->{ 'PAGE' } eq 'assembly' ) {
561 push @html, page_assembly( $cookie );
562 } elsif ( $cookie->{ 'PAGE' } eq 'contig' ) {
563 push @html, page_contig( $cookie );
566 return wantarray ? @html : \@html;
572 # Martin A. Hansen, December 2009.
574 # Renders the login page.
583 push @html, section_login( $cookie );
585 return wantarray ? @html : \@html;
591 # Martin A. Hansen, December 2009.
593 # Renders the search page.
602 push @html, section_taxonomy_table( $cookie );
603 push @html, section_search( $cookie );
605 return wantarray ? @html : \@html;
611 # Martin A. Hansen, November 2009.
613 # Renders the browse page.
622 push @html, section_taxonomy_table( $cookie );
623 push @html, section_navigate( $cookie );
624 push @html, section_browse( $cookie );
625 push @html, section_linkout( $cookie );
627 return wantarray ? @html : \@html;
633 # Martin A. Hansen, November 2009.
635 # Renders the DNA page.
644 push @html, section_taxonomy_table( $cookie );
645 push @html, section_dna( $cookie );
647 return wantarray ? @html : \@html;
653 # Martin A. Hansen, November 2009.
655 # Renders the export page.
664 push @html, section_taxonomy_table( $cookie );
665 push @html, section_export( $cookie );
667 return wantarray ? @html : \@html;
673 # Martin A. Hansen, March 2010.
675 # Renders the clade selection page.
677 my ( $cookie, # cookie hash
684 push @html, section_taxonomy_table( $cookie );
685 push @html, section_clade( $cookie );
687 return wantarray ? @html : \@html;
693 # Martin A. Hansen, March 2010.
695 # Renders the genome selection page.
697 my ( $cookie, # cookie hash
704 push @html, section_taxonomy_table( $cookie );
705 push @html, section_genome( $cookie );
707 return wantarray ? @html : \@html;
713 # Martin A. Hansen, March 2010.
715 # Renders the clade selection page.
717 my ( $cookie, # cookie hash
724 push @html, section_taxonomy_table( $cookie );
725 push @html, section_assembly( $cookie );
727 return wantarray ? @html : \@html;
733 # Martin A. Hansen, November 2009.
735 # Renders the browse page.
737 my ( $cookie, # cookie hash
744 push @html, section_taxonomy_table( $cookie );
745 push @html, section_contig( $cookie );
747 return wantarray ? @html : \@html;
751 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> SECTIONS <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
756 # Martin A. Hansen, December 2009.
758 # Returns a HTML section with a login menu.
760 my ( $cookie, # cookie hash
765 my ( $user, $password, $login, @html );
767 $user = Maasha::XHTML::text( name => "user", value => "", size => 20 );
768 $password = Maasha::XHTML::password( name => "password", value => "", size => 20 );
769 $login = Maasha::XHTML::submit( name => "login_submit", value => "Login" );
771 push @html, Maasha::XHTML::h2( txt => "Login", class => 'center' );
773 push @html, Maasha::XHTML::table_beg( summary => "Login table", align => 'center' );
774 push @html, Maasha::XHTML::table_row_simple( tr => [ "User:", $user ] );
775 push @html, Maasha::XHTML::table_row_simple( tr => [ "Password:", $password ] );
776 push @html, Maasha::XHTML::table_row_simple( tr => [ "", $login ] );
777 push @html, Maasha::XHTML::table_end;
779 if ( defined $cookie->{ 'CLADE' } and
780 defined $cookie->{ 'GENOME' } and
781 defined $cookie->{ 'ASSEMBLY' } and
782 defined $cookie->{ 'CONTIG' } and
783 defined $cookie->{ 'NAV_START' } and
784 defined $cookie->{ 'NAV_END' }
787 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "clade", value => $cookie->{ 'CLADE' } ) );
788 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "genome", value => $cookie->{ 'GENOME' } ) );
789 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "assembly", value => $cookie->{ 'ASSEMBLY' } ) );
790 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "contig", value => $cookie->{ 'CONTIG' } ) );
791 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "nav_start", value => $cookie->{ 'NAV_START' } ) );
792 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "nav_end", value => $cookie->{ 'NAV_END' } ) );
795 if ( $cookie->{ 'LOGIN_ERROR' } ) {
796 push @html, Maasha::XHTML::h3( txt => "Bad user or password - please retry", class => 'error' );
799 return wantarray ? @html : \@html;
803 sub section_taxonomy_table
805 # Martin A. Hansen, November 2009.
807 # Returns a HTML section with a taxonomy table
808 # showing the location in the taxonomy and with
809 # links to browse the taxonomy.
811 my ( $cookie, # cookie hash
816 my ( $page, @row, @html, $href, $txt );
818 foreach $page ( @{ $cookie->{ 'LIST_PAGES' } } )
820 last if $page eq $cookie->{ 'PAGE' } or $page eq 'browse';
822 $href = "$cookie->{ 'SCRIPT' }?page=$page";
823 $href .= "&session_id=$cookie->{ 'SESSION_ID' }";
824 $href .= "&user=$cookie->{ 'USER' }";
825 $href .= "&clade=$cookie->{ 'CLADE' }" if $page !~ /clade/;
826 $href .= "&genome=$cookie->{ 'GENOME' }" if $page !~ /clade|genome/;
827 $href .= "&assembly=$cookie->{ 'ASSEMBLY' }" if $page !~ /clade|genome|assembly/;
828 $href .= "&contig=$cookie->{ 'CONTIG' }" if $page !~ /clade|genome|assembly|contig/;
830 $txt = ": $cookie->{ uc $page }";
832 push @row, Maasha::XHTML::ln( txt => $page, href => $href, class => 'inline' );
833 push @row, Maasha::XHTML::p( txt => $txt, class => 'inline' );
836 push @html, Maasha::XHTML::table_beg( summary => "Taxonomy table", align => 'center', cellpadding => '5px' );
837 push @html, Maasha::XHTML::table_row_simple( tr => [ join( "\n", @row ) ], align => 'center' );
838 push @html, Maasha::XHTML::table_end;
840 return wantarray ? @html : \@html;
846 # Martin A. Hansen, March 2010.
848 # Returns a HTML section with clade selection choices
849 # for navigating the taxonomy tree.
851 my ( $cookie, # cookie hash
856 my ( @html, $clade, $href );
858 push @html, Maasha::XHTML::h2( txt => "Select clade", class => 'center' );
860 push @html, Maasha::XHTML::table_beg( summary => "Taxonomy select table", align => 'center', cellpadding => '5px' );
862 foreach $clade ( @{ $cookie->{ 'LIST_CLADE' } } )
864 $href = "$cookie->{ 'SCRIPT' }?page=genome";
865 $href .= "&session_id=$cookie->{ 'SESSION_ID' }";
866 $href .= "&user=$cookie->{ 'USER' }";
867 $href .= "&clade=$clade";
869 push @html, Maasha::XHTML::table_row_simple( tr => [ Maasha::XHTML::ln( txt => $clade, href => $href ) ] );
872 push @html, Maasha::XHTML::table_end;
874 return wantarray ? @html : \@html;
880 # Martin A. Hansen, March 2010.
882 # Returns a HTML section with genome selection choices
883 # for navigating the taxonomy tree.
885 my ( $cookie, # cookie hash
890 my ( @html, $genome, $href );
892 push @html, Maasha::XHTML::h2( txt => "Select genome", class => 'center' );
894 push @html, Maasha::XHTML::table_beg( summary => "Taxonomy select table", align => 'center', cellpadding => '5px' );
896 foreach $genome ( @{ $cookie->{ 'LIST_GENOME' } } )
898 $href = "$cookie->{ 'SCRIPT' }?page=assembly";
899 $href .= "&session_id=$cookie->{ 'SESSION_ID' }";
900 $href .= "&user=$cookie->{ 'USER' }";
901 $href .= "&clade=$cookie->{ 'CLADE' }";
902 $href .= "&genome=$genome";
904 push @html, Maasha::XHTML::table_row_simple( tr => [ Maasha::XHTML::ln( txt => $genome, href => $href ) ] );
907 push @html, Maasha::XHTML::table_end;
909 return wantarray ? @html : \@html;
915 # Martin A. Hansen, March 2010.
917 # Returns a HTML section with assembly selection choices
918 # for navigating the taxonomy tree.
920 my ( $cookie, # cookie hash
925 my ( @html, $assembly, $href );
927 push @html, Maasha::XHTML::h2( txt => "Select assembly", class => 'center' );
929 push @html, Maasha::XHTML::table_beg( summary => "Taxonomy select table", align => 'center', cellpadding => '5px' );
931 foreach $assembly ( @{ $cookie->{ 'LIST_ASSEMBLY' } } )
933 $href = "$cookie->{ 'SCRIPT' }?page=contig";
934 $href .= "&session_id=$cookie->{ 'SESSION_ID' }";
935 $href .= "&user=$cookie->{ 'USER' }";
936 $href .= "&clade=$cookie->{ 'CLADE' }";
937 $href .= "&genome=$cookie->{ 'GENOME' }";
938 $href .= "&assembly=$assembly";
940 push @html, Maasha::XHTML::table_row_simple( tr => [ Maasha::XHTML::ln( txt => $assembly, href => $href ) ] );
943 push @html, Maasha::XHTML::table_end;
945 return wantarray ? @html : \@html;
951 # Martin A. Hansen, March 2010.
953 # Returns a HTML section with contig selection choices
954 # for navigating the taxonomy tree.
956 my ( $cookie, # cookie hash
961 my ( @html, $contig, $href );
963 push @html, Maasha::XHTML::h2( txt => "Select contig", class => 'center' );
965 push @html, Maasha::XHTML::table_beg( summary => "Taxonomy select table", align => 'center', cellpadding => '5px' );
967 foreach $contig ( @{ $cookie->{ 'LIST_CONTIG' } } )
969 $href = "$cookie->{ 'SCRIPT' }?page=browse";
970 $href .= "&session_id=$cookie->{ 'SESSION_ID' }";
971 $href .= "&user=$cookie->{ 'USER' }";
972 $href .= "&clade=$cookie->{ 'CLADE' }";
973 $href .= "&genome=$cookie->{ 'GENOME' }";
974 $href .= "&assembly=$cookie->{ 'ASSEMBLY' }";
975 $href .= "&contig=$contig";
977 push @html, Maasha::XHTML::table_row_simple( tr => [ Maasha::XHTML::ln( txt => $contig, href => $href ) ] );
980 push @html, Maasha::XHTML::table_end;
982 return wantarray ? @html : \@html;
988 # Martin A. Hansen, November 2009.
990 # Returns a HTML section for navigating in the browser window.
992 my ( $cookie, # cookie hash
997 my ( @html, $nav_val );
999 $nav_val = Maasha::Calc::commify( $cookie->{ 'NAV_START' } ) . "-" . Maasha::Calc::commify( $cookie->{ 'NAV_END' } );
1001 push @html, Maasha::XHTML::table_beg( summary => "Navigation table", align => 'center' );
1002 push @html, Maasha::XHTML::table_row_simple( tr => [
1003 "Position or search term:",
1004 Maasha::XHTML::text( name => "nav_search", value => $nav_val, size => 30 ),
1005 Maasha::XHTML::submit( name => "nav_submit", value => "Submit" ),
1007 push @html, Maasha::XHTML::table_end;
1009 push @html, Maasha::XHTML::table_beg( summary => "Zoom table", align => 'center' );
1010 push @html, Maasha::XHTML::table_row_simple( tr => [
1011 Maasha::XHTML::p( txt => 'Move:' ),
1012 Maasha::XHTML::submit( name => "move_left3", value => "<<<", title => "move 95% to the left" ),
1013 Maasha::XHTML::submit( name => "move_left2", value => "<<", title => "move 47.5% to the left" ),
1014 Maasha::XHTML::submit( name => "move_left1", value => "<", title => "move 10% to the left" ),
1015 Maasha::XHTML::submit( name => "move_right1", value => ">", title => "move 10% to the rigth" ),
1016 Maasha::XHTML::submit( name => "move_right2", value => ">>", title => "move 47.5% to the rigth" ),
1017 Maasha::XHTML::submit( name => "move_right3", value => ">>>", title => "move 95% to the right" ),
1018 Maasha::XHTML::p( txt => 'Zoom in:' ),
1019 Maasha::XHTML::submit( name => "zoom_in1", value => "1.5x" ),
1020 Maasha::XHTML::submit( name => "zoom_in2", value => "3x" ),
1021 Maasha::XHTML::submit( name => "zoom_in3", value => "10x" ),
1022 Maasha::XHTML::p( txt => 'Zoom out:' ),
1023 Maasha::XHTML::submit( name => "zoom_out1", value => "1.5x" ),
1024 Maasha::XHTML::submit( name => "zoom_out2", value => "3x" ),
1025 Maasha::XHTML::submit( name => "zoom_out3", value => "10x" ),
1027 push @html, Maasha::XHTML::table_end;
1029 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "page", value => "browse" ) );
1030 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "user", value => $cookie->{ 'USER' } ) );
1031 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "clade", value => $cookie->{ 'CLADE' } ) );
1032 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "genome", value => $cookie->{ 'GENOME' } ) );
1033 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "assembly", value => $cookie->{ 'ASSEMBLY' } ) );
1034 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "contig", value => $cookie->{ 'CONTIG' } ) );
1036 return wantarray ? @html : \@html;
1042 # Martin A. Hansen, March 2010.
1044 # Returns a HTML section for a static link based on information in the cookie.
1046 my ( $cookie, # cookie hash
1051 my ( $link, @html );
1053 $link = Maasha::XHTML::ln(
1055 href => join( "&", "$cookie->{ 'SCRIPT' }?page=browse",
1056 "clade=$cookie->{ 'CLADE' }",
1057 "genome=$cookie->{ 'GENOME' }",
1058 "assembly=$cookie->{ 'ASSEMBLY' }",
1059 "contig=$cookie->{ 'CONTIG' }",
1060 "nav_start=$cookie->{ 'NAV_START' }",
1061 "nav_end=$cookie->{ 'NAV_END' }",
1063 title => "Static link to this view",
1066 push @html, Maasha::XHTML::p( txt => $link, class => 'center' );
1068 return wantarray ? @html : \@html;
1079 my ( @tracks, $i, @features, $feat, $elem, $surface, $cr, $png_data, @html, @img, $x1, $y1, $x2, $y2, $factor, $center );
1081 push @features, [ Maasha::BGB::Track::track_ruler( $cookie ) ];
1082 push @features, [ Maasha::BGB::Track::track_seq( $cookie ) ];
1084 @tracks = Maasha::BGB::Track::path_tracks( $cookie );
1086 for ( $i = 0; $i < @tracks; $i++ )
1088 $cookie->{ 'FEAT_COLOR' } = Maasha::BGB::Draw::palette( $i );
1090 push @features, [ Maasha::BGB::Track::track_feature( $tracks[ $i ], $cookie ) ];
1093 $surface = Cairo::ImageSurface->create( 'argb32', $cookie->{ 'IMG_WIDTH' }, $cookie->{ 'TRACK_OFFSET' } );
1094 $cr = Cairo::Context->create( $surface );
1096 $cr->rectangle ( 0, 0, $cookie->{ 'IMG_WIDTH' }, $cookie->{ 'TRACK_OFFSET' } );
1097 $cr->set_source_rgb ( 1, 1, 1 );
1100 foreach $feat ( @features ) {
1101 Maasha::BGB::Draw::draw_feature( $cr, $feat ) if $feat;
1104 $png_data = Maasha::BGB::Draw::base64_png( $surface );
1106 push @img, Maasha::XHTML::img(
1107 src => "data:image/png;base64,$png_data",
1108 alt => "Browser Tracks",
1109 height => $cookie->{ 'TRACK_OFFSET' },
1110 width => $cookie->{ 'IMG_WIDTH' },
1111 id => "browser_map",
1112 usemap => "#browser_map"
1115 push @img, Maasha::XHTML::map_beg( name => "browser_map", id => "browser_map" );
1117 $factor = ( $cookie->{ 'NAV_END' } - $cookie->{ 'NAV_START' } + 1 ) / $cookie->{ 'IMG_WIDTH' };
1119 for ( $i = 0; $i < $cookie->{ 'IMG_WIDTH' }; $i += 5 )
1126 $center = int( $cookie->{ 'NAV_START' } + $factor * $i );
1128 push @img, Maasha::XHTML::area(
1129 href => join( "&", "$cookie->{ 'SCRIPT' }?page=browse",
1130 "session_id=$cookie->{ 'SESSION_ID' }",
1131 "user=$cookie->{ 'USER' }",
1132 "clade=$cookie->{ 'CLADE' }",
1133 "genome=$cookie->{ 'GENOME' }",
1134 "assembly=$cookie->{ 'ASSEMBLY' }",
1135 "contig=$cookie->{ 'CONTIG' }",
1136 "nav_start=$cookie->{ 'NAV_START' }",
1137 "nav_end=$cookie->{ 'NAV_END' }",
1138 "nav_center=$center",
1141 coords => "$x1, $y1, $x2, $y2",
1142 title => "Center on " . Maasha::Calc::commify( $center ),
1146 foreach $feat ( @features )
1148 foreach $elem ( @{ $feat } )
1150 next if $elem->{ 'type' } eq 'text';
1151 next if $elem->{ 'type' } eq 'wiggle';
1153 #$elem->{ 'strand' } = '+' if $elem->{ 'strand' } eq '+';
1155 $cookie->{ 'Q_ID' } = $elem->{ 'q_id' };
1156 $cookie->{ 'S_BEG' } = $elem->{ 's_beg' };
1157 $cookie->{ 'S_END' } = $elem->{ 's_end' };
1158 $cookie->{ 'STRAND' } = $elem->{ 'strand' };
1160 push @img, Maasha::XHTML::area(
1161 href => join( "&", "$cookie->{ 'SCRIPT' }?page=export",
1162 "session_id=$cookie->{ 'SESSION_ID' }",
1163 "user=$cookie->{ 'USER' }",
1164 "clade=$cookie->{ 'CLADE' }",
1165 "genome=$cookie->{ 'GENOME' }",
1166 "assembly=$cookie->{ 'ASSEMBLY' }",
1167 "contig=$cookie->{ 'CONTIG' }",
1168 "s_beg=$cookie->{ 'S_BEG' }",
1169 "s_end=$cookie->{ 'S_END' }",
1170 "strand=$cookie->{ 'STRAND' }",
1173 coords => "$elem->{ x1 }, $elem->{ y1 }, $elem->{ x2 }, $elem->{ y2 }",
1174 title => "$elem->{ 'title' }",
1179 push @img, Maasha::XHTML::map_end();
1181 push @html, Maasha::XHTML::p( txt => join( "\n", @img ) );
1183 @html = Maasha::XHTML::div( txt => join( "\n", @html ), class => 'browse' );
1185 return wantarray ? @html : \@html;
1191 # Martin A. Hansen, November 2009.
1193 # Returns a HTML section with export table.
1195 my ( $cookie, # cookie hash
1200 my ( $feat, @row_dna_contig, @html );
1202 $feat = $cookie->{ 'Q_ID' } || "[no name]";
1204 push @row_dna_contig, Maasha::XHTML::p( txt => qq(Export Feature: "$feat" DNA from Contig: ), class => 'inline' );
1205 push @row_dna_contig, Maasha::XHTML::p( txt => "$cookie->{ 'CONTIG' } Start: ", class => 'inline' );
1206 push @row_dna_contig, Maasha::XHTML::text( name => "s_beg", value => Maasha::Calc::commify( $cookie->{ 'S_BEG' } ), size => 15 );
1207 push @row_dna_contig, Maasha::XHTML::p( txt => "End: ", class => 'inline' );
1208 push @row_dna_contig, Maasha::XHTML::text( name => "s_end", value => Maasha::Calc::commify( $cookie->{ 'S_END' } ), size => 15 );
1209 push @row_dna_contig, Maasha::XHTML::p( txt => "Strand: ", class => 'inline' );
1210 push @row_dna_contig, Maasha::XHTML::menu( name => "strand", options => [ qw( + - ) ], selected => $cookie->{ 'STRAND' } );
1211 push @row_dna_contig, Maasha::XHTML::submit( name => "export", value => "Export", title => "Fetch DNA from this region" );
1213 push @html, Maasha::XHTML::h2( txt => "Export", class => 'center' );
1214 push @html, Maasha::XHTML::table_beg( summary => "Taxonomy select table", align => 'center' );
1215 push @html, Maasha::XHTML::table_row_simple( tr => \@row_dna_contig );
1216 push @html, Maasha::XHTML::table_end;
1218 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "page", value => "dna" ) );
1219 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "user", value => $cookie->{ 'USER' } ) );
1220 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "clade", value => $cookie->{ 'CLADE' } ) );
1221 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "genome", value => $cookie->{ 'GENOME' } ) );
1222 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "assembly", value => $cookie->{ 'ASSEMBLY' } ) );
1223 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "contig", value => $cookie->{ 'CONTIG' } ) );
1225 return wantarray ? @html : \@html;
1231 # Martin A. Hansen, November 2009.
1233 # Returns a HTML section with export table.
1235 my ( $cookie, # cookie hash
1240 my ( $results, $result, $count, @html, $export, $browse );
1242 $results = Maasha::BGB::Track::search_tracks( $cookie );
1244 $count = scalar @{ $results };
1246 push @html, Maasha::XHTML::h2( txt => "Search", class => 'center' );
1247 push @html, Maasha::XHTML::p( txt => qq(Results for "$cookie->{ 'SEARCH' }": $count), class => 'center' );
1251 push @html, Maasha::XHTML::table_beg( summary => "Search table", align => 'center', cellpadding => '5px' );
1252 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) ] );
1254 foreach $result ( @{ $results } )
1256 $cookie->{ 'CONTIG' } = $result->{ 'S_ID' };
1257 $cookie->{ 'NAV_START' } = $result->{ 'S_BEG' };
1258 $cookie->{ 'NAV_END' } = $result->{ 'S_END' };
1259 $cookie->{ 'S_BEG' } = $result->{ 'S_BEG' };
1260 $cookie->{ 'S_END' } = $result->{ 'S_END' };
1261 $cookie->{ 'STRAND' } = $result->{ 'STRAND' };
1262 $cookie->{ 'Q_ID' } = $result->{ 'Q_ID' };
1264 $browse = Maasha::XHTML::ln(
1266 href => join( "&", "$cookie->{ 'SCRIPT' }?page=browse",
1267 "session_id=$cookie->{ 'SESSION_ID' }",
1268 "user=$cookie->{ 'USER' }",
1269 "clade=$cookie->{ 'CLADE' }",
1270 "genome=$cookie->{ 'GENOME' }",
1271 "assembly=$cookie->{ 'ASSEMBLY' }",
1272 "contig=$cookie->{ 'CONTIG' }",
1273 "nav_start=$cookie->{ 'NAV_START' }",
1274 "nav_end=$cookie->{ 'NAV_END' }",
1279 $export = Maasha::XHTML::ln(
1281 href => join( "&", "$cookie->{ 'SCRIPT' }?page=export",
1282 "session_id=$cookie->{ 'SESSION_ID' }",
1283 "user=$cookie->{ 'USER' }",
1284 "clade=$cookie->{ 'CLADE' }",
1285 "genome=$cookie->{ 'GENOME' }",
1286 "assembly=$cookie->{ 'ASSEMBLY' }",
1287 "contig=$cookie->{ 'CONTIG' }",
1288 "s_beg=$cookie->{ 'S_BEG' }",
1289 "s_end=$cookie->{ 'S_END' }",
1290 "strand=$cookie->{ 'STRAND' }",
1294 push @html, Maasha::XHTML::table_row_advanced(
1295 tr => [ { td => $result->{ 'S_ID' } },
1296 { td => $result->{ 'S_BEG' }, align => 'right' },
1297 { td => $result->{ 'S_END' }, align => 'right' },
1298 { td => $result->{ 'Q_ID' } },
1299 { td => $result->{ 'SCORE' }, align => 'right' },
1300 { td => $result->{ 'STRAND' } },
1301 { td => $result->{ 'HITS' }, align => 'right' },
1302 { td => $result->{ 'ALIGN' } },
1303 { td => $result->{ 'BLOCK_COUNT' }, align => 'right' },
1304 { td => $result->{ 'BLOCK_BEGS' } },
1305 { td => $result->{ 'BLOCK_LENS' } },
1306 { td => $result->{ 'BLOCK_TYPE' } },
1309 ], class => "monospace"
1313 push @html, Maasha::XHTML::table_end;
1316 return wantarray ? @html : \@html;
1322 # Martin A. Hansen, November 2009.
1324 # Returns a HTML section with extracted DNA.
1326 my ( $cookie, # cookie hash
1331 my ( @html, $beg, $end, $seq );
1333 $beg = $cookie->{ 'S_BEG' };
1334 $end = $cookie->{ 'S_END' };
1338 $seq = join ";", ">$cookie->{ 'GENOME' }", $cookie->{ 'ASSEMBLY' }, $cookie->{ 'CONTIG' }, $beg, $end, "$cookie->{ 'STRAND' }\n";
1339 $seq .= Maasha::BGB::Track::dna_get( $cookie );
1341 push @html, Maasha::XHTML::h2( txt => "DNA", class => 'center' );
1342 push @html, Maasha::XHTML::pre( txt => $seq );
1344 return wantarray ? @html : \@html;
1348 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<