class Bio::GFF::GFF3::FileIterator
GFF3::FileIterator
takes a file and yields GFF3
records with their seek position included in the record.
Attributes
fasta_io_seek[R]
fh[RW]
Public Class Methods
new(filename)
click to toggle source
# File lib/bio/db/gff/file/gfffileiterator.rb, line 40 def initialize filename @fh = File.open(filename) end
Public Instance Methods
each_rec() { |fpos, line| ... }
click to toggle source
Iterate over every record in the file, yielding the seekpos and line containing the record
# File lib/bio/db/gff/file/gfffileiterator.rb, line 46 def each_rec @fh.seek(0) fpos = 0 @fh.each_line do | line | line = line.strip if line == "##FASTA" @fasta_io_seek = fpos break end if line.size != 0 and line !~ /^#/ lastpos = @fh.tell yield fpos, line @fh.seek(lastpos) # reset filepos, just in case it changed end fpos = @fh.tell end end
each_sequence() { |id, fastarec| ... }
click to toggle source
Iterate over all contained FASTA sequences, yielding the ID and sequence as a FASTA record. Normally call each_rec
first and you can test for existing FASTA records if fasta_io_seek
!= nil
# File lib/bio/db/gff/file/gfffileiterator.rb, line 67 def each_sequence if @fasta_io_seek == nil # Find the FASTA location first @fh.each_line do | line | break if line.strip == "##FASTA" end else @fh.seek(@fasta_io_seek) end fasta = Bio::GFF::FastaReader.new(@fh) fasta.each do | id, fastarec | yield id, fastarec end end