class FastaParser

Public Class Methods

new(handle) click to toggle source
# File lib/dna/parsers/fasta.rb, line 3
def initialize(handle)
  @handle = handle
end

Public Instance Methods

each() { |fasta(:name => header, :sequence => sequence)| ... } click to toggle source
# 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