]> git.donarmstrong.com Git - biopieces.git/commitdiff
fixed bugs in calc_fixedstep
authormartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Mon, 24 Nov 2008 02:27:44 +0000 (02:27 +0000)
committermartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Mon, 24 Nov 2008 02:27:44 +0000 (02:27 +0000)
git-svn-id: http://biopieces.googlecode.com/svn/trunk@321 74ccb610-7750-0410-82ae-013aeee3265d

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

index 3f46538bda5151417734dd6874ec52b15d79d9a7..53a0a24e33080e60b0908cdc368357eb0f87c2c4 100644 (file)
@@ -2674,13 +2674,13 @@ sub script_calc_fixedstep
 
     close $fh_out;
 
-    $file_hash = Maasha::UCSC::BED::bed_file_split_on_chr( $bed_file );
+    $file_hash = Maasha::UCSC::BED::bed_file_split_on_chr( $bed_file, $BP_TMP, $cols );
 
     unlink $bed_file;
 
     foreach $chr ( sort keys %{ $file_hash } )
     {
-        $fixedstep_file = Maasha::UCSC::Wiggle::fixedstep_calc( $file_hash->{ $chr }, $chr, $options->{ 'score' } );
+        $fixedstep_file = Maasha::UCSC::Wiggle::fixedstep_calc( $file_hash->{ $chr }, $chr, $options->{ 'score' }, $options->{ 'log10' } );
 
         $fh_in = Maasha::Filesys::file_read_open( $fixedstep_file );
 
@@ -4374,7 +4374,7 @@ sub script_write_fixedstep
     while ( $record = get_record( $in ) ) 
     {
         if ( $entry = Maasha::UCSC::Wiggle::biopiece2fixedstep( $record ) ) {
-            map { print $fh "$_\n" } @{ $entry };
+            Maasha::UCSC::Wiggle::fixedstep_entry_put( $entry, $fh );
         }
 
         put_record( $record, $out ) if not $options->{ "no_stream" };
index 5e7b5deff59ac74ba8c70e060a15f70cf6aeea5f..1fbd926c3f5f74238b5a359a1f2adcec93a49172 100644 (file)
@@ -35,6 +35,7 @@ use strict;
 use Data::Dumper;
 use Maasha::Common;
 use Maasha::Filesys;
+use Maasha::Calc;
 
 use vars qw( @ISA @EXPORT_OK );
 
@@ -104,21 +105,15 @@ sub fixedstep_entry_put
     # Outputs a block of fixedStep values.
     # Used for outputting wiggle data.
 
-    my ( $chr,      # chromosome
-         $beg,      # start position
-         $block,    # list of scores
+    my ( $entry,    # fixedStep entry
          $fh,       # filehandle - OPTIONAL
        ) = @_;
 
     # Returns nothing.
 
-    $beg += 1;   # fixedStep format is 1 based.
-
     $fh ||= \*STDOUT;
 
-    print $fh "fixedStep chrom=$chr start=$beg step=1\n";
-
-    map { print $fh "$_\n" } @{ $block };
+    map { print $fh "$_\n" } @{ $entry };
 }
 
 
@@ -141,7 +136,7 @@ sub fixedstep2biopiece
     {
         $record{ "REC_TYPE" } = "fixed_step";
         $record{ "CHR" }      = $1;
-        $record{ "CHR_BEG" }  = $2;
+        $record{ "CHR_BEG" }  = $2 - 1;  # fixedStep is 1-based
         $record{ "STEP" }     = $3;
         $record{ "VALS" }     = join ";", @{ $entry };
     }
@@ -165,13 +160,14 @@ sub biopiece2fixedstep
 
     # Returns a list
 
-    my ( @entry, $vals );
+    my ( @entry, $beg, $vals );
 
     if ( exists $record->{ "REC_TYPE" } and $record->{ "REC_TYPE" } eq 'fixed_step' )
     {
         if ( exists $record->{ 'CHR' } and exists $record->{ 'CHR_BEG' } and exists $record->{ 'STEP' } )
         {
-            push @entry, "fixedStep chrom=$record->{ 'CHR' } start=$record->{ 'CHR_BEG' } step=$record->{ 'STEP' }";
+            $beg = $record->{ 'CHR_BEG' } + 1;   # fixedStep is 1-based
+            push @entry, "fixedStep chrom=$record->{ 'CHR' } start=$beg step=$record->{ 'STEP' }";
 
             $vals = $record->{ 'VALS' };
 
@@ -198,6 +194,7 @@ sub fixedstep_calc
     my ( $bed_file,   # path to BED file
          $chr,        # chromosome name
          $use_score,  # flag indicating that the score field should be used - OPTIONAL
+         $use_log10,  # flag indicating that the score should be in log10   - OPTIONAL
        ) = @_;
 
     # Returns a string
@@ -218,9 +215,13 @@ sub fixedstep_calc
 
     while ( ( $beg, $end ) = fixedstep_scan( $array, $beg ) and $beg )
     {
-        @block = @{ $array }[ $beg .. $end ];
+        @block = @{ $array }[ $beg .. $end - 1 ];
+
+        map { $_ = sprintf "%.4f", Maasha::Calc::log10( $_ ) } @block if $use_log10;
+
+        unshift @block, "fixedStep chrom=$chr start=" . ( $beg + 1 ) . " step=1";
 
-        fixedstep_entry_put( $chr, $beg, \@block, $fh_out );
+        fixedstep_entry_put( \@block, $fh_out );
 
         $beg = $end;
     }