From: martinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Date: Thu, 11 Dec 2008 03:55:05 +0000 (+0000)
Subject: calc_fixedstep reverted to perl
X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=db338dae15d788d8b8203618a3af79dcd26ad6d0;p=biopieces.git

calc_fixedstep reverted to perl

git-svn-id: http://biopieces.googlecode.com/svn/trunk@354 74ccb610-7750-0410-82ae-013aeee3265d
---

diff --git a/code_perl/Maasha/Biopieces.pm b/code_perl/Maasha/Biopieces.pm
index 51c25aa..8a9bbb4 100644
--- a/code_perl/Maasha/Biopieces.pm
+++ b/code_perl/Maasha/Biopieces.pm
@@ -2693,9 +2693,13 @@ sub script_calc_fixedstep
     foreach $chr ( sort keys %{ $file_hash } )
     {
         $bed_file       = $file_hash->{ $chr };
-        $fixedstep_file = "$bed_file.fixedstep";
+
+        $fixedstep_file = Maasha::UCSC::Wiggle::fixedstep_calc( $bed_file, $chr, $options->{ 'use_score' }, $options->{ 'use_log10' } );        
+
+        #$fixedstep_file = "$bed_file.fixedstep";
         
-        Maasha::Common::run( "bed2fixedstep", "< $bed_file > $fixedstep_file" );
+        # Maasha::Common::run( "bed2fixedstep", "< $bed_file > $fixedstep_file" );
+
 
         $fh_in = Maasha::Filesys::file_read_open( $fixedstep_file );
 
diff --git a/code_perl/Maasha/UCSC/Wiggle.pm b/code_perl/Maasha/UCSC/Wiggle.pm
index 8718b31..2a0ff23 100644
--- a/code_perl/Maasha/UCSC/Wiggle.pm
+++ b/code_perl/Maasha/UCSC/Wiggle.pm
@@ -35,7 +35,6 @@ use strict;
 use Data::Dumper;
 use Maasha::Common;
 use Maasha::Filesys;
-use Maasha::C_bitarray;
 use Maasha::Calc;
 
 use vars qw( @ISA @EXPORT_OK );
@@ -116,7 +115,7 @@ sub fixedstep_entry_put
 
     $fh ||= \*STDOUT;
 
-    map { print $fh "$_\n" } @{ $entry };
+    print $fh join( "\n", @{ $entry } ), "\n";
 }
 
 
@@ -202,7 +201,7 @@ sub fixedstep_calc
 
     # Returns a string
 
-    my ( $fixedstep_file, $fh_in, $fh_out, $array, $beg, $end, @block );
+    my ( $fixedstep_file, $fh_in, $fh_out, $array, $beg, $end, @block, $i );
 
     $fixedstep_file = "$bed_file.fixedstep";
 
@@ -216,13 +215,18 @@ sub fixedstep_calc
 
     $beg = 0;
 
-    while ( ( $beg, $end ) = Maasha::C_bitarray::c_array_interval_scan( $array, $beg ) and $beg != -1 )
+    while ( ( $beg, $end ) = fixedstep_scan( $array, $beg ) and $beg != -1 )
     {
-        @block = Maasha::C_bitarray::c_array_interval_get( $array, $beg, $end );
+        @block = "fixedStep chrom=$chr start=" . ( $beg + 1 ) . " step=1";
 
-        map { $_ = sprintf "%.4f", Maasha::Calc::log10( $_ ) } @block if $use_log10;
-
-        unshift @block, "fixedStep chrom=$chr start=" . ( $beg + 1 ) . " step=1";
+        for ( $i = $beg; $i <= $end; $i++ )
+        {
+            if ( $use_log10 ) {
+                push @block, sprintf "%.4f", Maasha::Calc::log10( $array->[ $i ] );
+            } else {
+                push @block, $array->[ $i ];
+            }
+        }
 
         fixedstep_entry_put( \@block, $fh_out );
 
@@ -253,11 +257,9 @@ sub fixedstep_calc_array
 
     # Returns a bitarray.
 
-    my ( $bed, $clones, $vec );
-
-    $vec = Maasha::C_bitarray::c_array_init( SEQ_MAX, BITS );
+    my ( $bed, $clones, @array );
 
-    while ( $bed = Maasha::UCSC::BED::bed_entry_get( $fh_in, 5 ) )
+    while ( $bed = Maasha::UCSC::BED::bed_entry_get( $fh_in, 4 ) )
     {
         if ( $use_score ) {
             $clones = $bed->[ score ];
@@ -267,10 +269,10 @@ sub fixedstep_calc_array
             $clones = 1;
         }
 
-        Maasha::C_bitarray::c_array_interval_fill( $vec, $bed->[ chromStart ], $bed->[ chromEnd ] - 1, $clones );
+        map { $array[ $_ ] += $clones } ( $bed->[ chromStart ] .. $bed->[ chromEnd ] - 1 );
     }
 
-    return $vec;
+    return wantarray ? @array : \@array;
 }