From 0fdfd9393010438c4654fd3fea7ae10ed38b8eed Mon Sep 17 00:00:00 2001 From: martinahansen Date: Thu, 11 Dec 2008 05:05:17 +0000 Subject: [PATCH] added exon capabilities to calc_fixedstep git-svn-id: http://biopieces.googlecode.com/svn/trunk@355 74ccb610-7750-0410-82ae-013aeee3265d --- code_perl/Maasha/Biopieces.pm | 9 ++++----- code_perl/Maasha/UCSC/Wiggle.pm | 18 +++++++++++++++--- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/code_perl/Maasha/Biopieces.pm b/code_perl/Maasha/Biopieces.pm index 8a9bbb4..4cbf81b 100644 --- a/code_perl/Maasha/Biopieces.pm +++ b/code_perl/Maasha/Biopieces.pm @@ -2671,22 +2671,21 @@ sub script_calc_fixedstep # Returns nothing. - my ( $bed_file, $fh_in, $fh_out, $cols, $record, $file_hash, $chr, $bed_entry, $fixedstep_file, $fixedstep_entry ); + my ( $bed_file, $fh_in, $fh_out, $record, $file_hash, $chr, $bed_entry, $fixedstep_file, $fixedstep_entry ); $bed_file = "$BP_TMP/calc_fixedstep.bed"; $fh_out = Maasha::Filesys::file_write_open( $bed_file ); - $cols = 5; # we only need the first 5 BED columns while ( $record = get_record( $in ) ) { - if ( $bed_entry = Maasha::UCSC::BED::biopiece2bed( $record, $cols ) ) { - Maasha::UCSC::BED::bed_entry_put( $bed_entry, $fh_out, $cols, $options->{ 'check' } ); + if ( $bed_entry = Maasha::UCSC::BED::biopiece2bed( $record ) ) { + Maasha::UCSC::BED::bed_entry_put( $bed_entry, $fh_out, undef, $options->{ 'check' } ); } } close $fh_out; - $file_hash = Maasha::UCSC::BED::bed_file_split_on_chr( $bed_file, $BP_TMP, $cols ); + $file_hash = Maasha::UCSC::BED::bed_file_split_on_chr( $bed_file, $BP_TMP ); unlink $bed_file; diff --git a/code_perl/Maasha/UCSC/Wiggle.pm b/code_perl/Maasha/UCSC/Wiggle.pm index 2a0ff23..b8131bf 100644 --- a/code_perl/Maasha/UCSC/Wiggle.pm +++ b/code_perl/Maasha/UCSC/Wiggle.pm @@ -257,9 +257,9 @@ sub fixedstep_calc_array # Returns a bitarray. - my ( $bed, $clones, @array ); + my ( $bed, $clones, @begs, @lens, $i, @array ); - while ( $bed = Maasha::UCSC::BED::bed_entry_get( $fh_in, 4 ) ) + while ( $bed = Maasha::UCSC::BED::bed_entry_get( $fh_in ) ) { if ( $use_score ) { $clones = $bed->[ score ]; @@ -269,7 +269,19 @@ sub fixedstep_calc_array $clones = 1; } - map { $array[ $_ ] += $clones } ( $bed->[ chromStart ] .. $bed->[ chromEnd ] - 1 ); + if ( $bed->[ blockCount ] and $bed->[ blockCount ] > 1 ) + { + @begs = split ",", $bed->[ blockStarts ]; + @lens = split ",", $bed->[ blockSizes ]; + + for ( $i = 0; $i < @begs; $i++ ) { + map { $array[ $_ ] += $clones } ( $begs[ $i ] .. $begs[ $i ] + $lens[ $i ] - 1 ); + } + } + else + { + map { $array[ $_ ] += $clones } ( $bed->[ chromStart ] .. $bed->[ chromEnd ] - 1 ); + } } return wantarray ? @array : \@array; -- 2.39.5