Class: FastaFile
- Inherits:
-
File
- Object
- File
- FastaFile
- Defined in:
- lib/parse_fasta/fasta_file.rb
Overview
Provides simple interface for parsing fasta format files. Gzipped files are no problem.
Instance Method Summary collapse
-
#each_record(separate_lines = nil) {|header, sequence| ... } ⇒ Object
Analagous to IO#each_line, #each_record is used to go through a fasta file record by record.
Instance Method Details
#each_record(separate_lines = nil) {|header, sequence| ... } ⇒ Object
Analagous to IO#each_line, #each_record is used to go through a fasta file record by record. It will accept gzipped files as well.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/parse_fasta/fasta_file.rb', line 53 def each_record(separate_lines=nil) begin f = Zlib::GzipReader.open(self) rescue Zlib::GzipFile::Error => e f = self end if separate_lines f.each("\n>") do |line| header, sequence = parse_line_separately(line) yield(header.strip, sequence) end else f.each("\n>") do |line| header, sequence = parse_line(line) yield(header.strip, Sequence.new(sequence)) end end f.close if f.instance_of?(Zlib::GzipReader) return f end |