Class: BioDSL::Random

Inherits:
Object
  • Object
show all
Defined in:
lib/BioDSL/commands/random.rb

Overview

Pick number of rand om records from the stream.

random can be used to pick a random number of records from the stream. Note that the order of records is preserved.

Using the `pair: true` option allows random picking of interleaved paired-end sequence records.

Usage

random(<number: <uint>[, pairs: <bool>])

Options

  • number: <uint> - Number of records to pick.

  • pairs: <bool> - Preserve interleaved pair order.

Examples

To pick some random records from the stream do:

BD.new.
read_fasta(input: "in.fna").
random(number: 10_000).
write_fasta(output: "out.fna").
run

Constant Summary

STATS =
%i(records_in records_out)

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Random

Constructor for Randowm.

Parameters:

  • options (Hash)

    Options hash.

Options Hash (options):

  • :number (Fixnum)
  • :pairs (Boolean)


66
67
68
69
70
71
# File 'lib/BioDSL/commands/random.rb', line 66

def initialize(options)
  @options = options
  @wanted  = nil

  check_options
end

Instance Method Details

#lmbProc

Return command lambda for random.

Returns:

  • (Proc)

    Command lambda.



76
77
78
79
80
81
82
83
84
85
86
# File 'lib/BioDSL/commands/random.rb', line 76

def lmb
  lambda do |input, output, status|
    status_init(status, STATS)

    TmpDir.create('random') do |file, _|
      process_input(input, file)
      decide_wanted
      process_output(output, file)
    end
  end
end