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;
70 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> SUBROUTINES <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
73 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> COOKIE <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
78 # Martin A. Hansen, November 2009.
80 # Set a cookie with values from the CGI object or defaults.
82 my ( $cgi, # CGI object
87 my ( $cookie, $session );
91 if ( $cgi->param( 'nav_search' ) )
93 if ( $cgi->param( 'nav_search' ) =~ /([0-9,]+)[ -]([0-9,]+)/ )
95 $cookie->{ 'NAV_START' } = $1;
96 $cookie->{ 'NAV_END' } = $2;
100 $cookie->{ 'SEARCH' } = $cgi->param( 'nav_search' );
102 $cgi->param( 'page', 'search' );
106 $cookie->{ 'SCRIPT' } = Maasha::Common::get_scriptname();
107 $cookie->{ 'DATA_DIR' } = "Data";
108 $cookie->{ 'SESSION_DIR' } = "Sessions";
109 $cookie->{ 'LIST_PAGES' } = [ qw( clade genome assembly contig browse ) ];
110 $cookie->{ 'USER' } = $cgi->param( 'user' );
111 $cookie->{ 'PASSWORD' } = $cgi->param( 'password' );
112 $cookie->{ 'SESSION_ID' } = $cgi->param( 'session_id' );
114 $session = session_restore( $cookie );
116 cookie_login( $cookie );
118 # session_id_check( $cookie, $session );
120 if ( $cookie->{ 'LOGIN_ERROR' } or $cookie->{ 'SESSION_ERROR' } )
122 $cookie->{ 'PAGE' } = 'login';
124 elsif ( $cookie->{ 'LOGIN' } )
126 if ( $cgi->param( 'genome' ) ) {
127 $cookie->{ 'PAGE' } = 'browse';
129 $cookie->{ 'PAGE' } = $session->{ 'PAGE' } || 'clade';
132 elsif ( not defined $cookie->{ 'USER' } )
134 $cookie->{ 'PAGE' } = 'login';
138 $cookie->{ 'PAGE' } = $cgi->param( 'page' ) || 'login';
141 $cookie->{ 'CLADE' } = $cgi->param( 'clade' ) || $session->{ 'CLADE' };
142 $cookie->{ 'GENOME' } = $cgi->param( 'genome' ) || $session->{ 'GENOME' };
143 $cookie->{ 'ASSEMBLY' } = $cgi->param( 'assembly' ) || $session->{ 'ASSEMBLY' };
144 $cookie->{ 'CONTIG' } = $cgi->param( 'contig' ) || $session->{ 'CONTIG' };
145 $cookie->{ 'Q_ID' } = $cgi->param( 'q_id' ) || $session->{ 'Q_ID' };
146 $cookie->{ 'NAV_START' } ||= defined $cgi->param( 'nav_start' ) ? $cgi->param( 'nav_start' ) : $session->{ 'NAV_START' };
147 $cookie->{ 'NAV_END' } ||= $cgi->param( 'nav_end' ) || $session->{ 'NAV_END' };
148 $cookie->{ 'NAV_CENTER' } = $cgi->param( 'nav_center' );
149 $cookie->{ 'S_BEG' } = $cgi->param( 's_beg' ) || $session->{ 'S_BEG' };
150 $cookie->{ 'S_END' } = $cgi->param( 's_end' ) || $session->{ 'S_END' };
151 $cookie->{ 'STRAND' } = $cgi->param( 'strand' ) || $session->{ 'STRAND' };
152 $cookie->{ 'ZOOM_IN1' } = $cgi->param( 'zoom_in1' );
153 $cookie->{ 'ZOOM_IN2' } = $cgi->param( 'zoom_in2' );
154 $cookie->{ 'ZOOM_IN3' } = $cgi->param( 'zoom_in3' );
155 $cookie->{ 'ZOOM_OUT1' } = $cgi->param( 'zoom_out1' );
156 $cookie->{ 'ZOOM_OUT2' } = $cgi->param( 'zoom_out2' );
157 $cookie->{ 'ZOOM_OUT3' } = $cgi->param( 'zoom_out3' );
158 $cookie->{ 'MOVE_LEFT1' } = $cgi->param( 'move_left1' );
159 $cookie->{ 'MOVE_LEFT2' } = $cgi->param( 'move_left2' );
160 $cookie->{ 'MOVE_LEFT3' } = $cgi->param( 'move_left3' );
161 $cookie->{ 'MOVE_RIGHT1' } = $cgi->param( 'move_right1' );
162 $cookie->{ 'MOVE_RIGHT2' } = $cgi->param( 'move_right2' );
163 $cookie->{ 'MOVE_RIGHT3' } = $cgi->param( 'move_right3' );
165 $cookie->{ 'IMG_WIDTH' } = 1200; # Width of browser image in pixels
166 $cookie->{ 'IMG_HEIGHT' } = 800; # Height of browser image in pixels
167 $cookie->{ 'WIGGLE_HEIGHT' } = 75; # Height of Wiggle tracks in pixels
168 $cookie->{ 'TRACK_OFFSET' } = 20;
169 $cookie->{ 'TRACK_SPACE' } = 20;
170 $cookie->{ 'RULER_FONT_SIZE' } = 10; # Size of ruler font in pixels
171 $cookie->{ 'RULER_COLOR' } = [ 0, 0, 0 ];
172 $cookie->{ 'SEQ_FONT_SIZE' } = 10;
173 $cookie->{ 'SEQ_COLOR' } = [ 0, 0, 0, ];
174 $cookie->{ 'FEAT_WIDTH' } = 5;
175 $cookie->{ 'FEAT_COLOR' } = [ 0, 0, 0 ];
176 $cookie->{ 'FEAT_MAX' } = 5000; # TODO: Reduntant?
178 # $cookie->{ 'LIST_USER' } = Maasha::BGB::Track::list_users(); # TODO: Redundant?
180 if ( $cookie->{ 'USER' } and not $cookie->{ 'LOGIN_ERROR' } )
182 $cookie->{ 'LIST_CLADE' } = Maasha::BGB::Track::list_clades( $cookie->{ 'USER' } );
183 $cookie->{ 'LIST_GENOME' } = Maasha::BGB::Track::list_genomes( $cookie->{ 'USER' }, $cookie->{ 'CLADE' } );
184 $cookie->{ 'LIST_ASSEMBLY' } = Maasha::BGB::Track::list_assemblies( $cookie->{ 'USER' }, $cookie->{ 'CLADE' }, $cookie->{ 'GENOME' } );
185 $cookie->{ 'LIST_CONTIG' } = Maasha::BGB::Track::list_contigs( $cookie->{ 'USER' }, $cookie->{ 'CLADE' }, $cookie->{ 'GENOME' }, $cookie->{ 'ASSEMBLY' } );
187 if ( $cookie->{ 'CONTIG' } )
189 cookie_start( $cookie );
190 cookie_end( $cookie );
191 cookie_zoom( $cookie );
192 cookie_move( $cookie );
193 cookie_center( $cookie );
197 $cookie->{ 'STRAND' } = '+' if defined $cookie->{ 'STRAND' } and $cookie->{ 'STRAND' } eq ' '; # FIXME ugly HTML fix
199 session_store( $cookie, $session );
201 return wantarray ? %{ $cookie } : $cookie;
207 # Martin A. Hansen, March 2010.
209 # Restores session and returns this.
211 my ( $cookie, # cookie hash
218 if ( defined $cookie->{ 'USER' } and -d "$cookie->{ 'SESSION_DIR' }/$cookie->{ 'USER' }" ) {
219 $session = Maasha::BGB::Session::session_restore( "$cookie->{ 'SESSION_DIR' }/$cookie->{ 'USER' }/session.json" );
222 return wantarray ? %{ $session } : $session;
228 # Martin A. Hansen, March 2010.
230 # Store a session updated with cookie information to session file.
232 my ( $cookie, # cookie hash
233 $session, # session hash
240 if ( defined $cookie->{ 'USER' } and $cookie->{ 'USER' } ne '' and -d "$cookie->{ 'SESSION_DIR' }/$cookie->{ 'USER' }" )
242 $new_session->{ 'PASSWORD' } = $session->{ 'PASSWORD' };
243 $new_session->{ 'SESSION_ID' } = $session->{ 'SESSION_ID' };
244 $new_session->{ 'TIME' } = Maasha::Common::time_stamp();
245 $new_session->{ 'PAGE' } = $cookie->{ 'PAGE' };
247 if ( $cookie->{ 'PAGE' } eq 'browse' )
249 $new_session->{ 'CLADE' } = $cookie->{ 'CLADE' };
250 $new_session->{ 'GENOME' } = $cookie->{ 'GENOME' };
251 $new_session->{ 'ASSEMBLY' } = $cookie->{ 'ASSEMBLY' };
252 $new_session->{ 'CONTIG' } = $cookie->{ 'CONTIG' };
253 $new_session->{ 'NAV_START' } = $cookie->{ 'NAV_START' };
254 $new_session->{ 'NAV_END' } = $cookie->{ 'NAV_END' };
256 elsif ( $cookie->{ 'PAGE' } eq 'contig' )
258 $new_session->{ 'CLADE' } = $cookie->{ 'CLADE' };
259 $new_session->{ 'GENOME' } = $cookie->{ 'GENOME' };
260 $new_session->{ 'ASSEMBLY' } = $cookie->{ 'ASSEMBLY' };
262 elsif ( $cookie->{ 'PAGE' } eq 'assembly' )
264 $new_session->{ 'CLADE' } = $cookie->{ 'CLADE' };
265 $new_session->{ 'GENOME' } = $cookie->{ 'GENOME' };
267 elsif ( $cookie->{ 'PAGE' } eq 'genome' )
269 $new_session->{ 'CLADE' } = $cookie->{ 'CLADE' };
271 elsif ( $cookie->{ 'PAGE' } eq 'export' )
273 $new_session->{ 'CLADE' } = $cookie->{ 'CLADE' };
274 $new_session->{ 'GENOME' } = $cookie->{ 'GENOME' };
275 $new_session->{ 'ASSEMBLY' } = $cookie->{ 'ASSEMBLY' };
276 $new_session->{ 'CONTIG' } = $cookie->{ 'CONTIG' };
277 $new_session->{ 'Q_ID' } = $cookie->{ 'Q_ID' };
278 $new_session->{ 'S_BEG' } = $cookie->{ 'S_BEG' };
279 $new_session->{ 'S_END' } = $cookie->{ 'S_END' };
280 $new_session->{ 'STRAND' } = $cookie->{ 'STRAND' };
283 Maasha::BGB::Session::session_store( "$cookie->{ 'SESSION_DIR' }/$cookie->{ 'USER' }/session.json", $new_session );
290 # Martin A. Hansen, March 2010.
292 # Check that the session id in the cookie and session match.
293 # Sets SESSION_ERROR flag in cookie if not matching.
295 my ( $cookie, # cookie hash
296 $session, # session hash
301 if ( defined $cookie->{ 'SESSION_ID' } and defined $session->{ 'SESSION_ID' } )
303 if ( $cookie->{ 'SESSION_ID' } ne $session->{ 'SESSION_ID' } ) {
304 $cookie->{ 'SESSION_ERROR' } = 1;
306 $cookie->{ 'SESSION_ERROR' } = 0;
314 # Martin A. Hansen, December 2009.
316 # Check a user and password from CGI against the password file and
317 # set the session ID, if found, in the cookie.
319 my ( $cookie, # cookie hash
326 if ( defined $cookie->{ 'PASSWORD' } )
328 if ( defined $cookie->{ 'USER' } and -d "$cookie->{ 'SESSION_DIR' }/$cookie->{ 'USER' }" )
330 $session = Maasha::BGB::Session::session_restore( "$cookie->{ 'SESSION_DIR' }/$cookie->{ 'USER' }/session.json" );
332 if ( $session->{ 'PASSWORD' } eq Digest::MD5::md5_hex( $cookie->{ 'PASSWORD' } ) )
334 $cookie->{ 'TIME' } = Maasha::Common::time_stamp();
335 $cookie->{ 'SESSION_ID' } ||= Maasha::BGB::Session::session_new();
336 $cookie->{ 'LOGIN' } = 1;
337 $cookie->{ 'LOGIN_ERROR' } = 0;
341 $cookie->{ 'LOGIN_ERROR' } = 1;
346 $cookie->{ 'LOGIN_ERROR' } = 1;
354 # Martin A. Hansen, November 2009.
356 # Decommify the cookie value for NAV_START and adjust it to
357 # to prevent negative values.
359 my ( $cookie, # cookie hash
364 if ( defined $cookie->{ 'NAV_START' } )
366 $cookie->{ 'NAV_START' } =~ tr/,//d;
367 $cookie->{ 'NAV_START' } = 0 if $cookie->{ 'NAV_START' } < 0;
371 $cookie->{ 'NAV_START' } = 0;
378 # Martin A. Hansen, November 2009.
380 # Decommify the cookie value for NAV_END and adjust it to prevent
381 # overshooting the max value for the contig size as determined
384 my ( $cookie, # cookie hash
391 $max = Maasha::Filesys::file_size( Maasha::BGB::Track::path_seq( $cookie ) );
393 if ( defined $cookie->{ 'NAV_END' } )
395 $cookie->{ 'NAV_END' } =~ tr/,//d;
396 $cookie->{ 'NAV_END' } = $max if $cookie->{ 'NAV_END' } > $max;
400 $cookie->{ 'NAV_END' } = $max;
407 # Martin A. Hansen, November 2009.
409 # Adjust the cookie values for NAV_START and NAV_END based
410 # on cookie ZOOM values.
412 my ( $cookie, # cookie hash
417 my ( $max, $dist, $new_dist, $dist_diff );
419 $max = Maasha::Filesys::file_size( Maasha::BGB::Track::path_seq( $cookie ) );
421 $dist = $cookie->{ 'NAV_END' } - $cookie->{ 'NAV_START' };
423 if ( defined $cookie->{ 'ZOOM_IN1' } ) {
424 $new_dist = $dist / 1.5;
425 } elsif ( defined $cookie->{ 'ZOOM_IN2' } ) {
426 $new_dist = $dist / 3;
427 } elsif ( defined $cookie->{ 'ZOOM_IN3' } ) {
428 $new_dist = $dist / 10;
429 } elsif ( defined $cookie->{ 'ZOOM_OUT1' } ) {
430 $new_dist = $dist * 1.5;
431 } elsif ( defined $cookie->{ 'ZOOM_OUT2' } ) {
432 $new_dist = $dist * 3;
433 } elsif ( defined $cookie->{ 'ZOOM_OUT3' } ) {
434 $new_dist = $dist * 10;
439 $dist_diff = $dist - $new_dist;
441 $cookie->{ 'NAV_START' } = int( $cookie->{ 'NAV_START' } + ( $dist_diff / 2 ) );
442 $cookie->{ 'NAV_END' } = int( $cookie->{ 'NAV_END' } - ( $dist_diff / 2 ) );
444 $cookie->{ 'NAV_START' } = 0 if $cookie->{ 'NAV_START' } < 0;
445 $cookie->{ 'NAV_END' } = $max if $cookie->{ 'NAV_END' } > $max;
452 # Martin A. Hansen, November 2009.
454 # Adjust the cookie values for NAV_START and NAV_END based
455 # on cookie MOVE values.
457 my ( $cookie, # cookie hash
462 my ( $max, $dist, $shift, $new_start, $new_end );
464 $max = Maasha::Filesys::file_size( Maasha::BGB::Track::path_seq( $cookie ) );
466 $dist = $cookie->{ 'NAV_END' } - $cookie->{ 'NAV_START' };
468 if ( defined $cookie->{ 'MOVE_LEFT1' } ) {
469 $shift = -1 * $dist * 0.10;
470 } elsif ( defined $cookie->{ 'MOVE_LEFT2' } ) {
471 $shift = -1 * $dist * 0.475;
472 } elsif ( defined $cookie->{ 'MOVE_LEFT3' } ) {
473 $shift = -1 * $dist * 0.95;
474 } elsif ( defined $cookie->{ 'MOVE_RIGHT1' } ) {
475 $shift = $dist * 0.10;
476 } elsif ( defined $cookie->{ 'MOVE_RIGHT2' } ) {
477 $shift = $dist * 0.475;
478 } elsif ( defined $cookie->{ 'MOVE_RIGHT3' } ) {
479 $shift = $dist * 0.95;
484 $new_start = int( $cookie->{ 'NAV_START' } + $shift );
485 $new_end = int( $cookie->{ 'NAV_END' } + $shift );
487 if ( $new_start > 0 and $new_end < $max )
489 $cookie->{ 'NAV_START' } = $new_start;
490 $cookie->{ 'NAV_END' } = $new_end;
498 # Martin A. Hansen, March 2010
500 # Adjust the cookie values for NAV_START and NAV_END based
501 # on cookie CENTER value if defined.
503 my ( $cookie, # cookie hash
508 my ( $l_dist, $r_dist );
510 if ( defined $cookie->{ 'NAV_CENTER' } )
512 $l_dist = $cookie->{ 'NAV_CENTER' } - $cookie->{ 'NAV_START' };
513 $r_dist = $cookie->{ 'NAV_END' } - $cookie->{ 'NAV_CENTER' };
515 if ( $l_dist > $r_dist ) {
516 $cookie->{ 'NAV_START' } = $cookie->{ 'NAV_END' } - 2 * $r_dist;
518 $cookie->{ 'NAV_END' } = $cookie->{ 'NAV_START' } + 2 * $l_dist;
524 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> PAGES <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
529 # Martin A. Hansen, November 2009.
531 # Determines what page to render based on
532 # the cookie's PAGE setting.
534 my ( $cookie, # cookie hash
541 if ( $cookie->{ 'SESSION_ID' } ) {
542 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "session_id", value => $cookie->{ 'SESSION_ID' } ) );
545 if ( $cookie->{ 'PAGE' } eq 'login' ) {
546 push @html, page_login( $cookie );
547 } elsif ( $cookie->{ 'PAGE' } eq 'search' ) {
548 push @html, page_search( $cookie );
549 } elsif ( $cookie->{ 'PAGE' } eq 'browse' ) {
550 push @html, page_browse( $cookie );
551 } elsif ( $cookie->{ 'PAGE' } eq 'dna' ) {
552 push @html, page_dna( $cookie );
553 } elsif ( $cookie->{ 'PAGE' } eq 'export' ) {
554 push @html, page_export( $cookie );
555 } elsif ( $cookie->{ 'PAGE' } eq 'clade' ) {
556 push @html, page_clade( $cookie );
557 } elsif ( $cookie->{ 'PAGE' } eq 'genome' ) {
558 push @html, page_genome( $cookie );
559 } elsif ( $cookie->{ 'PAGE' } eq 'assembly' ) {
560 push @html, page_assembly( $cookie );
561 } elsif ( $cookie->{ 'PAGE' } eq 'contig' ) {
562 push @html, page_contig( $cookie );
565 return wantarray ? @html : \@html;
571 # Martin A. Hansen, December 2009.
573 # Renders the login page.
582 push @html, section_login( $cookie );
584 return wantarray ? @html : \@html;
590 # Martin A. Hansen, December 2009.
592 # Renders the search page.
601 push @html, section_taxonomy_table( $cookie );
602 push @html, section_search( $cookie );
604 return wantarray ? @html : \@html;
610 # Martin A. Hansen, November 2009.
612 # Renders the browse page.
621 push @html, section_taxonomy_table( $cookie );
622 push @html, section_navigate( $cookie );
623 push @html, section_browse( $cookie );
624 push @html, section_linkout( $cookie );
626 return wantarray ? @html : \@html;
632 # Martin A. Hansen, November 2009.
634 # Renders the DNA page.
643 push @html, section_taxonomy_table( $cookie );
644 push @html, section_dna( $cookie );
646 return wantarray ? @html : \@html;
652 # Martin A. Hansen, November 2009.
654 # Renders the export page.
663 push @html, section_taxonomy_table( $cookie );
664 push @html, section_export( $cookie );
666 return wantarray ? @html : \@html;
672 # Martin A. Hansen, March 2010.
674 # Renders the clade selection page.
676 my ( $cookie, # cookie hash
683 push @html, section_taxonomy_table( $cookie );
684 push @html, section_clade( $cookie );
686 return wantarray ? @html : \@html;
692 # Martin A. Hansen, March 2010.
694 # Renders the genome selection page.
696 my ( $cookie, # cookie hash
703 push @html, section_taxonomy_table( $cookie );
704 push @html, section_genome( $cookie );
706 return wantarray ? @html : \@html;
712 # Martin A. Hansen, March 2010.
714 # Renders the clade selection page.
716 my ( $cookie, # cookie hash
723 push @html, section_taxonomy_table( $cookie );
724 push @html, section_assembly( $cookie );
726 return wantarray ? @html : \@html;
732 # Martin A. Hansen, November 2009.
734 # Renders the browse page.
736 my ( $cookie, # cookie hash
743 push @html, section_taxonomy_table( $cookie );
744 push @html, section_contig( $cookie );
746 return wantarray ? @html : \@html;
750 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> SECTIONS <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
755 # Martin A. Hansen, December 2009.
757 # Returns a HTML section with a login menu.
759 my ( $cookie, # cookie hash
764 my ( $user, $password, $login, @html );
766 $user = Maasha::XHTML::text( name => "user", value => "", size => 20 );
767 $password = Maasha::XHTML::password( name => "password", value => "", size => 20 );
768 $login = Maasha::XHTML::submit( name => "login_submit", value => "Login" );
770 push @html, Maasha::XHTML::h2( txt => "Login", class => 'center' );
772 push @html, Maasha::XHTML::table_beg( summary => "Login table", align => 'center' );
773 push @html, Maasha::XHTML::table_row_simple( tr => [ "User:", $user ] );
774 push @html, Maasha::XHTML::table_row_simple( tr => [ "Password:", $password ] );
775 push @html, Maasha::XHTML::table_row_simple( tr => [ "", $login ] );
776 push @html, Maasha::XHTML::table_end;
778 if ( defined $cookie->{ 'CLADE' } and
779 defined $cookie->{ 'GENOME' } and
780 defined $cookie->{ 'ASSEMBLY' } and
781 defined $cookie->{ 'CONTIG' } and
782 defined $cookie->{ 'NAV_START' } and
783 defined $cookie->{ 'NAV_END' }
786 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "clade", value => $cookie->{ 'CLADE' } ) );
787 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "genome", value => $cookie->{ 'GENOME' } ) );
788 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "assembly", value => $cookie->{ 'ASSEMBLY' } ) );
789 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "contig", value => $cookie->{ 'CONTIG' } ) );
790 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "nav_start", value => $cookie->{ 'NAV_START' } ) );
791 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "nav_end", value => $cookie->{ 'NAV_END' } ) );
794 if ( $cookie->{ 'LOGIN_ERROR' } ) {
795 push @html, Maasha::XHTML::h3( txt => "Bad user or password - please retry", class => 'error' );
798 return wantarray ? @html : \@html;
802 sub section_taxonomy_table
804 # Martin A. Hansen, November 2009.
806 # Returns a HTML section with a taxonomy table
807 # showing the location in the taxonomy and with
808 # links to browse the taxonomy.
810 my ( $cookie, # cookie hash
815 my ( $page, @row, @html, $href, $txt );
817 foreach $page ( @{ $cookie->{ 'LIST_PAGES' } } )
819 last if $page eq $cookie->{ 'PAGE' } or $page eq 'browse';
821 $href = "$cookie->{ 'SCRIPT' }?page=$page";
822 $href .= "&session_id=$cookie->{ 'SESSION_ID' }";
823 $href .= "&user=$cookie->{ 'USER' }";
824 $href .= "&clade=$cookie->{ 'CLADE' }" if $page !~ /clade/;
825 $href .= "&genome=$cookie->{ 'GENOME' }" if $page !~ /clade|genome/;
826 $href .= "&assembly=$cookie->{ 'ASSEMBLY' }" if $page !~ /clade|genome|assembly/;
827 $href .= "&contig=$cookie->{ 'CONTIG' }" if $page !~ /clade|genome|assembly|contig/;
829 $txt = ": $cookie->{ uc $page }";
831 push @row, Maasha::XHTML::ln( txt => $page, href => $href, class => 'inline' );
832 push @row, Maasha::XHTML::p( txt => $txt, class => 'inline' );
835 push @html, Maasha::XHTML::table_beg( summary => "Taxonomy table", align => 'center', cellpadding => '5px' );
836 push @html, Maasha::XHTML::table_row_simple( tr => [ join( "\n", @row ) ], align => 'center' );
837 push @html, Maasha::XHTML::table_end;
839 return wantarray ? @html : \@html;
845 # Martin A. Hansen, March 2010.
847 # Returns a HTML section with clade selection choices
848 # for navigating the taxonomy tree.
850 my ( $cookie, # cookie hash
855 my ( @html, $clade, $href );
857 push @html, Maasha::XHTML::h2( txt => "Select clade", class => 'center' );
859 push @html, Maasha::XHTML::table_beg( summary => "Taxonomy select table", align => 'center', cellpadding => '5px' );
861 foreach $clade ( @{ $cookie->{ 'LIST_CLADE' } } )
863 $href = "$cookie->{ 'SCRIPT' }?page=genome";
864 $href .= "&session_id=$cookie->{ 'SESSION_ID' }";
865 $href .= "&user=$cookie->{ 'USER' }";
866 $href .= "&clade=$clade";
868 push @html, Maasha::XHTML::table_row_simple( tr => [ Maasha::XHTML::ln( txt => $clade, href => $href ) ] );
871 push @html, Maasha::XHTML::table_end;
873 return wantarray ? @html : \@html;
879 # Martin A. Hansen, March 2010.
881 # Returns a HTML section with genome selection choices
882 # for navigating the taxonomy tree.
884 my ( $cookie, # cookie hash
889 my ( @html, $genome, $href );
891 push @html, Maasha::XHTML::h2( txt => "Select genome", class => 'center' );
893 push @html, Maasha::XHTML::table_beg( summary => "Taxonomy select table", align => 'center', cellpadding => '5px' );
895 foreach $genome ( @{ $cookie->{ 'LIST_GENOME' } } )
897 $href = "$cookie->{ 'SCRIPT' }?page=assembly";
898 $href .= "&session_id=$cookie->{ 'SESSION_ID' }";
899 $href .= "&user=$cookie->{ 'USER' }";
900 $href .= "&clade=$cookie->{ 'CLADE' }";
901 $href .= "&genome=$genome";
903 push @html, Maasha::XHTML::table_row_simple( tr => [ Maasha::XHTML::ln( txt => $genome, href => $href ) ] );
906 push @html, Maasha::XHTML::table_end;
908 return wantarray ? @html : \@html;
914 # Martin A. Hansen, March 2010.
916 # Returns a HTML section with assembly selection choices
917 # for navigating the taxonomy tree.
919 my ( $cookie, # cookie hash
924 my ( @html, $assembly, $href );
926 push @html, Maasha::XHTML::h2( txt => "Select assembly", class => 'center' );
928 push @html, Maasha::XHTML::table_beg( summary => "Taxonomy select table", align => 'center', cellpadding => '5px' );
930 foreach $assembly ( @{ $cookie->{ 'LIST_ASSEMBLY' } } )
932 $href = "$cookie->{ 'SCRIPT' }?page=contig";
933 $href .= "&session_id=$cookie->{ 'SESSION_ID' }";
934 $href .= "&user=$cookie->{ 'USER' }";
935 $href .= "&clade=$cookie->{ 'CLADE' }";
936 $href .= "&genome=$cookie->{ 'GENOME' }";
937 $href .= "&assembly=$assembly";
939 push @html, Maasha::XHTML::table_row_simple( tr => [ Maasha::XHTML::ln( txt => $assembly, href => $href ) ] );
942 push @html, Maasha::XHTML::table_end;
944 return wantarray ? @html : \@html;
950 # Martin A. Hansen, March 2010.
952 # Returns a HTML section with contig selection choices
953 # for navigating the taxonomy tree.
955 my ( $cookie, # cookie hash
960 my ( @html, $contig, $href );
962 push @html, Maasha::XHTML::h2( txt => "Select contig", class => 'center' );
964 push @html, Maasha::XHTML::table_beg( summary => "Taxonomy select table", align => 'center', cellpadding => '5px' );
966 foreach $contig ( @{ $cookie->{ 'LIST_CONTIG' } } )
968 $href = "$cookie->{ 'SCRIPT' }?page=browse";
969 $href .= "&session_id=$cookie->{ 'SESSION_ID' }";
970 $href .= "&user=$cookie->{ 'USER' }";
971 $href .= "&clade=$cookie->{ 'CLADE' }";
972 $href .= "&genome=$cookie->{ 'GENOME' }";
973 $href .= "&assembly=$cookie->{ 'ASSEMBLY' }";
974 $href .= "&contig=$contig";
976 push @html, Maasha::XHTML::table_row_simple( tr => [ Maasha::XHTML::ln( txt => $contig, href => $href ) ] );
979 push @html, Maasha::XHTML::table_end;
981 return wantarray ? @html : \@html;
987 # Martin A. Hansen, November 2009.
989 # Returns a HTML section for navigating in the browser window.
991 my ( $cookie, # cookie hash
996 my ( @html, $nav_val );
998 $nav_val = Maasha::Calc::commify( $cookie->{ 'NAV_START' } ) . "-" . Maasha::Calc::commify( $cookie->{ 'NAV_END' } );
1000 push @html, Maasha::XHTML::table_beg( summary => "Navigation table", align => 'center' );
1001 push @html, Maasha::XHTML::table_row_simple( tr => [
1002 "Position or search term:",
1003 Maasha::XHTML::text( name => "nav_search", value => $nav_val, size => 30 ),
1004 Maasha::XHTML::submit( name => "nav_submit", value => "Submit" ),
1006 push @html, Maasha::XHTML::table_end;
1008 push @html, Maasha::XHTML::table_beg( summary => "Zoom table", align => 'center' );
1009 push @html, Maasha::XHTML::table_row_simple( tr => [
1010 Maasha::XHTML::p( txt => 'Move:' ),
1011 Maasha::XHTML::submit( name => "move_left3", value => "<<<", title => "move 95% to the left" ),
1012 Maasha::XHTML::submit( name => "move_left2", value => "<<", title => "move 47.5% to the left" ),
1013 Maasha::XHTML::submit( name => "move_left1", value => "<", title => "move 10% to the left" ),
1014 Maasha::XHTML::submit( name => "move_right1", value => ">", title => "move 10% to the rigth" ),
1015 Maasha::XHTML::submit( name => "move_right2", value => ">>", title => "move 47.5% to the rigth" ),
1016 Maasha::XHTML::submit( name => "move_right3", value => ">>>", title => "move 95% to the right" ),
1017 Maasha::XHTML::p( txt => 'Zoom in:' ),
1018 Maasha::XHTML::submit( name => "zoom_in1", value => "1.5x" ),
1019 Maasha::XHTML::submit( name => "zoom_in2", value => "3x" ),
1020 Maasha::XHTML::submit( name => "zoom_in3", value => "10x" ),
1021 Maasha::XHTML::p( txt => 'Zoom out:' ),
1022 Maasha::XHTML::submit( name => "zoom_out1", value => "1.5x" ),
1023 Maasha::XHTML::submit( name => "zoom_out2", value => "3x" ),
1024 Maasha::XHTML::submit( name => "zoom_out3", value => "10x" ),
1026 push @html, Maasha::XHTML::table_end;
1028 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "page", value => "browse" ) );
1029 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "user", value => $cookie->{ 'USER' } ) );
1030 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "clade", value => $cookie->{ 'CLADE' } ) );
1031 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "genome", value => $cookie->{ 'GENOME' } ) );
1032 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "assembly", value => $cookie->{ 'ASSEMBLY' } ) );
1033 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "contig", value => $cookie->{ 'CONTIG' } ) );
1035 return wantarray ? @html : \@html;
1041 # Martin A. Hansen, March 2010.
1043 # Returns a HTML section for a static link based on information in the cookie.
1045 my ( $cookie, # cookie hash
1050 my ( $link, @html );
1052 $link = Maasha::XHTML::ln(
1054 href => join( "&", "$cookie->{ 'SCRIPT' }?page=browse",
1055 "clade=$cookie->{ 'CLADE' }",
1056 "genome=$cookie->{ 'GENOME' }",
1057 "assembly=$cookie->{ 'ASSEMBLY' }",
1058 "contig=$cookie->{ 'CONTIG' }",
1059 "nav_start=$cookie->{ 'NAV_START' }",
1060 "nav_end=$cookie->{ 'NAV_END' }",
1062 title => "Static link to this view",
1065 push @html, Maasha::XHTML::p( txt => $link, class => 'center' );
1067 return wantarray ? @html : \@html;
1078 my ( @tracks, $i, @features, $feat, $elem, $surface, $cr, $png_data, @html, @img, $x1, $y1, $x2, $y2, $factor, $center );
1080 push @features, [ Maasha::BGB::Track::track_ruler( $cookie ) ];
1081 push @features, [ Maasha::BGB::Track::track_seq( $cookie ) ];
1083 @tracks = Maasha::BGB::Track::path_tracks( $cookie );
1085 for ( $i = 0; $i < @tracks; $i++ )
1087 $cookie->{ 'FEAT_COLOR' } = Maasha::BGB::Draw::palette( $i );
1089 push @features, [ Maasha::BGB::Track::track_feature( $tracks[ $i ], $cookie ) ];
1092 $surface = Cairo::ImageSurface->create( 'argb32', $cookie->{ 'IMG_WIDTH' }, $cookie->{ 'TRACK_OFFSET' } );
1093 $cr = Cairo::Context->create( $surface );
1095 $cr->rectangle ( 0, 0, $cookie->{ 'IMG_WIDTH' }, $cookie->{ 'TRACK_OFFSET' } );
1096 $cr->set_source_rgb ( 1, 1, 1 );
1099 foreach $feat ( @features ) {
1100 Maasha::BGB::Draw::draw_feature( $cr, $feat ) if $feat;
1103 $png_data = Maasha::BGB::Draw::base64_png( $surface );
1105 push @img, Maasha::XHTML::img(
1106 src => "data:image/png;base64,$png_data",
1107 alt => "Browser Tracks",
1108 height => $cookie->{ 'TRACK_OFFSET' },
1109 width => $cookie->{ 'IMG_WIDTH' },
1110 id => "browser_map",
1111 usemap => "#browser_map"
1114 push @img, Maasha::XHTML::map_beg( name => "browser_map", id => "browser_map" );
1116 $factor = ( $cookie->{ 'NAV_END' } - $cookie->{ 'NAV_START' } + 1 ) / $cookie->{ 'IMG_WIDTH' };
1118 for ( $i = 0; $i < $cookie->{ 'IMG_WIDTH' }; $i += 5 )
1125 $center = int( $cookie->{ 'NAV_START' } + $factor * $i );
1127 push @img, Maasha::XHTML::area(
1128 href => join( "&", "$cookie->{ 'SCRIPT' }?page=browse",
1129 "session_id=$cookie->{ 'SESSION_ID' }",
1130 "user=$cookie->{ 'USER' }",
1131 "clade=$cookie->{ 'CLADE' }",
1132 "genome=$cookie->{ 'GENOME' }",
1133 "assembly=$cookie->{ 'ASSEMBLY' }",
1134 "contig=$cookie->{ 'CONTIG' }",
1135 "nav_start=$cookie->{ 'NAV_START' }",
1136 "nav_end=$cookie->{ 'NAV_END' }",
1137 "nav_center=$center",
1140 coords => "$x1, $y1, $x2, $y2",
1141 title => "Center on " . Maasha::Calc::commify( $center ),
1145 foreach $feat ( @features )
1147 foreach $elem ( @{ $feat } )
1149 next if $elem->{ 'type' } eq 'text';
1150 next if $elem->{ 'type' } eq 'wiggle';
1152 #$elem->{ 'strand' } = '+' if $elem->{ 'strand' } eq '+';
1154 $cookie->{ 'Q_ID' } = $elem->{ 'q_id' };
1155 $cookie->{ 'S_BEG' } = $elem->{ 's_beg' };
1156 $cookie->{ 'S_END' } = $elem->{ 's_end' };
1157 $cookie->{ 'STRAND' } = $elem->{ 'strand' };
1159 push @img, Maasha::XHTML::area(
1160 href => join( "&", "$cookie->{ 'SCRIPT' }?page=export",
1161 "session_id=$cookie->{ 'SESSION_ID' }",
1162 "user=$cookie->{ 'USER' }",
1163 "clade=$cookie->{ 'CLADE' }",
1164 "genome=$cookie->{ 'GENOME' }",
1165 "assembly=$cookie->{ 'ASSEMBLY' }",
1166 "contig=$cookie->{ 'CONTIG' }",
1167 "s_beg=$cookie->{ 'S_BEG' }",
1168 "s_end=$cookie->{ 'S_END' }",
1169 "strand=$cookie->{ 'STRAND' }",
1172 coords => "$elem->{ x1 }, $elem->{ y1 }, $elem->{ x2 }, $elem->{ y2 }",
1173 title => "$elem->{ 'title' }",
1178 push @img, Maasha::XHTML::map_end();
1180 push @html, Maasha::XHTML::p( txt => join( "\n", @img ) );
1182 @html = Maasha::XHTML::div( txt => join( "\n", @html ), class => 'browse' );
1184 return wantarray ? @html : \@html;
1190 # Martin A. Hansen, November 2009.
1192 # Returns a HTML section with export table.
1194 my ( $cookie, # cookie hash
1199 my ( $feat, @row_dna_contig, @html );
1201 $feat = $cookie->{ 'Q_ID' } || "[no name]";
1203 push @row_dna_contig, Maasha::XHTML::p( txt => qq(Export Feature: "$feat" DNA from Contig: ), class => 'inline' );
1204 push @row_dna_contig, Maasha::XHTML::p( txt => "$cookie->{ 'CONTIG' } Start: ", class => 'inline' );
1205 push @row_dna_contig, Maasha::XHTML::text( name => "s_beg", value => Maasha::Calc::commify( $cookie->{ 'S_BEG' } ), size => 15 );
1206 push @row_dna_contig, Maasha::XHTML::p( txt => "End: ", class => 'inline' );
1207 push @row_dna_contig, Maasha::XHTML::text( name => "s_end", value => Maasha::Calc::commify( $cookie->{ 'S_END' } ), size => 15 );
1208 push @row_dna_contig, Maasha::XHTML::p( txt => "Strand: ", class => 'inline' );
1209 push @row_dna_contig, Maasha::XHTML::menu( name => "strand", options => [ qw( + - ) ], selected => $cookie->{ 'STRAND' } );
1210 push @row_dna_contig, Maasha::XHTML::submit( name => "export", value => "Export", title => "Fetch DNA from this region" );
1212 push @html, Maasha::XHTML::h2( txt => "Export", class => 'center' );
1213 push @html, Maasha::XHTML::table_beg( summary => "Taxonomy select table", align => 'center' );
1214 push @html, Maasha::XHTML::table_row_simple( tr => \@row_dna_contig );
1215 push @html, Maasha::XHTML::table_end;
1217 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "page", value => "dna" ) );
1218 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "user", value => $cookie->{ 'USER' } ) );
1219 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "clade", value => $cookie->{ 'CLADE' } ) );
1220 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "genome", value => $cookie->{ 'GENOME' } ) );
1221 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "assembly", value => $cookie->{ 'ASSEMBLY' } ) );
1222 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "contig", value => $cookie->{ 'CONTIG' } ) );
1224 return wantarray ? @html : \@html;
1230 # Martin A. Hansen, November 2009.
1232 # Returns a HTML section with export table.
1234 my ( $cookie, # cookie hash
1239 my ( $results, $result, $count, @html, $export, $browse );
1241 $results = Maasha::BGB::Track::search_tracks( $cookie );
1243 $count = scalar @{ $results };
1245 push @html, Maasha::XHTML::h2( txt => "Search", class => 'center' );
1246 push @html, Maasha::XHTML::p( txt => qq(Results for "$cookie->{ 'SEARCH' }": $count), class => 'center' );
1250 push @html, Maasha::XHTML::table_beg( summary => "Search table", align => 'center', cellpadding => '5px' );
1251 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) ] );
1253 foreach $result ( @{ $results } )
1255 $cookie->{ 'CONTIG' } = $result->{ 'S_ID' };
1256 $cookie->{ 'NAV_START' } = $result->{ 'S_BEG' };
1257 $cookie->{ 'NAV_END' } = $result->{ 'S_END' };
1258 $cookie->{ 'S_BEG' } = $result->{ 'S_BEG' };
1259 $cookie->{ 'S_END' } = $result->{ 'S_END' };
1260 $cookie->{ 'STRAND' } = $result->{ 'STRAND' };
1261 $cookie->{ 'Q_ID' } = $result->{ 'Q_ID' };
1263 $browse = Maasha::XHTML::ln(
1265 href => join( "&", "$cookie->{ 'SCRIPT' }?page=browse",
1266 "session_id=$cookie->{ 'SESSION_ID' }",
1267 "user=$cookie->{ 'USER' }",
1268 "clade=$cookie->{ 'CLADE' }",
1269 "genome=$cookie->{ 'GENOME' }",
1270 "assembly=$cookie->{ 'ASSEMBLY' }",
1271 "contig=$cookie->{ 'CONTIG' }",
1272 "nav_start=$cookie->{ 'NAV_START' }",
1273 "nav_end=$cookie->{ 'NAV_END' }",
1278 $export = Maasha::XHTML::ln(
1280 href => join( "&", "$cookie->{ 'SCRIPT' }?page=export",
1281 "session_id=$cookie->{ 'SESSION_ID' }",
1282 "user=$cookie->{ 'USER' }",
1283 "clade=$cookie->{ 'CLADE' }",
1284 "genome=$cookie->{ 'GENOME' }",
1285 "assembly=$cookie->{ 'ASSEMBLY' }",
1286 "contig=$cookie->{ 'CONTIG' }",
1287 "s_beg=$cookie->{ 'S_BEG' }",
1288 "s_end=$cookie->{ 'S_END' }",
1289 "strand=$cookie->{ 'STRAND' }",
1293 push @html, Maasha::XHTML::table_row_advanced(
1294 tr => [ { td => $result->{ 'S_ID' } },
1295 { td => $result->{ 'S_BEG' }, align => 'right' },
1296 { td => $result->{ 'S_END' }, align => 'right' },
1297 { td => $result->{ 'Q_ID' } },
1298 { td => $result->{ 'SCORE' }, align => 'right' },
1299 { td => $result->{ 'STRAND' } },
1300 { td => $result->{ 'HITS' }, align => 'right' },
1301 { td => $result->{ 'ALIGN' } },
1302 { td => $result->{ 'BLOCK_COUNT' }, align => 'right' },
1303 { td => $result->{ 'BLOCK_BEGS' } },
1304 { td => $result->{ 'BLOCK_LENS' } },
1305 { td => $result->{ 'BLOCK_TYPE' } },
1308 ], class => "monospace"
1312 push @html, Maasha::XHTML::table_end;
1315 return wantarray ? @html : \@html;
1321 # Martin A. Hansen, November 2009.
1323 # Returns a HTML section with extracted DNA.
1325 my ( $cookie, # cookie hash
1330 my ( @html, $beg, $end, $seq );
1332 $beg = $cookie->{ 'S_BEG' };
1333 $end = $cookie->{ 'S_END' };
1337 $seq = join ";", ">$cookie->{ 'GENOME' }", $cookie->{ 'ASSEMBLY' }, $cookie->{ 'CONTIG' }, $beg, $end, "$cookie->{ 'STRAND' }\n";
1338 $seq .= Maasha::BGB::Track::dna_get( $cookie );
1340 push @html, Maasha::XHTML::h2( txt => "DNA", class => 'center' );
1341 push @html, Maasha::XHTML::pre( txt => $seq );
1343 return wantarray ? @html : \@html;
1347 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<