Class: FastaParser
- Inherits:
-
Object
- Object
- FastaParser
- Defined in:
- lib/dna/parsers/fasta.rb
Instance Method Summary collapse
- #each {|Fasta.new(:name => header, :sequence => sequence)| ... } ⇒ Object
-
#initialize(handle) ⇒ FastaParser
constructor
A new instance of FastaParser.
Constructor Details
#initialize(handle) ⇒ FastaParser
Returns a new instance of FastaParser.
3 4 5 |
# File 'lib/dna/parsers/fasta.rb', line 3 def initialize(handle) @handle = handle end |
Instance Method Details
#each {|Fasta.new(:name => header, :sequence => sequence)| ... } ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/dna/parsers/fasta.rb', line 7 def each sequence, header = nil, nil @handle.each do |line| line.strip! next if line.strip.empty? # skip blank lines if line[0].chr == '>' yield Fasta.new(:name => header, :sequence => sequence) if sequence sequence = '' header = line[1..-1] else sequence << line.tr(' ','') end end yield Fasta.new(:name => header, :sequence => sequence) end |