]> git.donarmstrong.com Git - biopieces.git/blob - www/index.cgi
set bbrowser and GFF to 0-base
[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 Data::Dumper;
30 use Maasha::Common;
31 use Maasha::Filesys;
32 use Maasha::Calc;
33 use Maasha::XHTML;
34 use Maasha::KISS;
35 use Maasha::BBrowser::Track;
36 use Maasha::BBrowser::Draw;
37
38 my ( $cgi, $cookie, @html );
39
40 $cgi    = new CGI;
41 $cookie = cookie_default( $cgi );;
42
43 push @html, Maasha::XHTML::html_header(
44     cgi_header  => 1,
45     title       => "Biopieces Genome Browser",
46     css_file    => "bgb.css",
47     author      => "Martin A. Hansen, mail\@maasha.dk",
48     description => "Biopieces Genome Browser",
49     keywords    => [ qw( Biopieces biopiece genome browser viewer bacterium bacteria prokaryote prokaryotes ) ],
50     no_cache    => 1,
51 );
52
53 push @html, Maasha::XHTML::h1( txt => "Biopieces Genome Browser", class => 'center' );
54 push @html, Maasha::XHTML::form_beg( action => $cookie->{ 'SCRIPT' }, method => "get", enctype => "multipart/form-data" );
55
56 push @html, page( $cookie );
57
58 push @html, Maasha::XHTML::form_end;
59 push @html, Maasha::XHTML::body_end;
60 push @html, Maasha::XHTML::html_end;
61
62 # push @html, Maasha::XHTML::hdump( [ $cgi->Vars ] );  # DEBUG
63 # push @html, Maasha::XHTML::hdump( $cookie );     # DEBUG
64
65 print "$_\n" foreach @html;
66
67
68 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> SUBROUTINES <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
69
70
71 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> COOKIE <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
72
73
74 sub cookie_default
75 {
76     # Martin A. Hansen, November 2009.
77
78     # Set a cookie with values from the CGI object or defaults.
79
80     my ( $cgi,   # CGI object
81        ) = @_;
82
83     # Returns a hash.
84
85     my ( $cookie, $path );
86
87     $cookie = {};
88
89     $cookie->{ 'SCRIPT' }          = Maasha::Common::get_scriptname();
90     $cookie->{ 'DATA_DIR' }        = "Data";
91     $cookie->{ 'LIST_PAGES' }      = [ qw( user clade genome assembly contig browse ) ];
92     $cookie->{ 'PAGE' }            = $cgi->param( 'page' )     || 'user';
93     $cookie->{ 'USER' }            = $cgi->param( 'user' )     || '';
94     $cookie->{ 'CLADE' }           = $cgi->param( 'clade' )    || '';
95     $cookie->{ 'GENOME' }          = $cgi->param( 'genome' )   || '';
96     $cookie->{ 'ASSEMBLY' }        = $cgi->param( 'assembly' ) || '';
97     $cookie->{ 'CONTIG' }          = $cgi->param( 'contig' )   || '';
98     $cookie->{ 'Q_ID' }            = $cgi->param( 'q_id' );
99     $cookie->{ 'S_BEG' }           = $cgi->param( 's_beg' );
100     $cookie->{ 'S_END' }           = $cgi->param( 's_end' );
101     $cookie->{ 'STRAND' }          = $cgi->param( 'strand' );
102     $cookie->{ 'NAV_START' }       = $cgi->param( 'nav_start' );
103     $cookie->{ 'NAV_END' }         = $cgi->param( 'nav_end' );
104     $cookie->{ 'ZOOM_IN1' }        = $cgi->param( 'zoom_in1' );
105     $cookie->{ 'ZOOM_IN2' }        = $cgi->param( 'zoom_in2' );
106     $cookie->{ 'ZOOM_IN3' }        = $cgi->param( 'zoom_in3' );
107     $cookie->{ 'ZOOM_OUT1' }       = $cgi->param( 'zoom_out1' );
108     $cookie->{ 'ZOOM_OUT2' }       = $cgi->param( 'zoom_out2' );
109     $cookie->{ 'ZOOM_OUT3' }       = $cgi->param( 'zoom_out3' );
110     $cookie->{ 'MOVE_LEFT1' }      = $cgi->param( 'move_left1' );
111     $cookie->{ 'MOVE_LEFT2' }      = $cgi->param( 'move_left2' );
112     $cookie->{ 'MOVE_LEFT3' }      = $cgi->param( 'move_left3' );
113     $cookie->{ 'MOVE_RIGHT1' }     = $cgi->param( 'move_right1' );
114     $cookie->{ 'MOVE_RIGHT2' }     = $cgi->param( 'move_right2' );
115     $cookie->{ 'MOVE_RIGHT3' }     = $cgi->param( 'move_right3' );
116
117     $cookie->{ 'IMG_WIDTH' }       = 1200;
118     $cookie->{ 'IMG_HEIGHT' }      = 800;
119     $cookie->{ 'TRACK_OFFSET' }    = 20;
120     $cookie->{ 'TRACK_SPACE' }     = 20;
121     $cookie->{ 'RULER_FONT_SIZE' } = 10;
122     $cookie->{ 'RULER_COLOR' }     = [ 0, 0, 0 ];
123     $cookie->{ 'SEQ_FONT_SIZE' }   = 10;
124     $cookie->{ 'SEQ_COLOR' }       = [ 0, 0, 0, ];
125     $cookie->{ 'FEAT_WIDTH' }      = 5;
126     $cookie->{ 'FEAT_COLOR' }      = [ 0, 0, 0 ];
127     $cookie->{ 'FEAT_MAX' }        = 5000;
128
129     $path = "$cookie->{ 'DATA_DIR' }/Users";
130
131     $cookie->{ 'LIST_USER' }       = Maasha::Filesys::ls_dirs_base( $path ) if -d $path;
132
133     $path .= "/$cookie->{ 'USER' }";
134
135     $cookie->{ 'LIST_CLADE' }      = Maasha::Filesys::ls_dirs_base( $path ) if -d $path;
136
137     $path .= "/$cookie->{ 'CLADE' }";
138
139     $cookie->{ 'LIST_GENOME' }     = Maasha::Filesys::ls_dirs_base( $path ) if -d $path;
140
141     $path .= "/$cookie->{ 'GENOME' }";
142
143     $cookie->{ 'LIST_ASSEMBLY' }   = Maasha::Filesys::ls_dirs_base( $path ) if -d $path;
144
145     $path .= "/$cookie->{ 'ASSEMBLY' }";
146
147     $cookie->{ 'LIST_CONTIG' }     = Maasha::Filesys::ls_dirs_base( $path ) if -d $path;
148
149     if ( $cookie->{ 'CONTIG' } )
150     {
151         cookie_start( $cookie );
152         cookie_end( $cookie );
153         cookie_zoom( $cookie );
154         cookie_move( $cookie );
155     }
156
157     $cookie->{ 'STRAND' } = '+' if $cookie->{ 'STRAND' } eq ' ';
158
159     return wantarray ? %{ $cookie } : $cookie;
160 }
161
162
163 sub cookie_start
164 {
165     # Martin A. Hansen, November 2009.
166
167     # Decommify the cookie value for NAV_START and adjust it to
168     # to prevent negative values.
169
170     my ( $cookie,   # cookie hash
171        ) = @_;
172
173     # Returns nothing.
174
175     if ( defined $cookie->{ 'NAV_START' } )
176     {
177         $cookie->{ 'NAV_START' } =~ tr/,//d;
178         $cookie->{ 'NAV_START' } = 0 if $cookie->{ 'NAV_START' } < 0;
179     }
180     else
181     {
182         $cookie->{ 'NAV_START' } = 0;
183     }
184 }
185
186
187 sub cookie_end
188 {
189     # Martin A. Hansen, November 2009.
190
191     # Decommify the cookie value for NAV_END and adjust it to prevent
192     # overshooting the max value for the contig size as determined
193     # from the cookie.
194
195     my ( $cookie,   # cookie hash
196        ) = @_;
197
198     # Returns nothing.
199
200     my ( $max );
201     
202     $max = Maasha::Filesys::file_size( Maasha::BBrowser::Track::path_seq( $cookie ) );
203
204     if ( defined $cookie->{ 'NAV_END' } )
205     {
206         $cookie->{ 'NAV_END' } =~ tr/,//d;
207         $cookie->{ 'NAV_END' } = $max if $cookie->{ 'NAV_END' } > $max;
208     }
209     else
210     {
211         $cookie->{ 'NAV_END' } = $max;
212     }
213 }
214
215
216 sub cookie_zoom
217 {
218     # Martin A. Hansen, November 2009.
219
220     # Adjust the cookie values for NAV_START and NAV_END based
221     # on cookie ZOOM values.
222
223     my ( $cookie,   # cookie hash
224        ) = @_;
225
226     # Returns nothing.
227
228     my ( $max, $dist, $new_dist, $dist_diff );
229
230     $max = Maasha::Filesys::file_size( Maasha::BBrowser::Track::path_seq( $cookie ) );
231
232     $dist = $cookie->{ 'NAV_END' } - $cookie->{ 'NAV_START' };
233
234     if ( defined $cookie->{ 'ZOOM_IN1' } ) {
235         $new_dist = $dist / 1.5;
236     } elsif ( defined $cookie->{ 'ZOOM_IN2' } ) {
237         $new_dist = $dist / 3;
238     } elsif ( defined $cookie->{ 'ZOOM_IN3' } ) {
239         $new_dist = $dist / 10;
240     } elsif ( defined $cookie->{ 'ZOOM_OUT1' } ) {
241         $new_dist = $dist * 1.5;
242     } elsif ( defined $cookie->{ 'ZOOM_OUT2' } ) {
243         $new_dist = $dist * 3;
244     } elsif ( defined $cookie->{ 'ZOOM_OUT3' } ) {
245         $new_dist = $dist * 10;
246     }
247
248     if ( $new_dist )
249     {
250         $dist_diff = $dist - $new_dist;
251
252         $cookie->{ 'NAV_START' } = int( $cookie->{ 'NAV_START' } + ( $dist_diff / 2 ) );
253         $cookie->{ 'NAV_END' }   = int( $cookie->{ 'NAV_END' }   - ( $dist_diff / 2 ) );
254
255         $cookie->{ 'NAV_START' } = 0    if $cookie->{ 'NAV_START' } < 0;
256         $cookie->{ 'NAV_END' }   = $max if $cookie->{ 'NAV_END' } > $max;
257     }
258 }
259
260
261 sub cookie_move
262 {
263     # Martin A. Hansen, November 2009.
264
265     # Adjust the cookie values for NAV_START and NAV_END based
266     # on cookie MOVE values.
267
268     my ( $cookie,   # cookie hash
269        ) = @_;
270
271     my ( $max, $dist, $shift, $new_start, $new_end );
272
273     $max = Maasha::Filesys::file_size( Maasha::BBrowser::Track::path_seq( $cookie ) );
274
275     $dist = $cookie->{ 'NAV_END' } - $cookie->{ 'NAV_START' };
276
277     if ( defined $cookie->{ 'MOVE_LEFT1' } ) {
278         $shift = -1 * $dist * 0.10;
279     } elsif ( defined $cookie->{ 'MOVE_LEFT2' } ) {
280         $shift = -1 * $dist * 0.475;
281     } elsif ( defined $cookie->{ 'MOVE_LEFT3' } ) {
282         $shift = -1 * $dist * 0.95;
283     } elsif ( defined $cookie->{ 'MOVE_RIGHT1' } ) {
284         $shift = $dist * 0.10;
285     } elsif ( defined $cookie->{ 'MOVE_RIGHT2' } ) {
286         $shift = $dist * 0.475;
287     } elsif ( defined $cookie->{ 'MOVE_RIGHT3' } ) {
288         $shift = $dist * 0.95;
289     }
290
291     if ( $shift )
292     {
293         $new_start = int( $cookie->{ 'NAV_START' } + $shift );
294         $new_end   = int( $cookie->{ 'NAV_END' }   + $shift );
295
296         if ( $new_start > 0 and $new_end < $max )
297         {
298             $cookie->{ 'NAV_START' } = $new_start;
299             $cookie->{ 'NAV_END' }   = $new_end;
300         }
301     }
302 }
303
304
305 sub cookie_href
306 {
307     # Martin A. Hansen, November 2009.
308
309     # Returns the href for a taxonomy path terminated at a given
310     # page using information stored in a cookie.
311
312     my ( $cookie,   # cookie hash
313          $page,     # page
314        ) = @_;
315
316     # Returns a string.
317
318     my ( @href );
319
320     while ( 1 )
321     {
322         push @href, "$cookie->{ 'SCRIPT' }?page=$page";
323         push @href, "user=$cookie->{ 'USER' }"         if $cookie->{ 'USER' };
324         last if $page eq 'user';
325         push @href, "clade=$cookie->{ 'CLADE' }"       if $cookie->{ 'CLADE' };
326         last if $page eq 'clade';
327         push @href, "genome=$cookie->{ 'GENOME' }"     if $cookie->{ 'GENOME' };
328         last if $page eq 'genome';
329         push @href, "assembly=$cookie->{ 'ASSEMBLY' }" if $cookie->{ 'ASSEMBLY' };
330         last if $page eq 'assembly';
331         push @href, "contig=$cookie->{ 'CONTIG' }"     if $cookie->{ 'CONTIG' };
332         last if $page eq 'contig';
333         last;
334     }
335
336     return join "&", @href;
337 }
338
339
340 sub cookie_page_next
341 {
342     # Martin A. Hansen, November 2009.
343     
344     # Returns the next page in the taxonomy path.
345
346     my ( $cookie,   # cookie hash
347        ) = @_;
348
349     # Returns a string.
350
351     my ( $i );
352
353     for ( $i = 0; $i < @{ $cookie->{ 'LIST_PAGES' } }; $i++ ) {
354         last if $cookie->{ 'PAGE' } eq $cookie->{ 'LIST_PAGES' }->[ $i ];
355     }
356
357     return $cookie->{ 'LIST_PAGES' }->[ $i + 1 ];
358 }
359
360
361 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> PAGES <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
362
363
364 sub page
365 {
366     # Martin A. Hansen, November 2009.
367
368     # Determines what page to render based on
369     # the cookie's PAGE setting.
370
371     my ( $cookie,   # cookie hash
372        ) = @_;
373
374     # Returns a list.
375
376     my ( @html );
377
378     if ( $cookie->{ 'PAGE' } eq 'export' ) {
379         push @html, page_export( $cookie );
380     } elsif ( $cookie->{ 'PAGE' } eq 'browse' ) {
381         push @html, page_browse( $cookie );
382     } elsif ( $cookie->{ 'PAGE' } eq 'dna' ) {
383         push @html, page_dna( $cookie );
384     } else {
385         push @html, page_taxonomy( $cookie );
386     }
387
388     return wantarray ? @html : \@html;
389 }
390
391
392 sub page_export
393 {
394     # Martin A. Hansen, November 2009.
395
396     # Renders the export page.
397
398     my ( $cookie,
399        ) = @_;
400
401     # Returns a list.
402
403     my ( @html );
404
405     push @html, section_taxonomy_table( $cookie );
406     push @html, section_export( $cookie );
407
408     return wantarray ? @html : \@html;
409 }
410
411
412 sub page_browse
413 {
414     # Martin A. Hansen, November 2009.
415     
416     # Renders the browse page.
417
418     my ( $cookie,
419        ) = @_;
420
421     # Returns a list.
422
423     my ( @html );
424
425     push @html, section_taxonomy_table( $cookie );
426     push @html, section_navigate( $cookie );
427     push @html, section_browse( $cookie );
428
429     return wantarray ? @html : \@html;
430 }
431
432
433 sub page_dna
434 {
435     # Martin A. Hansen, November 2009.
436     
437     # Renders the DNA page.
438
439     my ( $cookie,
440        ) = @_;
441
442     # Returns a list.
443
444     my ( @html );
445
446     push @html, section_taxonomy_table( $cookie );
447     push @html, section_dna( $cookie );
448
449     return wantarray ? @html : \@html;
450 }
451
452
453 sub page_taxonomy
454 {
455     # Martin A. Hansen, November 2009.
456     
457     # Renders the browse page.
458
459     my ( $cookie,   # cookie hash
460        ) = @_;
461
462     # Returns a list.
463
464     my ( @html );
465
466     push @html, section_taxonomy_table( $cookie );
467     push @html, section_taxonomy_select( $cookie );
468
469     return wantarray ? @html : \@html;
470 }
471
472
473 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> SECTIONS <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
474
475
476 sub section_taxonomy_table
477 {
478     # Martin A. Hansen, November 2009.
479
480     # Returns a HTML section with a taxonomy table
481     # showing the location in the taxonomy and with
482     # links to browse the taxonomy.
483
484     my ( $cookie,   # cookie hash
485        ) = @_;
486
487     # Returns a list.
488
489     my ( $page, @row, @html, $href, $txt );
490     
491     foreach $page ( @{ $cookie->{ 'LIST_PAGES' } } )
492     {
493         last if $page eq $cookie->{ 'PAGE' } or $page eq 'browse';
494
495         $href = cookie_href( $cookie, $page );
496
497         $txt = ": $cookie->{ uc $page }";
498
499         push @row, Maasha::XHTML::ln( txt => $page, href => $href, class => 'inline' );
500         push @row, Maasha::XHTML::p(  txt => $txt, class => 'inline' );
501     }
502
503     push @html, Maasha::XHTML::table_beg( summary => "Taxonomy table", align => 'center', cellpadding => '5px' );
504     push @html, Maasha::XHTML::table_row_simple( tr => [ join( "\n", @row ) ], align => 'center' );
505     push @html, Maasha::XHTML::table_end;
506
507     return wantarray ? @html : \@html;
508 }
509
510
511 sub section_taxonomy_select
512 {
513     # Martin A. Hansen, November 2009.
514     
515     # Returns a HTML section with selection choices
516     # for navigating the taxonomy tree.
517
518     my ( $cookie,   # cookie hash
519        ) = @_;
520
521     # Returns a list.
522
523     my ( $list, @html, $item, $href );
524
525     $list = "LIST_" . uc $cookie->{ 'PAGE' };
526
527     push @html, Maasha::XHTML::h2( txt => "Select $cookie->{ 'PAGE' }", class => 'center' );
528
529     push @html, Maasha::XHTML::table_beg( summary => "Taxonomy select table", align => 'center', cellpadding => '5px' );
530
531     foreach $item ( @{ $cookie->{ $list } } )
532     {
533         $cookie->{ uc $cookie->{ 'PAGE' } } = $item;
534
535         $href = cookie_href( $cookie, cookie_page_next( $cookie ) );
536
537         push @html, Maasha::XHTML::table_row_simple( tr => [ Maasha::XHTML::ln( txt => $item, href => $href ) ] );
538     }
539
540     push @html, Maasha::XHTML::table_end;
541
542     return wantarray ? @html : \@html;
543 }
544
545
546 sub section_navigate
547 {
548     # Martin A. Hansen, November 2009.
549
550     # Returns a HTML section for navigating in the browser window.
551
552     my ( $cookie,   # cookie hash
553        ) = @_;
554
555     # Returns a list.
556
557     my ( @html );
558
559     push @html, Maasha::XHTML::table_beg( summary => "Navigation table", align => 'center' );
560     push @html, Maasha::XHTML::table_row_simple( tr => [
561         "Start:",
562         Maasha::XHTML::text( name => "nav_start", value => Maasha::Calc::commify( $cookie->{ 'NAV_START' } ), size => 15 ),
563         "End:",
564         Maasha::XHTML::text( name => "nav_end",   value => Maasha::Calc::commify( $cookie->{ 'NAV_END' } ),   size => 15 ), 
565         Maasha::XHTML::submit( name => "nav_submit", value => "Submit" ),
566     ] );
567     push @html, Maasha::XHTML::table_end;
568
569     push @html, Maasha::XHTML::table_beg( summary => "Zoom table", align => 'center' );
570     push @html, Maasha::XHTML::table_row_simple( tr => [
571         Maasha::XHTML::p( txt => 'Move:' ),
572         Maasha::XHTML::submit( name => "move_left3",  value => "<<<", title => "move 95% to the left" ),
573         Maasha::XHTML::submit( name => "move_left2",  value => "<<",  title => "move 47.5% to the left" ),
574         Maasha::XHTML::submit( name => "move_left1",  value => "<",   title => "move 10% to the left" ),
575         Maasha::XHTML::submit( name => "move_right1", value => ">",   title => "move 10% to the rigth" ),
576         Maasha::XHTML::submit( name => "move_right2", value => ">>",  title => "move 47.5% to the rigth" ),
577         Maasha::XHTML::submit( name => "move_right3", value => ">>>", title => "move 95% to the right" ),
578         Maasha::XHTML::p( txt => 'Zoom in:' ),
579         Maasha::XHTML::submit( name => "zoom_in1", value => "1.5x" ),
580         Maasha::XHTML::submit( name => "zoom_in2", value => "3x" ),
581         Maasha::XHTML::submit( name => "zoom_in3", value => "10x" ),
582         Maasha::XHTML::p( txt => 'Zoom out:' ),
583         Maasha::XHTML::submit( name => "zoom_out1", value => "1.5x" ),
584         Maasha::XHTML::submit( name => "zoom_out2", value => "3x" ),
585         Maasha::XHTML::submit( name => "zoom_out3", value => "10x" ),
586     ] );
587     push @html, Maasha::XHTML::table_end;
588
589     push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "page",     value => "browse" ) );
590     push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "user",     value => "$cookie->{ 'USER' }" ) );
591     push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "clade",    value => "$cookie->{ 'CLADE' }" ) );
592     push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "genome",   value => "$cookie->{ 'GENOME' }" ) );
593     push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "assembly", value => "$cookie->{ 'ASSEMBLY' }" ) );
594     push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "contig",   value => "$cookie->{ 'CONTIG' }" ) );
595
596     return wantarray ? @html : \@html;
597 }
598
599
600 sub section_browse
601 {
602     my ( $cookie,
603        ) = @_;
604
605     # Returns a list.
606
607     my ( @tracks, $i, @features, $feat, $elem, $file, $surface, $cr, @html, @img );
608
609     push @features, [ Maasha::BBrowser::Track::track_ruler( $cookie ) ];
610     push @features, [ Maasha::BBrowser::Track::track_seq( $cookie ) ];
611
612     @tracks = Maasha::BBrowser::Track::path_tracks( $cookie );
613
614     for ( $i = 0; $i < @tracks; $i++ )
615     {
616         $cookie->{ 'FEAT_COLOR' } = Maasha::BBrowser::Draw::palette( $i );
617
618         push @features, [ Maasha::BBrowser::Track::track_feature( $tracks[ $i ], $cookie ) ];
619     }
620
621     $file = "fisk.png";   # FIXME
622
623     $surface = Cairo::ImageSurface->create( 'argb32', $cookie->{ 'IMG_WIDTH' }, $cookie->{ 'TRACK_OFFSET' } );
624     $cr      = Cairo::Context->create( $surface );
625
626     $cr->rectangle ( 0, 0, $cookie->{ 'IMG_WIDTH' },  $cookie->{ 'TRACK_OFFSET' } );
627     $cr->set_source_rgb ( 1, 1, 1 );
628     $cr->fill;
629
630     foreach $feat ( @features ) {
631         Maasha::BBrowser::Draw::draw_feature( $cr, $feat ) if $feat;
632     }
633
634     Maasha::BBrowser::Draw::file_png( $surface, $file );
635
636     push @img, Maasha::XHTML::img(
637         src    => $file,
638         alt    => "Browser Tracks",
639         height => $cookie->{ 'TRACK_OFFSET' },
640         width  => $cookie->{ 'IMG_WIDTH' },
641         id     => "browser_map",
642         usemap => "#browser_map"
643     );
644
645     push @img, Maasha::XHTML::map_beg( name => "browser_map", id => "browser_map" );
646
647     foreach $feat ( @features )
648     {
649         foreach $elem ( @{ $feat } )
650         {
651             next if $elem->{ 'type' } eq 'text';
652
653             #$elem->{ 'strand' } = '&#43' if $elem->{ 'strand' } eq '+';
654
655             push @img, Maasha::XHTML::area(
656                 href   => cookie_href( $cookie, "export" ) . "&q_id=$elem->{ 'q_id' }&s_beg=$elem->{ 's_beg' }&s_end=$elem->{ 's_end' }&strand=$elem->{ 'strand' }",
657                 shape  => "rect",
658                 coords => "$elem->{ x1 }, $elem->{ y1 }, $elem->{ x2 }, $elem->{ y2 }", title => "$elem->{ 'title' }",
659             );
660         }
661     }
662
663     push @img, Maasha::XHTML::map_end();
664
665     push @html, Maasha::XHTML::p( txt => join( "\n", @img ) );
666
667     @html = Maasha::XHTML::div( txt => join( "\n", @html ), class => 'browse' );
668
669     return wantarray ? @html : \@html;
670 }
671
672
673 sub section_export
674 {
675     # Martin A. Hansen, November 2009.
676
677     # Returns a HTML section with export table.
678
679     my ( $cookie,   # cookie hash
680        ) = @_;
681
682     # Returns a list.
683
684     my ( @row_dna_contig, @html );
685
686     push @row_dna_contig, Maasha::XHTML::p( txt => qq(Export Feature: "$cookie->{ 'Q_ID' }" DNA from Contig: ), class => 'inline' );
687     push @row_dna_contig, Maasha::XHTML::p( txt  => "$cookie->{ 'CONTIG' } Start: ", class => 'inline' );
688     push @row_dna_contig, Maasha::XHTML::text( name => "s_beg", value => Maasha::Calc::commify( $cookie->{ 'S_BEG' } ), size => 15 );
689     push @row_dna_contig, Maasha::XHTML::p( txt => "End: ", class => 'inline' );
690     push @row_dna_contig, Maasha::XHTML::text( name => "s_end", value => Maasha::Calc::commify( $cookie->{ 'S_END' } ), size => 15 );
691     push @row_dna_contig, Maasha::XHTML::p( txt => "Strand: ", class => 'inline' );
692     push @row_dna_contig, Maasha::XHTML::menu( name => "strand", options => [ qw( + - ) ], selected => $cookie->{ 'STRAND' } );
693     push @row_dna_contig, Maasha::XHTML::submit( name => "export", value => "Export", title => "Fetch DNA from this region" );
694
695     push @html, Maasha::XHTML::h2( txt => "Export", class => 'center' );
696     push @html, Maasha::XHTML::table_beg( summary => "Taxonomy select table", align => 'center' );
697     push @html, Maasha::XHTML::table_row_simple( tr => \@row_dna_contig );
698     push @html, Maasha::XHTML::table_end;
699
700     push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "page", value => "dna" ) );
701     push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "user",     value => "$cookie->{ 'USER' }" ) );
702     push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "clade",    value => "$cookie->{ 'CLADE' }" ) );
703     push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "genome",   value => "$cookie->{ 'GENOME' }" ) );
704     push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "assembly", value => "$cookie->{ 'ASSEMBLY' }" ) );
705     push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "contig",   value => "$cookie->{ 'CONTIG' }" ) );
706
707     return wantarray ? @html : \@html;
708 }
709
710
711 sub section_dna
712 {
713     # Martin A. Hansen, November 2009.
714
715     # Returns a HTML section with extracted DNA.
716
717     my ( $cookie,   # cookie hash
718        ) = @_;
719
720     # Returns a list.
721
722     my ( @html, $beg, $end, $seq );
723     
724     $beg = $cookie->{ 'S_BEG' };
725     $end = $cookie->{ 'S_END' };
726     $beg =~ tr/,//d;
727     $end =~ tr/,//d;
728
729     $seq = ">$cookie->{ 'CONTIG' }_$beg" . "_$end" . "_$cookie->{ 'STRAND' }\n";
730     $seq .= Maasha::BBrowser::Track::dna_get( $cookie );
731
732     push @html, Maasha::XHTML::h2( txt => "DNA", class => 'center' );
733     push @html, Maasha::XHTML::pre( txt => $seq );
734
735     return wantarray ? @html : \@html;
736 }
737
738
739 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
740
741
742 __END__