Class: Dna
- Inherits:
-
Object
- Object
- Dna
- Includes:
- Enumerable
- Defined in:
- lib/dna/dna.rb,
lib/dna/version.rb
Overview
Dna
Defined Under Namespace
Classes: Version
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, args = {}) ⇒ Dna
constructor
A new instance of Dna.
Constructor Details
#initialize(handle, args = {}) ⇒ Dna
Returns a new instance of Dna.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/dna/dna.rb', line 10 def initialize(handle, args = {}) @handle = handle @format = args[:format] || detect_format @iterator = case @format when :fasta FastaParser.new @handle when :fastq FastqParser.new @handle when :qseq QSEQParser.new @handle else raise IOError, "format '#{@format}' not supported. (or file is empty)" end end |
Instance Attribute Details
#format ⇒ Object (readonly)
Returns the value of attribute format.
8 9 10 |
# File 'lib/dna/dna.rb', line 8 def format @format end |
Instance Method Details
#detect_format ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/dna/dna.rb', line 26 def detect_format # is gzipped? unless @handle.class == Array # for tests mostly... begin @handle = Zlib::GzipReader.new(@handle) rescue @handle.rewind end end 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
54 55 56 |
# File 'lib/dna/dna.rb', line 54 def each &block @iterator.each(&block) end |