Class: BioDSL::Count

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(options) ⇒ Count

Constructor for the count command.

Parameters:

  • options (Hash)

    Options hash.

Options Hash (options):

  • :output (String)

    Path to output file.

  • :force (Boolean)

    Force overwrite of output file.



78
79
80
81
82
# File 'lib/BioDSL/commands/count.rb', line 78

def initialize(options)
  @options = options

  check_options
end

Instance Method Details

#lmbProc

Return the command lambda for count.

Returns:

  • (Proc)

    Command lambda.



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