From 44657343cca3171ad1c9b53d8b4c5b914b7785c7 Mon Sep 17 00:00:00 2001 From: martinahansen Date: Wed, 2 Dec 2009 12:08:13 +0000 Subject: [PATCH] implemented search function in bbrowser git-svn-id: http://biopieces.googlecode.com/svn/trunk@792 74ccb610-7750-0410-82ae-013aeee3265d --- code_perl/Maasha/BBrowser/Track.pm | 51 ++++++++++ code_perl/Maasha/KISS.pm | 34 +++++++ www/bgb.css | 4 + www/index.cgi | 153 +++++++++++++++++++++++++---- 4 files changed, 225 insertions(+), 17 deletions(-) diff --git a/code_perl/Maasha/BBrowser/Track.pm b/code_perl/Maasha/BBrowser/Track.pm index e24bde8..c43ca5f 100644 --- a/code_perl/Maasha/BBrowser/Track.pm +++ b/code_perl/Maasha/BBrowser/Track.pm @@ -35,6 +35,7 @@ use Maasha::Common; use Maasha::Calc; use Maasha::Filesys; use Maasha::KISS; +use Maasha::Biopieces; use Maasha::Seq; use vars qw( @ISA @EXPORT ); @@ -527,6 +528,56 @@ sub path_tracks } } + +sub search_tracks +{ + # Martin A. Hansen, December 2009. + + # Uses grep to search all tracks in all contigs + # for a given pattern and return a list of KISS entries. + + my ( $cookie, # cookie hash + ) = @_; + + # Returns a list. + + my ( $contig, @tracks, $track, $file, $line, $out_file, $fh, $entry, @entries ); + + foreach $contig ( @{ $cookie->{ 'LIST_CONTIG' } } ) + { + $cookie->{ 'CONTIG' } = $contig; + + push @tracks, path_tracks( $cookie ); + } + + foreach $track ( @tracks ) + { + $file = "$track/track_data.kiss"; + + if ( -f $file ) + { + $fh = Maasha::Filesys::file_read_open( $file ); + + while ( $line = <$fh> ) + { + chomp $line; + + if ( $line =~ /$cookie->{ 'SEARCH' }/i ) + { + $entry = Maasha::KISS::kiss_entry_parse( $line ); + + push @entries, $entry; + } + } + + close $fh; + } + } + + return wantarray ? @entries : \@entries; +} + + # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 1; diff --git a/code_perl/Maasha/KISS.pm b/code_perl/Maasha/KISS.pm index f15dc88..d026767 100644 --- a/code_perl/Maasha/KISS.pm +++ b/code_perl/Maasha/KISS.pm @@ -103,6 +103,40 @@ sub kiss_entry_get } +sub kiss_entry_parse +{ + # Martin A. Hansen, December 2009. + + # Parses a line with a KISS entry. + + my ( $line, # KISS line to parse + ) = @_; + + # Returns a hash + + my ( @fields, %entry ); + + @fields = split /\t/, $line; + + Maasha::Common::error( qq(BAD kiss entry: $line) ) if not @fields == 12; + + $entry{ 'S_ID' } = $fields[ S_ID ]; + $entry{ 'S_BEG' } = $fields[ S_BEG ]; + $entry{ 'S_END' } = $fields[ S_END ]; + $entry{ 'Q_ID' } = $fields[ Q_ID ]; + $entry{ 'SCORE' } = $fields[ SCORE ]; + $entry{ 'STRAND' } = $fields[ STRAND ]; + $entry{ 'HITS' } = $fields[ HITS ]; + $entry{ 'ALIGN' } = $fields[ ALIGN ]; + $entry{ 'BLOCK_COUNT' } = $fields[ BLOCK_COUNT ]; + $entry{ 'BLOCK_BEGS' } = $fields[ BLOCK_BEGS ]; + $entry{ 'BLOCK_LENS' } = $fields[ BLOCK_LENS ]; + $entry{ 'BLOCK_TYPE' } = $fields[ BLOCK_TYPE ]; + + return wantarray ? %entry : \%entry; +} + + sub kiss_entry_put { # Martin A. Hansen, November 2009. diff --git a/www/bgb.css b/www/bgb.css index c550c9f..d0f5368 100644 --- a/www/bgb.css +++ b/www/bgb.css @@ -267,6 +267,10 @@ div.browse { display: inline; } +.monospace { + font-family: courier; +} + /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> IMAGE <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< */ diff --git a/www/index.cgi b/www/index.cgi index 21d0f9e..a8eabb3 100755 --- a/www/index.cgi +++ b/www/index.cgi @@ -86,6 +86,21 @@ sub cookie_default $cookie = {}; + if ( $cgi->param( 'nav_search' ) ) + { + if ( $cgi->param( 'nav_search' ) =~ /([0-9,]+)[ -]([0-9,]+)/ ) + { + $cookie->{ 'NAV_START' } = $1; + $cookie->{ 'NAV_END' } = $2; + } + else + { + $cookie->{ 'SEARCH' } = $cgi->param( 'nav_search' ); + + $cgi->param( 'page', 'search' ); + } + } + $cookie->{ 'SCRIPT' } = Maasha::Common::get_scriptname(); $cookie->{ 'DATA_DIR' } = "Data"; $cookie->{ 'LIST_PAGES' } = [ qw( user clade genome assembly contig browse ) ]; @@ -99,8 +114,6 @@ sub cookie_default $cookie->{ 'S_BEG' } = $cgi->param( 's_beg' ); $cookie->{ 'S_END' } = $cgi->param( 's_end' ); $cookie->{ 'STRAND' } = $cgi->param( 'strand' ); - $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' ); @@ -154,7 +167,7 @@ sub cookie_default cookie_move( $cookie ); } - $cookie->{ 'STRAND' } = '+' if $cookie->{ 'STRAND' } eq ' '; + $cookie->{ 'STRAND' } = '+' if defined $cookie->{ 'STRAND' } and $cookie->{ 'STRAND' } eq ' '; # FIXME ugly HTML fix return wantarray ? %{ $cookie } : $cookie; } @@ -315,25 +328,39 @@ sub cookie_href # Returns a string. - my ( @href ); + my ( @href_list, %href_hash, $href ); while ( 1 ) { - push @href, "$cookie->{ 'SCRIPT' }?page=$page"; - push @href, "user=$cookie->{ 'USER' }" if $cookie->{ 'USER' }; + $href_hash{ "user" } = $cookie->{ 'USER' } if $cookie->{ 'USER' }; last if $page eq 'user'; - push @href, "clade=$cookie->{ 'CLADE' }" if $cookie->{ 'CLADE' }; + $href_hash{ "clade" } = $cookie->{ 'CLADE' } if $cookie->{ 'CLADE' }; last if $page eq 'clade'; - push @href, "genome=$cookie->{ 'GENOME' }" if $cookie->{ 'GENOME' }; + $href_hash{ "genome" } = $cookie->{ 'GENOME' } if $cookie->{ 'GENOME' }; last if $page eq 'genome'; - push @href, "assembly=$cookie->{ 'ASSEMBLY' }" if $cookie->{ 'ASSEMBLY' }; + $href_hash{ "assembly" } = $cookie->{ 'ASSEMBLY' } if $cookie->{ 'ASSEMBLY' }; last if $page eq 'assembly'; - push @href, "contig=$cookie->{ 'CONTIG' }" if $cookie->{ 'CONTIG' }; + $href_hash{ "contig" } = $cookie->{ 'CONTIG' } if $cookie->{ 'CONTIG' }; last if $page eq 'contig'; last; } - return join "&", @href; + if ( defined $cookie->{ 'NAV_START' } and defined $cookie->{ 'NAV_END' } ) { + $href_hash{ "nav_search" } = "$cookie->{ 'NAV_START' }-$cookie->{ 'NAV_END' }"; + } + + $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' }; + + push @href_list, "$cookie->{ 'SCRIPT' }?page=$page"; + + foreach $href ( keys %href_hash ) { + push @href_list, "$href=$href_hash{ $href }"; + } + + return join "&", @href_list; } @@ -377,6 +404,8 @@ sub page if ( $cookie->{ 'PAGE' } eq 'export' ) { push @html, page_export( $cookie ); + } elsif ( $cookie->{ 'PAGE' } eq 'search' ) { + push @html, page_search( $cookie ); } elsif ( $cookie->{ 'PAGE' } eq 'browse' ) { push @html, page_browse( $cookie ); } elsif ( $cookie->{ 'PAGE' } eq 'dna' ) { @@ -409,6 +438,26 @@ sub page_export } +sub page_search +{ + # Martin A. Hansen, December 2009. + + # Renders the search page. + + my ( $cookie, + ) = @_; + + # Returns a list. + + my ( @html ); + + push @html, section_taxonomy_table( $cookie ); + push @html, section_search( $cookie ); + + return wantarray ? @html : \@html; +} + + sub page_browse { # Martin A. Hansen, November 2009. @@ -554,14 +603,14 @@ sub section_navigate # Returns a list. - my ( @html ); + my ( @html, $nav_val ); + + $nav_val = Maasha::Calc::commify( $cookie->{ 'NAV_START' } ) . "-" . Maasha::Calc::commify( $cookie->{ 'NAV_END' } ); push @html, Maasha::XHTML::table_beg( summary => "Navigation table", align => 'center' ); push @html, Maasha::XHTML::table_row_simple( tr => [ - "Start:", - Maasha::XHTML::text( name => "nav_start", value => Maasha::Calc::commify( $cookie->{ 'NAV_START' } ), size => 15 ), - "End:", - Maasha::XHTML::text( name => "nav_end", value => Maasha::Calc::commify( $cookie->{ 'NAV_END' } ), size => 15 ), + "Position or search term:", + Maasha::XHTML::text( name => "nav_search", value => $nav_val, size => 30 ), Maasha::XHTML::submit( name => "nav_submit", value => "Submit" ), ] ); push @html, Maasha::XHTML::table_end; @@ -652,8 +701,14 @@ sub section_browse #$elem->{ 'strand' } = '+' if $elem->{ 'strand' } eq '+'; + $cookie->{ 'Q_ID' } = $elem->{ 'q_id' }; + $cookie->{ 'S_BEG' } = $elem->{ 's_beg' }; + $cookie->{ 'S_END' } = $elem->{ 's_end' }; + $cookie->{ 'STRAND' } = $elem->{ 'strand' }; + push @img, Maasha::XHTML::area( - href => cookie_href( $cookie, "export" ) . "&q_id=$elem->{ 'q_id' }&s_beg=$elem->{ 's_beg' }&s_end=$elem->{ 's_end' }&strand=$elem->{ 'strand' }", + 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' }", ); @@ -708,6 +763,70 @@ sub section_export } +sub section_search +{ + # Martin A. Hansen, November 2009. + + # Returns a HTML section with export table. + + my ( $cookie, # cookie hash + ) = @_; + + # Returns a list. + + my ( $results, $result, $count, @html, $export, $browse ); + + $results = Maasha::BBrowser::Track::search_tracks( $cookie ); + + $count = scalar @{ $results }; + + push @html, Maasha::XHTML::h2( txt => "Search", class => 'center' ); + push @html, Maasha::XHTML::p( txt => qq(Results for "$cookie->{ 'SEARCH' }": $count), class => 'center' ); + + if ( $count > 0 ) + { + push @html, Maasha::XHTML::table_beg( summary => "Search table", align => 'center', cellpadding => '5px' ); + push @html, Maasha::XHTML::table_row_simple( tr => [ qw( S_ID S_BEG S_END Q_ID SCORE STRAND HITS ALIGN BLOCK_COUNT BLOCK_BEGS BLOCK_LENS BLOCK_TYPE) ] ); + + foreach $result ( @{ $results } ) + { + $cookie->{ 'CONTIG' } = $result->{ 'S_ID' }; + $cookie->{ 'NAV_START' } = $result->{ 'S_BEG' }; + $cookie->{ 'NAV_END' } = $result->{ 'S_END' }; + $cookie->{ 'S_BEG' } = $result->{ 'S_BEG' }; + $cookie->{ 'S_END' } = $result->{ 'S_END' }; + $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" ) ); + + push @html, Maasha::XHTML::table_row_advanced( + tr => [ { td => $result->{ 'S_ID' } }, + { td => $result->{ 'S_BEG' }, align => 'right' }, + { td => $result->{ 'S_END' }, align => 'right' }, + { td => $result->{ 'Q_ID' } }, + { td => $result->{ 'SCORE' }, align => 'right' }, + { td => $result->{ 'STRAND' } }, + { td => $result->{ 'HITS' }, align => 'right' }, + { td => $result->{ 'ALIGN' } }, + { td => $result->{ 'BLOCK_COUNT' }, align => 'right' }, + { td => $result->{ 'BLOCK_BEGS' } }, + { td => $result->{ 'BLOCK_LENS' } }, + { td => $result->{ 'BLOCK_TYPE' } }, + { td => $browse }, + { td => $export }, + ], class => "monospace" + ); + } + + push @html, Maasha::XHTML::table_end; + } + + return wantarray ? @html : \@html; +} + + sub section_dna { # Martin A. Hansen, November 2009. -- 2.39.2