From 8b6b8cb49facd3cb2f4c6f0d98e3bb84de9a6ddf Mon Sep 17 00:00:00 2001 From: martinahansen Date: Fri, 25 Oct 2013 09:42:48 +0000 Subject: [PATCH] added -o and -x to analyze_vals git-svn-id: http://biopieces.googlecode.com/svn/trunk@2250 74ccb610-7750-0410-82ae-013aeee3265d --- bp_bin/analyze_vals | 18 +++++++++++++++--- bp_test/out/analyze_vals.out.1 | 9 +++++++++ bp_test/out/analyze_vals.out.2 | 8 ++++++++ bp_test/out/analyze_vals.out.3 | 21 +++++++++++++++------ bp_test/out/analyze_vals.out.4 | 17 +++++++++++++++++ bp_test/out/analyze_vals.out.5 | 16 ++++++++++++++++ bp_test/test/test_analyze_vals | 12 ++++++++++-- code_ruby/lib/maasha/seq/backtrack.rb | 2 +- 8 files changed, 91 insertions(+), 12 deletions(-) create mode 100644 bp_test/out/analyze_vals.out.4 create mode 100644 bp_test/out/analyze_vals.out.5 diff --git a/bp_bin/analyze_vals b/bp_bin/analyze_vals index e7e8249..951f321 100755 --- a/bp_bin/analyze_vals +++ b/bp_bin/analyze_vals @@ -31,8 +31,10 @@ 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) @@ -91,6 +93,12 @@ Biopieces.open(options[:stream_in], options[:stream_out]) do |input, output| 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 +112,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 diff --git a/bp_test/out/analyze_vals.out.1 b/bp_test/out/analyze_vals.out.1 index 6afc4df..29aaf12 100644 --- a/bp_test/out/analyze_vals.out.1 +++ b/bp_test/out/analyze_vals.out.1 @@ -1,3 +1,12 @@ +V0: Human +V1: 123 +--- +V0: Dog +V1: 45 +--- +V0: Mouse +V1: 6 +--- KEY: V0 TYPE: Alphabetic COUNT: 3 diff --git a/bp_test/out/analyze_vals.out.2 b/bp_test/out/analyze_vals.out.2 index e1d6bb5..6afc4df 100644 --- a/bp_test/out/analyze_vals.out.2 +++ b/bp_test/out/analyze_vals.out.2 @@ -6,3 +6,11 @@ MAX: 5 SUM: 13 MEAN: 4.33 --- +KEY: V1 +TYPE: Numeric +COUNT: 3 +MIN: 6 +MAX: 123 +SUM: 174 +MEAN: 58.00 +--- diff --git a/bp_test/out/analyze_vals.out.3 b/bp_test/out/analyze_vals.out.3 index 6d628d0..9ce53d7 100644 --- a/bp_test/out/analyze_vals.out.3 +++ b/bp_test/out/analyze_vals.out.3 @@ -1,8 +1,17 @@ -KEY: V1 -TYPE: Numeric +V0: Human +V1: 123 +--- +V0: Dog +V1: 45 +--- +V0: Mouse +V1: 6 +--- +KEY: V0 +TYPE: Alphabetic COUNT: 3 -MIN: 6 -MAX: 123 -SUM: 174 -MEAN: 58.00 +MIN: 3 +MAX: 5 +SUM: 13 +MEAN: 4.33 --- diff --git a/bp_test/out/analyze_vals.out.4 b/bp_test/out/analyze_vals.out.4 new file mode 100644 index 0000000..48f9086 --- /dev/null +++ b/bp_test/out/analyze_vals.out.4 @@ -0,0 +1,17 @@ +V0: Human +V1: 123 +--- +V0: Dog +V1: 45 +--- +V0: Mouse +V1: 6 +--- +KEY: V1 +TYPE: Numeric +COUNT: 3 +MIN: 6 +MAX: 123 +SUM: 174 +MEAN: 58.00 +--- diff --git a/bp_test/out/analyze_vals.out.5 b/bp_test/out/analyze_vals.out.5 new file mode 100644 index 0000000..6afc4df --- /dev/null +++ b/bp_test/out/analyze_vals.out.5 @@ -0,0 +1,16 @@ +KEY: V0 +TYPE: Alphabetic +COUNT: 3 +MIN: 3 +MAX: 5 +SUM: 13 +MEAN: 4.33 +--- +KEY: V1 +TYPE: Numeric +COUNT: 3 +MIN: 6 +MAX: 123 +SUM: 174 +MEAN: 58.00 +--- diff --git a/bp_test/test/test_analyze_vals b/bp_test/test/test_analyze_vals index 918b3fc..f81f2b6 100755 --- a/bp_test/test/test_analyze_vals +++ b/bp_test/test/test_analyze_vals @@ -6,10 +6,18 @@ run "$bp -I $in -O $tmp" assert_no_diff $tmp $out.1 clean -run "$bp -I $in -k V0 -O $tmp" +run "$bp -I $in -O $tmp -x" assert_no_diff $tmp $out.2 clean -run "$bp -I $in -K V0 -O $tmp" +run "$bp -I $in -k V0 -O $tmp" assert_no_diff $tmp $out.3 clean + +run "$bp -I $in -K V0 -O $tmp" +assert_no_diff $tmp $out.4 +clean + +run "$bp -I $in -o $tmp -x" +assert_no_diff $tmp $out.5 +clean diff --git a/code_ruby/lib/maasha/seq/backtrack.rb b/code_ruby/lib/maasha/seq/backtrack.rb index 7822524..3e9a781 100644 --- a/code_ruby/lib/maasha/seq/backtrack.rb +++ b/code_ruby/lib/maasha/seq/backtrack.rb @@ -146,7 +146,7 @@ module BackTrack options[:start] = result.first + 1 end - return matches.empty? ? nil : matches unless block_given? + return matches unless block_given? end private -- 2.39.2