]> git.donarmstrong.com Git - biopieces.git/commitdiff
fixing wiggle tracks in BGB
authormartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Fri, 5 Mar 2010 10:22:45 +0000 (10:22 +0000)
committermartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Fri, 5 Mar 2010 10:22:45 +0000 (10:22 +0000)
git-svn-id: http://biopieces.googlecode.com/svn/trunk@893 74ccb610-7750-0410-82ae-013aeee3265d

code_perl/Maasha/BGB/Track.pm
www/index.cgi

index 6e2d0867844cbeea9188806a7a6ca72f7dc9b030..1c8ba95a963a7643286366668470854def5f813f 100644 (file)
@@ -77,7 +77,7 @@ sub track_ruler
 
     $beg    = $cookie->{ 'NAV_START' };
     $end    = $cookie->{ 'NAV_END' };
-    $factor = $cookie->{ 'IMG_WIDTH' } / ( $end - $beg + 1 );
+    $factor = $cookie->{ 'IMG_WIDTH' } / ( $end - $beg );
     
     $step = 10;
 
@@ -225,47 +225,55 @@ sub track_wiggle
 
     # Returns a list.
 
-    my ( $i, $height, $max_val, $min_val, $max, $factor, $x1, $y1, $x2, $y2, @features );
+    my ( $i, $max_val, $min_val, $factor, $factor_height, $x1, $y1, $x2, $y2, @block, $mean, @features );
 
-    $height  = 75;   # pixels
+    $factor = $cookie->{ 'IMG_WIDTH' } / ( $end - $beg );
 
     ( $min_val, $max_val ) = Maasha::Calc::minmax( $vals );
 
-    $vals    = Maasha::BGB::Wiggle::wiggle_normalize( $vals, $cookie->{ 'IMG_WIDTH' } );
-
-    $max     = Maasha::Calc::list_max( $vals );
-    $max   ||= 1;
-
-    $factor = $height / $max;
+    if ( $max_val == 0 ) {
+        $factor_height = $cookie->{ 'WIGGLE_HEIGHT' } / 1;
+    } else {
+        $factor_height = $cookie->{ 'WIGGLE_HEIGHT' } / $max_val;
+    }
 
     $x1 = 0;
-    $y1 = $cookie->{ 'TRACK_OFFSET' } + $height;
+    $y1 = $cookie->{ 'TRACK_OFFSET' } + $cookie->{ 'WIGGLE_HEIGHT' };
 
     for ( $i = 0; $i < scalar @{ $vals }; $i++ )
     {
-        $x2 = $i;
-        $y2 = $cookie->{ 'TRACK_OFFSET' } + $height - sprintf( "%.0f", $vals->[ $i ] * $factor );
-
-        push @features, {
-            type  => 'wiggle',
-            color => $cookie->{ 'FEAT_COLOR' },
-            line_width => 1,
-            x1         => $x1,
-            y1         => $y1,
-            x2         => $x2,
-            y2         => $y2,
-        };
-
-        $x1 = $x2;
-        $y1 = $y2;
+        push @block, $vals->[ $i ];
+
+        $x2 = int( $i * $factor );
+
+        if ( $x2 > $x1 )
+        {
+            $mean = sprintf( "%.0f", Maasha::Calc::mean( \@block ) );
+
+            $y2 = $cookie->{ 'TRACK_OFFSET' } + $cookie->{ 'WIGGLE_HEIGHT' } - ( $mean * $factor_height );
+
+            push @features, {
+                type       => 'wiggle',
+                color      => $cookie->{ 'FEAT_COLOR' },
+                line_width => 1,
+                x1         => $x1,
+                y1         => $y1,
+                x2         => $x2,
+                y2         => $y2,
+            };
+
+            $x1 = $x2;
+            $y1 = $y2;
+
+            undef @block;
+        }
     }
 
