From f07c098d8cd5def3c66d6e1d2f9736314ff318a9 Mon Sep 17 00:00:00 2001 From: martinahansen Date: Mon, 24 Nov 2008 02:27:44 +0000 Subject: [PATCH] fixed bugs in calc_fixedstep git-svn-id: http://biopieces.googlecode.com/svn/trunk@321 74ccb610-7750-0410-82ae-013aeee3265d --- code_perl/Maasha/Biopieces.pm | 6 +++--- code_perl/Maasha/UCSC/Wiggle.pm | 27 ++++++++++++++------------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/code_perl/Maasha/Biopieces.pm b/code_perl/Maasha/Biopieces.pm index 3f46538..53a0a24 100644 --- a/code_perl/Maasha/Biopieces.pm +++ b/code_perl/Maasha/Biopieces.pm @@ -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" }; diff --git a/code_perl/Maasha/UCSC/Wiggle.pm b/code_perl/Maasha/UCSC/Wiggle.pm index 5e7b5de..1fbd926 100644 --- a/code_perl/Maasha/UCSC/Wiggle.pm +++ b/code_perl/Maasha/UCSC/Wiggle.pm @@ -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; } -- 2.39.5