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