]> git.donarmstrong.com Git - biopieces.git/blobdiff - bp_bin/analyze_vals
removed debug message
[biopieces.git] / bp_bin / analyze_vals
index e7e8249a8faf73c53bce080d333e56a73a2b7aa1..40dd0e0239737e08b16eb75d815f6445a8ed7a72 100755 (executable)
 require 'maasha/biopieces'
 
 casts = []
-casts << {long: 'keys',    short: 'k', type: 'list', mandatory: false, default: nil, allowed: nil, disallowed: nil}
-casts << {long: 'no_keys', short: 'K', type: 'list', mandatory: false, default: nil, allowed: nil, disallowed: nil}
+casts << {long: 'keys',      short: 'k', type: 'list', mandatory: false, default: nil, allowed: nil, disallowed: nil}
+casts << {long: 'no_keys',   short: 'K', type: 'list', mandatory: false, default: nil, allowed: nil, disallowed: nil}
+casts << {long: 'no_stream', short: 'x', type: 'flag', mandatory: false, default: nil, allowed: nil, disallowed: nil}
+casts << {long: 'data_out',  short: 'o', type: 'file', mandatory: false, default: nil, allowed: nil, disallowed: nil}
 
 options = Biopieces.options_parse(ARGV, casts)
 
@@ -74,23 +76,31 @@ Biopieces.open(options[:stream_in], options[:stream_out]) do |input, output|
       key = key.to_sym
       value = record[key]
 
-      stats[key][:sum]   ||= 0
-      stats[key][:count] ||= 0
-
-      if num = to_number(value)
-        stats[key][:min]   = min(stats[key][:min], num)
-        stats[key][:max]   = max(stats[key][:max], num)
-        stats[key][:type]  = :numeric
-        stats[key][:sum]  += num
-      else
-        stats[key][:min]   = min(stats[key][:min], value.length)
-        stats[key][:max]   = max(stats[key][:max], value.length)
-        stats[key][:type]  = :alphabetic
-        stats[key][:sum]  += value.length
+      if value
+        stats[key][:sum]   ||= 0
+        stats[key][:count] ||= 0
+
+        if num = to_number(value)
+          stats[key][:min]   = min(stats[key][:min], num)
+          stats[key][:max]   = max(stats[key][:max], num)
+          stats[key][:type]  = :numeric
+          stats[key][:sum]  += num
+        else
+          stats[key][:min]   = min(stats[key][:min], value.length)
+          stats[key][:max]   = max(stats[key][:max], value.length)
+          stats[key][:type]  = :alphabetic
+          stats[key][:sum]  += value.length
+        end
+
+        stats[key][:count] += 1
       end
-
-      stats[key][:count] += 1
     end
+
+    output.puts record unless options[:no_stream]
+  end
+
+  if options[:data_out]
+    data_out = File.open(options[:data_out], 'w')
   end
 
   stats.each do |key, value|
@@ -104,7 +114,11 @@ Biopieces.open(options[:stream_in], options[:stream_out]) do |input, output|
       :MEAN  => "%0.2f" % (value[:sum] / value[:count].to_f)
     }
 
-    output.puts stat_record
+    if options[:data_out]
+      data_out.puts stat_record
+    else
+      output.puts stat_record
+    end
   end
 end