From 5cde47ecbd1c354f385bdcd8f86b0a2794c8ecfc Mon Sep 17 00:00:00 2001 From: martinahansen Date: Mon, 1 Mar 2010 14:58:51 +0000 Subject: [PATCH] added center navigation to BGB git-svn-id: http://biopieces.googlecode.com/svn/trunk@880 74ccb610-7750-0410-82ae-013aeee3265d --- www/index.cgi | 70 ++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 67 insertions(+), 3 deletions(-) diff --git a/www/index.cgi b/www/index.cgi index faec6a5..81d133c 100755 --- a/www/index.cgi +++ b/www/index.cgi @@ -125,6 +125,7 @@ sub cookie_default $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_CENTER' } = $cgi->param( 'nav_center' ); $cookie->{ 'S_BEG' } = $cgi->param( 's_beg' ); $cookie->{ 'S_END' } = $cgi->param( 's_end' ); $cookie->{ 'STRAND' } = $cgi->param( 'strand' ); @@ -179,6 +180,7 @@ sub cookie_default 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 @@ -381,6 +383,8 @@ sub cookie_move 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 ) ); @@ -415,6 +419,34 @@ sub cookie_move } +sub cookie_center +{ + # 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 + ) = @_; + + # Returns nothing. + + my ( $l_dist, $r_dist ); + + if ( defined $cookie->{ 'NAV_CENTER' } ) + { + $l_dist = $cookie->{ 'NAV_CENTER' } - $cookie->{ 'NAV_START' }; + $r_dist = $cookie->{ 'NAV_END' } - $cookie->{ 'NAV_CENTER' }; + + if ( $l_dist > $r_dist ) { + $cookie->{ 'NAV_START' } = $cookie->{ 'NAV_END' } - 2 * $r_dist; + } else { + $cookie->{ 'NAV_END' } = $cookie->{ 'NAV_START' } + 2 * $l_dist; + } + } +} + + sub cookie_href { # Martin A. Hansen, November 2009. @@ -812,7 +844,7 @@ sub section_browse # 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 ) ]; @@ -867,12 +899,44 @@ sub section_browse 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' }", + shape => 'rect', + coords => "$elem->{ x1 }, $elem->{ y1 }, $elem->{ x2 }, $elem->{ y2 }", + title => "$elem->{ 'title' }", ); } } + $factor = $cookie->{ 'IMG_WIDTH' } / ( $cookie->{ 'NAV_END' } - $cookie->{ 'NAV_START' } + 1 ); + $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 => cookie_href( $cookie, "browse" ) . "&nav_start=$cookie->{ 'NAV_START' }&nav_end=$cookie->{ 'NAV_END' }&nav_center=$center", + 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 ), + ); + } + push @img, Maasha::XHTML::map_end(); push @html, Maasha::XHTML::p( txt => join( "\n", @img ) ); -- 2.39.5