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->{ 'TRACK_STATUS' } = $session->{ 'TRACK_STATUS' };
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' } ||= defined $cgi->param( 'nav_end' ) ? $cgi->param( 'nav_end' ) : $session->{ 'NAV_END' };
149 $cookie->{ 'NAV_CENTER' } = $cgi->param( 'nav_center' );
150 $cookie->{ 'S_BEG' } = defined $cgi->param( 's_beg' ) ? $cgi->param( 's_beg' ) : $session->{ 'S_BEG' };
151 $cookie->{ 'S_END' } = defined $cgi->param( 's_end' ) ? $cgi->param( 's_end' ) : $session->{ 'S_END' };
152 $cookie->{ 'STRAND' } = $cgi->param( 'strand' ) || $session->{ 'STRAND' };
153 $cookie->{ 'TRACK' } = $cgi->param( 'track' );
154 $cookie->{ 'ZOOM_IN1' } = $cgi->param( 'zoom_in1' );
155 $cookie->{ 'ZOOM_IN2' } = $cgi->param( 'zoom_in2' );
156 $cookie->{ 'ZOOM_IN3' } = $cgi->param( 'zoom_in3' );
157 $cookie->{ 'ZOOM_OUT1' } = $cgi->param( 'zoom_out1' );
158 $cookie->{ 'ZOOM_OUT2' } = $cgi->param( 'zoom_out2' );
159 $cookie->{ 'ZOOM_OUT3' } = $cgi->param( 'zoom_out3' );
160 $cookie->{ 'MOVE_LEFT1' } = $cgi->param( 'move_left1' );
161 $cookie->{ 'MOVE_LEFT2' } = $cgi->param( 'move_left2' );
162 $cookie->{ 'MOVE_LEFT3' } = $cgi->param( 'move_left3' );
163 $cookie->{ 'MOVE_RIGHT1' } = $cgi->param( 'move_right1' );
164 $cookie->{ 'MOVE_RIGHT2' } = $cgi->param( 'move_right2' );
165 $cookie->{ 'MOVE_RIGHT3' } = $cgi->param( 'move_right3' );
167 $cookie->{ 'IMG_WIDTH' } = 1200; # Width of browser image in pixels
168 $cookie->{ 'IMG_HEIGHT' } = 800; # Height of browser image in pixels # TODO: Redundant?
169 $cookie->{ 'WIGGLE_HEIGHT' } = 75; # Height of Wiggle tracks in pixels
170 $cookie->{ 'TRACK_OFFSET' } = 20;
171 $cookie->{ 'TRACK_SPACE' } = 20;
172 $cookie->{ 'RULER_FONT_SIZE' } = 10; # Size of ruler font in pixels
173 $cookie->{ 'RULER_COLOR' } = [ 0, 0, 0 ];
174 $cookie->{ 'SEQ_FONT_SIZE' } = 10;
175 $cookie->{ 'SEQ_COLOR' } = [ 0, 0, 0, ];
176 $cookie->{ 'FEAT_WIDTH' } = 5;
177 $cookie->{ 'FEAT_COLOR' } = [ 0, 0, 0 ];
178 # $cookie->{ 'FEAT_MAX' } = 5000; # TODO: Reduntant?
180 # $cookie->{ 'LIST_USER' } = Maasha::BGB::Track::list_users(); # TODO: Redundant?
182 if ( $cookie->{ 'USER' } and not $cookie->{ 'LOGIN_ERROR' } )
184 $cookie->{ 'LIST_CLADE' } = Maasha::BGB::Track::list_clades( $cookie->{ 'USER' } );
185 $cookie->{ 'LIST_GENOME' } = Maasha::BGB::Track::list_genomes( $cookie->{ 'USER' }, $cookie->{ 'CLADE' } );
186 $cookie->{ 'LIST_ASSEMBLY' } = Maasha::BGB::Track::list_assemblies( $cookie->{ 'USER' }, $cookie->{ 'CLADE' }, $cookie->{ 'GENOME' } );
187 $cookie->{ 'LIST_CONTIG' } = Maasha::BGB::Track::list_contigs( $cookie->{ 'USER' }, $cookie->{ 'CLADE' }, $cookie->{ 'GENOME' }, $cookie->{ 'ASSEMBLY' } );
189 if ( $cookie->{ 'CONTIG' } )
191 cookie_start( $cookie );
192 cookie_end( $cookie );
193 cookie_zoom( $cookie );
194 cookie_move( $cookie );
195 cookie_center( $cookie );
196 cookie_track_status( $cookie );
200 $cookie->{ 'STRAND' } = '+' if defined $cookie->{ 'STRAND' } and $cookie->{ 'STRAND' } eq ' '; # FIXME ugly HTML fix
202 session_store( $cookie, $session );
204 return wantarray ? %{ $cookie } : $cookie;
210 # Martin A. Hansen, March 2010.
212 # Restores session and returns this.
214 my ( $cookie, # cookie hash
221 if ( defined $cookie->{ 'USER' } and -d "$cookie->{ 'SESSION_DIR' }/$cookie->{ 'USER' }" ) {
222 $session = Maasha::BGB::Session::session_restore( "$cookie->{ 'SESSION_DIR' }/$cookie->{ 'USER' }/session.json" );
225 return wantarray ? %{ $session } : $session;
231 # Martin A. Hansen, March 2010.
233 # Store a session updated with cookie information to session file.
235 my ( $cookie, # cookie hash
236 $session, # session hash
243 if ( defined $cookie->{ 'USER' } and $cookie->{ 'USER' } ne '' and -d "$cookie->{ 'SESSION_DIR' }/$cookie->{ 'USER' }" )
245 $new_session->{ 'PASSWORD' } = $session->{ 'PASSWORD' };
246 $new_session->{ 'SESSION_ID' } = $session->{ 'SESSION_ID' };
247 $new_session->{ 'TIME' } = Maasha::Common::time_stamp();
248 $new_session->{ 'PAGE' } = $cookie->{ 'PAGE' };
250 if ( $cookie->{ 'PAGE' } =~ /browse|export_pdf|export_svg/ )
252 $new_session->{ 'CLADE' } = $cookie->{ 'CLADE' };
253 $new_session->{ 'GENOME' } = $cookie->{ 'GENOME' };
254 $new_session->{ 'ASSEMBLY' } = $cookie->{ 'ASSEMBLY' };
255 $new_session->{ 'CONTIG' } = $cookie->{ 'CONTIG' };
256 $new_session->{ 'NAV_START' } = $cookie->{ 'NAV_START' };
257 $new_session->{ 'NAV_END' } = $cookie->{ 'NAV_END' };
259 elsif ( $cookie->{ 'PAGE' } eq 'contig' )
261 $new_session->{ 'CLADE' } = $cookie->{ 'CLADE' };
262 $new_session->{ 'GENOME' } = $cookie->{ 'GENOME' };
263 $new_session->{ 'ASSEMBLY' } = $cookie->{ 'ASSEMBLY' };
265 elsif ( $cookie->{ 'PAGE' } eq 'assembly' )
267 $new_session->{ 'CLADE' } = $cookie->{ 'CLADE' };
268 $new_session->{ 'GENOME' } = $cookie->{ 'GENOME' };
270 elsif ( $cookie->{ 'PAGE' } eq 'genome' )
272 $new_session->{ 'CLADE' } = $cookie->{ 'CLADE' };
274 elsif ( $cookie->{ 'PAGE' } =~ /export|dna/ )
276 $new_session->{ 'CLADE' } = $cookie->{ 'CLADE' };
277 $new_session->{ 'GENOME' } = $cookie->{ 'GENOME' };
278 $new_session->{ 'ASSEMBLY' } = $cookie->{ 'ASSEMBLY' };
279 $new_session->{ 'CONTIG' } = $cookie->{ 'CONTIG' };
280 $new_session->{ 'Q_ID' } = $cookie->{ 'Q_ID' };
281 $new_session->{ 'S_BEG' } = $cookie->{ 'S_BEG' };
282 $new_session->{ 'S_END' } = $cookie->{ 'S_END' };
283 $new_session->{ 'STRAND' } = $cookie->{ 'STRAND' };
286 $new_session->{ 'TRACK_STATUS' } = $cookie->{ 'TRACK_STATUS' };
288 Maasha::BGB::Session::session_store( "$cookie->{ 'SESSION_DIR' }/$cookie->{ 'USER' }/session.json", $new_session );
295 # Martin A. Hansen, March 2010.
297 # Check that the session id in the cookie and session match.
298 # Sets SESSION_ERROR flag in cookie if not matching.
300 my ( $cookie, # cookie hash
301 $session, # session hash
306 if ( defined $cookie->{ 'SESSION_ID' } and defined $session->{ 'SESSION_ID' } )
308 if ( $cookie->{ 'SESSION_ID' } ne $session->{ 'SESSION_ID' } ) {
309 $cookie->{ 'SESSION_ERROR' } = 1;
311 $cookie->{ 'SESSION_ERROR' } = 0;
319 # Martin A. Hansen, December 2009.
321 # Check a user and password from CGI against the password file and
322 # set the session ID, if found, in the cookie.
324 my ( $cookie, # cookie hash
331 if ( defined $cookie->{ 'PASSWORD' } )
333 if ( defined $cookie->{ 'USER' } and -d "$cookie->{ 'SESSION_DIR' }/$cookie->{ 'USER' }" )
335 $session = Maasha::BGB::Session::session_restore( "$cookie->{ 'SESSION_DIR' }/$cookie->{ 'USER' }/session.json" );
337 if ( $session->{ 'PASSWORD' } eq Digest::MD5::md5_hex( $cookie->{ 'PASSWORD' } ) )
339 $cookie->{ 'TIME' } = Maasha::Common::time_stamp();
340 $cookie->{ 'SESSION_ID' } ||= Maasha::BGB::Session::session_new();
341 $cookie->{ 'LOGIN' } = 1;
342 $cookie->{ 'LOGIN_ERROR' } = 0;
346 $cookie->{ 'LOGIN_ERROR' } = 1;
351 $cookie->{ 'LOGIN_ERROR' } = 1;
359 # Martin A. Hansen, November 2009.
361 # Decommify the cookie value for NAV_START and adjust it to
362 # to prevent negative values.
364 my ( $cookie, # cookie hash
369 if ( defined $cookie->{ 'NAV_START' } )
371 $cookie->{ 'NAV_START' } =~ tr/,//d;
372 $cookie->{ 'NAV_START' } = 0 if $cookie->{ 'NAV_START' } < 0;
376 $cookie->{ 'NAV_START' } = 0;
383 # Martin A. Hansen, November 2009.
385 # Decommify the cookie value for NAV_END and adjust it to prevent
386 # overshooting the max value for the contig size as determined
389 my ( $cookie, # cookie hash
396 $max = Maasha::Filesys::file_size( Maasha::BGB::Track::path_seq( $cookie ) );
398 if ( defined $cookie->{ 'NAV_END' } )
400 $cookie->{ 'NAV_END' } =~ tr/,//d;
401 $cookie->{ 'NAV_END' } = $max if $cookie->{ 'NAV_END' } > $max;
405 $cookie->{ 'NAV_END' } = $max;
412 # Martin A. Hansen, November 2009.
414 # Adjust the cookie values for NAV_START and NAV_END based
415 # on cookie ZOOM values.
417 my ( $cookie, # cookie hash
422 my ( $max, $dist, $new_dist, $dist_diff );
424 $max = Maasha::Filesys::file_size( Maasha::BGB::Track::path_seq( $cookie ) );
426 $dist = $cookie->{ 'NAV_END' } - $cookie->{ 'NAV_START' };
428 if ( defined $cookie->{ 'ZOOM_IN1' } ) {
429 $new_dist = $dist / 1.5;
430 } elsif ( defined $cookie->{ 'ZOOM_IN2' } ) {
431 $new_dist = $dist / 3;
432 } elsif ( defined $cookie->{ 'ZOOM_IN3' } ) {
433 $new_dist = $dist / 10;
434 } elsif ( defined $cookie->{ 'ZOOM_OUT1' } ) {
435 $new_dist = $dist * 1.5;
436 } elsif ( defined $cookie->{ 'ZOOM_OUT2' } ) {
437 $new_dist = $dist * 3;
438 } elsif ( defined $cookie->{ 'ZOOM_OUT3' } ) {
439 $new_dist = $dist * 10;
444 $dist_diff = $dist - $new_dist;
446 $cookie->{ 'NAV_START' } = int( $cookie->{ 'NAV_START' } + ( $dist_diff / 2 ) );
447 $cookie->{ 'NAV_END' } = int( $cookie->{ 'NAV_END' } - ( $dist_diff / 2 ) );
449 $cookie->{ 'NAV_START' } = 0 if $cookie->{ 'NAV_START' } < 0;
450 $cookie->{ 'NAV_END' } = $max if $cookie->{ 'NAV_END' } > $max;
457 # Martin A. Hansen, November 2009.
459 # Adjust the cookie values for NAV_START and NAV_END based
460 # on cookie MOVE values.
462 my ( $cookie, # cookie hash
467 my ( $max, $dist, $shift, $new_start, $new_end );
469 $max = Maasha::Filesys::file_size( Maasha::BGB::Track::path_seq( $cookie ) );
471 $dist = $cookie->{ 'NAV_END' } - $cookie->{ 'NAV_START' };
473 if ( defined $cookie->{ 'MOVE_LEFT1' } ) {
474 $shift = -1 * $dist * 0.10;
475 } elsif ( defined $cookie->{ 'MOVE_LEFT2' } ) {
476 $shift = -1 * $dist * 0.475;
477 } elsif ( defined $cookie->{ 'MOVE_LEFT3' } ) {
478 $shift = -1 * $dist * 0.95;
479 } elsif ( defined $cookie->{ 'MOVE_RIGHT1' } ) {
480 $shift = $dist * 0.10;
481 } elsif ( defined $cookie->{ 'MOVE_RIGHT2' } ) {
482 $shift = $dist * 0.475;
483 } elsif ( defined $cookie->{ 'MOVE_RIGHT3' } ) {
484 $shift = $dist * 0.95;
489 $new_start = int( $cookie->{ 'NAV_START' } + $shift );
490 $new_end = int( $cookie->{ 'NAV_END' } + $shift );
492 if ( $new_start > 0 and $new_end < $max )
494 $cookie->{ 'NAV_START' } = $new_start;
495 $cookie->{ 'NAV_END' } = $new_end;
503 # Martin A. Hansen, March 2010.
505 # Adjust the cookie values for NAV_START and NAV_END based
506 # on cookie CENTER value if defined.
508 my ( $cookie, # cookie hash
513 my ( $l_dist, $r_dist );
515 if ( defined $cookie->{ 'NAV_CENTER' } )
517 $l_dist = $cookie->{ 'NAV_CENTER' } - $cookie->{ 'NAV_START' };
518 $r_dist = $cookie->{ 'NAV_END' } - $cookie->{ 'NAV_CENTER' };
520 if ( $l_dist > $r_dist ) {
521 $cookie->{ 'NAV_START' } = $cookie->{ 'NAV_END' } - 2 * $r_dist;
523 $cookie->{ 'NAV_END' } = $cookie->{ 'NAV_START' } + 2 * $l_dist;
529 sub cookie_track_status
531 # Martin A. Hansen, March 2010.
535 my ( $cookie, # cookie hash
540 my ( $clade, $genome, $assembly, $track );
542 $clade = $cookie->{ 'CLADE' };
543 $genome = $cookie->{ 'GENOME' };
544 $assembly = $cookie->{ 'ASSEMBLY' };
545 $track = $cookie->{ 'TRACK' };
549 if ( $cookie->{ 'TRACK_STATUS' }->{ $clade }->{ $genome }->{ $assembly }->{ $track } ) {
550 $cookie->{ 'TRACK_STATUS' }->{ $clade }->{ $genome }->{ $assembly }->{ $track } = 0;
552 $cookie->{ 'TRACK_STATUS' }->{ $clade }->{ $genome }->{ $assembly }->{ $track } = 1;
558 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> PAGES <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
563 # Martin A. Hansen, November 2009.
565 # Determines what page to render based on
566 # the cookie's PAGE setting.
568 my ( $cookie, # cookie hash
575 if ( $cookie->{ 'SESSION_ID' } ) {
576 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "session_id", value => $cookie->{ 'SESSION_ID' } ) );
579 if ( $cookie->{ 'PAGE' } eq 'login' ) {
580 push @html, page_login( $cookie );
581 } elsif ( $cookie->{ 'PAGE' } eq 'search' ) {
582 push @html, page_search( $cookie );
583 } elsif ( $cookie->{ 'PAGE' } eq 'browse' ) {
584 push @html, page_browse( $cookie );
585 } elsif ( $cookie->{ 'PAGE' } eq 'dna' ) {
586 push @html, page_dna( $cookie );
587 } elsif ( $cookie->{ 'PAGE' } eq 'export' ) {
588 push @html, page_export( $cookie );
589 } elsif ( $cookie->{ 'PAGE' } eq 'export_pdf' ) {
590 push @html, page_export_pdf( $cookie );
591 } elsif ( $cookie->{ 'PAGE' } eq 'export_svg' ) {
592 push @html, page_export_svg( $cookie );
593 } elsif ( $cookie->{ 'PAGE' } eq 'clade' ) {
594 push @html, page_clade( $cookie );
595 } elsif ( $cookie->{ 'PAGE' } eq 'genome' ) {
596 push @html, page_genome( $cookie );
597 } elsif ( $cookie->{ 'PAGE' } eq 'assembly' ) {
598 push @html, page_assembly( $cookie );
599 } elsif ( $cookie->{ 'PAGE' } eq 'contig' ) {
600 push @html, page_contig( $cookie );
603 return wantarray ? @html : \@html;
609 # Martin A. Hansen, December 2009.
611 # Renders the login page.
620 push @html, section_login( $cookie );
622 return wantarray ? @html : \@html;
628 # Martin A. Hansen, December 2009.
630 # Renders the search page.
639 push @html, section_taxonomy_table( $cookie );
640 push @html, section_search( $cookie );
642 return wantarray ? @html : \@html;
648 # Martin A. Hansen, November 2009.
650 # Renders the browse page.
659 push @html, section_taxonomy_table( $cookie );
660 push @html, section_navigate( $cookie );
661 push @html, section_browse( $cookie );
662 push @html, section_linkout( $cookie );
664 return wantarray ? @html : \@html;
670 # Martin A. Hansen, November 2009.
672 # Renders the DNA page.
681 push @html, section_taxonomy_table( $cookie );
682 push @html, section_dna( $cookie );
684 return wantarray ? @html : \@html;
690 # Martin A. Hansen, November 2009.
692 # Renders the export page.
701 push @html, section_taxonomy_table( $cookie );
702 push @html, section_export( $cookie );
704 return wantarray ? @html : \@html;
710 # Martin A. Hansen, March 2010.
712 # Renders the export PDF page.
721 push @html, section_taxonomy_table( $cookie );
722 push @html, section_export_pdf( $cookie );
724 return wantarray ? @html : \@html;
730 # Martin A. Hansen, March 2010.
732 # Renders the export SVG page.
741 push @html, section_taxonomy_table( $cookie );
742 push @html, section_export_svg( $cookie );
744 return wantarray ? @html : \@html;
750 # Martin A. Hansen, March 2010.
752 # Renders the clade selection page.
754 my ( $cookie, # cookie hash
761 push @html, section_taxonomy_table( $cookie );
762 push @html, section_clade( $cookie );
764 return wantarray ? @html : \@html;
770 # Martin A. Hansen, March 2010.
772 # Renders the genome selection page.
774 my ( $cookie, # cookie hash
781 push @html, section_taxonomy_table( $cookie );
782 push @html, section_genome( $cookie );
784 return wantarray ? @html : \@html;
790 # Martin A. Hansen, March 2010.
792 # Renders the clade selection page.
794 my ( $cookie, # cookie hash
801 push @html, section_taxonomy_table( $cookie );
802 push @html, section_assembly( $cookie );
804 return wantarray ? @html : \@html;
810 # Martin A. Hansen, November 2009.
812 # Renders the browse page.
814 my ( $cookie, # cookie hash
821 push @html, section_taxonomy_table( $cookie );
822 push @html, section_contig( $cookie );
824 return wantarray ? @html : \@html;
828 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> SECTIONS <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
833 # Martin A. Hansen, December 2009.
835 # Returns a HTML section with a login menu.
837 my ( $cookie, # cookie hash
842 my ( $user, $password, $login, @html );
844 $user = Maasha::XHTML::text( name => "user", value => "", size => 20 );
845 $password = Maasha::XHTML::password( name => "password", value => "", size => 20 );
846 $login = Maasha::XHTML::submit( name => "login_submit", value => "Login" );
848 push @html, Maasha::XHTML::h2( txt => "Login", class => 'center' );
850 push @html, Maasha::XHTML::table_beg( summary => "Login table", align => 'center' );
851 push @html, Maasha::XHTML::table_row_simple( tr => [ "User:", $user ] );
852 push @html, Maasha::XHTML::table_row_simple( tr => [ "Password:", $password ] );
853 push @html, Maasha::XHTML::table_row_simple( tr => [ "", $login ] );
854 push @html, Maasha::XHTML::table_end;
856 if ( defined $cookie->{ 'CLADE' } and
857 defined $cookie->{ 'GENOME' } and
858 defined $cookie->{ 'ASSEMBLY' } and
859 defined $cookie->{ 'CONTIG' } and
860 defined $cookie->{ 'NAV_START' } and
861 defined $cookie->{ 'NAV_END' }
864 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "clade", value => $cookie->{ 'CLADE' } ) );
865 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "genome", value => $cookie->{ 'GENOME' } ) );
866 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "assembly", value => $cookie->{ 'ASSEMBLY' } ) );
867 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "contig", value => $cookie->{ 'CONTIG' } ) );
868 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "nav_start", value => $cookie->{ 'NAV_START' } ) );
869 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "nav_end", value => $cookie->{ 'NAV_END' } ) );
872 if ( $cookie->{ 'LOGIN_ERROR' } ) {
873 push @html, Maasha::XHTML::h3( txt => "Bad user or password - please retry", class => 'error' );
876 return wantarray ? @html : \@html;
880 sub section_taxonomy_table
882 # Martin A. Hansen, November 2009.
884 # Returns a HTML section with a taxonomy table
885 # showing the location in the taxonomy and with
886 # links to browse the taxonomy.
888 my ( $cookie, # cookie hash
893 my ( $page, @row, @html, $href, $txt );
895 foreach $page ( @{ $cookie->{ 'LIST_PAGES' } } )
897 last if $page eq $cookie->{ 'PAGE' } or $page eq 'browse';
899 $href = "$cookie->{ 'SCRIPT' }?page=$page";
900 $href .= "&session_id=$cookie->{ 'SESSION_ID' }";
901 $href .= "&user=$cookie->{ 'USER' }";
902 $href .= "&clade=$cookie->{ 'CLADE' }" if $page !~ /clade/;
903 $href .= "&genome=$cookie->{ 'GENOME' }" if $page !~ /clade|genome/;
904 $href .= "&assembly=$cookie->{ 'ASSEMBLY' }" if $page !~ /clade|genome|assembly/;
905 $href .= "&contig=$cookie->{ 'CONTIG' }" if $page !~ /clade|genome|assembly|contig/;
907 $txt = ": $cookie->{ uc $page }";
909 push @row, Maasha::XHTML::ln( txt => $page, href => $href, class => 'inline' );
910 push @row, Maasha::XHTML::p( txt => $txt, class => 'inline' );
913 push @html, Maasha::XHTML::table_beg( summary => "Taxonomy table", align => 'center', cellpadding => '5px' );
914 push @html, Maasha::XHTML::table_row_simple( tr => [ join( "\n", @row ) ], align => 'center' );
915 push @html, Maasha::XHTML::table_end;
917 return wantarray ? @html : \@html;
923 # Martin A. Hansen, March 2010.
925 # Returns a HTML section with clade selection choices
926 # for navigating the taxonomy tree.
928 my ( $cookie, # cookie hash
933 my ( @html, $clade, $href );
935 push @html, Maasha::XHTML::h2( txt => "Select clade", class => 'center' );
937 push @html, Maasha::XHTML::table_beg( summary => "Taxonomy select table", align => 'center', cellpadding => '5px' );
939 foreach $clade ( @{ $cookie->{ 'LIST_CLADE' } } )
941 $href = "$cookie->{ 'SCRIPT' }?page=genome";
942 $href .= "&session_id=$cookie->{ 'SESSION_ID' }";
943 $href .= "&user=$cookie->{ 'USER' }";
944 $href .= "&clade=$clade";
946 push @html, Maasha::XHTML::table_row_simple( tr => [ Maasha::XHTML::ln( txt => $clade, href => $href ) ] );
949 push @html, Maasha::XHTML::table_end;
951 return wantarray ? @html : \@html;
957 # Martin A. Hansen, March 2010.
959 # Returns a HTML section with genome selection choices
960 # for navigating the taxonomy tree.
962 my ( $cookie, # cookie hash
967 my ( @html, $genome, $href );
969 push @html, Maasha::XHTML::h2( txt => "Select genome", class => 'center' );
971 push @html, Maasha::XHTML::table_beg( summary => "Taxonomy select table", align => 'center', cellpadding => '5px' );
973 foreach $genome ( @{ $cookie->{ 'LIST_GENOME' } } )
975 $href = "$cookie->{ 'SCRIPT' }?page=assembly";
976 $href .= "&session_id=$cookie->{ 'SESSION_ID' }";
977 $href .= "&user=$cookie->{ 'USER' }";
978 $href .= "&clade=$cookie->{ 'CLADE' }";
979 $href .= "&genome=$genome";
981 push @html, Maasha::XHTML::table_row_simple( tr => [ Maasha::XHTML::ln( txt => $genome, href => $href ) ] );
984 push @html, Maasha::XHTML::table_end;
986 return wantarray ? @html : \@html;
992 # Martin A. Hansen, March 2010.
994 # Returns a HTML section with assembly selection choices
995 # for navigating the taxonomy tree.
997 my ( $cookie, # cookie hash
1002 my ( @html, $assembly, $href );
1004 push @html, Maasha::XHTML::h2( txt => "Select assembly", class => 'center' );
1006 push @html, Maasha::XHTML::table_beg( summary => "Taxonomy select table", align => 'center', cellpadding => '5px' );
1008 foreach $assembly ( @{ $cookie->{ 'LIST_ASSEMBLY' } } )
1010 $href = "$cookie->{ 'SCRIPT' }?page=contig";
1011 $href .= "&session_id=$cookie->{ 'SESSION_ID' }";
1012 $href .= "&user=$cookie->{ 'USER' }";
1013 $href .= "&clade=$cookie->{ 'CLADE' }";
1014 $href .= "&genome=$cookie->{ 'GENOME' }";
1015 $href .= "&assembly=$assembly";
1017 push @html, Maasha::XHTML::table_row_simple( tr => [ Maasha::XHTML::ln( txt => $assembly, href => $href ) ] );
1020 push @html, Maasha::XHTML::table_end;
1022 return wantarray ? @html : \@html;
1028 # Martin A. Hansen, March 2010.
1030 # Returns a HTML section with contig selection choices
1031 # for navigating the taxonomy tree.
1033 my ( $cookie, # cookie hash
1038 my ( @html, $contig, $href );
1040 push @html, Maasha::XHTML::h2( txt => "Select contig", class => 'center' );
1042 push @html, Maasha::XHTML::table_beg( summary => "Taxonomy select table", align => 'center', cellpadding => '5px' );
1044 foreach $contig ( @{ $cookie->{ 'LIST_CONTIG' } } )
1046 $href = "$cookie->{ 'SCRIPT' }?page=browse";
1047 $href .= "&session_id=$cookie->{ 'SESSION_ID' }";
1048 $href .= "&user=$cookie->{ 'USER' }";
1049 $href .= "&clade=$cookie->{ 'CLADE' }";
1050 $href .= "&genome=$cookie->{ 'GENOME' }";
1051 $href .= "&assembly=$cookie->{ 'ASSEMBLY' }";
1052 $href .= "&contig=$contig";
1054 push @html, Maasha::XHTML::table_row_simple( tr => [ Maasha::XHTML::ln( txt => $contig, href => $href ) ] );
1057 push @html, Maasha::XHTML::table_end;
1059 return wantarray ? @html : \@html;
1063 sub section_navigate
1065 # Martin A. Hansen, November 2009.
1067 # Returns a HTML section for navigating in the browser window.
1069 my ( $cookie, # cookie hash
1074 my ( @html, $nav_val );
1076 $nav_val = Maasha::Calc::commify( $cookie->{ 'NAV_START' } ) . "-" . Maasha::Calc::commify( $cookie->{ 'NAV_END' } );
1078 push @html, Maasha::XHTML::table_beg( summary => "Navigation table", align => 'center' );
1079 push @html, Maasha::XHTML::table_row_simple( tr => [
1080 "Position or search term:",
1081 Maasha::XHTML::text( name => "nav_search", value => $nav_val, size => 30 ),
1082 Maasha::XHTML::submit( name => "nav_submit", value => "Submit" ),
1084 push @html, Maasha::XHTML::table_end;
1086 push @html, Maasha::XHTML::table_beg( summary => "Zoom table", align => 'center' );
1087 push @html, Maasha::XHTML::table_row_simple( tr => [
1088 Maasha::XHTML::p( txt => 'Move:' ),
1089 Maasha::XHTML::submit( name => "move_left3", value => "<<<", title => "move 95% to the left" ),
1090 Maasha::XHTML::submit( name => "move_left2", value => "<<", title => "move 47.5% to the left" ),
1091 Maasha::XHTML::submit( name => "move_left1", value => "<", title => "move 10% to the left" ),
1092 Maasha::XHTML::submit( name => "move_right1", value => ">", title => "move 10% to the rigth" ),
1093 Maasha::XHTML::submit( name => "move_right2", value => ">>", title => "move 47.5% to the rigth" ),
1094 Maasha::XHTML::submit( name => "move_right3", value => ">>>", title => "move 95% to the right" ),
1095 Maasha::XHTML::p( txt => 'Zoom in:' ),
1096 Maasha::XHTML::submit( name => "zoom_in1", value => "1.5x" ),
1097 Maasha::XHTML::submit( name => "zoom_in2", value => "3x" ),
1098 Maasha::XHTML::submit( name => "zoom_in3", value => "10x" ),
1099 Maasha::XHTML::p( txt => 'Zoom out:' ),
1100 Maasha::XHTML::submit( name => "zoom_out1", value => "1.5x" ),
1101 Maasha::XHTML::submit( name => "zoom_out2", value => "3x" ),
1102 Maasha::XHTML::submit( name => "zoom_out3", value => "10x" ),
1104 push @html, Maasha::XHTML::table_end;
1106 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "page", value => "browse" ) );
1107 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "user", value => $cookie->{ 'USER' } ) );
1108 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "clade", value => $cookie->{ 'CLADE' } ) );
1109 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "genome", value => $cookie->{ 'GENOME' } ) );
1110 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "assembly", value => $cookie->{ 'ASSEMBLY' } ) );
1111 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "contig", value => $cookie->{ 'CONTIG' } ) );
1113 return wantarray ? @html : \@html;
1119 # Martin A. Hansen, March 2010.
1121 # Returns a HTML section for a static link based on information in the cookie.
1123 my ( $cookie, # cookie hash
1128 my ( $link_out, $link_pdf, $link_svg, @html );
1130 $link_out = Maasha::XHTML::ln(
1132 href => join( "&", "$cookie->{ 'SCRIPT' }?page=browse",
1133 "clade=$cookie->{ 'CLADE' }",
1134 "genome=$cookie->{ 'GENOME' }",
1135 "assembly=$cookie->{ 'ASSEMBLY' }",
1136 "contig=$cookie->{ 'CONTIG' }",
1137 "nav_start=$cookie->{ 'NAV_START' }",
1138 "nav_end=$cookie->{ 'NAV_END' }",
1140 title => "Static link to this view",
1143 $link_pdf = Maasha::XHTML::ln(
1145 href => join( "&", "$cookie->{ 'SCRIPT' }?page=export_pdf",
1146 "session_id=$cookie->{ 'SESSION_ID' }",
1147 "user=$cookie->{ 'USER' }",
1148 "clade=$cookie->{ 'CLADE' }",
1149 "genome=$cookie->{ 'GENOME' }",
1150 "assembly=$cookie->{ 'ASSEMBLY' }",
1151 "contig=$cookie->{ 'CONTIG' }",
1152 "nav_start=$cookie->{ 'NAV_START' }",
1153 "nav_end=$cookie->{ 'NAV_END' }",
1155 title => "Export view in PDF",
1158 $link_svg = Maasha::XHTML::ln(
1160 href => join( "&", "$cookie->{ 'SCRIPT' }?page=export_svg",
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 "nav_start=$cookie->{ 'NAV_START' }",
1168 "nav_end=$cookie->{ 'NAV_END' }",
1170 title => "Export view in SVG",
1173 push @html, Maasha::XHTML::p( txt => "$link_out $link_pdf $link_svg", class => 'center' );
1175 return wantarray ? @html : \@html;
1186 my ( @track_list, $i, @tracks, $track, $elem, $png_data, @html, @img, $x1, $y1, $x2, $y2, $factor, $center );
1188 push @tracks, [ Maasha::BGB::Track::track_ruler( $cookie ) ];
1189 push @tracks, [ Maasha::BGB::Track::track_seq( $cookie ) ];
1191 @track_list = Maasha::BGB::Track::list_track_dir( $cookie->{ 'USER' }, $cookie->{ 'CLADE' }, $cookie->{ 'GENOME' }, $cookie->{ 'ASSEMBLY' }, $cookie->{ 'CONTIG' } );
1193 for ( $i = 0; $i < @track_list; $i++ )
1195 $cookie->{ 'FEAT_COLOR' } = Maasha::BGB::Draw::palette( $i );
1197 push @tracks, [ Maasha::BGB::Track::track_feature( $track_list[ $i ], $cookie ) ];
1200 unshift @tracks, [ Maasha::BGB::Track::track_grid( $cookie ) ];
1202 $png_data = Maasha::BGB::Draw::render_png( $cookie->{ 'IMG_WIDTH' }, $cookie->{ 'TRACK_OFFSET' }, \@tracks );
1204 push @img, Maasha::XHTML::img(
1205 src => "data:image/png;base64,$png_data",
1206 alt => "Browser Tracks",
1207 height => $cookie->{ 'TRACK_OFFSET' },
1208 width => $cookie->{ 'IMG_WIDTH' },
1209 id => "browser_map",
1210 usemap => "#browser_map"
1213 push @img, Maasha::XHTML::map_beg( name => "browser_map", id => "browser_map" );
1215 $factor = ( $cookie->{ 'NAV_END' } - $cookie->{ 'NAV_START' } + 1 ) / $cookie->{ 'IMG_WIDTH' };
1217 for ( $i = 0; $i < $cookie->{ 'IMG_WIDTH' }; $i += 5 )
1224 $center = int( $cookie->{ 'NAV_START' } + $factor * $i );
1226 push @img, Maasha::XHTML::area(
1227 href => join( "&", "$cookie->{ 'SCRIPT' }?page=browse",
1228 "session_id=$cookie->{ 'SESSION_ID' }",
1229 "user=$cookie->{ 'USER' }",
1230 "clade=$cookie->{ 'CLADE' }",
1231 "genome=$cookie->{ 'GENOME' }",
1232 "assembly=$cookie->{ 'ASSEMBLY' }",
1233 "contig=$cookie->{ 'CONTIG' }",
1234 "nav_start=$cookie->{ 'NAV_START' }",
1235 "nav_end=$cookie->{ 'NAV_END' }",
1236 "nav_center=$center",
1239 coords => "$x1, $y1, $x2, $y2",
1240 title => "Center on " . Maasha::Calc::commify( $center ),
1244 foreach $track ( @tracks )
1246 foreach $elem ( @{ $track } )
1248 next if $elem->{ 'type' } =~ /grid|text|wiggle/;
1250 if ( $elem->{ 'type' } eq 'track_name' )
1252 $x1 = $elem->{ 'x1' };
1253 $y1 = $elem->{ 'y1' } - 10;
1254 $x2 = $elem->{ 'x1' } + 6 * length $elem->{ 'txt' };
1255 $y2 = $elem->{ 'y1' };
1257 if ( Maasha::BGB::Track::track_hide( $cookie, $elem->{ 'track' } ) )
1259 push @img, Maasha::XHTML::area(
1260 href => join( "&", "$cookie->{ 'SCRIPT' }?page=browse",
1261 "session_id=$cookie->{ 'SESSION_ID' }",
1262 "user=$cookie->{ 'USER' }",
1263 "clade=$cookie->{ 'CLADE' }",
1264 "genome=$cookie->{ 'GENOME' }",
1265 "assembly=$cookie->{ 'ASSEMBLY' }",
1266 "contig=$cookie->{ 'CONTIG' }",
1267 "track=$elem->{ 'track' }",
1270 coords => "$x1, $y1, $x2, $y2",
1271 title => qq(Show track: $elem->{ 'txt' }),
1276 push @img, Maasha::XHTML::area(
1277 href => join( "&", "$cookie->{ 'SCRIPT' }?page=browse",
1278 "session_id=$cookie->{ 'SESSION_ID' }",
1279 "user=$cookie->{ 'USER' }",
1280 "clade=$cookie->{ 'CLADE' }",
1281 "genome=$cookie->{ 'GENOME' }",
1282 "assembly=$cookie->{ 'ASSEMBLY' }",
1283 "contig=$cookie->{ 'CONTIG' }",
1284 "track=$elem->{ 'track' }",
1287 coords => "$x1, $y1, $x2, $y2",
1288 title => qq(Hide track: $elem->{ 'txt' }),
1294 push @img, Maasha::XHTML::area(
1295 href => join( "&", "$cookie->{ 'SCRIPT' }?page=export",
1296 "session_id=$cookie->{ 'SESSION_ID' }",
1297 "user=$cookie->{ 'USER' }",
1298 "clade=$cookie->{ 'CLADE' }",
1299 "genome=$cookie->{ 'GENOME' }",
1300 "assembly=$cookie->{ 'ASSEMBLY' }",
1301 "contig=$cookie->{ 'CONTIG' }",
1302 "s_beg=$elem->{ 's_beg' }",
1303 "s_end=$elem->{ 's_end' }",
1304 "strand=$elem->{ 'strand' }",
1305 "q_id=$elem->{ 'q_id' }",
1308 coords => "$elem->{ x1 }, $elem->{ y1 }, $elem->{ x2 }, $elem->{ y2 }",
1309 title => "$elem->{ 'title' }",
1315 push @img, Maasha::XHTML::map_end();
1317 push @html, Maasha::XHTML::p( txt => join( "\n", @img ) );
1319 @html = Maasha::XHTML::div( txt => join( "\n", @html ), class => 'browse' );
1321 return wantarray ? @html : \@html;
1327 # Martin A. Hansen, November 2009.
1329 # Returns a HTML section with export table.
1331 my ( $cookie, # cookie hash
1336 my ( $feat, @row_dna_contig, @html );
1338 $feat = $cookie->{ 'Q_ID' } || "[no name]";
1340 push @row_dna_contig, Maasha::XHTML::p( txt => qq(Export Feature: "$feat" DNA from Contig: ), class => 'inline' );
1341 push @row_dna_contig, Maasha::XHTML::p( txt => "$cookie->{ 'CONTIG' } Start: ", class => 'inline' );
1342 push @row_dna_contig, Maasha::XHTML::text( name => "s_beg", value => Maasha::Calc::commify( $cookie->{ 'S_BEG' } ), size => 15 );
1343 push @row_dna_contig, Maasha::XHTML::p( txt => "End: ", class => 'inline' );
1344 push @row_dna_contig, Maasha::XHTML::text( name => "s_end", value => Maasha::Calc::commify( $cookie->{ 'S_END' } ), size => 15 );
1345 push @row_dna_contig, Maasha::XHTML::p( txt => "Strand: ", class => 'inline' );
1346 push @row_dna_contig, Maasha::XHTML::menu( name => "strand", options => [ qw( + - ) ], selected => $cookie->{ 'STRAND' } );
1347 push @row_dna_contig, Maasha::XHTML::submit( name => "export", value => "Export", title => "Fetch DNA from this region" );
1349 push @html, Maasha::XHTML::h2( txt => "Export", class => 'center' );
1350 push @html, Maasha::XHTML::table_beg( summary => "Taxonomy select table", align => 'center' );
1351 push @html, Maasha::XHTML::table_row_simple( tr => \@row_dna_contig );
1352 push @html, Maasha::XHTML::table_end;
1354 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "page", value => "dna" ) );
1355 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "user", value => $cookie->{ 'USER' } ) );
1356 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "clade", value => $cookie->{ 'CLADE' } ) );
1357 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "genome", value => $cookie->{ 'GENOME' } ) );
1358 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "assembly", value => $cookie->{ 'ASSEMBLY' } ) );
1359 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "contig", value => $cookie->{ 'CONTIG' } ) );
1361 return wantarray ? @html : \@html;
1365 sub section_export_pdf
1367 # Martin A. Hansen, March 2010.
1369 # Returns a HTML section with export table.
1371 my ( $cookie, # cookie hash
1376 my ( @tracks, @track_list, $i, $file, @html );
1378 push @tracks, [ Maasha::BGB::Track::track_ruler( $cookie ) ];
1379 push @tracks, [ Maasha::BGB::Track::track_seq( $cookie ) ];
1381 @track_list = Maasha::BGB::Track::list_track_dir( $cookie->{ 'USER' }, $cookie->{ 'CLADE' }, $cookie->{ 'GENOME' }, $cookie->{ 'ASSEMBLY' }, $cookie->{ 'CONTIG' } );
1383 for ( $i = 0; $i < @track_list; $i++ )
1385 $cookie->{ 'FEAT_COLOR' } = Maasha::BGB::Draw::palette( $i );
1387 push @tracks, [ Maasha::BGB::Track::track_feature( $track_list[ $i ], $cookie ) ];
1390 unshift @tracks, [ Maasha::BGB::Track::track_grid( $cookie ) ];
1392 $file = "$cookie->{ 'SESSION_DIR' }/$cookie->{ 'USER' }/BGB_export.pdf";
1394 Maasha::BGB::Draw::render_pdf_file( $file, $cookie->{ 'IMG_WIDTH' }, $cookie->{ 'TRACK_OFFSET' }, \@tracks );
1396 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::ln( txt => "BGB_export.pdf", href => $file ), class => 'center' );
1398 return wantarray ? @html : \@html;
1402 sub section_export_svg
1404 # Martin A. Hansen, March 2010.
1406 # Export view in SVG format.
1408 my ( $cookie, # cookie hash
1413 my ( @tracks, @track_list, $i, $file, @html );
1415 push @tracks, [ Maasha::BGB::Track::track_ruler( $cookie ) ];
1416 push @tracks, [ Maasha::BGB::Track::track_seq( $cookie ) ];
1418 @track_list = Maasha::BGB::Track::list_track_dir( $cookie->{ 'USER' }, $cookie->{ 'CLADE' }, $cookie->{ 'GENOME' }, $cookie->{ 'ASSEMBLY' }, $cookie->{ 'CONTIG' } );
1420 for ( $i = 0; $i < @track_list; $i++ )
1422 $cookie->{ 'FEAT_COLOR' } = Maasha::BGB::Draw::palette( $i );
1424 push @tracks, [ Maasha::BGB::Track::track_feature( $track_list[ $i ], $cookie ) ];
1427 unshift @tracks, [ Maasha::BGB::Track::track_grid( $cookie ) ];
1429 $file = "$cookie->{ 'SESSION_DIR' }/$cookie->{ 'USER' }/BGB_export.svg";
1431 Maasha::BGB::Draw::render_svg_file( $file, $cookie->{ 'IMG_WIDTH' }, $cookie->{ 'TRACK_OFFSET' }, \@tracks );
1433 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::ln( txt => "BGB_export.svg", href => $file ), class => 'center' );
1435 return wantarray ? @html : \@html;
1441 # Martin A. Hansen, November 2009.
1443 # Returns a HTML section with export table.
1445 my ( $cookie, # cookie hash
1450 my ( $results, $result, $count, @html, $export, $browse );
1452 $results = Maasha::BGB::Track::search_tracks( $cookie );
1454 $count = scalar @{ $results };
1456 push @html, Maasha::XHTML::h2( txt => "Search", class => 'center' );
1457 push @html, Maasha::XHTML::p( txt => qq(Results for "$cookie->{ 'SEARCH' }": $count), class => 'center' );
1461 push @html, Maasha::XHTML::table_beg( summary => "Search table", align => 'center', cellpadding => '5px' );
1462 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) ] );
1464 foreach $result ( @{ $results } )
1466 $cookie->{ 'CONTIG' } = $result->{ 'S_ID' };
1467 $cookie->{ 'NAV_START' } = $result->{ 'S_BEG' };
1468 $cookie->{ 'NAV_END' } = $result->{ 'S_END' };
1469 $cookie->{ 'S_BEG' } = $result->{ 'S_BEG' };
1470 $cookie->{ 'S_END' } = $result->{ 'S_END' };
1471 $cookie->{ 'STRAND' } = $result->{ 'STRAND' };
1472 $cookie->{ 'Q_ID' } = $result->{ 'Q_ID' };
1474 $browse = Maasha::XHTML::ln(
1476 href => join( "&", "$cookie->{ 'SCRIPT' }?page=browse",
1477 "session_id=$cookie->{ 'SESSION_ID' }",
1478 "user=$cookie->{ 'USER' }",
1479 "clade=$cookie->{ 'CLADE' }",
1480 "genome=$cookie->{ 'GENOME' }",
1481 "assembly=$cookie->{ 'ASSEMBLY' }",
1482 "contig=$cookie->{ 'CONTIG' }",
1483 "nav_start=$cookie->{ 'NAV_START' }",
1484 "nav_end=$cookie->{ 'NAV_END' }",
1489 $export = Maasha::XHTML::ln(
1491 href => join( "&", "$cookie->{ 'SCRIPT' }?page=export",
1492 "session_id=$cookie->{ 'SESSION_ID' }",
1493 "user=$cookie->{ 'USER' }",
1494 "clade=$cookie->{ 'CLADE' }",
1495 "genome=$cookie->{ 'GENOME' }",
1496 "assembly=$cookie->{ 'ASSEMBLY' }",
1497 "contig=$cookie->{ 'CONTIG' }",
1498 "s_beg=$cookie->{ 'S_BEG' }",
1499 "s_end=$cookie->{ 'S_END' }",
1500 "strand=$cookie->{ 'STRAND' }",
1504 push @html, Maasha::XHTML::table_row_advanced(
1505 tr => [ { td => $result->{ 'S_ID' } },
1506 { td => $result->{ 'S_BEG' }, align => 'right' },
1507 { td => $result->{ 'S_END' }, align => 'right' },
1508 { td => $result->{ 'Q_ID' } },
1509 { td => $result->{ 'SCORE' }, align => 'right' },
1510 { td => $result->{ 'STRAND' } },
1511 { td => $result->{ 'HITS' }, align => 'right' },
1512 { td => $result->{ 'ALIGN' } },
1513 { td => $result->{ 'BLOCK_COUNT' }, align => 'right' },
1514 { td => $result->{ 'BLOCK_BEGS' } },
1515 { td => $result->{ 'BLOCK_LENS' } },
1516 { td => $result->{ 'BLOCK_TYPE' } },
1519 ], class => "monospace"
1523 push @html, Maasha::XHTML::table_end;
1526 return wantarray ? @html : \@html;
1532 # Martin A. Hansen, November 2009.
1534 # Returns a HTML section with extracted DNA.
1536 my ( $cookie, # cookie hash
1541 my ( @html, $beg, $end, $seq );
1543 $beg = $cookie->{ 'S_BEG' };
1544 $end = $cookie->{ 'S_END' };
1548 $seq = join ";", ">$cookie->{ 'GENOME' }", $cookie->{ 'ASSEMBLY' }, $cookie->{ 'CONTIG' }, $beg, $end, "$cookie->{ 'STRAND' }\n";
1549 $seq .= Maasha::BGB::Track::dna_get( $cookie );
1551 push @html, Maasha::XHTML::h2( txt => "DNA", class => 'center' );
1552 push @html, Maasha::XHTML::pre( txt => $seq );
1554 return wantarray ? @html : \@html;
1558 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<