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