]> git.donarmstrong.com Git - biopieces.git/blobdiff - bp_bin/compute
adding bzip2 support in ruby
[biopieces.git] / bp_bin / compute
index 299b787445e4bee7e6a89b9954e7fe3fe41b29df..0bcd6ca9fe6bea499411b1dc207bfcbc4a2bd64e 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env perl -w
+#!/usr/bin/env perl
 
 # Copyright (C) 2007-2009 Martin A. Hansen.
 
@@ -26,7 +26,9 @@
 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
 
 
+use warnings;
 use strict;
+use Data::Dumper;
 use Maasha::Common;
 use Maasha::Biopieces;
 
@@ -38,7 +40,8 @@ my ( $options, $in, $out, $record, $eval_key, @keys, $eval_val );
 
 $options = Maasha::Biopieces::parse_options(
     [
-        { long => 'eval', short => 'e', type => 'string', mandatory => 'yes', default => undef, allowed => undef, disallowed => undef },
+        { long => 'eval',   short => 'e', type => 'string', mandatory => 'yes', default => undef, allowed => undef, disallowed => undef },
+        { long => 'format', short => 'f', type => 'string', mandatory => 'no',  default => undef, allowed => undef, disallowed => undef },
     ]   
 );
 
@@ -61,8 +64,16 @@ while ( $record = Maasha::Biopieces::get_record( $in ) )
 
         map { $eval_val =~ s/\Q$_\E/$record->{ $_ }/g } @keys;
 
-        $record->{ $eval_key } = eval "$eval_val";
-        Maasha::Common::error( qq(eval "$eval_key = $eval_val" failed -> $@) ) if $@;
+        if ( $eval_val =~ /\+|\-|\*|\// or $eval_val =~ /\s+x\s+/)
+        {
+            $record->{ $eval_key } = eval "$eval_val";
+            Maasha::Common::error( qq(eval "$eval_key = $eval_val" failed -> $@) ) if $@;
+            $record->{ $eval_key } = sprintf( $options->{ 'format' }, $record->{ $eval_key } ) if $options->{ 'format' };
+        }
+        else
+        {
+            $record->{ $eval_key } = $eval_val;
+        }
     }
     else
     {
@@ -72,25 +83,22 @@ while ( $record = Maasha::Biopieces::get_record( $in ) )
     Maasha::Biopieces::put_record( $record, $out );
 }
 
+Maasha::Biopieces::close_stream( $in );
+Maasha::Biopieces::close_stream( $out );
+
 
 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
 
 
 BEGIN
 {
-    $run_time_beg = Maasha::Biopieces::run_time();
-
-    Maasha::Biopieces::log_biopiece();
+    Maasha::Biopieces::status_set();
 }
 
+
 END
 {
-    Maasha::Biopieces::close_stream( $in );
-    Maasha::Biopieces::close_stream( $out );
-
-    $run_time_end = Maasha::Biopieces::run_time();
-
-    Maasha::Biopieces::run_time_print( $run_time_beg, $run_time_end, $options );
+    Maasha::Biopieces::status_log();
 }