]> git.donarmstrong.com Git - biopieces.git/blob - www/index.cgi
added persistent sessions to BGB
[biopieces.git] / www / index.cgi
1 #!/usr/bin/env perl
2
3 # Copyright (C) 2006-2009 Martin A. Hansen.
4
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.
9
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.
14
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.
18
19 # http://www.gnu.org/copyleft/gpl.html
20
21 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
22
23 use strict;
24 use warnings;
25
26 use lib $ENV{ 'BP_PERL' };
27
28 use CGI;
29 use URI::Escape;
30 use Data::Dumper;
31 use Digest::MD5;
32 use Maasha::Common;
33 use Maasha::Filesys;
34 use Maasha::Calc;
35 use Maasha::XHTML;
36 use Maasha::BGB::Session;
37 use Maasha::BGB::Track;
38 use Maasha::BGB::Draw;
39
40 my ( $cgi, $cookie, @html );
41
42 $cgi    = new CGI;
43 $cookie = cookie_default( $cgi );;
44
45 push @html, Maasha::XHTML::html_header(
46     cgi_header  => 1,
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 ) ],
52     no_cache    => 1,
53 );
54
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" );
57
58 push @html, page( $cookie );
59
60 push @html, Maasha::XHTML::form_end;
61 push @html, Maasha::XHTML::body_end;
62 push @html, Maasha::XHTML::html_end;
63
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
67
68 print "$_\n" foreach @html;
69
70
71 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> SUBROUTINES <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
72
73
74 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> COOKIE <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
75
76
77 sub cookie_default
78 {
79     # Martin A. Hansen, November 2009.
80
81     # Set a cookie with values from the CGI object or defaults.
82
83     my ( $cgi,   # CGI object
84        ) = @_;
85
86     # Returns a hash.
87
88     my ( $cookie, $session );
89
90     $cookie = {};
91
92     if ( $cgi->param( 'nav_search' ) )
93     {
94         if ( $cgi->param( 'nav_search' ) =~ /([0-9,]+)[ -]([0-9,]+)/ )
95         {
96             $cookie->{ 'NAV_START' } = $1;
97             $cookie->{ 'NAV_END' }   = $2;
98         }
99         else
100         {
101             $cookie->{ 'SEARCH' } = $cgi->param( 'nav_search' );
102
103             $cgi->param( 'page', 'search' );
104         }
105     }
106
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' );
114
115     $session = session_restore( $cookie );
116
117     cookie_login( $cookie );
118
119     # session_id_check( $cookie, $session );
120
121     if ( $cookie->{ 'LOGIN_ERROR' } or $cookie->{ 'SESSION_ERROR' } )
122     {
123         $cookie->{ 'PAGE' } = 'login';
124     }
125     elsif ( $cookie->{ 'LOGIN' } )
126     {
127         if ( $cgi->param( 'genome' ) ) {
128             $cookie->{ 'PAGE' } = 'browse';
129         } else {
130             $cookie->{ 'PAGE' } = $session->{ 'PAGE' } || 'clade';
131         }
132     }
133     elsif ( not defined $cookie->{ 'USER' } )
134     {
135         $cookie->{ 'PAGE' } = 'login';
136     }
137     else
138     {
139          $cookie->{ 'PAGE' } = $cgi->param( 'page' ) || 'login';
140     }
141
142     $cookie->{ 'CLADE' }           = $cgi->param( 'clade' )       || $session->{ 'CLADE' };
143     $cookie->{ 'GENOME' }          = $cgi->param( 'genome' )      || $session->{ 'GENOME' };
144     $cookie->{ 'ASSEMBLY' }        = $cgi->param( 'assembly' )    || $session->{ 'ASSEMBLY' };
145     $cookie->{ 'CONTIG' }          = $cgi->param( 'contig' )      || $session->{ 'CONTIG' };
146     $cookie->{ 'Q_ID' }            = $cgi->param( 'q_id' )        || $session->{ 'Q_ID' };
147     $cookie->{ 'NAV_START' }       = defined $cgi->param( 'nav_start' ) ? $cgi->param( 'nav_start' ) : $session->{ 'NAV_START' };
148     $cookie->{ 'NAV_END' }         = $cgi->param( 'nav_end' )     || $session->{ 'NAV_END' };
149     $cookie->{ 'NAV_CENTER' }      = $cgi->param( 'nav_center' );
150     $cookie->{ 'S_BEG' }           = $cgi->param( 's_beg' )       || $session->{ 'S_BEG' };
151     $cookie->{ 'S_END' }           = $cgi->param( 's_end' )       || $session->{ 'S_END' };
152     $cookie->{ 'STRAND' }          = $cgi->param( 'strand' )      || $session->{ 'STRAND' };
153     $cookie->{ 'ZOOM_IN1' }        = $cgi->param( 'zoom_in1' );
154     $cookie->{ 'ZOOM_IN2' }        = $cgi->param( 'zoom_in2' );
155     $cookie->{ 'ZOOM_IN3' }        = $cgi->param( 'zoom_in3' );
156     $cookie->{ 'ZOOM_OUT1' }       = $cgi->param( 'zoom_out1' );
157     $cookie->{ 'ZOOM_OUT2' }       = $cgi->param( 'zoom_out2' );
158     $cookie->{ 'ZOOM_OUT3' }       = $cgi->param( 'zoom_out3' );
159     $cookie->{ 'MOVE_LEFT1' }      = $cgi->param( 'move_left1' );
160     $cookie->{ 'MOVE_LEFT2' }      = $cgi->param( 'move_left2' );
161     $cookie->{ 'MOVE_LEFT3' }      = $cgi->param( 'move_left3' );
162     $cookie->{ 'MOVE_RIGHT1' }     = $cgi->param( 'move_right1' );
163     $cookie->{ 'MOVE_RIGHT2' }     = $cgi->param( 'move_right2' );
164     $cookie->{ 'MOVE_RIGHT3' }     = $cgi->param( 'move_right3' );
165
166     $cookie->{ 'IMG_WIDTH' }       = 1200;   # Width of browser image in pixels
167     $cookie->{ 'IMG_HEIGHT' }      = 800;    # Height of browser image in pixels
168     $cookie->{ 'WIGGLE_HEIGHT' }   = 75;     # Height of Wiggle tracks in pixels
169     $cookie->{ 'TRACK_OFFSET' }    = 20;
170     $cookie->{ 'TRACK_SPACE' }     = 20;
171     $cookie->{ 'RULER_FONT_SIZE' } = 10;     # Size of ruler font in pixels
172     $cookie->{ 'RULER_COLOR' }     = [ 0, 0, 0 ];
173     $cookie->{ 'SEQ_FONT_SIZE' }   = 10;
174     $cookie->{ 'SEQ_COLOR' }       = [ 0, 0, 0, ];
175     $cookie->{ 'FEAT_WIDTH' }      = 5;
176     $cookie->{ 'FEAT_COLOR' }      = [ 0, 0, 0 ];
177     $cookie->{ 'FEAT_MAX' }        = 5000;   # TODO: Reduntant?
178
179 #    $cookie->{ 'LIST_USER' }       = Maasha::BGB::Track::list_users();  # TODO: Redundant?
180
181     if ( $cookie->{ 'USER' } and not $cookie->{ 'LOGIN_ERROR' } )
182     {
183         $cookie->{ 'LIST_CLADE' }      = Maasha::BGB::Track::list_clades(     $cookie->{ 'USER' } );
184         $cookie->{ 'LIST_GENOME' }     = Maasha::BGB::Track::list_genomes(    $cookie->{ 'USER' }, $cookie->{ 'CLADE' } );
185         $cookie->{ 'LIST_ASSEMBLY' }   = Maasha::BGB::Track::list_assemblies( $cookie->{ 'USER' }, $cookie->{ 'CLADE' }, $cookie->{ 'GENOME' } );
186         $cookie->{ 'LIST_CONTIG' }     = Maasha::BGB::Track::list_contigs(    $cookie->{ 'USER' }, $cookie->{ 'CLADE' }, $cookie->{ 'GENOME' }, $cookie->{ 'ASSEMBLY' } );
187
188         if ( $cookie->{ 'CONTIG' } )
189         {
190             cookie_start( $cookie );
191             cookie_end( $cookie );
192             cookie_zoom( $cookie );
193             cookie_move( $cookie );
194             cookie_center( $cookie );
195         }
196     }
197
198     $cookie->{ 'STRAND' } = '+' if defined $cookie->{ 'STRAND' } and $cookie->{ 'STRAND' } eq ' ';   # FIXME ugly HTML fix
199
200     session_store( $cookie, $session );
201
202     return wantarray ? %{ $cookie } : $cookie;
203 }
204
205
206 sub session_restore
207 {
208     # Martin A. Hansen, March 2010.
209
210     # Restores session and returns this.
211
212     my ( $cookie,   # cookie hash
213        ) = @_;
214
215     # Returns hashref.
216
217     my ( $session );
218
219     if ( defined $cookie->{ 'USER' } and -d "$cookie->{ 'SESSION_DIR' }/$cookie->{ 'USER' }" ) {
220         $session = Maasha::BGB::Session::session_restore( "$cookie->{ 'SESSION_DIR' }/$cookie->{ 'USER' }/session.json" );
221     }
222
223     return wantarray ? %{ $session } : $session;
224 }
225
226
227 sub session_store
228 {
229     # Martin A. Hansen, March 2010.
230
231     # Store a session updated with cookie information to session file.
232
233     my ( $cookie,    # cookie hash
234          $session,   # session hash
235        ) = @_;
236
237     # Returns nothing.
238
239     if ( defined $cookie->{ 'USER' } and $cookie->{ 'USER' } ne '' and -d "$cookie->{ 'SESSION_DIR' }/$cookie->{ 'USER' }" )
240     {
241         $session->{ 'TIME' }      = Maasha::Common::time_stamp();
242         $session->{ 'PAGE' }      = $cookie->{ 'PAGE' };
243         $session->{ 'CLADE' }     = $cookie->{ 'CLADE' };
244         $session->{ 'GENOME' }    = $cookie->{ 'GENOME' };
245         $session->{ 'ASSEMBLY' }  = $cookie->{ 'ASSEMBLY' };
246         $session->{ 'CONTIG' }    = $cookie->{ 'CONTIG' };
247         $session->{ 'Q_ID' }      = $cookie->{ 'Q_ID' };
248         $session->{ 'S_BEG' }     = $cookie->{ 'S_BEG' };
249         $session->{ 'S_END' }     = $cookie->{ 'S_END' };
250         $session->{ 'STRAND' }    = $cookie->{ 'STRAND' };
251         $session->{ 'NAV_START' } = $cookie->{ 'PAGE' } eq 'browse' ? $cookie->{ 'NAV_START' } : undef;
252         $session->{ 'NAV_END' }   = $cookie->{ 'PAGE' } eq 'browse' ? $cookie->{ 'NAV_END' }   : undef;
253
254         Maasha::BGB::Session::session_store( "$cookie->{ 'SESSION_DIR' }/$cookie->{ 'USER' }/session.json", $session );
255     }
256 }
257
258
259 sub session_id_check
260 {
261     # Martin A. Hansen, March 2010.
262
263     # Check that the session id in the cookie and session match.
264     # Sets SESSION_ERROR flag in cookie if not matching.
265
266     my ( $cookie,    # cookie hash
267          $session,   # session hash
268        ) = @_;
269
270     # Returns nothing.
271
272     if ( defined $cookie->{ 'SESSION_ID' } and defined $session->{ 'SESSION_ID' } )
273     {
274         if ( $cookie->{ 'SESSION_ID' } ne $session->{ 'SESSION_ID' } ) {
275             $cookie->{ 'SESSION_ERROR' } = 1;
276         } else {
277             $cookie->{ 'SESSION_ERROR' } = 0;
278         }
279     }
280 }
281
282
283 sub cookie_login
284 {
285     # Martin A. Hansen, December 2009.
286
287     # Check a user and password from CGI against the password file and
288     # set the session ID, if found, in the cookie.
289
290     my ( $cookie,   # cookie hash
291        ) = @_;
292
293     # Returns nothing.
294
295     my ( $session );
296
297     if ( defined $cookie->{ 'PASSWORD' } )
298     {
299         if ( defined $cookie->{ 'USER' } and -d "$cookie->{ 'SESSION_DIR' }/$cookie->{ 'USER' }" )
300         {
301             $session = Maasha::BGB::Session::session_restore( "$cookie->{ 'SESSION_DIR' }/$cookie->{ 'USER' }/session.json" );
302
303             if ( $session->{ 'PASSWORD' } eq Digest::MD5::md5_hex( $cookie->{ 'PASSWORD' } ) )
304             {
305                 $cookie->{ 'TIME' }          = Maasha::Common::time_stamp();
306                 $cookie->{ 'SESSION_ID' }  ||= Maasha::BGB::Session::session_new();
307                 $cookie->{ 'LOGIN' }         = 1;
308                 $cookie->{ 'LOGIN_ERROR' }   = 0;
309             }
310             else
311             {
312                 $cookie->{ 'LOGIN_ERROR' } = 1;
313             }
314         }
315         else
316         {
317             $cookie->{ 'LOGIN_ERROR' } = 1;
318         }
319     }
320 }
321
322
323 sub cookie_start
324 {
325     # Martin A. Hansen, November 2009.
326
327     # Decommify the cookie value for NAV_START and adjust it to
328     # to prevent negative values.
329
330     my ( $cookie,   # cookie hash
331        ) = @_;
332
333     # Returns nothing.
334
335     if ( defined $cookie->{ 'NAV_START' } )
336     {
337         $cookie->{ 'NAV_START' } =~ tr/,//d;
338         $cookie->{ 'NAV_START' } = 0 if $cookie->{ 'NAV_START' } < 0;
339     }
340     else
341     {
342         $cookie->{ 'NAV_START' } = 0;
343     }
344 }
345
346
347 sub cookie_end
348 {
349     # Martin A. Hansen, November 2009.
350
351     # Decommify the cookie value for NAV_END and adjust it to prevent
352     # overshooting the max value for the contig size as determined
353     # from the cookie.
354
355     my ( $cookie,   # cookie hash
356        ) = @_;
357
358     # Returns nothing.
359
360     my ( $max );
361     
362     $max = Maasha::Filesys::file_size( Maasha::BGB::Track::path_seq( $cookie ) );
363
364     if ( defined $cookie->{ 'NAV_END' } )
365     {
366         $cookie->{ 'NAV_END' } =~ tr/,//d;
367         $cookie->{ 'NAV_END' } = $max if $cookie->{ 'NAV_END' } > $max;
368     }
369     else
370     {
371         $cookie->{ 'NAV_END' } = $max;
372     }
373 }
374
375
376 sub cookie_zoom
377 {
378     # Martin A. Hansen, November 2009.
379
380     # Adjust the cookie values for NAV_START and NAV_END based
381     # on cookie ZOOM values.
382
383     my ( $cookie,   # cookie hash
384        ) = @_;
385
386     # Returns nothing.
387
388     my ( $max, $dist, $new_dist, $dist_diff );
389
390     $max = Maasha::Filesys::file_size( Maasha::BGB::Track::path_seq( $cookie ) );
391
392     $dist = $cookie->{ 'NAV_END' } - $cookie->{ 'NAV_START' };
393
394     if ( defined $cookie->{ 'ZOOM_IN1' } ) {
395         $new_dist = $dist / 1.5;
396     } elsif ( defined $cookie->{ 'ZOOM_IN2' } ) {
397         $new_dist = $dist / 3;
398     } elsif ( defined $cookie->{ 'ZOOM_IN3' } ) {
399         $new_dist = $dist / 10;
400     } elsif ( defined $cookie->{ 'ZOOM_OUT1' } ) {
401         $new_dist = $dist * 1.5;
402     } elsif ( defined $cookie->{ 'ZOOM_OUT2' } ) {
403         $new_dist = $dist * 3;
404     } elsif ( defined $cookie->{ 'ZOOM_OUT3' } ) {
405         $new_dist = $dist * 10;
406     }
407
408     if ( $new_dist )
409     {
410         $dist_diff = $dist - $new_dist;
411
412         $cookie->{ 'NAV_START' } = int( $cookie->{ 'NAV_START' } + ( $dist_diff / 2 ) );
413         $cookie->{ 'NAV_END' }   = int( $cookie->{ 'NAV_END' }   - ( $dist_diff / 2 ) );
414
415         $cookie->{ 'NAV_START' } = 0    if $cookie->{ 'NAV_START' } < 0;
416         $cookie->{ 'NAV_END' }   = $max if $cookie->{ 'NAV_END' } > $max;
417     }
418 }
419
420
421 sub cookie_move
422 {
423     # Martin A. Hansen, November 2009.
424
425     # Adjust the cookie values for NAV_START and NAV_END based
426     # on cookie MOVE values.
427
428     my ( $cookie,   # cookie hash
429        ) = @_;
430
431     # Returns nothing.
432     
433     my ( $max, $dist, $shift, $new_start, $new_end );
434
435     $max = Maasha::Filesys::file_size( Maasha::BGB::Track::path_seq( $cookie ) );
436
437     $dist = $cookie->{ 'NAV_END' } - $cookie->{ 'NAV_START' };
438
439     if ( defined $cookie->{ 'MOVE_LEFT1' } ) {
440         $shift = -1 * $dist * 0.10;
441     } elsif ( defined $cookie->{ 'MOVE_LEFT2' } ) {
442         $shift = -1 * $dist * 0.475;
443     } elsif ( defined $cookie->{ 'MOVE_LEFT3' } ) {
444         $shift = -1 * $dist * 0.95;
445     } elsif ( defined $cookie->{ 'MOVE_RIGHT1' } ) {
446         $shift = $dist * 0.10;
447     } elsif ( defined $cookie->{ 'MOVE_RIGHT2' } ) {
448         $shift = $dist * 0.475;
449     } elsif ( defined $cookie->{ 'MOVE_RIGHT3' } ) {
450         $shift = $dist * 0.95;
451     }
452
453     if ( $shift )
454     {
455         $new_start = int( $cookie->{ 'NAV_START' } + $shift );
456         $new_end   = int( $cookie->{ 'NAV_END' }   + $shift );
457
458         if ( $new_start > 0 and $new_end < $max )
459         {
460             $cookie->{ 'NAV_START' } = $new_start;
461             $cookie->{ 'NAV_END' }   = $new_end;
462         }
463     }
464 }
465
466
467 sub cookie_center
468 {
469     # Martin A. Hansen, March 2010
470    
471     # Adjust the cookie values for NAV_START and NAV_END based
472     # on cookie CENTER value if defined.
473
474     my ( $cookie,   # cookie hash
475        ) = @_;
476
477     # Returns nothing.
478
479     my ( $l_dist, $r_dist );
480
481     if ( defined $cookie->{ 'NAV_CENTER' } )
482     {
483         $l_dist = $cookie->{ 'NAV_CENTER' } - $cookie->{ 'NAV_START' };
484         $r_dist = $cookie->{ 'NAV_END' } - $cookie->{ 'NAV_CENTER' };
485
486         if ( $l_dist > $r_dist ) {
487             $cookie->{ 'NAV_START' } = $cookie->{ 'NAV_END' } - 2 * $r_dist;
488         } else {
489             $cookie->{ 'NAV_END' } = $cookie->{ 'NAV_START' } + 2 * $l_dist;
490         }
491     }
492 }
493
494
495 sub cookie_page_next
496 {
497     # Martin A. Hansen, November 2009.
498     
499     # Returns the next page in the taxonomy path.
500
501     my ( $cookie,   # cookie hash
502        ) = @_;
503
504     # Returns a string.
505
506     my ( $i );
507
508     for ( $i = 0; $i < @{ $cookie->{ 'LIST_PAGES' } }; $i++ ) {
509         last if $cookie->{ 'PAGE' } eq $cookie->{ 'LIST_PAGES' }->[ $i ];
510     }
511
512     return $cookie->{ 'LIST_PAGES' }->[ $i + 1 ];
513 }
514
515
516 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> PAGES <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
517
518
519 sub page
520 {
521     # Martin A. Hansen, November 2009.
522
523     # Determines what page to render based on
524     # the cookie's PAGE setting.
525
526     my ( $cookie,   # cookie hash
527        ) = @_;
528
529     # Returns a list.
530
531     my ( @html );
532
533     if ( $cookie->{ 'SESSION_ID' } ) {
534         push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "session_id", value => $cookie->{ 'SESSION_ID' } ) );
535     }
536
537     if ( $cookie->{ 'PAGE' } eq 'login' ) {
538         push @html, page_login( $cookie );
539     } elsif ( $cookie->{ 'PAGE' } eq 'search' ) {
540         push @html, page_search( $cookie );
541     } elsif ( $cookie->{ 'PAGE' } eq 'browse' ) {
542         push @html, page_browse( $cookie );
543     } elsif ( $cookie->{ 'PAGE' } eq 'dna' ) {
544         push @html, page_dna( $cookie );
545     } elsif ( $cookie->{ 'PAGE' } eq 'export' ) {
546         push @html, page_export( $cookie );
547     } else {
548         push @html, page_taxonomy( $cookie );
549     }
550
551     return wantarray ? @html : \@html;
552 }
553
554
555 sub page_login
556 {
557     # Martin A. Hansen, December 2009.
558
559     # Renders the login page.
560
561     my ( $cookie,
562        ) = @_;
563
564     # Returns a list.
565
566     my ( @html );
567
568     push @html, section_login( $cookie );
569
570     return wantarray ? @html : \@html;
571 }
572
573
574 sub page_search
575 {
576     # Martin A. Hansen, December 2009.
577
578     # Renders the search page.
579
580     my ( $cookie,
581        ) = @_;
582
583     # Returns a list.
584
585     my ( @html );
586
587     push @html, section_taxonomy_table( $cookie );
588     push @html, section_search( $cookie );
589
590     return wantarray ? @html : \@html;
591 }
592
593
594 sub page_browse
595 {
596     # Martin A. Hansen, November 2009.
597     
598     # Renders the browse page.
599
600     my ( $cookie,
601        ) = @_;
602
603     # Returns a list.
604
605     my ( @html );
606
607     push @html, section_taxonomy_table( $cookie );
608     push @html, section_navigate( $cookie );
609     push @html, section_browse( $cookie );
610     push @html, section_linkout( $cookie );
611
612     return wantarray ? @html : \@html;
613 }
614
615
616 sub page_dna
617 {
618     # Martin A. Hansen, November 2009.
619     
620     # Renders the DNA page.
621
622     my ( $cookie,
623        ) = @_;
624
625     # Returns a list.
626
627     my ( @html );
628
629     push @html, section_taxonomy_table( $cookie );
630     push @html, section_dna( $cookie );
631
632     return wantarray ? @html : \@html;
633 }
634
635
636 sub page_export
637 {
638     # Martin A. Hansen, November 2009.
639
640     # Renders the export page.
641
642     my ( $cookie,
643        ) = @_;
644
645     # Returns a list.
646
647     my ( @html );
648
649     push @html, section_taxonomy_table( $cookie );
650     push @html, section_export( $cookie );
651
652     return wantarray ? @html : \@html;
653 }
654
655
656 sub page_taxonomy
657 {
658     # Martin A. Hansen, November 2009.
659     
660     # Renders the browse page.
661
662     my ( $cookie,   # cookie hash
663        ) = @_;
664
665     # Returns a list.
666
667     my ( @html );
668
669     push @html, section_taxonomy_table( $cookie );
670     push @html, section_taxonomy_select( $cookie );
671
672     return wantarray ? @html : \@html;
673 }
674
675
676 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> SECTIONS <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
677
678
679 sub section_login
680 {
681     # Martin A. Hansen, December 2009.
682    
683     # Returns a HTML section with a login menu.
684
685     my ( $cookie,   # cookie hash
686        ) = @_;
687
688     # Returns a list.
689
690     my ( $user, $password, $login, @html );
691
692     $user     = Maasha::XHTML::text( name => "user", value => "", size => 20 );
693     $password = Maasha::XHTML::password( name => "password", value => "", size => 20 );
694     $login    = Maasha::XHTML::submit( name => "login_submit", value => "Login" );
695
696     push @html, Maasha::XHTML::h2( txt => "Login", class => 'center' );
697
698     push @html, Maasha::XHTML::table_beg( summary => "Login table", align => 'center' );
699     push @html, Maasha::XHTML::table_row_simple( tr => [ "User:", $user ] );
700     push @html, Maasha::XHTML::table_row_simple( tr => [ "Password:", $password ] );
701     push @html, Maasha::XHTML::table_row_simple( tr => [ "", $login ] );
702     push @html, Maasha::XHTML::table_end;
703
704     if ( defined $cookie->{ 'CLADE' }     and
705          defined $cookie->{ 'GENOME' }    and
706          defined $cookie->{ 'ASSEMBLY' }  and
707          defined $cookie->{ 'CONTIG' }    and
708          defined $cookie->{ 'NAV_START' } and
709          defined $cookie->{ 'NAV_END' }
710     )
711     {
712         push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "clade",     value => $cookie->{ 'CLADE' } ) );
713         push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "genome",    value => $cookie->{ 'GENOME' } ) );
714         push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "assembly",  value => $cookie->{ 'ASSEMBLY' } ) );
715         push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "contig",    value => $cookie->{ 'CONTIG' } ) );
716         push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "nav_start", value => $cookie->{ 'NAV_START' } ) );
717         push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "nav_end",   value => $cookie->{ 'NAV_END' } ) );
718     }
719
720     if ( $cookie->{ 'LOGIN_ERROR' } ) {
721         push @html, Maasha::XHTML::h3( txt => "Bad user or password - please retry", class => 'error' );
722     }
723
724     return wantarray ? @html : \@html;
725 }
726
727
728 sub section_taxonomy_table
729 {
730     # Martin A. Hansen, November 2009.
731
732     # Returns a HTML section with a taxonomy table
733     # showing the location in the taxonomy and with
734     # links to browse the taxonomy.
735
736     my ( $cookie,   # cookie hash
737        ) = @_;
738
739     # Returns a list.
740
741     my ( $page, @row, @html, $href, $txt );
742     
743     foreach $page ( @{ $cookie->{ 'LIST_PAGES' } } )
744     {
745         last if $page eq $cookie->{ 'PAGE' } or $page eq 'browse';
746
747         $href  = "$cookie->{ 'SCRIPT' }?page=$page";
748         $href .= "&session_id=$cookie->{ 'SESSION_ID' }";
749         $href .= "&user=$cookie->{ 'USER' }";
750         $href .= "&clade=$cookie->{ 'CLADE' }"       if $page !~ /clade/;
751         $href .= "&genome=$cookie->{ 'GENOME' }"     if $page !~ /clade|genome/;
752         $href .= "&assembly=$cookie->{ 'ASSEMBLY' }" if $page !~ /clade|genome|assembly/;
753         $href .= "&contig=$cookie->{ 'CONTIG' }"     if $page !~ /clade|genome|assembly|contig/;
754
755         $txt = ": $cookie->{ uc $page }";
756
757         push @row, Maasha::XHTML::ln( txt => $page, href => $href, class => 'inline' );
758         push @row, Maasha::XHTML::p(  txt => $txt, class => 'inline' );
759     }
760
761     push @html, Maasha::XHTML::table_beg( summary => "Taxonomy table", align => 'center', cellpadding => '5px' );
762     push @html, Maasha::XHTML::table_row_simple( tr => [ join( "\n", @row ) ], align => 'center' );
763     push @html, Maasha::XHTML::table_end;
764
765     return wantarray ? @html : \@html;
766 }
767
768
769 sub section_taxonomy_select
770 {
771     # Martin A. Hansen, November 2009.
772     
773     # Returns a HTML section with selection choices
774     # for navigating the taxonomy tree.
775
776     my ( $cookie,   # cookie hash
777        ) = @_;
778
779     # Returns a list.
780
781     my ( $list, @html, $item, $href );
782
783     $list = "LIST_" . uc $cookie->{ 'PAGE' };
784
785     push @html, Maasha::XHTML::h2( txt => "Select $cookie->{ 'PAGE' }", class => 'center' );
786
787     push @html, Maasha::XHTML::table_beg( summary => "Taxonomy select table", align => 'center', cellpadding => '5px' );
788
789     foreach $item ( @{ $cookie->{ $list } } )
790     {
791         $cookie->{ uc $cookie->{ 'PAGE' } } = $item;
792
793         $href  = "$cookie->{ 'SCRIPT' }?page=" . cookie_page_next( $cookie );
794         $href .= "&session_id=$cookie->{ 'SESSION_ID' }";
795         $href .= "&user=$cookie->{ 'USER' }";
796         $href .= "&clade=$cookie->{ 'CLADE' }";
797         $href .= "&genome=$cookie->{ 'GENOME' }"     if $cookie->{ 'GENOME' };
798         $href .= "&assembly=$cookie->{ 'ASSEMBLY' }" if $cookie->{ 'ASSEMBLY' };
799         $href .= "&contig=$cookie->{ 'CONTIG' }"     if $cookie->{ 'CONTIG' };
800
801         push @html, Maasha::XHTML::table_row_simple( tr => [ Maasha::XHTML::ln( txt => $item, href => $href ) ] );
802     }
803
804     push @html, Maasha::XHTML::table_end;
805
806     return wantarray ? @html : \@html;
807 }
808
809
810 sub section_navigate
811 {
812     # Martin A. Hansen, November 2009.
813
814     # Returns a HTML section for navigating in the browser window.
815
816     my ( $cookie,   # cookie hash
817        ) = @_;
818
819     # Returns a list.
820
821     my ( @html, $nav_val );
822
823     $nav_val = Maasha::Calc::commify( $cookie->{ 'NAV_START' } ) . "-" . Maasha::Calc::commify( $cookie->{ 'NAV_END' } );
824
825     push @html, Maasha::XHTML::table_beg( summary => "Navigation table", align => 'center' );
826     push @html, Maasha::XHTML::table_row_simple( tr => [
827         "Position or search term:",
828         Maasha::XHTML::text( name => "nav_search", value => $nav_val, size => 30 ),
829         Maasha::XHTML::submit( name => "nav_submit", value => "Submit" ),
830     ] );
831     push @html, Maasha::XHTML::table_end;
832
833     push @html, Maasha::XHTML::table_beg( summary => "Zoom table", align => 'center' );
834     push @html, Maasha::XHTML::table_row_simple( tr => [
835         Maasha::XHTML::p( txt => 'Move:' ),
836         Maasha::XHTML::submit( name => "move_left3",  value => "<<<", title => "move 95% to the left" ),
837         Maasha::XHTML::submit( name => "move_left2",  value => "<<",  title => "move 47.5% to the left" ),
838         Maasha::XHTML::submit( name => "move_left1",  value => "<",   title => "move 10% to the left" ),
839         Maasha::XHTML::submit( name => "move_right1", value => ">",   title => "move 10% to the rigth" ),
840         Maasha::XHTML::submit( name => "move_right2", value => ">>",  title => "move 47.5% to the rigth" ),
841         Maasha::XHTML::submit( name => "move_right3", value => ">>>", title => "move 95% to the right" ),
842         Maasha::XHTML::p( txt => 'Zoom in:' ),
843         Maasha::XHTML::submit( name => "zoom_in1", value => "1.5x" ),
844         Maasha::XHTML::submit( name => "zoom_in2", value => "3x" ),
845         Maasha::XHTML::submit( name => "zoom_in3", value => "10x" ),
846         Maasha::XHTML::p( txt => 'Zoom out:' ),
847         Maasha::XHTML::submit( name => "zoom_out1", value => "1.5x" ),
848         Maasha::XHTML::submit( name => "zoom_out2", value => "3x" ),
849         Maasha::XHTML::submit( name => "zoom_out3", value => "10x" ),
850     ] );
851     push @html, Maasha::XHTML::table_end;
852
853     push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "page",     value => "browse" ) );
854     push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "user",     value => $cookie->{ 'USER' } ) );
855     push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "clade",    value => $cookie->{ 'CLADE' } ) );
856     push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "genome",   value => $cookie->{ 'GENOME' } ) );
857     push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "assembly", value => $cookie->{ 'ASSEMBLY' } ) );
858     push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "contig",   value => $cookie->{ 'CONTIG' } ) );
859
860     return wantarray ? @html : \@html;
861 }
862
863
864 sub section_linkout
865 {
866     # Martin A. Hansen, March 2010.
867
868     # Returns a HTML section for a static link based on information in the cookie.
869
870     my ( $cookie,   # cookie hash
871        ) = @_;
872
873     # Returns a list.
874
875     my ( $link, @html );
876
877     $link = Maasha::XHTML::ln(
878         txt  => 'link',
879         href => join( "&", "$cookie->{ 'SCRIPT' }?page=browse",
880                            "clade=$cookie->{ 'CLADE' }",
881                            "genome=$cookie->{ 'GENOME' }",
882                            "assembly=$cookie->{ 'ASSEMBLY' }",
883                            "contig=$cookie->{ 'CONTIG' }",
884                            "nav_start=$cookie->{ 'NAV_START' }",
885                            "nav_end=$cookie->{ 'NAV_END' }",
886               ),
887         title  => "Static link to this view",
888     );
889
890     push @html, Maasha::XHTML::p( txt => $link, class => 'center' );
891
892     return wantarray ? @html : \@html;
893 }
894
895
896 sub section_browse
897 {
898     my ( $cookie,
899        ) = @_;
900
901     # Returns a list.
902
903     my ( @tracks, $i, @features, $feat, $elem, $surface, $cr, $png_data, @html, @img, $x1, $y1, $x2, $y2, $factor, $center );
904
905     push @features, [ Maasha::BGB::Track::track_ruler( $cookie ) ];
906     push @features, [ Maasha::BGB::Track::track_seq( $cookie ) ];
907
908     @tracks = Maasha::BGB::Track::path_tracks( $cookie );
909
910     for ( $i = 0; $i < @tracks; $i++ )
911     {
912         $cookie->{ 'FEAT_COLOR' } = Maasha::BGB::Draw::palette( $i );
913
914         push @features, [ Maasha::BGB::Track::track_feature( $tracks[ $i ], $cookie ) ];
915     }
916
917     $surface = Cairo::ImageSurface->create( 'argb32', $cookie->{ 'IMG_WIDTH' }, $cookie->{ 'TRACK_OFFSET' } );
918     $cr      = Cairo::Context->create( $surface );
919
920     $cr->rectangle ( 0, 0, $cookie->{ 'IMG_WIDTH' },  $cookie->{ 'TRACK_OFFSET' } );
921     $cr->set_source_rgb ( 1, 1, 1 );
922     $cr->fill;
923
924     foreach $feat ( @features ) {
925         Maasha::BGB::Draw::draw_feature( $cr, $feat ) if $feat;
926     }
927
928     $png_data = Maasha::BGB::Draw::base64_png( $surface );
929
930     push @img, Maasha::XHTML::img(
931         src    => "data:image/png;base64,$png_data",
932         alt    => "Browser Tracks",
933         height => $cookie->{ 'TRACK_OFFSET' },
934         width  => $cookie->{ 'IMG_WIDTH' },
935         id     => "browser_map",
936         usemap => "#browser_map"
937     );
938
939     push @img, Maasha::XHTML::map_beg( name => "browser_map", id => "browser_map" );
940
941     $factor = ( $cookie->{ 'NAV_END' } - $cookie->{ 'NAV_START' } + 1 ) / $cookie->{ 'IMG_WIDTH' };
942
943     for ( $i = 0; $i < $cookie->{ 'IMG_WIDTH' }; $i += 5 )
944     {
945         $x1 = $i;
946         $y1 = 10;
947         $x2 = $i + 5;
948         $y2 = 20;
949
950         $center = int( $cookie->{ 'NAV_START' } + $factor * $i );
951
952         push @img, Maasha::XHTML::area(
953             href     => join( "&", "$cookie->{ 'SCRIPT' }?page=browse",
954                                    "session_id=$cookie->{ 'SESSION_ID' }",
955                                    "user=$cookie->{ 'USER' }",
956                                    "clade=$cookie->{ 'CLADE' }",
957                                    "genome=$cookie->{ 'GENOME' }",
958                                    "assembly=$cookie->{ 'ASSEMBLY' }",
959                                    "contig=$cookie->{ 'CONTIG' }",
960                                    "nav_start=$cookie->{ 'NAV_START' }",
961                                    "nav_end=$cookie->{ 'NAV_END' }",
962                                    "nav_center=$center",
963                       ),
964             shape  => 'rect',
965             coords => "$x1, $y1, $x2, $y2",
966             title  => "Center on " . Maasha::Calc::commify( $center ),
967         );
968     }
969
970     foreach $feat ( @features )
971     {
972         foreach $elem ( @{ $feat } )
973         {
974             next if $elem->{ 'type' } eq 'text';
975             next if $elem->{ 'type' } eq 'wiggle';
976
977             #$elem->{ 'strand' } = '&#43' if $elem->{ 'strand' } eq '+';
978
979             $cookie->{ 'Q_ID' }   = $elem->{ 'q_id' };
980             $cookie->{ 'S_BEG' }  = $elem->{ 's_beg' };
981             $cookie->{ 'S_END' }  = $elem->{ 's_end' };
982             $cookie->{ 'STRAND' } = $elem->{ 'strand' };
983
984             push @img, Maasha::XHTML::area(
985                 href     => join( "&", "$cookie->{ 'SCRIPT' }?page=export",
986                                        "session_id=$cookie->{ 'SESSION_ID' }",
987                                        "user=$cookie->{ 'USER' }",
988                                        "clade=$cookie->{ 'CLADE' }",
989                                        "genome=$cookie->{ 'GENOME' }",
990                                        "assembly=$cookie->{ 'ASSEMBLY' }",
991                                        "contig=$cookie->{ 'CONTIG' }",
992                                        "s_beg=$cookie->{ 'S_BEG' }",
993                                        "s_end=$cookie->{ 'S_END' }",
994                                        "strand=$cookie->{ 'STRAND' }",
995                           ),
996                 shape  => 'rect',
997                 coords => "$elem->{ x1 }, $elem->{ y1 }, $elem->{ x2 }, $elem->{ y2 }",
998                 title  => "$elem->{ 'title' }",
999             );
1000         }
1001     }
1002
1003     push @img, Maasha::XHTML::map_end();
1004
1005     push @html, Maasha::XHTML::p( txt => join( "\n", @img ) );
1006
1007     @html = Maasha::XHTML::div( txt => join( "\n", @html ), class => 'browse' );
1008
1009     return wantarray ? @html : \@html;
1010 }
1011
1012
1013 sub section_export
1014 {
1015     # Martin A. Hansen, November 2009.
1016
1017     # Returns a HTML section with export table.
1018
1019     my ( $cookie,   # cookie hash
1020        ) = @_;
1021
1022     # Returns a list.
1023
1024     my ( $feat, @row_dna_contig, @html );
1025
1026     $feat = $cookie->{ 'Q_ID' } || "[no name]";
1027
1028     push @row_dna_contig, Maasha::XHTML::p( txt => qq(Export Feature: "$feat" DNA from Contig: ), class => 'inline' );
1029     push @row_dna_contig, Maasha::XHTML::p( txt  => "$cookie->{ 'CONTIG' } Start: ", class => 'inline' );
1030     push @row_dna_contig, Maasha::XHTML::text( name => "s_beg", value => Maasha::Calc::commify( $cookie->{ 'S_BEG' } ), size => 15 );
1031     push @row_dna_contig, Maasha::XHTML::p( txt => "End: ", class => 'inline' );
1032     push @row_dna_contig, Maasha::XHTML::text( name => "s_end", value => Maasha::Calc::commify( $cookie->{ 'S_END' } ), size => 15 );
1033     push @row_dna_contig, Maasha::XHTML::p( txt => "Strand: ", class => 'inline' );
1034     push @row_dna_contig, Maasha::XHTML::menu( name => "strand", options => [ qw( + - ) ], selected => $cookie->{ 'STRAND' } );
1035     push @row_dna_contig, Maasha::XHTML::submit( name => "export", value => "Export", title => "Fetch DNA from this region" );
1036
1037     push @html, Maasha::XHTML::h2( txt => "Export", class => 'center' );
1038     push @html, Maasha::XHTML::table_beg( summary => "Taxonomy select table", align => 'center' );
1039     push @html, Maasha::XHTML::table_row_simple( tr => \@row_dna_contig );
1040     push @html, Maasha::XHTML::table_end;
1041
1042     push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "page",     value => "dna" ) );
1043     push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "user",     value => $cookie->{ 'USER' } ) );
1044     push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "clade",    value => $cookie->{ 'CLADE' } ) );
1045     push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "genome",   value => $cookie->{ 'GENOME' } ) );
1046     push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "assembly", value => $cookie->{ 'ASSEMBLY' } ) );
1047     push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "contig",   value => $cookie->{ 'CONTIG' } ) );
1048
1049     return wantarray ? @html : \@html;
1050 }
1051
1052
1053 sub section_search
1054 {
1055     # Martin A. Hansen, November 2009.
1056
1057     # Returns a HTML section with export table.
1058
1059     my ( $cookie,   # cookie hash
1060        ) = @_;
1061
1062     # Returns a list.
1063
1064     my ( $results, $result, $count, @html, $export, $browse );
1065
1066     $results = Maasha::BGB::Track::search_tracks( $cookie );
1067
1068     $count = scalar @{ $results };
1069
1070     push @html, Maasha::XHTML::h2( txt => "Search", class => 'center' );
1071     push @html, Maasha::XHTML::p( txt => qq(Results for "$cookie->{ 'SEARCH' }": $count), class => 'center' );
1072
1073     if ( $count > 0 )
1074     {
1075         push @html, Maasha::XHTML::table_beg( summary => "Search table", align => 'center', cellpadding => '5px' );
1076         push @html, Maasha::XHTML::table_row_simple( tr => [ qw( S_ID S_BEG S_END Q_ID SCORE STRAND HITS ALIGN BLOCK_COUNT BLOCK_BEGS BLOCK_LENS BLOCK_TYPE) ] );
1077
1078         foreach $result ( @{ $results } )
1079         {
1080             $cookie->{ 'CONTIG' }    = $result->{ 'S_ID' };
1081             $cookie->{ 'NAV_START' } = $result->{ 'S_BEG' };
1082             $cookie->{ 'NAV_END' }   = $result->{ 'S_END' };
1083             $cookie->{ 'S_BEG' }     = $result->{ 'S_BEG' };
1084             $cookie->{ 'S_END' }     = $result->{ 'S_END' };
1085             $cookie->{ 'STRAND' }    = $result->{ 'STRAND' };
1086             $cookie->{ 'Q_ID' }      = $result->{ 'Q_ID' };
1087
1088             $browse = Maasha::XHTML::ln(
1089                 txt  => "browse",
1090                 href => join( "&", "$cookie->{ 'SCRIPT' }?page=browse",
1091                                    "session_id=$cookie->{ 'SESSION_ID' }",
1092                                    "user=$cookie->{ 'USER' }",
1093                                    "clade=$cookie->{ 'CLADE' }",
1094                                    "genome=$cookie->{ 'GENOME' }",
1095                                    "assembly=$cookie->{ 'ASSEMBLY' }",
1096                                    "contig=$cookie->{ 'CONTIG' }",
1097                                    "nav_start=$cookie->{ 'NAV_START' }",
1098                                    "nav_end=$cookie->{ 'NAV_END' }",
1099                 ),
1100             );
1101
1102
1103             $export = Maasha::XHTML::ln(
1104                 txt  => "export",
1105                 href => join( "&", "$cookie->{ 'SCRIPT' }?page=export",
1106                                    "session_id=$cookie->{ 'SESSION_ID' }",
1107                                    "user=$cookie->{ 'USER' }",
1108                                    "clade=$cookie->{ 'CLADE' }",
1109                                    "genome=$cookie->{ 'GENOME' }",
1110                                    "assembly=$cookie->{ 'ASSEMBLY' }",
1111                                    "contig=$cookie->{ 'CONTIG' }",
1112                                    "s_beg=$cookie->{ 'S_BEG' }",
1113                                    "s_end=$cookie->{ 'S_END' }",
1114                                    "strand=$cookie->{ 'STRAND' }",
1115                 ),
1116             );
1117
1118             push @html, Maasha::XHTML::table_row_advanced(
1119                 tr => [ { td => $result->{ 'S_ID' } },
1120                         { td => $result->{ 'S_BEG' }, align => 'right' },
1121                         { td => $result->{ 'S_END' }, align => 'right' },
1122                         { td => $result->{ 'Q_ID' } },
1123                         { td => $result->{ 'SCORE' }, align => 'right' },
1124                         { td => $result->{ 'STRAND' } },
1125                         { td => $result->{ 'HITS' }, align => 'right' },
1126                         { td => $result->{ 'ALIGN' } },
1127                         { td => $result->{ 'BLOCK_COUNT' }, align => 'right' },
1128                         { td => $result->{ 'BLOCK_BEGS' } },
1129                         { td => $result->{ 'BLOCK_LENS' } },
1130                         { td => $result->{ 'BLOCK_TYPE' } },
1131                         { td => $browse },
1132                         { td => $export },
1133                 ], class => "monospace"
1134             );
1135         }
1136
1137         push @html, Maasha::XHTML::table_end;
1138     }
1139
1140     return wantarray ? @html : \@html;
1141 }
1142
1143
1144 sub section_dna
1145 {
1146     # Martin A. Hansen, November 2009.
1147
1148     # Returns a HTML section with extracted DNA.
1149
1150     my ( $cookie,   # cookie hash
1151        ) = @_;
1152
1153     # Returns a list.
1154
1155     my ( @html, $beg, $end, $seq );
1156     
1157     $beg = $cookie->{ 'S_BEG' };
1158     $end = $cookie->{ 'S_END' };
1159     $beg =~ tr/,//d;
1160     $end =~ tr/,//d;
1161
1162     $seq = join ";", ">$cookie->{ 'GENOME' }", $cookie->{ 'ASSEMBLY' }, $cookie->{ 'CONTIG' }, $beg, $end, "$cookie->{ 'STRAND' }\n";
1163     $seq .= Maasha::BGB::Track::dna_get( $cookie );
1164
1165     push @html, Maasha::XHTML::h2( txt => "DNA", class => 'center' );
1166     push @html, Maasha::XHTML::pre( txt => $seq );
1167
1168     return wantarray ? @html : \@html;
1169 }
1170
1171
1172 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
1173
1174
1175 __END__