Class: Dna
Overview
Dna
Instance Attribute Summary collapse
-
#format ⇒ Object
readonly
Returns the value of attribute format.
Instance Method Summary collapse
- #detect_format ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(handle) ⇒ Dna
constructor
A new instance of Dna.
Constructor Details
#initialize(handle) ⇒ Dna
Returns a new instance of Dna.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/dna.rb', line 11 def initialize(handle) @handle = handle @format = detect_format @iterator = case @format when :fasta FastaParser.new @handle when :fastq FastqParser.new @handle when :qseq QSEQParser.new @handle else raise "#{@format} not supported." end end |
Instance Attribute Details
#format ⇒ Object (readonly)
Returns the value of attribute format.
9 10 11 |
# File 'lib/dna.rb', line 9 def format @format end |
Instance Method Details
#detect_format ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/dna.rb', line 27 def detect_format first_line = @handle.first @handle.rewind if @handle.class == File return :unknown if first_line == nil # detect qseq by counting number of tabs. if first_line.split("\t").length == 11 return :qseq elsif first_line[0].chr == '>' return :fasta elsif first_line[0].chr == '@' return :fastq else raise Exception, "cannot detect format of input" end end |
#each(&block) ⇒ Object
45 46 47 |
# File 'lib/dna.rb', line 45 def each &block @iterator.each(&block) end |