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,
);
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;
# 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;
}
my ( $user, @dirs, $dir );
- $user = $cookie->{ 'DEF_USER' };
+ $user = $cookie->{ 'USER' };
@dirs = Maasha::Filesys::ls_dirs( "$cookie->{ 'DATA_DIR' }/Users/$user" );
push @{ $cookie->{ 'LIST_CLADE' } }, ( split "/", $dir )[ -1 ];
}
-
- if ( not defined $cookie->{ 'DEF_CLADE' } ) {
- $cookie->{ 'DEF_CLADE' } = $cookie->{ 'LIST_CLADE' }->[ 1 ];
- }
}
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" );
push @{ $cookie->{ 'LIST_GENOME' } }, ( split "/", $dir )[ -1 ];
}
-
- if ( not defined $cookie->{ 'DEF_GENOME' } ) {
- $cookie->{ 'DEF_GENOME' } = $cookie->{ 'LIST_GENOME' }->[ 0 ];
- }
}
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" );
push @{ $cookie->{ 'LIST_ASSEMBLY' } }, ( split "/", $dir )[ -1 ];
}
-
- if ( not defined $cookie->{ 'DEF_ASSEMBLY' } ) {
- $cookie->{ 'DEF_ASSEMBLY' } = $cookie->{ 'LIST_ASSEMBLY' }->[ 0 ];
- }
}
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" );
push @{ $cookie->{ 'LIST_CONTIG' } }, ( split "/", $dir )[ -1 ];
}
-
- if ( not defined $cookie->{ 'DEF_CONTIG' } ) {
- $cookie->{ 'DEF_CONTIG' } = $cookie->{ 'LIST_CONTIG' }->[ 0 ];
- }
}
}
+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,
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" ),
] );
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;
}
__END__
- # push @html, Maasha::KISS::Draw::hdump( $entries );
# push @html, Maasha::KISS::Draw::hdump( $features );
$t0 = Time::HiRes::gettimeofday();