class Bio::DB

Public Class Methods

open(filename, *mode, &block) click to toggle source
    # File lib/bio/db.rb
156 def self.open(filename, *mode, &block)
157   Bio::FlatFile.open(self, filename, *mode, &block)
158 end

Public Instance Methods

entry_id() click to toggle source

Returns an entry identifier as a String. This method must be implemented in every database classes by overriding this method.

    # File lib/bio/db.rb
162 def entry_id
163   raise NotImplementedError
164 end
exists?(tag) click to toggle source

Returns true or false - wether the entry contains the field of the given tag name.

    # File lib/bio/db.rb
173 def exists?(tag)
174   @orig.include?(tag)
175 end
fetch(tag, skip = 0) click to toggle source

Similar to the get method, however, fetch returns the content of the field without its tag and any extra white spaces stripped.

    # File lib/bio/db.rb
184 def fetch(tag, skip = 0)
185   field = @orig[tag].split(/\n/, skip + 1).last.to_s
186   truncate(field.gsub(/^.{0,#{@tagsize}}/,''))
187 end
get(tag) click to toggle source

Returns an intact field of the tag as a String.

    # File lib/bio/db.rb
178 def get(tag)
179   @orig[tag]
180 end
tags() click to toggle source

Returns a list of the top level tags of the entry as an Array of String.

    # File lib/bio/db.rb
167 def tags
168   @orig.keys
169 end

Private Instance Methods

field_fetch(tag, skip = 0) click to toggle source

Returns the content of the field as a String like the fetch method. Furthermore, field_fetch stores the result in the @data hash.

    # File lib/bio/db.rb
214 def field_fetch(tag, skip = 0)
215   unless @data[tag]
216     @data[tag] = fetch(tag, skip)
217   end
218   return @data[tag]
219 end
lines_fetch(tag) click to toggle source

Returns an Array containing each line of the field without a tag. lines_fetch also stores the result in the @data hash.

    # File lib/bio/db.rb
223 def lines_fetch(tag)
224   unless @data[tag]
225     list = []
226     lines = get(tag).split(/\n/)
227     lines.each do |line|
228       data = tag_cut(line)
229       if data[/^\S/]                  # next sub field
230         list << data
231       else                            # continued sub field
232         data.strip!
233         if list.last[/\-$/]           # folded
234           list[-1] += data
235         else
236           list[-1] += " #{data}"     # rest of list
237         end
238       end
239     end
240     @data[tag] = list
241   end
242   @data[tag]
243 end
tag_cut(str) click to toggle source

Returns a String of the field without a tag name.

    # File lib/bio/db.rb
206 def tag_cut(str)
207   str ||= ""
208   str[0,@tagsize] = ''
209   return str
210 end
tag_get(str) click to toggle source

Returns a tag name of the field as a String.

    # File lib/bio/db.rb
200 def tag_get(str)
201   str ||= ""
202   return str[0,@tagsize].strip
203 end
truncate(str) click to toggle source

Returns a String with successive white spaces are replaced by one space and stripeed.

    # File lib/bio/db.rb
194 def truncate(str)
195   str ||= ""
196   return str.gsub(/\s+/, ' ').strip
197 end