Class: Unipept::BatchIterator
Instance Attribute Summary collapse
-
#batch_size ⇒ Object
readonly
Returns the value of attribute batch_size.
Instance Method Summary collapse
- #csv_taxa2tree?(line) ⇒ Boolean
-
#fasta?(line) ⇒ Boolean
Checks if the geven line is a fasta header.
-
#initialize(batch_size) ⇒ BatchIterator
constructor
A new instance of BatchIterator.
-
#iterate(lines, &block) ⇒ Object
Splits the input lines into slices, based on the batch_size of the current command.
Constructor Details
#initialize(batch_size) ⇒ BatchIterator
7 8 9 |
# File 'lib/batch_iterator.rb', line 7 def initialize(batch_size) @batch_size = batch_size end |
Instance Attribute Details
#batch_size ⇒ Object (readonly)
Returns the value of attribute batch_size.
5 6 7 |
# File 'lib/batch_iterator.rb', line 5 def batch_size @batch_size end |
Instance Method Details
#csv_taxa2tree?(line) ⇒ Boolean
39 40 41 |
# File 'lib/batch_iterator.rb', line 39 def csv_taxa2tree?(line) line.include? 'taxon_id' end |
#fasta?(line) ⇒ Boolean
Checks if the geven line is a fasta header.
35 36 37 |
# File 'lib/batch_iterator.rb', line 35 def fasta?(line) line.start_with? '>' end |
#iterate(lines, &block) ⇒ Object
Splits the input lines into slices, based on the batch_size of the current command. Executes the given block for each of the batches.
Supports both normal input and input in the fasta format.
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/batch_iterator.rb', line 19 def iterate(lines, &block) first_line = lines.next rescue return if fasta? first_line fasta_iterator(first_line, lines, &block) elsif csv_taxa2tree? first_line csv_taxa_iterator(first_line, lines, &block) else normal_iterator(first_line, lines, &block) end end |