Sha256: 3bc48eff750d7e332e6f895f39e2fa6fd0978f046c4e6c1237bd75272d31f82c

Contents?: true

Size: 899 Bytes

Versions: 21

Compression:

Stored size: 899 Bytes

Contents

require 'obo' # the gem obo

module Obo
  class Ontology
    DIR = File.expand_path(File.dirname(__FILE__) + '/../../obo')
    attr_accessor :header
    attr_accessor :elements

    def initialize(file_or_io)
      obo = Obo::Parser.new(file_or_io)
      @elements = obo.elements.to_a
      @header = elements.shift
    end
    
    # returns an id to name Hash
    def id_to_name
      @id_to_name ||= build_hash('id', 'name')
    end
    # returns a name to id Hash
    def name_to_id
      @name_to_id ||= build_hash('name', 'id')
    end
    def id_to_element
      @id_to_element ||= build_hash('id', nil)
    end

    protected
    def build_hash(key,val)
      hash = {}
      @elements.each do |el| 
        tv = el.tagvalues
        if val.nil?
          hash[tv[key].first] = el
        else
          hash[tv[key].first] = tv[val].first
        end
      end
      hash
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
mspire-0.7.7 lib/obo/ontology.rb
mspire-0.7.6 lib/obo/ontology.rb
mspire-0.7.5 lib/obo/ontology.rb
mspire-0.7.4 lib/obo/ontology.rb
mspire-0.7.3 lib/obo/ontology.rb
mspire-0.7.2 lib/obo/ontology.rb
mspire-0.6.26 lib/obo/ontology.rb
mspire-0.6.25 lib/obo/ontology.rb
mspire-0.6.24 lib/obo/ontology.rb
mspire-0.6.22 lib/obo/ontology.rb
mspire-0.6.21 lib/obo/ontology.rb
mspire-0.6.20 lib/obo/ontology.rb
mspire-0.6.19 lib/obo/ontology.rb
mspire-0.6.18 lib/obo/ontology.rb
mspire-0.6.12 lib/obo/ontology.rb
mspire-0.6.11 lib/obo/ontology.rb
mspire-0.6.9 lib/obo/ontology.rb
mspire-0.6.7 lib/obo/ontology.rb
mspire-0.6.6 lib/obo/ontology.rb
mspire-0.6.2 lib/obo/ontology.rb