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 );
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" };
use Data::Dumper;
use Maasha::Common;
use Maasha::Filesys;
+use Maasha::Calc;
use vars qw( @ISA @EXPORT_OK );
# 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 };
}
{
$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 };
}
# 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' };
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
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;
}