Class: BioDSL::Count
- Inherits:
-
Object
- Object
- BioDSL::Count
- Defined in:
- lib/BioDSL/commands/count.rb
Overview
Count the number of records in the stream.
count
counts the number of records in the stream and outputs the count as a record who’s count is not included. Using the output
option will output the count in a file as a table with header.
Usage
count([output: <file>[, force: <bool]])
Options
-
output: <file> - Output file.
-
force: <bool> - Force overwrite existing output file.
Examples
To count the number of records in the file ‘test.fq`:
BD.new.read_fastq(input: "test.fq").count(output: "count.txt").dump.run
{:SEQ_NAME=>"ILLUMINA-52179E_0004:2:1:1040:5263#TTAGGC/1",
:SEQ=>"TTCGGCATCGGCGGCGACGTTGGCGGCGGGGCCGGGCGGGTCGANNNCAT",
:SEQ_LEN=>50,
:SCORES=>"GGFBGGEADFAFFDDD,-5AC5?>C:)7?#####################"}
{:SEQ_NAME=>"ILLUMINA-52179E_0004:2:1:1041:14486#TTAGGC/1",
:SEQ=>"CATGGCGTATGCCAGACGGCCAGAACGATGGCCGCCGGGCTTCANNNAAG",
:SEQ_LEN=>50,
:SCORES=>"FFFFDBD?EEEEEEEFGGFAGAGEFDF=BFGFFGGDDDD=ABAA######"}
{:SEQ_NAME=>"ILLUMINA-52179E_0004:2:1:1043:19446#TTAGGC/1",
:SEQ=>"CGGTACTGATCGAGTGTCAGGCTGTTGATCGCCGCGGGCGGGGGTNNGAC",
:SEQ_LEN=>50,
:SCORES=>"ECAEBEEEEEFFFFFEFFFFDDEEEGGGGGDEBEECBDAE@#########"}
{:RECORD_TYPE=>"count", :COUNT=>3}
And the count is also saved in the file ‘count.txt`:
#RECORD_TYPE COUNT
count 3
Constant Summary collapse
- STATS =
%i(records_in records_out)
Instance Method Summary collapse
-
#initialize(options) ⇒ Count
constructor
Constructor for the count command.
-
#lmb ⇒ Proc
Return the command lambda for count.
Constructor Details
#initialize(options) ⇒ Count
Constructor for the count command.
78 79 80 81 82 |
# File 'lib/BioDSL/commands/count.rb', line 78 def initialize() @options = end |
Instance Method Details
#lmb ⇒ Proc
Return the command lambda for count.
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/BioDSL/commands/count.rb', line 87 def lmb lambda do |input, output, status| status_init(status, STATS) process_input(input, output) new_record = { RECORD_TYPE: 'count', COUNT: @status[:records_in] } output << new_record @status[:records_out] += 1 write_output if @options[:output] end end |