]> git.donarmstrong.com Git - biopieces.git/blobdiff - code_perl/Maasha/UCSC/Wiggle.pm
added python code
[biopieces.git] / code_perl / Maasha / UCSC / Wiggle.pm
index 1fbd926c3f5f74238b5a359a1f2adcec93a49172..8718b315a1bfcc95eeb6c960889f5f6b61f7c5f8 100644 (file)
@@ -35,6 +35,7 @@ use strict;
 use Data::Dumper;
 use Maasha::Common;
 use Maasha::Filesys;
+use Maasha::C_bitarray;
 use Maasha::Calc;
 
 use vars qw( @ISA @EXPORT_OK );
@@ -48,7 +49,9 @@ require Exporter;
 
 
 use constant {
-    chrom       => 0,   # BED field names
+    BITS        => 32,            # Number of bits in an integer
+    SEQ_MAX     => 200_000_000,   # Maximum sequence size
+    chrom       => 0,             # BED field names
     chromStart  => 1,
     chromEnd    => 2,
     name        => 3,
@@ -213,9 +216,9 @@ sub fixedstep_calc
 
     $beg = 0;
 
-    while ( ( $beg, $end ) = fixedstep_scan( $array, $beg ) and $beg )
+    while ( ( $beg, $end ) = Maasha::C_bitarray::c_array_interval_scan( $array, $beg ) and $beg != -1 )
     {
-        @block = @{ $array }[ $beg .. $end - 1 ];
+        @block = Maasha::C_bitarray::c_array_interval_get( $array, $beg, $end );
 
         map { $_ = sprintf "%.4f", Maasha::Calc::log10( $_ ) } @block if $use_log10;
 
@@ -223,11 +226,13 @@ sub fixedstep_calc
 
         fixedstep_entry_put( \@block, $fh_out );
 
-        $beg = $end;
+        $beg = $end + 1;
     }
 
     close $fh_out;
 
+    undef $array;
+
     return $fixedstep_file;
 }
 
@@ -246,9 +251,11 @@ sub fixedstep_calc_array
          $use_score,   # flag indicating that the score field should be used - OPTIONAL
        ) = @_;
 
-    # Returns arrayref.
+    # Returns a bitarray.
+
+    my ( $bed, $clones, $vec );
 
-    my ( $bed, $clones, @array );
+    $vec = Maasha::C_bitarray::c_array_init( SEQ_MAX, BITS );
 
     while ( $bed = Maasha::UCSC::BED::bed_entry_get( $fh_in, 5 ) )
     {
@@ -260,10 +267,10 @@ sub fixedstep_calc_array
             $clones = 1;
         }
 
-        map { $array[ $_ ] += $clones } $bed->[ chromStart ] .. $bed->[ chromEnd ] - 1;
+        Maasha::C_bitarray::c_array_interval_fill( $vec, $bed->[ chromStart ], $bed->[ chromEnd ] - 1, $clones );
     }
 
-    return wantarray ? @array : \@array;
+    return $vec;
 }