use lib $ENV{ 'BP_PERL' };
use CGI;
+use URI::Escape;
use Data::Dumper;
use Digest::MD5;
use Maasha::Common;
use Maasha::Filesys;
use Maasha::Calc;
use Maasha::XHTML;
-use Maasha::KISS;
use Maasha::BGB::Session;
use Maasha::BGB::Track;
use Maasha::BGB::Draw;
push @html, Maasha::XHTML::html_header(
cgi_header => 1,
- title => "Biopieces Genome Browser",
- css_file => "bgb.css",
- author => "Martin A. Hansen, mail\@maasha.dk",
- description => "Biopieces Genome Browser",
+ title => 'Biopieces Genome Browser',
+ css_file => 'bgb.css',
+ author => 'Martin A. Hansen, mail@maasha.dk',
+ description => 'Biopieces Genome Browser',
keywords => [ qw( Biopieces biopiece genome browser viewer bacterium bacteria prokaryote prokaryotes ) ],
no_cache => 1,
);
# Returns a hash.
- my ( $cookie, $path );
+ my ( $cookie );
$cookie = {};
$cookie->{ 'ASSEMBLY' } = $cgi->param( 'assembly' ) || '';
$cookie->{ 'CONTIG' } = $cgi->param( 'contig' ) || '';
$cookie->{ 'Q_ID' } = $cgi->param( 'q_id' );
- $cookie->{ 'NAV_START' } ||= $cgi->param( 'nav_start' ) || $cgi->param( 's_beg' ); # FIXME this is ugly!
- $cookie->{ 'NAV_END' } ||= $cgi->param( 'nav_end' ) || $cgi->param( 's_end' );
+ $cookie->{ 'NAV_START' } ||= $cgi->param( 'nav_start' );
+ $cookie->{ 'NAV_END' } ||= $cgi->param( 'nav_end' );
+ $cookie->{ 'NAV_CENTER' } = $cgi->param( 'nav_center' );
$cookie->{ 'S_BEG' } = $cgi->param( 's_beg' );
$cookie->{ 'S_END' } = $cgi->param( 's_end' );
$cookie->{ 'STRAND' } = $cgi->param( 'strand' );
$cookie->{ 'FEAT_COLOR' } = [ 0, 0, 0 ];
$cookie->{ 'FEAT_MAX' } = 5000;
- $path = "$cookie->{ 'DATA_DIR' }/Users";
-
- $cookie->{ 'LIST_USER' } = Maasha::Filesys::ls_dirs_base( $path ) if -d $path;
-
- $path .= "/$cookie->{ 'USER' }";
-
- $cookie->{ 'LIST_CLADE' } = Maasha::Filesys::ls_dirs_base( $path ) if -d $path;
-
- $path .= "/$cookie->{ 'CLADE' }";
-
- $cookie->{ 'LIST_GENOME' } = Maasha::Filesys::ls_dirs_base( $path ) if -d $path;
-
- $path .= "/$cookie->{ 'GENOME' }";
-
- $cookie->{ 'LIST_ASSEMBLY' } = Maasha::Filesys::ls_dirs_base( $path ) if -d $path;
-
- $path .= "/$cookie->{ 'ASSEMBLY' }";
-
- $cookie->{ 'LIST_CONTIG' } = Maasha::Filesys::ls_dirs_base( $path ) if -d $path;
+ $cookie->{ 'LIST_USER' } = Maasha::BGB::Track::list_users();
+ $cookie->{ 'LIST_CLADE' } = Maasha::BGB::Track::list_clades( $cookie->{ 'USER' } );
+ $cookie->{ 'LIST_GENOME' } = Maasha::BGB::Track::list_genomes( $cookie->{ 'USER' }, $cookie->{ 'CLADE' } );
+ $cookie->{ 'LIST_ASSEMBLY' } = Maasha::BGB::Track::list_assemblies( $cookie->{ 'USER' }, $cookie->{ 'CLADE' }, $cookie->{ 'GENOME' } );
+ $cookie->{ 'LIST_CONTIG' } = Maasha::BGB::Track::list_contigs( $cookie->{ 'USER' }, $cookie->{ 'CLADE' }, $cookie->{ 'GENOME' }, $cookie->{ 'ASSEMBLY' } );
if ( $cookie->{ 'CONTIG' } )
{
cookie_end( $cookie );
cookie_zoom( $cookie );
cookie_move( $cookie );
+ cookie_center( $cookie );
}
$cookie->{ 'STRAND' } = '+' if defined $cookie->{ 'STRAND' } and $cookie->{ 'STRAND' } eq ' '; # FIXME ugly HTML fix
$cookie->{ 'PAGE' } = 'login';
print STDERR "HER4"; # DEBUG
print STDERR "NO COOKIE SESSION ID\n" if not $cookie->{ 'SESSION_ID' }; # DEBUG
- print STDERR "NO COOKIE SESSION ID\n" if not $cookie->{ 'USER' }; # DEBUG
+ print STDERR "NO COOKIE USER\n" if not $cookie->{ 'USER' }; # DEBUG
print STDERR "NO SESSION USER\n" if not exists $session->{ $cookie->{ 'USER' } }; # DEBUG
}
}
my ( $cookie, # cookie hash
) = @_;
+ # Returns nothing.
+
my ( $max, $dist, $shift, $new_start, $new_end );
$max = Maasha::Filesys::file_size( Maasha::BGB::Track::path_seq( $cookie ) );
}
-sub cookie_href
+sub cookie_center
{
- # Martin A. Hansen, November 2009.
-
- # Returns the href for a taxonomy path terminated at a given
- # page using information stored in a cookie.
+ # Martin A. Hansen, March 2010
+
+ # Adjust the cookie values for NAV_START and NAV_END based
+ # on cookie CENTER value if defined.
my ( $cookie, # cookie hash
- $page, # page
) = @_;
- # Returns a string.
-
- my ( @href_list, %href_hash, $href );
+ # Returns nothing.
- $href_hash{ "user" } = $cookie->{ 'USER' } if $cookie->{ 'USER' };
+ my ( $l_dist, $r_dist );
- while ( 1 )
+ if ( defined $cookie->{ 'NAV_CENTER' } )
{
- $href_hash{ "clade" } = $cookie->{ 'CLADE' } if $cookie->{ 'CLADE' };
- last if $page eq 'clade';
- $href_hash{ "genome" } = $cookie->{ 'GENOME' } if $cookie->{ 'GENOME' };
- last if $page eq 'genome';
- $href_hash{ "assembly" } = $cookie->{ 'ASSEMBLY' } if $cookie->{ 'ASSEMBLY' };
- last if $page eq 'assembly';
- $href_hash{ "contig" } = $cookie->{ 'CONTIG' } if $cookie->{ 'CONTIG' };
- last if $page eq 'contig';
- last;
- }
-
- if ( defined $cookie->{ 'NAV_START' } and defined $cookie->{ 'NAV_END' } and $page !~ /clade|genome|assembly|contig|browse/ ) {
- $href_hash{ "nav_search" } = "$cookie->{ 'NAV_START' }-$cookie->{ 'NAV_END' }";
- }
+ $l_dist = $cookie->{ 'NAV_CENTER' } - $cookie->{ 'NAV_START' };
+ $r_dist = $cookie->{ 'NAV_END' } - $cookie->{ 'NAV_CENTER' };
- $href_hash{ "s_beg" } = $cookie->{ 'S_BEG' } if defined $cookie->{ 'S_BEG' };
- $href_hash{ "s_end" } = $cookie->{ 'S_END' } if defined $cookie->{ 'S_END' };
- $href_hash{ "q_id" } = $cookie->{ 'Q_ID' } if defined $cookie->{ 'Q_ID' };
- $href_hash{ "strand" } = $cookie->{ 'STRAND' } if defined $cookie->{ 'STRAND' };
- $href_hash{ "session_id" } = $cookie->{ 'SESSION_ID' } if defined $cookie->{ 'SESSION_ID' };
-
- push @href_list, "$cookie->{ 'SCRIPT' }?page=$page";
-
- foreach $href ( keys %href_hash ) {
- push @href_list, "$href=$href_hash{ $href }";
+ if ( $l_dist > $r_dist ) {
+ $cookie->{ 'NAV_START' } = $cookie->{ 'NAV_END' } - 2 * $r_dist;
+ } else {
+ $cookie->{ 'NAV_END' } = $cookie->{ 'NAV_START' } + 2 * $l_dist;
+ }
}
-
- return join "&", @href_list;
}
my ( @html );
+ if ( $cookie->{ 'SESSION_ID' } ) {
+ push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "session_id", value => $cookie->{ 'SESSION_ID' } ) );
+ }
+
if ( $cookie->{ 'PAGE' } eq 'login' ) {
push @html, page_login( $cookie );
} elsif ( $cookie->{ 'PAGE' } eq 'search' ) {
push @html, page_taxonomy( $cookie );
}
- if ( $cookie->{ 'SESSION_ID' } ) {
- push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "session_id", value => $cookie->{ 'SESSION_ID' } ) );
- }
-
return wantarray ? @html : \@html;
}
{
last if $page eq $cookie->{ 'PAGE' } or $page eq 'browse';
- $href = cookie_href( $cookie, $page );
+ $href = "$cookie->{ 'SCRIPT' }?page=$page";
+ $href .= "&session_id=$cookie->{ 'SESSION_ID' }";
+ $href .= "&user=$cookie->{ 'USER' }";
+ $href .= "&clade=$cookie->{ 'CLADE' }" if $page !~ /clade/;
+ $href .= "&genome=$cookie->{ 'GENOME' }" if $page !~ /clade|genome/;
+ $href .= "&assembly=$cookie->{ 'ASSEMBLY' }" if $page !~ /clade|genome|assembly/;
+ $href .= "&contig=$cookie->{ 'CONTIG' }" if $page !~ /clade|genome|assembly|contig/;
$txt = ": $cookie->{ uc $page }";
{
$cookie->{ uc $cookie->{ 'PAGE' } } = $item;
- $href = cookie_href( $cookie, cookie_page_next( $cookie ) );
+ $href = "$cookie->{ 'SCRIPT' }?page=" . cookie_page_next( $cookie );
+ $href .= "&session_id=$cookie->{ 'SESSION_ID' }";
+ $href .= "&user=$cookie->{ 'USER' }";
+ $href .= "&clade=$cookie->{ 'CLADE' }";
+ $href .= "&genome=$cookie->{ 'GENOME' }" if $cookie->{ 'GENOME' };
+ $href .= "&assembly=$cookie->{ 'ASSEMBLY' }" if $cookie->{ 'ASSEMBLY' };
+ $href .= "&contig=$cookie->{ 'CONTIG' }" if $cookie->{ 'CONTIG' };
push @html, Maasha::XHTML::table_row_simple( tr => [ Maasha::XHTML::ln( txt => $item, href => $href ) ] );
}
# Returns a list.
- my ( @tracks, $i, @features, $feat, $elem, $surface, $cr, $png_data, @html, @img );
+ my ( @tracks, $i, @features, $feat, $elem, $surface, $cr, $png_data, @html, @img, $x1, $y1, $x2, $y2, $factor, $center );
push @features, [ Maasha::BGB::Track::track_ruler( $cookie ) ];
push @features, [ Maasha::BGB::Track::track_seq( $cookie ) ];
push @img, Maasha::XHTML::map_beg( name => "browser_map", id => "browser_map" );
+ $factor = ( $cookie->{ 'NAV_END' } - $cookie->{ 'NAV_START' } + 1 ) / $cookie->{ 'IMG_WIDTH' };
+
+ for ( $i = 0; $i < $cookie->{ 'IMG_WIDTH' }; $i += 5 )
+ {
+ $x1 = $i;
+ $y1 = 10;
+ $x2 = $i + 5;
+ $y2 = 20;
+
+ $center = int( $cookie->{ 'NAV_START' } + $factor * $i );
+
+ push @img, Maasha::XHTML::area(
+ href => join( "&", "$cookie->{ 'SCRIPT' }?page=browse",
+ "session_id=$cookie->{ 'SESSION_ID' }",
+ "user=$cookie->{ 'USER' }",
+ "clade=$cookie->{ 'CLADE' }",
+ "genome=$cookie->{ 'GENOME' }",
+ "contig=$cookie->{ 'CONTIG' }",
+ "assembly=$cookie->{ 'ASSEMBLY' }",
+ "nav_start=$cookie->{ 'NAV_START' }",
+ "nav_end=$cookie->{ 'NAV_END' }",
+ "nav_center=$center",
+ ),
+ shape => 'rect',
+ coords => "$x1, $y1, $x2, $y2",
+ title => "Center on " . Maasha::Calc::commify( $center ),
+ );
+ }
+
foreach $feat ( @features )
{
foreach $elem ( @{ $feat } )
{
next if $elem->{ 'type' } eq 'text';
+ next if $elem->{ 'type' } eq 'wiggle';
#$elem->{ 'strand' } = '+' if $elem->{ 'strand' } eq '+';
$cookie->{ 'STRAND' } = $elem->{ 'strand' };
push @img, Maasha::XHTML::area(
- href => cookie_href( $cookie, "export" ),
- # href => cookie_href( $cookie, "export" ) . "&q_id=$elem->{ 'q_id' }&s_beg=$elem->{ 's_beg' }&s_end=$elem->{ 's_end' }&strand=$elem->{ 'strand' }",
- shape => "rect",
- coords => "$elem->{ x1 }, $elem->{ y1 }, $elem->{ x2 }, $elem->{ y2 }", title => "$elem->{ 'title' }",
+ href => join( "&", "$cookie->{ 'SCRIPT' }?page=export",
+ "session_id=$cookie->{ 'SESSION_ID' }",
+ "user=$cookie->{ 'USER' }",
+ "clade=$cookie->{ 'CLADE' }",
+ "genome=$cookie->{ 'GENOME' }",
+ "contig=$cookie->{ 'CONTIG' }",
+ "assembly=$cookie->{ 'ASSEMBLY' }",
+ "s_beg=$cookie->{ 'S_BEG' }",
+ "s_end=$cookie->{ 'S_END' }",
+ "strand=$cookie->{ 'STRAND' }",
+ ),
+ shape => 'rect',
+ coords => "$elem->{ x1 }, $elem->{ y1 }, $elem->{ x2 }, $elem->{ y2 }",
+ title => "$elem->{ 'title' }",
);
}
}
$cookie->{ 'STRAND' } = $result->{ 'STRAND' };
$cookie->{ 'Q_ID' } = $result->{ 'Q_ID' };
- $browse = Maasha::XHTML::ln( txt => "browse", href => cookie_href( $cookie, "browse" ) );
- $export = Maasha::XHTML::ln( txt => "export", href => cookie_href( $cookie, "export" ) );
+ $browse = Maasha::XHTML::ln(
+ txt => "browse",
+ href => join( "&", "$cookie->{ 'SCRIPT' }?page=browse",
+ "session_id=$cookie->{ 'SESSION_ID' }",
+ "user=$cookie->{ 'USER' }",
+ "clade=$cookie->{ 'CLADE' }",
+ "genome=$cookie->{ 'GENOME' }",
+ "contig=$cookie->{ 'CONTIG' }",
+ "assembly=$cookie->{ 'ASSEMBLY' }",
+ "nav_start=$cookie->{ 'NAV_START' }",
+ "nav_end=$cookie->{ 'NAV_END' }",
+ ),
+ );
+
+
+ $export = Maasha::XHTML::ln(
+ txt => "export",
+ href => join( "&", "$cookie->{ 'SCRIPT' }?page=export",
+ "session_id=$cookie->{ 'SESSION_ID' }",
+ "user=$cookie->{ 'USER' }",
+ "clade=$cookie->{ 'CLADE' }",
+ "genome=$cookie->{ 'GENOME' }",
+ "contig=$cookie->{ 'CONTIG' }",
+ "assembly=$cookie->{ 'ASSEMBLY' }",
+ "s_beg=$cookie->{ 'S_BEG' }",
+ "s_end=$cookie->{ 'S_END' }",
+ "strand=$cookie->{ 'STRAND' }",
+ ),
+ );
push @html, Maasha::XHTML::table_row_advanced(
tr => [ { td => $result->{ 'S_ID' } },