From 05bd86460759d49c21423c2b0055df48f884d455 Mon Sep 17 00:00:00 2001 From: martinahansen Date: Wed, 25 Nov 2009 13:40:29 +0000 Subject: [PATCH] fixed KISS browser genome selection git-svn-id: http://biopieces.googlecode.com/svn/trunk@771 74ccb610-7750-0410-82ae-013aeee3265d --- code_perl/Maasha/KISS/Track.pm | 53 +++--- www/cgi-bin/index.cgi | 287 +++++++++++++++++++++++---------- www/cgi-bin/kiss.css | 5 + 3 files changed, 233 insertions(+), 112 deletions(-) diff --git a/code_perl/Maasha/KISS/Track.pm b/code_perl/Maasha/KISS/Track.pm index 6e2f9c0..77d823b 100644 --- a/code_perl/Maasha/KISS/Track.pm +++ b/code_perl/Maasha/KISS/Track.pm @@ -379,20 +379,20 @@ sub path_seq my ( $path ); - die qq(ERROR: no DEF_USER in cookie.\n) if not exists $cookie->{ 'DEF_USER' }; - die qq(ERROR: no DEF_CLADE in cookie.\n) if not exists $cookie->{ 'DEF_CLADE' }; - die qq(ERROR: no DEF_GENOME in cookie.\n) if not exists $cookie->{ 'DEF_GENOME' }; - die qq(ERROR: no DEF_ASSEMBLY in cookie.\n) if not exists $cookie->{ 'DEF_ASSEMBLY' }; - die qq(ERROR: no DEF_CONTIG in cookie.\n) if not exists $cookie->{ 'DEF_CONTIG' }; + die qq(ERROR: no USER in cookie.\n) if not $cookie->{ 'USER' }; + die qq(ERROR: no CLADE in cookie.\n) if not $cookie->{ 'CLADE' }; + die qq(ERROR: no GENOME in cookie.\n) if not $cookie->{ 'GENOME' }; + die qq(ERROR: no ASSEMBLY in cookie.\n) if not $cookie->{ 'ASSEMBLY' }; + die qq(ERROR: no CONTIG in cookie.\n) if not $cookie->{ 'CONTIG' }; $path = join( "/", $cookie->{ 'DATA_DIR' }, "Users", - $cookie->{ 'DEF_USER' }, - $cookie->{ 'DEF_CLADE' }, - $cookie->{ 'DEF_GENOME' }, - $cookie->{ 'DEF_ASSEMBLY' }, - $cookie->{ 'DEF_CONTIG' }, + $cookie->{ 'USER' }, + $cookie->{ 'CLADE' }, + $cookie->{ 'GENOME' }, + $cookie->{ 'ASSEMBLY' }, + $cookie->{ 'CONTIG' }, "Sequence", "sequence.txt" ); @@ -412,28 +412,35 @@ sub path_tracks # my ( $path, @tracks ); - die qq(ERROR: no DEF_USER in cookie.\n) if not exists $cookie->{ 'DEF_USER' }; - die qq(ERROR: no DEF_CLADE in cookie.\n) if not exists $cookie->{ 'DEF_CLADE' }; - die qq(ERROR: no DEF_GENOME in cookie.\n) if not exists $cookie->{ 'DEF_GENOME' }; - die qq(ERROR: no DEF_ASSEMBLY in cookie.\n) if not exists $cookie->{ 'DEF_ASSEMBLY' }; - die qq(ERROR: no DEF_CONTIG in cookie.\n) if not exists $cookie->{ 'DEF_CONTIG' }; + die qq(ERROR: no USER in cookie.\n) if not $cookie->{ 'USER' }; + die qq(ERROR: no CLADE in cookie.\n) if not $cookie->{ 'CLADE' }; + die qq(ERROR: no GENOME in cookie.\n) if not $cookie->{ 'GENOME' }; + die qq(ERROR: no ASSEMBLY in cookie.\n) if not $cookie->{ 'ASSEMBLY' }; + die qq(ERROR: no CONTIG in cookie.\n) if not $cookie->{ 'CONTIG' }; $path = join( "/", $cookie->{ 'DATA_DIR' }, "Users", - $cookie->{ 'DEF_USER' }, - $cookie->{ 'DEF_CLADE' }, - $cookie->{ 'DEF_GENOME' }, - $cookie->{ 'DEF_ASSEMBLY' }, - $cookie->{ 'DEF_CONTIG' }, + $cookie->{ 'USER' }, + $cookie->{ 'CLADE' }, + $cookie->{ 'GENOME' }, + $cookie->{ 'ASSEMBLY' }, + $cookie->{ 'CONTIG' }, "Tracks", ); - @tracks = Maasha::Filesys::ls_dirs( $path ); + if ( -d $path ) + { + @tracks = Maasha::Filesys::ls_dirs( $path ); - @tracks = grep { $_ !~ /\/\.\.?$/ } @tracks; + @tracks = grep { $_ !~ /\/\.\.?$/ } @tracks; - return wantarray ? @tracks : \@tracks; + return wantarray ? @tracks : \@tracks; + } + else + { + return wantarray ? () : []; + } } # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< diff --git a/www/cgi-bin/index.cgi b/www/cgi-bin/index.cgi index 3a34fd9..a2328e6 100755 --- a/www/cgi-bin/index.cgi +++ b/www/cgi-bin/index.cgi @@ -26,24 +26,20 @@ use warnings; use lib "/Users/maasha/biopieces/code_perl/"; use CGI; -use Cairo; -use Pango; use Data::Dumper; use Time::HiRes; use Maasha::Common; use Maasha::Filesys; use Maasha::Calc; use Maasha::XHTML; -use Maasha::Biopieces; use Maasha::KISS::IO; use Maasha::KISS::Track; use Maasha::KISS::Draw; -my ( $cgi, $cookie, $script, @html ); +my ( $cgi, $cookie, @html ); -$cgi = new CGI; -$script = Maasha::Common::get_scriptname(); -$cookie = cookie_default( $cgi );; +$cgi = new CGI; +$cookie = cookie_default( $cgi );; push @html, Maasha::XHTML::html_header( cgi_header => 1, @@ -56,15 +52,17 @@ push @html, Maasha::XHTML::html_header( ); push @html, Maasha::XHTML::h1( txt => "KISS Genome Browser", class => 'center' ); -push @html, Maasha::XHTML::form_beg( action => $script, method => "get", enctype => "multipart/form-data" ); +push @html, Maasha::XHTML::form_beg( action => $cookie->{ 'SCRIPT' }, method => "get", enctype => "multipart/form-data" ); -push @html, sec_navigate( $cookie ); -push @html, sec_browse( $cookie ); +push @html, page( $cookie ); push @html, Maasha::XHTML::form_end; push @html, Maasha::XHTML::body_end; push @html, Maasha::XHTML::html_end; +# push @html, Maasha::KISS::Draw::hdump( $cgi->param ); +# push @html, Maasha::KISS::Draw::hdump( $cookie ); + print "$_\n" foreach @html; @@ -78,77 +76,85 @@ sub cookie_default # Returns a hash - my ( $cookie ); + my ( $cookie, $path ); $cookie = {}; - $cookie->{ 'DATA_DIR' } = "Data"; + $cookie->{ 'SCRIPT' } = Maasha::Common::get_scriptname(); + $cookie->{ 'DATA_DIR' } = "Data"; + $cookie->{ 'LIST_PAGES' } = [ qw( user clade genome assembly contig browse ) ]; + $cookie->{ 'PAGE' } = $cgi->param( 'page' ) || 'user'; + $cookie->{ 'USER' } = $cgi->param( 'user' ) || ''; + $cookie->{ 'CLADE' } = $cgi->param( 'clade' ) || ''; + $cookie->{ 'GENOME' } = $cgi->param( 'genome' ) || ''; + $cookie->{ 'ASSEMBLY' } = $cgi->param( 'assembly' ) || ''; + $cookie->{ 'CONTIG' } = $cgi->param( 'contig' ) || ''; + $cookie->{ 'NAV_START' } = $cgi->param( 'nav_start' ); + $cookie->{ 'NAV_END' } = $cgi->param( 'nav_end' ); + $cookie->{ 'ZOOM_IN1' } = $cgi->param( 'zoom_in1' ); + $cookie->{ 'ZOOM_IN2' } = $cgi->param( 'zoom_in2' ); + $cookie->{ 'ZOOM_IN3' } = $cgi->param( 'zoom_in3' ); + $cookie->{ 'ZOOM_OUT1' } = $cgi->param( 'zoom_out1' ); + $cookie->{ 'ZOOM_OUT2' } = $cgi->param( 'zoom_out2' ); + $cookie->{ 'ZOOM_OUT3' } = $cgi->param( 'zoom_out3' ); + $cookie->{ 'MOVE_LEFT1' } = $cgi->param( 'move_left1' ); + $cookie->{ 'MOVE_LEFT2' } = $cgi->param( 'move_left2' ); + $cookie->{ 'MOVE_LEFT3' } = $cgi->param( 'move_left3' ); + $cookie->{ 'MOVE_RIGHT1' } = $cgi->param( 'move_right1' ); + $cookie->{ 'MOVE_RIGHT2' } = $cgi->param( 'move_right2' ); + $cookie->{ 'MOVE_RIGHT3' } = $cgi->param( 'move_right3' ); - cookie_cgi( $cookie, $cgi ); - cookie_user( $cookie ); - cookie_clade( $cookie ); - cookie_genome( $cookie ); - cookie_assembly( $cookie ); - cookie_contig( $cookie ); - cookie_start( $cookie ); - cookie_end( $cookie ); - cookie_zoom( $cookie ); - cookie_move( $cookie ); + $path = "$cookie->{ 'DATA_DIR' }/Users"; - # print STDERR Dumper( $cookie ); + $cookie->{ 'LIST_USER' } = ls_dir_base( $path ) if -d $path; - return wantarray ? %{ $cookie } : $cookie; -} + $path .= "/$cookie->{ 'USER' }"; + $cookie->{ 'LIST_CLADE' } = ls_dir_base( $path ) if -d $path; -sub cookie_cgi -{ - my ( $cookie, - $cgi, - ) = @_; + $path .= "/$cookie->{ 'CLADE' }"; - # Returns nothing. + $cookie->{ 'LIST_GENOME' } = ls_dir_base( $path ) if -d $path; + + $path .= "/$cookie->{ 'GENOME' }"; + + $cookie->{ 'LIST_ASSEMBLY' } = ls_dir_base( $path ) if -d $path; + + $path .= "/$cookie->{ 'ASSEMBLY' }"; + + $cookie->{ 'LIST_CONTIG' } = ls_dir_base( $path ) if -d $path; + + if ( $cookie->{ 'CONTIG' } ) + { + cookie_start( $cookie ); + cookie_end( $cookie ); + cookie_zoom( $cookie ); + cookie_move( $cookie ); + } - $cookie->{ 'DEF_CLADE' } = $cgi->param( 'nav_clade' ); - $cookie->{ 'DEF_GENOME' } = $cgi->param( 'nav_genome' ); - $cookie->{ 'DEF_ASSEMBLY' } = $cgi->param( 'nav_assembly' ); - $cookie->{ 'DEF_CONTIG' } = $cgi->param( 'nav_contig' ); - $cookie->{ 'NAV_START' } = $cgi->param( 'nav_start' ); - $cookie->{ 'NAV_END' } = $cgi->param( 'nav_end' ); - $cookie->{ 'ZOOM_IN1' } = $cgi->param( 'zoom_in1' ); - $cookie->{ 'ZOOM_IN2' } = $cgi->param( 'zoom_in2' ); - $cookie->{ 'ZOOM_IN3' } = $cgi->param( 'zoom_in3' ); - $cookie->{ 'ZOOM_OUT1' } = $cgi->param( 'zoom_out1' ); - $cookie->{ 'ZOOM_OUT2' } = $cgi->param( 'zoom_out2' ); - $cookie->{ 'ZOOM_OUT3' } = $cgi->param( 'zoom_out3' ); - $cookie->{ 'MOVE_LEFT1' } = $cgi->param( 'move_left1' ); - $cookie->{ 'MOVE_LEFT2' } = $cgi->param( 'move_left2' ); - $cookie->{ 'MOVE_LEFT3' } = $cgi->param( 'move_left3' ); - $cookie->{ 'MOVE_RIGHT1' } = $cgi->param( 'move_right1' ); - $cookie->{ 'MOVE_RIGHT2' } = $cgi->param( 'move_right2' ); - $cookie->{ 'MOVE_RIGHT3' } = $cgi->param( 'move_right3' ); + return wantarray ? %{ $cookie } : $cookie; } -sub cookie_user +sub ls_dir_base { - my ( $cookie, + my ( $path, ) = @_; - # Returns nothing. + # Returns a list. - my ( @dirs, $dir ); + my ( @dirs, $dir, @list ); - @dirs = Maasha::Filesys::ls_dirs( "$cookie->{ 'DATA_DIR' }/Users" ); + @dirs = Maasha::Filesys::ls_dirs( $path ); foreach $dir ( @dirs ) { next if $dir =~ /\/\.\.?$/; - push @{ $cookie->{ 'LIST_USER' } }, ( split "/", $dir )[ -1 ]; + push @list, ( split "/", $dir )[ -1 ]; } - $cookie->{ 'DEF_USER' } = $cookie->{ 'LIST_USER' }->[ 0 ]; + return wantarray ? @list : \@list; } @@ -161,7 +167,7 @@ sub cookie_clade my ( $user, @dirs, $dir ); - $user = $cookie->{ 'DEF_USER' }; + $user = $cookie->{ 'USER' }; @dirs = Maasha::Filesys::ls_dirs( "$cookie->{ 'DATA_DIR' }/Users/$user" ); @@ -171,10 +177,6 @@ sub cookie_clade push @{ $cookie->{ 'LIST_CLADE' } }, ( split "/", $dir )[ -1 ]; } - - if ( not defined $cookie->{ 'DEF_CLADE' } ) { - $cookie->{ 'DEF_CLADE' } = $cookie->{ 'LIST_CLADE' }->[ 1 ]; - } } @@ -187,8 +189,8 @@ sub cookie_genome my ( $user, $clade, @dirs, $dir ); - $user = $cookie->{ 'DEF_USER' }; - $clade = $cookie->{ 'DEF_CLADE' }; + $user = $cookie->{ 'USER' }; + $clade = $cookie->{ 'CLADE' }; @dirs = Maasha::Filesys::ls_dirs( "$cookie->{ 'DATA_DIR' }/Users/$user/$clade" ); @@ -198,10 +200,6 @@ sub cookie_genome push @{ $cookie->{ 'LIST_GENOME' } }, ( split "/", $dir )[ -1 ]; } - - if ( not defined $cookie->{ 'DEF_GENOME' } ) { - $cookie->{ 'DEF_GENOME' } = $cookie->{ 'LIST_GENOME' }->[ 0 ]; - } } @@ -214,9 +212,9 @@ sub cookie_assembly my ( $user, $clade, $genome, @dirs, $dir ); - $user = $cookie->{ 'DEF_USER' }; - $clade = $cookie->{ 'DEF_CLADE' }; - $genome = $cookie->{ 'DEF_GENOME' }; + $user = $cookie->{ 'USER' }; + $clade = $cookie->{ 'CLADE' }; + $genome = $cookie->{ 'GENOME' }; @dirs = Maasha::Filesys::ls_dirs( "$cookie->{ 'DATA_DIR' }/Users/$user/$clade/$genome" ); @@ -226,10 +224,6 @@ sub cookie_assembly push @{ $cookie->{ 'LIST_ASSEMBLY' } }, ( split "/", $dir )[ -1 ]; } - - if ( not defined $cookie->{ 'DEF_ASSEMBLY' } ) { - $cookie->{ 'DEF_ASSEMBLY' } = $cookie->{ 'LIST_ASSEMBLY' }->[ 0 ]; - } } @@ -242,10 +236,10 @@ sub cookie_contig my ( $user, $clade, $genome, $assembly, @dirs, $dir ); - $user = $cookie->{ 'DEF_USER' }; - $clade = $cookie->{ 'DEF_CLADE' }; - $genome = $cookie->{ 'DEF_GENOME' }; - $assembly = $cookie->{ 'DEF_ASSEMBLY' }; + $user = $cookie->{ 'USER' }; + $clade = $cookie->{ 'CLADE' }; + $genome = $cookie->{ 'GENOME' }; + $assembly = $cookie->{ 'ASSEMBLY' }; @dirs = Maasha::Filesys::ls_dirs( "$cookie->{ 'DATA_DIR' }/Users/$user/$clade/$genome/$assembly" ); @@ -255,10 +249,6 @@ sub cookie_contig push @{ $cookie->{ 'LIST_CONTIG' } }, ( split "/", $dir )[ -1 ]; } - - if ( not defined $cookie->{ 'DEF_CONTIG' } ) { - $cookie->{ 'DEF_CONTIG' } = $cookie->{ 'LIST_CONTIG' }->[ 0 ]; - } } @@ -383,6 +373,125 @@ sub cookie_move } +sub page +{ + my ( $cookie, + ) = @_; + + # Returns a list. + + my ( @html, $list, $item, $href ); + + push @html, breadcrumb( $cookie ); + + $list = "LIST_" . uc $cookie->{ 'PAGE' }; + + if ( $cookie->{ 'PAGE' } ne 'browse' ) + { + push @html, Maasha::XHTML::h2( txt => "Select $cookie->{ 'PAGE' }", class => 'center' ); + + push @html, Maasha::XHTML::table_beg( summary => "Select table", align => 'center', cellpadding => '5px' ); + + foreach $item ( @{ $cookie->{ $list } } ) + { + $cookie->{ uc $cookie->{ 'PAGE' } } = $item; + + $href = page_href( $cookie, page_next( $cookie ) ); + + push @html, Maasha::XHTML::table_row_simple( tr => [ Maasha::XHTML::ln( txt => $item, href => $href ) ] ); + } + + push @html, Maasha::XHTML::table_end; + } + else + { + push @html, sec_navigate( $cookie ); + push @html, sec_browse( $cookie ); + } + + return wantarray ? @html : \@html; +} + + +sub page_next +{ + my ( $cookie, + ) = @_; + + my ( $i ); + + for ( $i = 0; $i < @{ $cookie->{ 'LIST_PAGES' } }; $i++ ) { + last if $cookie->{ 'PAGE' } eq $cookie->{ 'LIST_PAGES' }->[ $i ]; + } + + return $cookie->{ 'LIST_PAGES' }->[ $i + 1 ]; +} + + +sub breadcrumb +{ + my ( $cookie, + ) = @_; + + # Returns a list. + + my ( @pages, $page, @row1, @row2, @html, $href, $txt ); + + @pages = @{ $cookie->{ 'LIST_PAGES' } }; + + pop @pages; # remove 'browse' + + foreach $page ( @pages ) + { + $href = page_href( $cookie, $page ); + + $txt = $cookie->{ uc $page } || ""; + + push @row1, Maasha::XHTML::ln( txt => $page, href => $href, class => 'inline' ); + push @row2, Maasha::XHTML::p( txt => $txt, class => 'inline' ); + + last if $page eq $cookie->{ 'PAGE' }; + } + + push @html, Maasha::XHTML::table_beg( summary => "Taxonomy table", align => 'center', cellpadding => '5px' ); + push @html, Maasha::XHTML::table_row_simple( tr => \@row1, align => 'center' ); + push @html, Maasha::XHTML::table_row_simple( tr => \@row2, align => 'center' ); + push @html, Maasha::XHTML::table_end; + + return wantarray ? @html : \@html; +} + + +sub page_href +{ + my ( $cookie, + $page, + ) = @_; + + # Returns a string. + + my ( @href ); + + while ( 1 ) + { + push @href, "$cookie->{ 'SCRIPT' }?page=$page"; + push @href, "user=$cookie->{ 'USER' }" if $cookie->{ 'USER' }; + last if $page eq 'user'; + push @href, "clade=$cookie->{ 'CLADE' }" if $cookie->{ 'CLADE' }; + last if $page eq 'clade'; + push @href, "genome=$cookie->{ 'GENOME' }" if $cookie->{ 'GENOME' }; + last if $page eq 'genome'; + push @href, "assembly=$cookie->{ 'ASSEMBLY' }" if $cookie->{ 'ASSEMBLY' }; + last if $page eq 'assembly'; + push @href, "contig=$cookie->{ 'CONTIG' }" if $cookie->{ 'CONTIG' }; + last if $page eq 'contig'; + last; + } + + return join "&", @href; +} + + sub sec_navigate { my ( $cookie, @@ -393,12 +502,8 @@ sub sec_navigate my ( @html ); push @html, Maasha::XHTML::table_beg( summary => "Navigation table", align => 'center' ); - push @html, Maasha::XHTML::table_row_simple( tr => [ qw( Clade Genome Assembly Contig Start End ) ], align => 'center' ); + push @html, Maasha::XHTML::table_row_simple( tr => [ qw( Start End ) ], align => 'center' ); push @html, Maasha::XHTML::table_row_simple( tr => [ - Maasha::XHTML::menu( name => "nav_clade", options => $cookie->{ 'LIST_CLADE' }, selected => $cookie->{ 'DEF_CLADE' } ), - Maasha::XHTML::menu( name => "nav_genome", options => $cookie->{ 'LIST_GENOME' }, selected => $cookie->{ 'DEF_GENOME' } ), - Maasha::XHTML::menu( name => "nav_assembly", options => $cookie->{ 'LIST_ASSEMBLY' }, selected => $cookie->{ 'DEF_ASSEMBLY' } ), - Maasha::XHTML::menu( name => "nav_contig", options => $cookie->{ 'LIST_CONTIG' }, selected => $cookie->{ 'DEF_CONTIG' } ), Maasha::XHTML::text( name => "nav_start", value => Maasha::Calc::commify( $cookie->{ 'NAV_START' } ), size => 20 ), Maasha::XHTML::text( name => "nav_end", value => Maasha::Calc::commify( $cookie->{ 'NAV_END' } ), size => 20 ), Maasha::XHTML::submit( name => "nav_submit", value => "Submit" ), @@ -425,7 +530,12 @@ sub sec_navigate ] ); push @html, Maasha::XHTML::table_end; - @html = Maasha::XHTML::div( txt => join( "\n", @html ), class => 'navigate' ); + push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "page", value => "browse" ) ); + push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "user", value => "$cookie->{ 'USER' }" ) ); + push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "clade", value => "$cookie->{ 'CLADE' }" ) ); + push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "genome", value => "$cookie->{ 'GENOME' }" ) ); + push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "assembly", value => "$cookie->{ 'ASSEMBLY' }" ) ); + push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "contig", value => "$cookie->{ 'CONTIG' }" ) ); return wantarray ? @html : \@html; } @@ -516,7 +626,6 @@ sub sec_browse __END__ - # push @html, Maasha::KISS::Draw::hdump( $entries ); # push @html, Maasha::KISS::Draw::hdump( $features ); $t0 = Time::HiRes::gettimeofday(); diff --git a/www/cgi-bin/kiss.css b/www/cgi-bin/kiss.css index af21647..6f6928a 100644 --- a/www/cgi-bin/kiss.css +++ b/www/cgi-bin/kiss.css @@ -255,6 +255,11 @@ div.browse { text-align: center; } +.inline { + display: inline; +} + + /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> HEADINGS AND PARAGRAPH <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< */ -- 2.39.2