-    $x2 = $i;
-    $y2 = $cookie->{ 'TRACK_OFFSET' } + $height;
+    $y2 = $cookie->{ 'TRACK_OFFSET' } + $cookie->{ 'WIGGLE_HEIGHT' };
 
     push @features, {
-        type  => 'wiggle',
-        color => $cookie->{ 'FEAT_COLOR' },
+        type       => 'wiggle',
+        color      => $cookie->{ 'FEAT_COLOR' },
         line_width => 1,
         x1         => $x1,
         y1         => $y1,
@@ -282,7 +290,7 @@ sub track_wiggle
         y1        => $cookie->{ 'TRACK_OFFSET' },
     };
 
-    $cookie->{ 'TRACK_OFFSET' } += $height + $cookie->{ 'TRACK_SPACE' };
+    $cookie->{ 'TRACK_OFFSET' } += $cookie->{ 'WIGGLE_HEIGHT' } + $cookie->{ 'TRACK_SPACE' };
 
     return wantarray ? @features : \@features;
 }
@@ -305,7 +313,7 @@ sub track_linear
     
     my ( $factor, $entry, $y_step, @ladder, $y_max, $w, $x1, $y1, $x2, $y2, $feature, @features );
 
-    $factor = $cookie->{ 'IMG_WIDTH' } / ( $end - $beg + 1 );
+    $factor = $cookie->{ 'IMG_WIDTH' } / ( $end - $beg );
     $y_step = 0;
     $y_max  = 0;
 
@@ -449,7 +457,7 @@ sub track_feature_histogram
     $hist_height  = 100;   # pixels
     $bucket_width = 5;
     $bucket_count = $cookie->{ 'IMG_WIDTH' } / $bucket_width;
-    $factor       = ( $cookie->{ 'IMG_WIDTH' } / $bucket_width ) / ( $max - $min + 1 );
+    $factor       = ( $cookie->{ 'IMG_WIDTH' } / $bucket_width ) / ( $max - $min );
 
     $min_bucket = 999999999;
     $max_height = 0;
index db4845106749bbdf44582bffb005aa4dbc5d2d60..aa9842db94266b4b8a367158f1ba69a28ebcfd2b 100755 (executable)
@@ -141,17 +141,18 @@ sub cookie_default
     $cookie->{ 'MOVE_RIGHT2' }     = $cgi->param( 'move_right2' );
     $cookie->{ 'MOVE_RIGHT3' }     = $cgi->param( 'move_right3' );
 
-    $cookie->{ 'IMG_WIDTH' }       = 1200;
-    $cookie->{ 'IMG_HEIGHT' }      = 800;
+    $cookie->{ 'IMG_WIDTH' }       = 1200;   # Width of browser image in pixels
+    $cookie->{ 'IMG_HEIGHT' }      = 800;    # Height of browser image in pixels
+    $cookie->{ 'WIGGLE_HEIGHT' }   = 75;     # Height of Wiggle tracks in pixels
     $cookie->{ 'TRACK_OFFSET' }    = 20;
     $cookie->{ 'TRACK_SPACE' }     = 20;
-    $cookie->{ 'RULER_FONT_SIZE' } = 10;
+    $cookie->{ 'RULER_FONT_SIZE' } = 10;     # Size of ruler font in pixels
     $cookie->{ 'RULER_COLOR' }     = [ 0, 0, 0 ];
     $cookie->{ 'SEQ_FONT_SIZE' }   = 10;
     $cookie->{ 'SEQ_COLOR' }       = [ 0, 0, 0, ];
     $cookie->{ 'FEAT_WIDTH' }      = 5;
     $cookie->{ 'FEAT_COLOR' }      = [ 0, 0, 0 ];
-    $cookie->{ 'FEAT_MAX' }        = 5000;
+    $cookie->{ 'FEAT_MAX' }        = 5000;   # TODO: Reduntant?
 
     $cookie->{ 'LIST_USER' }       = Maasha::BGB::Track::list_users();
     $cookie->{ 'LIST_CLADE' }      = Maasha::BGB::Track::list_clades(     $cookie->{ 'USER' } );