Class: OboParser::OboParser

Inherits:
Object
  • Object
show all
Defined in:
lib/obo_parser.rb

Defined Under Namespace

Classes: Stanza, Tag, Term, Typedef

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeOboParser

Returns a new instance of OboParser.



18
19
20
21
22
# File 'lib/obo_parser.rb', line 18

def initialize 
  @terms = []
  @typedefs = [] 
  true
end

Instance Attribute Details

#termsObject

Returns the value of attribute terms.



16
17
18
# File 'lib/obo_parser.rb', line 16

def terms
  @terms
end

#typedefsObject

Returns the value of attribute typedefs.



16
17
18
# File 'lib/obo_parser.rb', line 16

def typedefs
  @typedefs
end

Instance Method Details

#id_hashHash

Returns a hash of ‘id:012345’ => ‘term label’

Returns:

  • (Hash)

    a hash of => string for the file



37
38
39
# File 'lib/obo_parser.rb', line 37

def id_hash
  @terms.inject({}) {|sum, t| sum.update(t.id.value => t.name.value)}
end

#id_indexHash

Returns a hash of ‘id:012345’ => Term

Returns:

  • (Hash)

    a hash of => Term for the file



44
45
46
# File 'lib/obo_parser.rb', line 44

def id_index 
  @terms.inject({}) {|sum, t| sum.update(t.id.value => t)}
end

#term_hashObject

Warning! This assumes terms are unique, they are NOT required to be so in an OBO file. Ignores hash colisions!!



30
31
32
# File 'lib/obo_parser.rb', line 30

def term_hash # :yields: Hash (String => String) (name => id)
  @terms.inject({}) {|sum, t| sum.update(t.name.value => t.id.value)}
end

#term_stringsObject

:yields: Array of Strings



24
25
26
# File 'lib/obo_parser.rb', line 24

def term_strings # :yields: Array of Strings
  @terms.collect{|t| t.name.value}.sort
end