From: martinahansen Date: Mon, 30 Apr 2012 10:20:17 +0000 (+0000) Subject: upgraded write_fixedstep X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=a197111fcdba9e69da96c1daca9d85b4f275e8c0;hp=d3691e42dfead189e6b8d0150c086e1f74678120;p=biopieces.git upgraded write_fixedstep git-svn-id: http://biopieces.googlecode.com/svn/trunk@1812 74ccb610-7750-0410-82ae-013aeee3265d --- diff --git a/bp_bin/write_fixedstep b/bp_bin/write_fixedstep index a80bf0f..17957c1 100755 --- a/bp_bin/write_fixedstep +++ b/bp_bin/write_fixedstep @@ -40,9 +40,11 @@ my ( $options, $in, $out, $fh, $record, $entry ); $options = Maasha::Biopieces::parse_options( [ - { long => 'no_stream', short => 'x', type => 'flag', mandatory => 'no', default => undef, allowed => undef, disallowed => undef }, - { long => 'data_out', short => 'o', type => 'file', mandatory => 'no', default => undef, allowed => undef, disallowed => undef }, - { long => 'compress', short => 'Z', type => 'flag', mandatory => 'no', default => undef, allowed => undef, disallowed => undef }, + { long => 'key', short => 'k', type => 'string', mandatory => 'no', default => undef, allowed => undef, disallowed => undef }, + { long => 'step', short => 's', type => 'uint', mandatory => 'no', default => 1, allowed => undef, disallowed => undef }, + { long => 'no_stream', short => 'x', type => 'flag', mandatory => 'no', default => undef, allowed => undef, disallowed => undef }, + { long => 'data_out', short => 'o', type => 'file', mandatory => 'no', default => undef, allowed => undef, disallowed => undef }, + { long => 'compress', short => 'Z', type => 'flag', mandatory => 'no', default => undef, allowed => undef, disallowed => undef }, ] ); @@ -53,7 +55,7 @@ $fh = Maasha::Biopieces::write_stream( $options->{ "data_out" }, $options->{ "co while ( $record = Maasha::Biopieces::get_record( $in ) ) { - if ( $entry = Maasha::UCSC::Wiggle::biopiece2fixedstep( $record ) ) { + if ( $entry = Maasha::UCSC::Wiggle::biopiece2fixedstep( $record, $options->{ "key" }, $options->{ "step" } ) ) { Maasha::UCSC::Wiggle::fixedstep_entry_put( $entry, $fh ); } diff --git a/code_perl/Maasha/UCSC/Wiggle.pm b/code_perl/Maasha/UCSC/Wiggle.pm index 77755ce..f182ac5 100644 --- a/code_perl/Maasha/UCSC/Wiggle.pm +++ b/code_perl/Maasha/UCSC/Wiggle.pm @@ -161,28 +161,28 @@ sub biopiece2fixedstep # Converts a Biopiece record to a fixedStep entry. - my ( $record, # Biopiece record + my ( $record, # Biopiece record + $opt_key, # Key from option hash + $opt_step, # Step from option hash ) = @_; # Returns a list - my ( @entry, $beg, $vals ); + my ( @entry, $chr, $beg, $step, $vals ); - if ( exists $record->{ "REC_TYPE" } and $record->{ "REC_TYPE" } eq 'fixed_step' ) + $chr = $record->{ 'CHR' } || $record->{ 'S_ID' }; + $beg = $record->{ 'CHR_BEG' } || $record->{ 'S_BEG' }; + $step = $record->{ 'STEP' } || $opt_step; + $vals = $record->{ 'VALS' }; + $vals = $record->{ $opt_key } if $opt_key; + + if ( defined $chr and defined $beg and defined $step and defined $vals) { - if ( exists $record->{ 'CHR' } and exists $record->{ 'CHR_BEG' } and exists $record->{ 'STEP' } ) - { - $beg = $record->{ 'CHR_BEG' } + 1; # fixedStep is 1-based - push @entry, "fixedStep chrom=$record->{ 'CHR' } start=$beg step=$record->{ 'STEP' }"; + $beg += 1; # fixedStep is 1-based - $vals = $record->{ 'VALS' }; + push @entry, "fixedStep chrom=$chr start=$beg step=$step"; - map { push @entry, $_ } split ";", $vals; - } - else - { - Maasha::Common::error( qq(could not convert Biopiece record to fixedStep) ); - } + map { push @entry, $_ } split ";", $vals; } unless ( @entry ) {