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' };
37 use Maasha::BGB::Session;
38 use Maasha::BGB::Track;
39 use Maasha::BGB::Draw;
41 my ( $cgi, $cookie, @html );
44 $cookie = cookie_default( $cgi );;
46 push @html, Maasha::XHTML::html_header(
48 title => 'Biopieces Genome Browser',
49 css_file => 'bgb.css',
50 author => 'Martin A. Hansen, mail@maasha.dk',
51 description => 'Biopieces Genome Browser',
52 keywords => [ qw( Biopieces biopiece genome browser viewer bacterium bacteria prokaryote prokaryotes ) ],
56 push @html, Maasha::XHTML::h1( txt => "Biopieces Genome Browser", class => 'center' );
57 push @html, Maasha::XHTML::form_beg( action => $cookie->{ 'SCRIPT' }, method => "post", enctype => "multipart/form-data" );
59 push @html, page( $cookie );
61 push @html, Maasha::XHTML::form_end;
62 push @html, Maasha::XHTML::body_end;
63 push @html, Maasha::XHTML::html_end;
65 # push @html, Maasha::XHTML::hdump( { $cgi->Vars } ); # DEBUG
66 # push @html, Maasha::XHTML::hdump( $cookie ); # DEBUG
67 # push @html, Maasha::XHTML::hdump( \%ENV ); # DEBUG
69 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->{ 'TRACK_STATUS' } = $session->{ 'TRACK_STATUS' };
143 $cookie->{ 'CLADE' } = $cgi->param( 'clade' ) || $session->{ 'CLADE' };
144 $cookie->{ 'GENOME' } = $cgi->param( 'genome' ) || $session->{ 'GENOME' };
145 $cookie->{ 'ASSEMBLY' } = $cgi->param( 'assembly' ) || $session->{ 'ASSEMBLY' };
146 $cookie->{ 'CONTIG' } = $cgi->param( 'contig' ) || $session->{ 'CONTIG' };
147 $cookie->{ 'Q_ID' } = $cgi->param( 'q_id' ) || $session->{ 'Q_ID' };
148 $cookie->{ 'NAV_START' } ||= defined $cgi->param( 'nav_start' ) ? $cgi->param( 'nav_start' ) : $session->{ 'NAV_START' };
149 $cookie->{ 'NAV_END' } ||= defined $cgi->param( 'nav_end' ) ? $cgi->param( 'nav_end' ) : $session->{ 'NAV_END' };
150 $cookie->{ 'NAV_CENTER' } = $cgi->param( 'nav_center' );
151 $cookie->{ 'S_BEG' } = defined $cgi->param( 's_beg' ) ? $cgi->param( 's_beg' ) : $session->{ 'S_BEG' };
152 $cookie->{ 'S_END' } = defined $cgi->param( 's_end' ) ? $cgi->param( 's_end' ) : $session->{ 'S_END' };
153 $cookie->{ 'STRAND' } = $cgi->param( 'strand' ) || $session->{ 'STRAND' };
154 $cookie->{ 'TRACK' } = $cgi->param( 'track' );
155 $cookie->{ 'ZOOM_IN1' } = $cgi->param( 'zoom_in1' );
156 $cookie->{ 'ZOOM_IN2' } = $cgi->param( 'zoom_in2' );
157 $cookie->{ 'ZOOM_IN3' } = $cgi->param( 'zoom_in3' );
158 $cookie->{ 'ZOOM_OUT1' } = $cgi->param( 'zoom_out1' );
159 $cookie->{ 'ZOOM_OUT2' } = $cgi->param( 'zoom_out2' );
160 $cookie->{ 'ZOOM_OUT3' } = $cgi->param( 'zoom_out3' );
161 $cookie->{ 'MOVE_LEFT1' } = $cgi->param( 'move_left1' );
162 $cookie->{ 'MOVE_LEFT2' } = $cgi->param( 'move_left2' );
163 $cookie->{ 'MOVE_LEFT3' } = $cgi->param( 'move_left3' );
164 $cookie->{ 'MOVE_RIGHT1' } = $cgi->param( 'move_right1' );
165 $cookie->{ 'MOVE_RIGHT2' } = $cgi->param( 'move_right2' );
166 $cookie->{ 'MOVE_RIGHT3' } = $cgi->param( 'move_right3' );
168 $cookie->{ 'IMG_WIDTH' } = 1200; # Width of browser image in pixels
169 $cookie->{ 'IMG_HEIGHT' } = 800; # Height of browser image in pixels # TODO: Redundant?
170 $cookie->{ 'WIGGLE_HEIGHT' } = 75; # Height of Wiggle tracks in pixels
171 $cookie->{ 'TRACK_OFFSET' } = 20;
172 $cookie->{ 'TRACK_SPACE' } = 20;
173 $cookie->{ 'RULER_FONT_SIZE' } = 10; # Size of ruler font in pixels
174 $cookie->{ 'RULER_COLOR' } = [ 0, 0, 0 ];
175 $cookie->{ 'SEQ_FONT_SIZE' } = 10;
176 $cookie->{ 'SEQ_COLOR' } = [ 0, 0, 0, ];
177 $cookie->{ 'FEAT_WIDTH' } = 5;
178 $cookie->{ 'FEAT_COLOR' } = [ 0, 0, 0 ];
179 # $cookie->{ 'FEAT_MAX' } = 5000; # TODO: Reduntant?
181 # $cookie->{ 'LIST_USER' } = Maasha::BGB::Track::list_users(); # TODO: Redundant?
183 if ( $cookie->{ 'USER' } and not $cookie->{ 'LOGIN_ERROR' } )
185 $cookie->{ 'LIST_CLADE' } = Maasha::BGB::Track::list_clades( $cookie->{ 'USER' } );
187 if ( $cookie->{ 'CLADE' } )
189 $cookie->{ 'LIST_GENOME' } = Maasha::BGB::Track::list_genomes( $cookie->{ 'USER' }, $cookie->{ 'CLADE' } );
191 if ( $cookie->{ 'GENOME' } )
193 $cookie->{ 'LIST_ASSEMBLY' } = Maasha::BGB::Track::list_assemblies( $cookie->{ 'USER' }, $cookie->{ 'CLADE' }, $cookie->{ 'GENOME' } );
195 if ( $cookie->{ 'ASSEMBLY' } )
197 $cookie->{ 'LIST_CONTIG' } = Maasha::BGB::Track::list_contigs( $cookie->{ 'USER' }, $cookie->{ 'CLADE' }, $cookie->{ 'GENOME' }, $cookie->{ 'ASSEMBLY' } );
202 if ( $cookie->{ 'CONTIG' } )
204 cookie_start( $cookie );
205 cookie_end( $cookie );
206 cookie_zoom( $cookie );
207 cookie_move( $cookie );
208 cookie_center( $cookie );
209 cookie_track_status( $cookie );
213 $cookie->{ 'STRAND' } = '+' if defined $cookie->{ 'STRAND' } and $cookie->{ 'STRAND' } eq ' '; # FIXME ugly HTML fix
215 session_store( $cookie, $session );
217 return wantarray ? %{ $cookie } : $cookie;
223 # Martin A. Hansen, March 2010.
225 # Restores session and returns this.
227 my ( $cookie, # cookie hash
234 if ( defined $cookie->{ 'USER' } and -d "$cookie->{ 'SESSION_DIR' }/$cookie->{ 'USER' }" ) {
235 $session = Maasha::BGB::Session::session_restore( "$cookie->{ 'SESSION_DIR' }/$cookie->{ 'USER' }/session.json" );
238 return wantarray ? %{ $session } : $session;
244 # Martin A. Hansen, March 2010.
246 # Store a session updated with cookie information to session file.
248 my ( $cookie, # cookie hash
249 $session, # session hash
256 if ( defined $cookie->{ 'USER' } and $cookie->{ 'USER' } ne '' and -d "$cookie->{ 'SESSION_DIR' }/$cookie->{ 'USER' }" )
258 $new_session->{ 'PASSWORD' } = $session->{ 'PASSWORD' };
259 $new_session->{ 'SESSION_ID' } = $session->{ 'SESSION_ID' };
260 $new_session->{ 'TIME' } = Maasha::Common::time_stamp();
261 $new_session->{ 'PAGE' } = $cookie->{ 'PAGE' };
263 if ( $cookie->{ 'PAGE' } =~ /browse|export_pdf|export_svg/ )
265 $new_session->{ 'CLADE' } = $cookie->{ 'CLADE' };
266 $new_session->{ 'GENOME' } = $cookie->{ 'GENOME' };
267 $new_session->{ 'ASSEMBLY' } = $cookie->{ 'ASSEMBLY' };
268 $new_session->{ 'CONTIG' } = $cookie->{ 'CONTIG' };
269 $new_session->{ 'NAV_START' } = $cookie->{ 'NAV_START' };
270 $new_session->{ 'NAV_END' } = $cookie->{ 'NAV_END' };
272 elsif ( $cookie->{ 'PAGE' } eq 'contig' )
274 $new_session->{ 'CLADE' } = $cookie->{ 'CLADE' };
275 $new_session->{ 'GENOME' } = $cookie->{ 'GENOME' };
276 $new_session->{ 'ASSEMBLY' } = $cookie->{ 'ASSEMBLY' };
278 elsif ( $cookie->{ 'PAGE' } eq 'assembly' )
280 $new_session->{ 'CLADE' } = $cookie->{ 'CLADE' };
281 $new_session->{ 'GENOME' } = $cookie->{ 'GENOME' };
283 elsif ( $cookie->{ 'PAGE' } eq 'genome' )
285 $new_session->{ 'CLADE' } = $cookie->{ 'CLADE' };
287 elsif ( $cookie->{ 'PAGE' } =~ /export|dna/ )
289 $new_session->{ 'CLADE' } = $cookie->{ 'CLADE' };
290 $new_session->{ 'GENOME' } = $cookie->{ 'GENOME' };
291 $new_session->{ 'ASSEMBLY' } = $cookie->{ 'ASSEMBLY' };
292 $new_session->{ 'CONTIG' } = $cookie->{ 'CONTIG' };
293 $new_session->{ 'Q_ID' } = $cookie->{ 'Q_ID' };
294 $new_session->{ 'S_BEG' } = $cookie->{ 'S_BEG' };
295 $new_session->{ 'S_END' } = $cookie->{ 'S_END' };
296 $new_session->{ 'STRAND' } = $cookie->{ 'STRAND' };
299 $new_session->{ 'TRACK_STATUS' } = $cookie->{ 'TRACK_STATUS' };
301 Maasha::BGB::Session::session_store( "$cookie->{ 'SESSION_DIR' }/$cookie->{ 'USER' }/session.json", $new_session );
308 # Martin A. Hansen, March 2010.
310 # Check that the session id in the cookie and session match.
311 # Sets SESSION_ERROR flag in cookie if not matching.
313 my ( $cookie, # cookie hash
314 $session, # session hash
319 if ( defined $cookie->{ 'SESSION_ID' } and defined $session->{ 'SESSION_ID' } )
321 if ( $cookie->{ 'SESSION_ID' } ne $session->{ 'SESSION_ID' } ) {
322 $cookie->{ 'SESSION_ERROR' } = 1;
324 $cookie->{ 'SESSION_ERROR' } = 0;
332 # Martin A. Hansen, December 2009.
334 # Check a user and password from CGI against the password file and
335 # set the session ID, if found, in the cookie.
337 my ( $cookie, # cookie hash
344 if ( defined $cookie->{ 'PASSWORD' } )
346 if ( defined $cookie->{ 'USER' } and -d "$cookie->{ 'SESSION_DIR' }/$cookie->{ 'USER' }" )
348 $session = Maasha::BGB::Session::session_restore( "$cookie->{ 'SESSION_DIR' }/$cookie->{ 'USER' }/session.json" );
350 if ( $session->{ 'PASSWORD' } eq Digest::MD5::md5_hex( $cookie->{ 'PASSWORD' } ) )
352 $cookie->{ 'TIME' } = Maasha::Common::time_stamp();
353 $cookie->{ 'SESSION_ID' } ||= Maasha::BGB::Session::session_new();
354 $cookie->{ 'LOGIN' } = 1;
355 $cookie->{ 'LOGIN_ERROR' } = 0;
359 $cookie->{ 'LOGIN_ERROR' } = 1;
364 $cookie->{ 'LOGIN_ERROR' } = 1;
372 # Martin A. Hansen, November 2009.
374 # Decommify the cookie value for NAV_START and adjust it to
375 # to prevent negative values.
377 my ( $cookie, # cookie hash
382 if ( defined $cookie->{ 'NAV_START' } )
384 $cookie->{ 'NAV_START' } =~ tr/,//d;
385 $cookie->{ 'NAV_START' } = 0 if $cookie->{ 'NAV_START' } < 0;
389 $cookie->{ 'NAV_START' } = 0;
396 # Martin A. Hansen, November 2009.
398 # Decommify the cookie value for NAV_END and adjust it to prevent
399 # overshooting the max value for the contig size as determined
402 my ( $cookie, # cookie hash
409 $max = Maasha::Filesys::file_size( Maasha::BGB::Track::path_seq( $cookie ) );
411 if ( defined $cookie->{ 'NAV_END' } )
413 $cookie->{ 'NAV_END' } =~ tr/,//d;
414 $cookie->{ 'NAV_END' } = $max if $cookie->{ 'NAV_END' } > $max;
418 $cookie->{ 'NAV_END' } = $max;
425 # Martin A. Hansen, November 2009.
427 # Adjust the cookie values for NAV_START and NAV_END based
428 # on cookie ZOOM values.
430 my ( $cookie, # cookie hash
435 my ( $max, $dist, $new_dist, $dist_diff );
437 $max = Maasha::Filesys::file_size( Maasha::BGB::Track::path_seq( $cookie ) );
439 $dist = $cookie->{ 'NAV_END' } - $cookie->{ 'NAV_START' };
441 if ( defined $cookie->{ 'ZOOM_IN1' } ) {
442 $new_dist = $dist / 1.5;
443 } elsif ( defined $cookie->{ 'ZOOM_IN2' } ) {
444 $new_dist = $dist / 3;
445 } elsif ( defined $cookie->{ 'ZOOM_IN3' } ) {
446 $new_dist = $dist / 10;
447 } elsif ( defined $cookie->{ 'ZOOM_OUT1' } ) {
448 $new_dist = $dist * 1.5;
449 } elsif ( defined $cookie->{ 'ZOOM_OUT2' } ) {
450 $new_dist = $dist * 3;
451 } elsif ( defined $cookie->{ 'ZOOM_OUT3' } ) {
452 $new_dist = $dist * 10;
457 $dist_diff = $dist - $new_dist;
459 $cookie->{ 'NAV_START' } = int( $cookie->{ 'NAV_START' } + ( $dist_diff / 2 ) );
460 $cookie->{ 'NAV_END' } = int( $cookie->{ 'NAV_END' } - ( $dist_diff / 2 ) );
462 $cookie->{ 'NAV_START' } = 0 if $cookie->{ 'NAV_START' } < 0;
463 $cookie->{ 'NAV_END' } = $max if $cookie->{ 'NAV_END' } > $max;
470 # Martin A. Hansen, November 2009.
472 # Adjust the cookie values for NAV_START and NAV_END based
473 # on cookie MOVE values.
475 my ( $cookie, # cookie hash
480 my ( $max, $dist, $shift, $new_start, $new_end );
482 $max = Maasha::Filesys::file_size( Maasha::BGB::Track::path_seq( $cookie ) );
484 $dist = $cookie->{ 'NAV_END' } - $cookie->{ 'NAV_START' };
486 if ( defined $cookie->{ 'MOVE_LEFT1' } ) {
487 $shift = -1 * $dist * 0.10;
488 } elsif ( defined $cookie->{ 'MOVE_LEFT2' } ) {
489 $shift = -1 * $dist * 0.475;
490 } elsif ( defined $cookie->{ 'MOVE_LEFT3' } ) {
491 $shift = -1 * $dist * 0.95;
492 } elsif ( defined $cookie->{ 'MOVE_RIGHT1' } ) {
493 $shift = $dist * 0.10;
494 } elsif ( defined $cookie->{ 'MOVE_RIGHT2' } ) {
495 $shift = $dist * 0.475;
496 } elsif ( defined $cookie->{ 'MOVE_RIGHT3' } ) {
497 $shift = $dist * 0.95;
502 $new_start = int( $cookie->{ 'NAV_START' } + $shift );
503 $new_end = int( $cookie->{ 'NAV_END' } + $shift );
505 if ( $new_start > 0 and $new_end < $max )
507 $cookie->{ 'NAV_START' } = $new_start;
508 $cookie->{ 'NAV_END' } = $new_end;
516 # Martin A. Hansen, March 2010.
518 # Adjust the cookie values for NAV_START and NAV_END based
519 # on cookie CENTER value if defined.
521 my ( $cookie, # cookie hash
526 my ( $l_dist, $r_dist );
528 if ( defined $cookie->{ 'NAV_CENTER' } )
530 $l_dist = $cookie->{ 'NAV_CENTER' } - $cookie->{ 'NAV_START' };
531 $r_dist = $cookie->{ 'NAV_END' } - $cookie->{ 'NAV_CENTER' };
533 if ( $l_dist > $r_dist ) {
534 $cookie->{ 'NAV_START' } = $cookie->{ 'NAV_END' } - 2 * $r_dist;
536 $cookie->{ 'NAV_END' } = $cookie->{ 'NAV_START' } + 2 * $l_dist;
542 sub cookie_track_status
544 # Martin A. Hansen, March 2010.
548 my ( $cookie, # cookie hash
553 my ( $clade, $genome, $assembly, $track );
555 $clade = $cookie->{ 'CLADE' };
556 $genome = $cookie->{ 'GENOME' };
557 $assembly = $cookie->{ 'ASSEMBLY' };
558 $track = $cookie->{ 'TRACK' };
562 if ( $cookie->{ 'TRACK_STATUS' }->{ $clade }->{ $genome }->{ $assembly }->{ $track } ) {
563 $cookie->{ 'TRACK_STATUS' }->{ $clade }->{ $genome }->{ $assembly }->{ $track } = 0;
565 $cookie->{ 'TRACK_STATUS' }->{ $clade }->{ $genome }->{ $assembly }->{ $track } = 1;
571 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> PAGES <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
576 # Martin A. Hansen, November 2009.
578 # Determines what page to render based on
579 # the cookie's PAGE setting.
581 my ( $cookie, # cookie hash
588 if ( $cookie->{ 'SESSION_ID' } ) {
589 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "session_id", value => $cookie->{ 'SESSION_ID' } ) );
592 if ( $cookie->{ 'PAGE' } eq 'login' ) {
593 push @html, page_login( $cookie );
594 } elsif ( $cookie->{ 'PAGE' } eq 'search' ) {
595 push @html, page_search( $cookie );
596 } elsif ( $cookie->{ 'PAGE' } eq 'browse' ) {
597 push @html, page_browse( $cookie );
598 } elsif ( $cookie->{ 'PAGE' } eq 'dna' ) {
599 push @html, page_dna( $cookie );
600 } elsif ( $cookie->{ 'PAGE' } eq 'export' ) {
601 push @html, page_export( $cookie );
602 } elsif ( $cookie->{ 'PAGE' } eq 'export_pdf' ) {
603 push @html, page_export_pdf( $cookie );
604 } elsif ( $cookie->{ 'PAGE' } eq 'export_svg' ) {
605 push @html, page_export_svg( $cookie );
606 } elsif ( $cookie->{ 'PAGE' } eq 'clade' ) {
607 push @html, page_clade( $cookie );
608 } elsif ( $cookie->{ 'PAGE' } eq 'genome' ) {
609 push @html, page_genome( $cookie );
610 } elsif ( $cookie->{ 'PAGE' } eq 'assembly' ) {
611 push @html, page_assembly( $cookie );
612 } elsif ( $cookie->{ 'PAGE' } eq 'contig' ) {
613 push @html, page_contig( $cookie );
616 return wantarray ? @html : \@html;
622 # Martin A. Hansen, December 2009.
624 # Renders the login page.
633 push @html, section_login( $cookie );
635 return wantarray ? @html : \@html;
641 # Martin A. Hansen, December 2009.
643 # Renders the search page.
652 push @html, section_taxonomy_table( $cookie );
653 push @html, section_search( $cookie );
655 return wantarray ? @html : \@html;
661 # Martin A. Hansen, November 2009.
663 # Renders the browse page.
672 push @html, section_taxonomy_table( $cookie );
673 push @html, section_navigate( $cookie );
674 push @html, section_browse( $cookie );
675 push @html, section_linkout( $cookie );
677 return wantarray ? @html : \@html;
683 # Martin A. Hansen, November 2009.
685 # Renders the DNA page.
694 push @html, section_taxonomy_table( $cookie );
695 push @html, section_dna( $cookie );
697 return wantarray ? @html : \@html;
703 # Martin A. Hansen, November 2009.
705 # Renders the export page.
714 push @html, section_taxonomy_table( $cookie );
715 push @html, section_export( $cookie );
717 return wantarray ? @html : \@html;
723 # Martin A. Hansen, March 2010.
725 # Renders the export PDF page.
734 push @html, section_taxonomy_table( $cookie );
735 push @html, section_export_pdf( $cookie );
737 return wantarray ? @html : \@html;
743 # Martin A. Hansen, March 2010.
745 # Renders the export SVG page.
754 push @html, section_taxonomy_table( $cookie );
755 push @html, section_export_svg( $cookie );
757 return wantarray ? @html : \@html;
763 # Martin A. Hansen, March 2010.
765 # Renders the clade selection page.
767 my ( $cookie, # cookie hash
774 push @html, section_taxonomy_table( $cookie );
775 push @html, section_clade( $cookie );
777 return wantarray ? @html : \@html;
783 # Martin A. Hansen, March 2010.
785 # Renders the genome selection page.
787 my ( $cookie, # cookie hash
794 push @html, section_taxonomy_table( $cookie );
795 push @html, section_genome( $cookie );
797 return wantarray ? @html : \@html;
803 # Martin A. Hansen, March 2010.
805 # Renders the clade selection page.
807 my ( $cookie, # cookie hash
814 push @html, section_taxonomy_table( $cookie );
815 push @html, section_assembly( $cookie );
817 return wantarray ? @html : \@html;
823 # Martin A. Hansen, November 2009.
825 # Renders the browse page.
827 my ( $cookie, # cookie hash
834 push @html, section_taxonomy_table( $cookie );
835 push @html, section_contig( $cookie );
837 return wantarray ? @html : \@html;
841 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> SECTIONS <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
846 # Martin A. Hansen, December 2009.
848 # Returns a HTML section with a login menu.
850 my ( $cookie, # cookie hash
855 my ( $user, $password, $login, @html );
857 $user = Maasha::XHTML::text( name => "user", value => "", size => 20 );
858 $password = Maasha::XHTML::password( name => "password", value => "", size => 20 );
859 $login = Maasha::XHTML::submit( name => "login_submit", value => "Login" );
861 push @html, Maasha::XHTML::h2( txt => "Login", class => 'center' );
863 push @html, Maasha::XHTML::table_beg( summary => "Login table", align => 'center' );
864 push @html, Maasha::XHTML::table_row_simple( tr => [ "User:", $user ] );
865 push @html, Maasha::XHTML::table_row_simple( tr => [ "Password:", $password ] );
866 push @html, Maasha::XHTML::table_row_simple( tr => [ "", $login ] );
867 push @html, Maasha::XHTML::table_end;
869 if ( defined $cookie->{ 'CLADE' } and
870 defined $cookie->{ 'GENOME' } and
871 defined $cookie->{ 'ASSEMBLY' } and
872 defined $cookie->{ 'CONTIG' } and
873 defined $cookie->{ 'NAV_START' } and
874 defined $cookie->{ 'NAV_END' }
877 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "clade", value => $cookie->{ 'CLADE' } ) );
878 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "genome", value => $cookie->{ 'GENOME' } ) );
879 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "assembly", value => $cookie->{ 'ASSEMBLY' } ) );
880 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "contig", value => $cookie->{ 'CONTIG' } ) );
881 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "nav_start", value => $cookie->{ 'NAV_START' } ) );
882 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "nav_end", value => $cookie->{ 'NAV_END' } ) );
885 if ( $cookie->{ 'LOGIN_ERROR' } ) {
886 push @html, Maasha::XHTML::h3( txt => "Bad user or password - please retry", class => 'error' );
889 return wantarray ? @html : \@html;
893 sub section_taxonomy_table
895 # Martin A. Hansen, November 2009.
897 # Returns a HTML section with a taxonomy table
898 # showing the location in the taxonomy and with
899 # links to browse the taxonomy.
901 my ( $cookie, # cookie hash
906 my ( $page, @row, @html, $href, $txt );
908 foreach $page ( @{ $cookie->{ 'LIST_PAGES' } } )
910 last if $page eq $cookie->{ 'PAGE' } or $page eq 'browse';
912 $href = "$cookie->{ 'SCRIPT' }?page=$page";
913 $href .= "&session_id=$cookie->{ 'SESSION_ID' }";
914 $href .= "&user=$cookie->{ 'USER' }";
915 $href .= "&clade=$cookie->{ 'CLADE' }" if $page !~ /clade/;
916 $href .= "&genome=$cookie->{ 'GENOME' }" if $page !~ /clade|genome/;
917 $href .= "&assembly=$cookie->{ 'ASSEMBLY' }" if $page !~ /clade|genome|assembly/;
918 $href .= "&contig=$cookie->{ 'CONTIG' }" if $page !~ /clade|genome|assembly|contig/;
920 $txt = ": $cookie->{ uc $page }";
922 push @row, Maasha::XHTML::ln( txt => $page, href => $href, class => 'inline' );
923 push @row, Maasha::XHTML::p( txt => $txt, class => 'inline' );
926 push @html, Maasha::XHTML::table_beg( summary => "Taxonomy table", align => 'center', cellpadding => '5px' );
927 push @html, Maasha::XHTML::table_row_simple( tr => [ join( "\n", @row ) ], align => 'center' );
928 push @html, Maasha::XHTML::table_end;
930 return wantarray ? @html : \@html;
936 # Martin A. Hansen, March 2010.
938 # Returns a HTML section with clade selection choices
939 # for navigating the taxonomy tree.
941 my ( $cookie, # cookie hash
946 my ( @html, $clade, $href );
948 push @html, Maasha::XHTML::h2( txt => "Select clade", class => 'center' );
950 push @html, Maasha::XHTML::table_beg( summary => "Taxonomy select table", align => 'center', cellpadding => '5px' );
952 foreach $clade ( @{ $cookie->{ 'LIST_CLADE' } } )
954 $href = "$cookie->{ 'SCRIPT' }?page=genome";
955 $href .= "&session_id=$cookie->{ 'SESSION_ID' }";
956 $href .= "&user=$cookie->{ 'USER' }";
957 $href .= "&clade=$clade";
959 push @html, Maasha::XHTML::table_row_simple( tr => [ Maasha::XHTML::ln( txt => $clade, href => $href ) ] );
962 push @html, Maasha::XHTML::table_end;
964 return wantarray ? @html : \@html;
970 # Martin A. Hansen, March 2010.
972 # Returns a HTML section with genome selection choices
973 # for navigating the taxonomy tree.
975 my ( $cookie, # cookie hash
980 my ( @html, $genome, $href );
982 push @html, Maasha::XHTML::h2( txt => "Select genome", class => 'center' );
984 push @html, Maasha::XHTML::table_beg( summary => "Taxonomy select table", align => 'center', cellpadding => '5px' );
986 foreach $genome ( @{ $cookie->{ 'LIST_GENOME' } } )
988 $href = "$cookie->{ 'SCRIPT' }?page=assembly";
989 $href .= "&session_id=$cookie->{ 'SESSION_ID' }";
990 $href .= "&user=$cookie->{ 'USER' }";
991 $href .= "&clade=$cookie->{ 'CLADE' }";
992 $href .= "&genome=$genome";
994 push @html, Maasha::XHTML::table_row_simple( tr => [ Maasha::XHTML::ln( txt => $genome, href => $href ) ] );
997 push @html, Maasha::XHTML::table_end;
999 return wantarray ? @html : \@html;
1003 sub section_assembly
1005 # Martin A. Hansen, March 2010.
1007 # Returns a HTML section with assembly selection choices
1008 # for navigating the taxonomy tree.
1010 my ( $cookie, # cookie hash
1015 my ( @html, $assembly, $href );
1017 push @html, Maasha::XHTML::h2( txt => "Select assembly", class => 'center' );
1019 push @html, Maasha::XHTML::table_beg( summary => "Taxonomy select table", align => 'center', cellpadding => '5px' );
1021 foreach $assembly ( @{ $cookie->{ 'LIST_ASSEMBLY' } } )
1023 $href = "$cookie->{ 'SCRIPT' }?page=contig";
1024 $href .= "&session_id=$cookie->{ 'SESSION_ID' }";
1025 $href .= "&user=$cookie->{ 'USER' }";
1026 $href .= "&clade=$cookie->{ 'CLADE' }";
1027 $href .= "&genome=$cookie->{ 'GENOME' }";
1028 $href .= "&assembly=$assembly";
1030 push @html, Maasha::XHTML::table_row_simple( tr => [ Maasha::XHTML::ln( txt => $assembly, href => $href ) ] );
1033 push @html, Maasha::XHTML::table_end;
1035 return wantarray ? @html : \@html;
1041 # Martin A. Hansen, March 2010.
1043 # Returns a HTML section with contig selection choices
1044 # for navigating the taxonomy tree.
1046 my ( $cookie, # cookie hash
1051 my ( @html, $contig, $href );
1053 push @html, Maasha::XHTML::h2( txt => "Select contig", class => 'center' );
1055 push @html, Maasha::XHTML::table_beg( summary => "Taxonomy select table", align => 'center', cellpadding => '5px' );
1057 foreach $contig ( @{ $cookie->{ 'LIST_CONTIG' } } )
1059 $href = "$cookie->{ 'SCRIPT' }?page=browse";
1060 $href .= "&session_id=$cookie->{ 'SESSION_ID' }";
1061 $href .= "&user=$cookie->{ 'USER' }";
1062 $href .= "&clade=$cookie->{ 'CLADE' }";
1063 $href .= "&genome=$cookie->{ 'GENOME' }";
1064 $href .= "&assembly=$cookie->{ 'ASSEMBLY' }";
1065 $href .= "&contig=$contig";
1067 push @html, Maasha::XHTML::table_row_simple( tr => [ Maasha::XHTML::ln( txt => $contig, href => $href ) ] );
1070 push @html, Maasha::XHTML::table_end;
1072 return wantarray ? @html : \@html;
1076 sub section_navigate
1078 # Martin A. Hansen, November 2009.
1080 # Returns a HTML section for navigating in the browser window.
1082 my ( $cookie, # cookie hash
1087 my ( @html, $nav_val );
1089 $nav_val = Maasha::Calc::commify( $cookie->{ 'NAV_START' } ) . "-" . Maasha::Calc::commify( $cookie->{ 'NAV_END' } );
1091 push @html, Maasha::XHTML::table_beg( summary => "Navigation table", align => 'center' );
1092 push @html, Maasha::XHTML::table_row_simple( tr => [
1093 "Position or search term:",
1094 Maasha::XHTML::text( name => "nav_search", value => $nav_val, size => 30 ),
1095 Maasha::XHTML::submit( name => "nav_submit", value => "Submit" ),
1097 push @html, Maasha::XHTML::table_end;
1099 push @html, Maasha::XHTML::table_beg( summary => "Zoom table", align => 'center' );
1100 push @html, Maasha::XHTML::table_row_simple( tr => [
1101 Maasha::XHTML::p( txt => 'Move:' ),
1102 Maasha::XHTML::submit( name => "move_left3", value => "<<<", title => "move 95% to the left" ),
1103 Maasha::XHTML::submit( name => "move_left2", value => "<<", title => "move 47.5% to the left" ),
1104 Maasha::XHTML::submit( name => "move_left1", value => "<", title => "move 10% to the left" ),
1105 Maasha::XHTML::submit( name => "move_right1", value => ">", title => "move 10% to the rigth" ),
1106 Maasha::XHTML::submit( name => "move_right2", value => ">>", title => "move 47.5% to the rigth" ),
1107 Maasha::XHTML::submit( name => "move_right3", value => ">>>", title => "move 95% to the right" ),
1108 Maasha::XHTML::p( txt => 'Zoom in:' ),
1109 Maasha::XHTML::submit( name => "zoom_in1", value => "1.5x" ),
1110 Maasha::XHTML::submit( name => "zoom_in2", value => "3x" ),
1111 Maasha::XHTML::submit( name => "zoom_in3", value => "10x" ),
1112 Maasha::XHTML::p( txt => 'Zoom out:' ),
1113 Maasha::XHTML::submit( name => "zoom_out1", value => "1.5x" ),
1114 Maasha::XHTML::submit( name => "zoom_out2", value => "3x" ),
1115 Maasha::XHTML::submit( name => "zoom_out3", value => "10x" ),
1117 push @html, Maasha::XHTML::table_end;
1119 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "page", value => "browse" ) );
1120 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "user", value => $cookie->{ 'USER' } ) );
1121 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "clade", value => $cookie->{ 'CLADE' } ) );
1122 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "genome", value => $cookie->{ 'GENOME' } ) );
1123 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "assembly", value => $cookie->{ 'ASSEMBLY' } ) );
1124 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "contig", value => $cookie->{ 'CONTIG' } ) );
1126 return wantarray ? @html : \@html;
1132 # Martin A. Hansen, March 2010.
1134 # Returns a HTML section for a static link based on information in the cookie.
1136 my ( $cookie, # cookie hash
1141 my ( $link_out, $link_pdf, $link_svg, @html );
1143 $link_out = Maasha::XHTML::ln(
1145 href => join( "&", "$cookie->{ 'SCRIPT' }?page=browse",
1146 "clade=$cookie->{ 'CLADE' }",
1147 "genome=$cookie->{ 'GENOME' }",
1148 "assembly=$cookie->{ 'ASSEMBLY' }",
1149 "contig=$cookie->{ 'CONTIG' }",
1150 "nav_start=$cookie->{ 'NAV_START' }",
1151 "nav_end=$cookie->{ 'NAV_END' }",
1153 title => "Static link to this view",
1156 $link_pdf = Maasha::XHTML::ln(
1158 href => join( "&", "$cookie->{ 'SCRIPT' }?page=export_pdf",
1159 "session_id=$cookie->{ 'SESSION_ID' }",
1160 "user=$cookie->{ 'USER' }",
1161 "clade=$cookie->{ 'CLADE' }",
1162 "genome=$cookie->{ 'GENOME' }",
1163 "assembly=$cookie->{ 'ASSEMBLY' }",
1164 "contig=$cookie->{ 'CONTIG' }",
1165 "nav_start=$cookie->{ 'NAV_START' }",
1166 "nav_end=$cookie->{ 'NAV_END' }",
1168 title => "Export view in PDF",
1171 $link_svg = Maasha::XHTML::ln(
1173 href => join( "&", "$cookie->{ 'SCRIPT' }?page=export_svg",
1174 "session_id=$cookie->{ 'SESSION_ID' }",
1175 "user=$cookie->{ 'USER' }",
1176 "clade=$cookie->{ 'CLADE' }",
1177 "genome=$cookie->{ 'GENOME' }",
1178 "assembly=$cookie->{ 'ASSEMBLY' }",
1179 "contig=$cookie->{ 'CONTIG' }",
1180 "nav_start=$cookie->{ 'NAV_START' }",
1181 "nav_end=$cookie->{ 'NAV_END' }",
1183 title => "Export view in SVG",
1186 push @html, Maasha::XHTML::p( txt => "$link_out $link_pdf $link_svg", class => 'center' );
1188 return wantarray ? @html : \@html;
1199 my ( @track_list, $i, @tracks, $track, $elem, $png_data, @html, @img, $x1, $y1, $x2, $y2, $factor, $center );
1201 push @tracks, [ Maasha::BGB::Track::track_ruler( $cookie ) ];
1202 push @tracks, [ Maasha::BGB::Track::track_seq( $cookie ) ];
1204 @track_list = Maasha::BGB::Track::list_track_dir( $cookie->{ 'USER' }, $cookie->{ 'CLADE' }, $cookie->{ 'GENOME' }, $cookie->{ 'ASSEMBLY' }, $cookie->{ 'CONTIG' } );
1206 for ( $i = 0; $i < @track_list; $i++ )
1208 $cookie->{ 'FEAT_COLOR' } = Maasha::BGB::Draw::palette( $i );
1210 push @tracks, [ Maasha::BGB::Track::track_feature( $track_list[ $i ], $cookie ) ];
1213 unshift @tracks, [ Maasha::BGB::Track::track_grid( $cookie ) ];
1215 $png_data = Maasha::BGB::Draw::render_png( $cookie->{ 'IMG_WIDTH' }, $cookie->{ 'TRACK_OFFSET' }, \@tracks );
1217 push @img, Maasha::XHTML::img(
1218 src => "data:image/png;base64,$png_data",
1219 alt => "Browser Tracks",
1220 height => $cookie->{ 'TRACK_OFFSET' },
1221 width => $cookie->{ 'IMG_WIDTH' },
1222 id => "browser_map",
1223 usemap => "#browser_map"
1226 push @img, Maasha::XHTML::map_beg( name => "browser_map", id => "browser_map" );
1228 $factor = ( $cookie->{ 'NAV_END' } - $cookie->{ 'NAV_START' } + 1 ) / $cookie->{ 'IMG_WIDTH' };
1230 for ( $i = 0; $i < $cookie->{ 'IMG_WIDTH' }; $i += 5 )
1237 $center = int( $cookie->{ 'NAV_START' } + $factor * $i );
1239 push @img, Maasha::XHTML::area(
1240 href => join( "&", "$cookie->{ 'SCRIPT' }?page=browse",
1241 "session_id=$cookie->{ 'SESSION_ID' }",
1242 "user=$cookie->{ 'USER' }",
1243 "clade=$cookie->{ 'CLADE' }",
1244 "genome=$cookie->{ 'GENOME' }",
1245 "assembly=$cookie->{ 'ASSEMBLY' }",
1246 "contig=$cookie->{ 'CONTIG' }",
1247 "nav_start=$cookie->{ 'NAV_START' }",
1248 "nav_end=$cookie->{ 'NAV_END' }",
1249 "nav_center=$center",
1252 coords => "$x1, $y1, $x2, $y2",
1253 title => "Center on " . Maasha::Calc::commify( $center ),
1257 foreach $track ( @tracks )
1259 foreach $elem ( @{ $track } )
1261 next if $elem->{ 'type' } =~ /grid|text|wiggle/;
1263 if ( $elem->{ 'type' } eq 'track_name' )
1265 $x1 = $elem->{ 'x1' };
1266 $y1 = $elem->{ 'y1' } - 10;
1267 $x2 = $elem->{ 'x1' } + 6 * length $elem->{ 'txt' };
1268 $y2 = $elem->{ 'y1' };
1270 if ( Maasha::BGB::Track::track_hide( $cookie, $elem->{ 'track' } ) )
1272 push @img, Maasha::XHTML::area(
1273 href => join( "&", "$cookie->{ 'SCRIPT' }?page=browse",
1274 "session_id=$cookie->{ 'SESSION_ID' }",
1275 "user=$cookie->{ 'USER' }",
1276 "clade=$cookie->{ 'CLADE' }",
1277 "genome=$cookie->{ 'GENOME' }",
1278 "assembly=$cookie->{ 'ASSEMBLY' }",
1279 "contig=$cookie->{ 'CONTIG' }",
1280 "track=$elem->{ 'track' }",
1283 coords => "$x1, $y1, $x2, $y2",
1284 title => qq(Show track: $elem->{ 'txt' }),
1289 push @img, Maasha::XHTML::area(
1290 href => join( "&", "$cookie->{ 'SCRIPT' }?page=browse",
1291 "session_id=$cookie->{ 'SESSION_ID' }",
1292 "user=$cookie->{ 'USER' }",
1293 "clade=$cookie->{ 'CLADE' }",
1294 "genome=$cookie->{ 'GENOME' }",
1295 "assembly=$cookie->{ 'ASSEMBLY' }",
1296 "contig=$cookie->{ 'CONTIG' }",
1297 "track=$elem->{ 'track' }",
1300 coords => "$x1, $y1, $x2, $y2",
1301 title => qq(Hide track: $elem->{ 'txt' }),
1307 push @img, Maasha::XHTML::area(
1308 href => join( "&", "$cookie->{ 'SCRIPT' }?page=export",
1309 "session_id=$cookie->{ 'SESSION_ID' }",
1310 "user=$cookie->{ 'USER' }",
1311 "clade=$cookie->{ 'CLADE' }",
1312 "genome=$cookie->{ 'GENOME' }",
1313 "assembly=$cookie->{ 'ASSEMBLY' }",
1314 "contig=$cookie->{ 'CONTIG' }",
1315 "s_beg=$elem->{ 's_beg' }",
1316 "s_end=$elem->{ 's_end' }",
1317 "strand=$elem->{ 'strand' }",
1318 "q_id=$elem->{ 'q_id' }",
1321 coords => "$elem->{ x1 }, $elem->{ y1 }, $elem->{ x2 }, $elem->{ y2 }",
1322 title => "$elem->{ 'title' }",
1328 push @img, Maasha::XHTML::map_end();
1330 push @html, Maasha::XHTML::p( txt => join( "\n", @img ) );
1332 @html = Maasha::XHTML::div( txt => join( "\n", @html ), class => 'browse' );
1334 return wantarray ? @html : \@html;
1340 # Martin A. Hansen, November 2009.
1342 # Returns a HTML section with export table.
1344 my ( $cookie, # cookie hash
1349 my ( $feat, @row_dna_contig, @html );
1351 $feat = $cookie->{ 'Q_ID' } || "[no name]";
1353 push @row_dna_contig, Maasha::XHTML::p( txt => qq(Export Feature: "$feat" DNA from Contig: ), class => 'inline' );
1354 push @row_dna_contig, Maasha::XHTML::p( txt => "$cookie->{ 'CONTIG' } Start: ", class => 'inline' );
1355 push @row_dna_contig, Maasha::XHTML::text( name => "s_beg", value => Maasha::Calc::commify( $cookie->{ 'S_BEG' } ), size => 15 );
1356 push @row_dna_contig, Maasha::XHTML::p( txt => "End: ", class => 'inline' );
1357 push @row_dna_contig, Maasha::XHTML::text( name => "s_end", value => Maasha::Calc::commify( $cookie->{ 'S_END' } ), size => 15 );
1358 push @row_dna_contig, Maasha::XHTML::p( txt => "Strand: ", class => 'inline' );
1359 push @row_dna_contig, Maasha::XHTML::menu( name => "strand", options => [ qw( + - ) ], selected => $cookie->{ 'STRAND' } );
1360 push @row_dna_contig, Maasha::XHTML::submit( name => "export", value => "Export", title => "Fetch DNA from this region" );
1362 push @html, Maasha::XHTML::h2( txt => "Export", class => 'center' );
1363 push @html, Maasha::XHTML::table_beg( summary => "Taxonomy select table", align => 'center' );
1364 push @html, Maasha::XHTML::table_row_simple( tr => \@row_dna_contig );
1365 push @html, Maasha::XHTML::table_end;
1367 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "page", value => "dna" ) );
1368 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "user", value => $cookie->{ 'USER' } ) );
1369 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "clade", value => $cookie->{ 'CLADE' } ) );
1370 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "genome", value => $cookie->{ 'GENOME' } ) );
1371 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "assembly", value => $cookie->{ 'ASSEMBLY' } ) );
1372 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "contig", value => $cookie->{ 'CONTIG' } ) );
1374 return wantarray ? @html : \@html;
1378 sub section_export_pdf
1380 # Martin A. Hansen, March 2010.
1382 # Returns a HTML section with export table.
1384 my ( $cookie, # cookie hash
1389 my ( @tracks, @track_list, $i, $file, @html );
1391 push @tracks, [ Maasha::BGB::Track::track_ruler( $cookie ) ];
1392 push @tracks, [ Maasha::BGB::Track::track_seq( $cookie ) ];
1394 @track_list = Maasha::BGB::Track::list_track_dir( $cookie->{ 'USER' }, $cookie->{ 'CLADE' }, $cookie->{ 'GENOME' }, $cookie->{ 'ASSEMBLY' }, $cookie->{ 'CONTIG' } );
1396 for ( $i = 0; $i < @track_list; $i++ )
1398 $cookie->{ 'FEAT_COLOR' } = Maasha::BGB::Draw::palette( $i );
1400 push @tracks, [ Maasha::BGB::Track::track_feature( $track_list[ $i ], $cookie ) ];
1403 unshift @tracks, [ Maasha::BGB::Track::track_grid( $cookie ) ];
1405 $file = "$cookie->{ 'SESSION_DIR' }/$cookie->{ 'USER' }/BGB_export.pdf";
1407 Maasha::BGB::Draw::render_pdf_file( $file, $cookie->{ 'IMG_WIDTH' }, $cookie->{ 'TRACK_OFFSET' }, \@tracks );
1409 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::ln( txt => "BGB_export.pdf", href => $file ), class => 'center' );
1411 return wantarray ? @html : \@html;
1415 sub section_export_svg
1417 # Martin A. Hansen, March 2010.
1419 # Export view in SVG format.
1421 my ( $cookie, # cookie hash
1426 my ( @tracks, @track_list, $i, $file, @html );
1428 push @tracks, [ Maasha::BGB::Track::track_ruler( $cookie ) ];
1429 push @tracks, [ Maasha::BGB::Track::track_seq( $cookie ) ];
1431 @track_list = Maasha::BGB::Track::list_track_dir( $cookie->{ 'USER' }, $cookie->{ 'CLADE' }, $cookie->{ 'GENOME' }, $cookie->{ 'ASSEMBLY' }, $cookie->{ 'CONTIG' } );
1433 for ( $i = 0; $i < @track_list; $i++ )
1435 $cookie->{ 'FEAT_COLOR' } = Maasha::BGB::Draw::palette( $i );
1437 push @tracks, [ Maasha::BGB::Track::track_feature( $track_list[ $i ], $cookie ) ];
1440 unshift @tracks, [ Maasha::BGB::Track::track_grid( $cookie ) ];
1442 $file = "$cookie->{ 'SESSION_DIR' }/$cookie->{ 'USER' }/BGB_export.svg";
1444 Maasha::BGB::Draw::render_svg_file( $file, $cookie->{ 'IMG_WIDTH' }, $cookie->{ 'TRACK_OFFSET' }, \@tracks );
1446 push @html, Maasha::XHTML::p( txt => Maasha::XHTML::ln( txt => "BGB_export.svg", href => $file ), class => 'center' );
1448 return wantarray ? @html : \@html;
1454 # Martin A. Hansen, November 2009.
1456 # Returns a HTML section with export table.
1458 my ( $cookie, # cookie hash
1463 my ( $results, $result, $count, @html, $export, $browse );
1465 $results = Maasha::BGB::Track::search_tracks( $cookie );
1467 $count = scalar @{ $results };
1469 push @html, Maasha::XHTML::h2( txt => "Search", class => 'center' );
1470 push @html, Maasha::XHTML::p( txt => qq(Results for "$cookie->{ 'SEARCH' }": $count), class => 'center' );
1474 push @html, Maasha::XHTML::table_beg( summary => "Search table", align => 'center', cellpadding => '5px' );
1475 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) ] );
1477 foreach $result ( @{ $results } )
1479 $cookie->{ 'CONTIG' } = $result->{ 'S_ID' };
1480 $cookie->{ 'NAV_START' } = $result->{ 'S_BEG' };
1481 $cookie->{ 'NAV_END' } = $result->{ 'S_END' };
1482 $cookie->{ 'S_BEG' } = $result->{ 'S_BEG' };
1483 $cookie->{ 'S_END' } = $result->{ 'S_END' };
1484 $cookie->{ 'STRAND' } = $result->{ 'STRAND' };
1485 $cookie->{ 'Q_ID' } = $result->{ 'Q_ID' };
1487 $browse = Maasha::XHTML::ln(
1489 href => join( "&", "$cookie->{ 'SCRIPT' }?page=browse",
1490 "session_id=$cookie->{ 'SESSION_ID' }",
1491 "user=$cookie->{ 'USER' }",
1492 "clade=$cookie->{ 'CLADE' }",
1493 "genome=$cookie->{ 'GENOME' }",
1494 "assembly=$cookie->{ 'ASSEMBLY' }",
1495 "contig=$cookie->{ 'CONTIG' }",
1496 "nav_start=$cookie->{ 'NAV_START' }",
1497 "nav_end=$cookie->{ 'NAV_END' }",
1502 $export = Maasha::XHTML::ln(
1504 href => join( "&", "$cookie->{ 'SCRIPT' }?page=export",
1505 "session_id=$cookie->{ 'SESSION_ID' }",
1506 "user=$cookie->{ 'USER' }",
1507 "clade=$cookie->{ 'CLADE' }",
1508 "genome=$cookie->{ 'GENOME' }",
1509 "assembly=$cookie->{ 'ASSEMBLY' }",
1510 "contig=$cookie->{ 'CONTIG' }",
1511 "s_beg=$cookie->{ 'S_BEG' }",
1512 "s_end=$cookie->{ 'S_END' }",
1513 "strand=$cookie->{ 'STRAND' }",
1517 push @html, Maasha::XHTML::table_row_advanced(
1518 tr => [ { td => $result->{ 'S_ID' } },
1519 { td => $result->{ 'S_BEG' }, align => 'right' },
1520 { td => $result->{ 'S_END' }, align => 'right' },
1521 { td => $result->{ 'Q_ID' } },
1522 { td => $result->{ 'SCORE' }, align => 'right' },
1523 { td => $result->{ 'STRAND' } },
1524 { td => $result->{ 'HITS' }, align => 'right' },
1525 { td => $result->{ 'ALIGN' } },
1526 { td => $result->{ 'BLOCK_COUNT' }, align => 'right' },
1527 { td => $result->{ 'BLOCK_BEGS' } },
1528 { td => $result->{ 'BLOCK_LENS' } },
1529 { td => $result->{ 'BLOCK_TYPE' } },
1532 ], class => "monospace"
1536 push @html, Maasha::XHTML::table_end;
1539 return wantarray ? @html : \@html;
1545 # Martin A. Hansen, November 2009.
1547 # Returns a HTML section with extracted DNA.
1549 my ( $cookie, # cookie hash
1554 my ( @html, $beg, $end, $seq );
1556 $beg = $cookie->{ 'S_BEG' };
1557 $end = $cookie->{ 'S_END' };
1561 $seq = join ";", ">$cookie->{ 'GENOME' }", $cookie->{ 'ASSEMBLY' }, $cookie->{ 'CONTIG' }, $beg, $end, "$cookie->{ 'STRAND' }\n";
1562 $seq .= Maasha::BGB::Track::dna_get( $cookie );
1564 push @html, Maasha::XHTML::h2( txt => "DNA", class => 'center' );
1565 push @html, Maasha::XHTML::pre( txt => $seq );
1567 return wantarray ? @html : \@html;
1571 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
1577 # my $t0 = Time::HiRes::gettimeofday();
1578 # my $t1 = Time::HiRes::gettimeofday(); print STDERR "Time: " . ( $t1 - $t0 ) . "\n";