Class: BioDSL::CountValues
- Inherits:
-
Object
- Object
- BioDSL::CountValues
- Defined in:
- lib/BioDSL/commands/count_values.rb
Overview
Count the number of times values of given keys exists in stream.
count_values
count the values for a given comma seperated list of keys.
Usage
count_values(<keys: <list>)
Options
-
keys: <list> - Keys whos values to count.
Examples
Consider the following two column table in the file ‘test.tab`:
Human H1
Human H2
Human H3
Dog D1
Dog D2
Mouse M1
To count the values of both columns we first read the table with read_table
and then pass the result to count_values
:
BD.new.
read_table(input: "test.tab").
count_values(keys: [:V0, :V1]).
dump.
run
{:V0=>"Human", :V1=>"H1", :V0_COUNT=>3, :V1_COUNT=>1}
{:V0=>"Human", :V1=>"H2", :V0_COUNT=>3, :V1_COUNT=>1}
{:V0=>"Human", :V1=>"H3", :V0_COUNT=>3, :V1_COUNT=>1}
{:V0=>"Dog", :V1=>"D1", :V0_COUNT=>2, :V1_COUNT=>1}
{:V0=>"Dog", :V1=>"D2", :V0_COUNT=>2, :V1_COUNT=>1}
{:V0=>"Mouse", :V1=>"M1", :V0_COUNT=>1, :V1_COUNT=>1}
Constant Summary collapse
- STATS =
%i(records_in records_out)
Instance Method Summary collapse
-
#initialize(options) ⇒ CountValues
constructor
Constructor for CountValues.
-
#lmb ⇒ Proc
Return the command lambda for the count_values command.
Constructor Details
#initialize(options) ⇒ CountValues
Constructor for CountValues.
76 77 78 79 80 81 82 83 |
# File 'lib/BioDSL/commands/count_values.rb', line 76 def initialize() @options = @keys = @options[:keys].map(&:to_sym) @count_hash = Hash.new { |h, k| h[k] = Hash.new(0) } end |
Instance Method Details
#lmb ⇒ Proc
Return the command lambda for the count_values command.
88 89 90 91 92 93 94 95 96 97 |
# File 'lib/BioDSL/commands/count_values.rb', line 88 def lmb lambda do |input, output, status| status_init(status, STATS) TmpDir.create('count_values') do |tmp_file, _| process_input(input, tmp_file) process_output(output, tmp_file) end end end |