]> git.donarmstrong.com Git - biopieces.git/commitdiff
upgraded write_fixedstep
authormartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Mon, 30 Apr 2012 10:20:17 +0000 (10:20 +0000)
committermartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Mon, 30 Apr 2012 10:20:17 +0000 (10:20 +0000)
git-svn-id: http://biopieces.googlecode.com/svn/trunk@1812 74ccb610-7750-0410-82ae-013aeee3265d

bp_bin/write_fixedstep
code_perl/Maasha/UCSC/Wiggle.pm

index a80bf0f810aa7a5af12e34f2c304e8076de22f19..17957c1bd978eb34b5b247202f7387b388084374 100755 (executable)
@@ -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 );
     }
 
index 77755ceadd7892a8956867a5d3a6b1abea8d17f7..f182ac56f35435a8f2606fd09d1c5195540684cc 100644 (file)
@@ -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 ) {