Class: FastaFile

Inherits:
File
  • Object
show all
Defined in:
lib/parse_fasta/fasta_file.rb

Overview

Provides simple interface for parsing fasta format files.

Instance Method Summary collapse

Instance Method Details

#each_record {|header, sequence| ... } ⇒ Object

Analagous to File#each_line, #each_record is used to go through a fasta file record by record.

Examples:

Parsing a fasta file

FastaFile.open('reads.fna', 'r').each_record do |header, sequence|
  puts [header, sequence.gc].join("\t")
end

Yields:

  • The header and sequence for each record in the fasta file to the block

Yield Parameters:

  • header (String) —

    The header of the fasta record without the leading '>'

  • sequence (Sequence) —

    The sequence of the fasta record



35
36
37
38
39
40
# File 'lib/parse_fasta/fasta_file.rb', line 35

def each_record
  self.each("\n>") do |line|
    header, sequence = parse_line(line)
    yield(header.strip, Sequence.new(sequence))
  end
end