class Bio::NCBIDB

Stores a NCBI style (GenBank, KEGG etc.) entry.

Public Class Methods

new(entry, tagsize) click to toggle source

The entire entry is passed as a String. The length of the tag field is passed as an Integer. Parses the entry roughly by the entry2hash method and returns a database object.

    # File lib/bio/db.rb
256 def initialize(entry, tagsize)
257   @tagsize = tagsize
258   @orig = entry2hash(entry.strip)     # Hash of the original entry
259   @data = {}                          # Hash of the parsed entry
260 end

Private Instance Methods

entry2hash(entry) click to toggle source

Returns the contents of the entry as a Hash with the top level tags as its keys.

    # File lib/bio/db.rb
278 def entry2hash(entry)
279   hash = Hash.new('')
280 
281   fields = toptag2array(entry)
282 
283   fields.each do |field|
284     tag = tag_get(field)
285     hash[tag] += field
286   end
287   return hash
288 end
subtag2array(str) click to toggle source

Splits a field into an Array of Strings at the level of sub tags.

    # File lib/bio/db.rb
271 def subtag2array(str)
272   sep = "\001"
273   str.gsub(/\n(\s{1,#{@tagsize-1}}\S)/, "\n#{sep}\\1").split(sep)
274 end
toptag2array(str) click to toggle source

Splits an entry into an Array of Strings at the level of top tags.

    # File lib/bio/db.rb
265 def toptag2array(str)
266   sep = "\001"
267   str.gsub(/\n([A-Za-z\/\*])/, "\n#{sep}\\1").split(sep)
268 end