]> git.donarmstrong.com Git - biopieces.git/blobdiff - bp_bin/analyze_vals
adding bzip2 support in ruby
[biopieces.git] / bp_bin / analyze_vals
index 1ddd36fc52152869835615e4a07517aedc08a431..726c91c53c62f5c22560b77260f45d094340b018 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env perl -w
+#!/usr/bin/env perl
 
 # Copyright (C) 2007-2009 Martin A. Hansen.
 
@@ -26,6 +26,7 @@
 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
 
 
+use warnings;
 use strict;
 use Maasha::Biopieces;
 use Maasha::Calc;
@@ -35,19 +36,25 @@ use Data::Dumper;
 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
 
 
-my ( $run_time_beg, $run_time_end, $options, $in, $out, $record, $analysis, $key, $len,
+my ( $options, $in, $out, $record, $analysis, $key, $len, %skip_hash, $data_out,
      %key_hash, $skip, $keys, $types, $counts, $mins, $maxs, $sums, $means );
 
 $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 => 'keys',      short => 'k', type => 'list', mandatory => 'no', default => undef, allowed => undef, disallowed => undef },
+        { long => 'no_keys',   short => 'K', type => 'list', mandatory => 'no', default => undef, allowed => undef, disallowed => undef },
     ]   
 );
 
 $in  = Maasha::Biopieces::read_stream( $options->{ "stream_in" } );
 $out = Maasha::Biopieces::write_stream( $options->{ "stream_out" } );
 
+$data_out = Maasha::Biopieces::write_stream( $options->{ "data_out" }, $options->{ "compress" } );
+$data_out ||= \*STDOUT;
+
+map { $skip_hash{ $_ } = 1 } @{ $options->{ "no_keys" } };
 map { $key_hash{ $_ } = 1; $skip = 1 } @{ $options->{ "keys" } };
 
 while ( $record = Maasha::Biopieces::get_record( $in ) ) 
@@ -55,6 +62,7 @@ while ( $record = Maasha::Biopieces::get_record( $in ) )
     foreach $key ( keys %{ $record } )
     {
         next if $skip and not exists $key_hash{ $key };
+        next if $skip_hash{ $key };
 
         if ( Maasha::Calc::is_a_number( $record->{ $key } ) )
         {
@@ -107,7 +115,7 @@ $maxs   = "MAX  ";
 $sums   = "SUM  ";
 $means  = "MEAN ";
 
-foreach $key ( keys %{ $analysis } )
+foreach $key ( sort keys %{ $analysis } )
 {
     $keys   .= sprintf "% 15s", $key;
     $types  .= sprintf "% 15s", $analysis->{ $key }->{ "TYPE" };
@@ -118,13 +126,18 @@ foreach $key ( keys %{ $analysis } )
     $means  .= sprintf "% 15s", $analysis->{ $key }->{ "MEAN" };
 }
 
-print "$keys\n";
-print "$types\n";
-print "$counts\n";
-print "$mins\n";
-print "$maxs\n";
-print "$sums\n";
-print "$means\n";
+print $data_out "$keys\n";
+print $data_out "$types\n";
+print $data_out "$counts\n";
+print $data_out "$mins\n";
+print $data_out "$maxs\n";
+print $data_out "$sums\n";
+print $data_out "$means\n";
+
+close $data_out;
+
+Maasha::Biopieces::close_stream( $in );
+Maasha::Biopieces::close_stream( $out );
 
 
 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
@@ -132,19 +145,13 @@ print "$means\n";
 
 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();
 }