From: martinahansen Date: Wed, 28 Oct 2009 09:30:09 +0000 (+0000) Subject: added ALIGN view support to KISS X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=13bdafe0dc516b3c2497f7641aa8b7b3b221590d;p=biopieces.git added ALIGN view support to KISS git-svn-id: http://biopieces.googlecode.com/svn/trunk@713 74ccb610-7750-0410-82ae-013aeee3265d --- diff --git a/code_perl/Maasha/KISS/Draw.pm b/code_perl/Maasha/KISS/Draw.pm index af48ac1..90ed4f6 100644 --- a/code_perl/Maasha/KISS/Draw.pm +++ b/code_perl/Maasha/KISS/Draw.pm @@ -83,14 +83,22 @@ sub track_feature my ( $feature ); - $cr->set_source_rgb( color_name2rgb( $color ) ); - - $cr->set_line_width( 5 ); - foreach $feature ( @{ $features } ) { + $cr->set_source_rgb( color_name2rgb( $feature->{ 'color' } ) ); $cr->move_to( $feature->{ 'x1' }, $feature->{ 'y1' } ); - $cr->line_to( $feature->{ 'x2' }, $feature->{ 'y2' } ); + + if ( $feature->{ 'type' } eq 'line' ) + { + $cr->set_line_width( $feature->{ 'line_width' } ); + $cr->line_to( $feature->{ 'x2' }, $feature->{ 'y2' } ); + } + elsif ( $feature->{ 'type' } eq 'text' ) + { + $cr->set_font_size( $feature->{ 'font_size' } ); + $cr->show_text( $feature->{ 'txt' } ); + } + $cr->stroke; } } @@ -104,7 +112,10 @@ sub color_name2rgb my ( %color_hash, $rgb ); %color_hash = ( - 'green' => [ 0, 255, 0 ], + 'black' => [ 0, 0, 0 ], + 'red' => [ 255, 0, 0 ], + 'green' => [ 0, 255, 0 ], + 'blue' => [ 0, 0, 255 ], ); if ( exists $color_hash{ $color_name } ) { diff --git a/code_perl/Maasha/KISS/IO.pm b/code_perl/Maasha/KISS/IO.pm index 1020b3e..15f4292 100644 --- a/code_perl/Maasha/KISS/IO.pm +++ b/code_perl/Maasha/KISS/IO.pm @@ -155,7 +155,7 @@ sub kiss_sql_get my ( $sql, $entries ); # $sql = "SELECT * FROM $table WHERE S_BEG >= $s_beg AND S_END <= $s_end ORDER BY S_BEG,S_END"; - $sql = "SELECT S_BEG,S_END FROM $table WHERE S_BEG >= $s_beg AND S_END <= $s_end"; + $sql = "SELECT S_BEG,S_END,ALIGN FROM $table WHERE S_BEG >= $s_beg AND S_END <= $s_end"; $entries = Maasha::SQL::query_hashref_list( $dbh, $sql ); diff --git a/code_perl/Maasha/KISS/Track.pm b/code_perl/Maasha/KISS/Track.pm index 1ae1c86..d0c7162 100644 --- a/code_perl/Maasha/KISS/Track.pm +++ b/code_perl/Maasha/KISS/Track.pm @@ -106,12 +106,13 @@ sub track_feature # Returns a list. - my ( $factor, $entry, $y_step, @ladder, $w, $x1, $y1, $x2, $y2, @features ); + my ( $feat_height, $factor, $entry, $y_step, @ladder, $w, $x1, $y1, $x2, $y2, @features ); @{ $entries } = sort { $a->{ 'S_BEG' } <=> $b->{ 'S_BEG' } or $a->{ 'S_END' } <=> $b->{ 'S_END' } } @{ $entries }; - $factor = $width / ( $end - $beg ); - $y_step = 0; + $feat_height = 5; + $factor = $width / ( $end - $beg ); + $y_step = 0; foreach $entry ( @{ $entries } ) { @@ -126,15 +127,20 @@ sub track_feature last if $x1 >= $ladder[ $y_step ] + 1; } - $y1 = $y_offset + ( 5 * $y_step ); + $y1 = $y_offset + ( $feat_height * $y_step ); push @features, { - x1 => $x1, - y1 => $y1, - x2 => $x1 + $w, - y2 => $y1, + type => 'line', + line_width => $feat_height, + color => 'green', + x1 => $x1, + y1 => $y1, + x2 => $x1 + $w, + y2 => $y1, }; + push @features, feature_align( $entry, $beg, $y1, $factor, $feat_height ) if defined $entry->{ 'ALIGN' }; + $ladder[ $y_step ] = $x1 + $w; } } @@ -143,6 +149,68 @@ sub track_feature } +sub feature_align +{ + # 17:A>T + + my ( $entry, # Partial KISS entry + $beg, # base window beg + $y_offset, # y axis draw offset + $factor, # scale factor + $feat_height, # hight of feature in pixels + ) = @_; + + # Returns a list. + + my ( $w, $align, $pos, $nt_before, $nt_after, $x1, @features ); + + $w = sprintf( "%.0f", 1 * $factor ); + + if ( $w >= 1 ) + { + foreach $align ( split /,/, $entry->{ 'ALIGN' } ) + { + if ( $align =~ /(\d+):(\w)>(\w)/ ) + { + $pos = $1; + $nt_before = $2; + $nt_after = $3; + } + else + { + die; + } + + $x1 = sprintf( "%.0f", ( $entry->{ 'S_BEG' } + $pos - $beg ) * $factor ); + + push @features, { + type => 'line', + line_width => $feat_height, + color => 'red', + x1 => $x1, + y1 => $y_offset, + x2 => $x1 + $w, + y2 => $y_offset, + }; + + if ( $w > 5 ) + { + push @features, { + type => 'text', + font_size => $feat_height, + color => 'black', + txt => $nt_after, + x1 => $x1 + sprintf( "%.0f", ( $w / 2 ) ) - $feat_height / 2, + y1 => $y_offset, + }; + } + } + } + + return wantarray ? @features : \@features; +} + + sub track_histogram { my ( $width, # draw window width @@ -196,10 +264,13 @@ sub track_histogram if ( $h >= 1 ) { push @hist, { - x1 => $x, - y1 => $y_offset + $hist_height, - x2 => $x, - y2 => $y_offset + $hist_height - $h, + type => 'line', + line_width => $bucket_width, + color => 'green', + x1 => $x, + y1 => $y_offset + $hist_height, + x2 => $x, + y2 => $y_offset + $hist_height - $h, }; } } diff --git a/www/cgi-bin/index.cgi b/www/cgi-bin/index.cgi index 1459279..15bb1de 100755 --- a/www/cgi-bin/index.cgi +++ b/www/cgi-bin/index.cgi @@ -197,8 +197,8 @@ sub sec_browse $t0 = Time::HiRes::gettimeofday(); - Maasha::KISS::Draw::track_text( $cr, $ruler, "red" ) if $ruler; - Maasha::KISS::Draw::track_text( $cr, $dna, "red" ) if $dna; + Maasha::KISS::Draw::track_text( $cr, $ruler, "black" ) if $ruler; + Maasha::KISS::Draw::track_text( $cr, $dna, "black" ) if $dna; Maasha::KISS::Draw::track_feature( $cr, $features, 'green' ) if $features; diff --git a/www/cgi-bin/test.svg b/www/cgi-bin/test.svg deleted file mode 100644 index 31ced33..0000000 --- a/www/cgi-bin/test.svg +++ /dev/null @@ -1,2270 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file