]> git.donarmstrong.com Git - biopieces.git/commitdiff
calc_fixedstep reverted to perl
authormartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Thu, 11 Dec 2008 03:55:05 +0000 (03:55 +0000)
committermartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Thu, 11 Dec 2008 03:55:05 +0000 (03:55 +0000)
git-svn-id: http://biopieces.googlecode.com/svn/trunk@354 74ccb610-7750-0410-82ae-013aeee3265d

code_perl/Maasha/Biopieces.pm
code_perl/Maasha/UCSC/Wiggle.pm

index 51c25aa3449ca8c4a32ccee26a076f1b9277073a..8a9bbb44363649bc9558ac8dfc6b26efa48a611d 100644 (file)
@@ -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 );
 
index 8718b315a1bfcc95eeb6c960889f5f6b61f7c5f8..2a0ff237c1ea0f8137a8b6533cdc4df3aa390e84 100644 (file)
@@ -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;
 }