Class: Bio::GFF::FastaReader
- Inherits:
-
Object
- Object
- Bio::GFF::FastaReader
- Defined in:
- lib/bio/db/gff/file/gfffasta.rb
Overview
Read FASTA records from file and store seek positions, which are used to retrieve the records. Note, this implementation merely retains records in memory (FIXME)
Instance Method Summary collapse
- #[](index) ⇒ Object
- #each ⇒ Object
-
#initialize(fh, io_seek = nil) ⇒ FastaReader
constructor
A new instance of FastaReader.
- #parse ⇒ Object
Constructor Details
#initialize(fh, io_seek = nil) ⇒ FastaReader
Returns a new instance of FastaReader.
18 19 20 21 22 |
# File 'lib/bio/db/gff/file/gfffasta.rb', line 18 def initialize fh, io_seek=nil @fh = fh @h = {} parse end |
Instance Method Details
#[](index) ⇒ Object
42 43 44 |
# File 'lib/bio/db/gff/file/gfffasta.rb', line 42 def [] index @h[index] end |
#each ⇒ Object
46 47 48 49 50 |
# File 'lib/bio/db/gff/file/gfffasta.rb', line 46 def each @h.each do | k,v | yield k, v end end |
#parse ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/bio/db/gff/file/gfffasta.rb', line 24 def parse # read FASTA records header = nil seqs = [] @fh.each_line do | line | line = line.strip next if line =~ /^#/ if line =~ /^>/ # FASTA record header add(header,seqs) header = line seqs = [] else seqs << line.gsub(/\s+/,'') end end add(header,seqs) end |