class Bio::GO::Ontology

Bio::GO::Ontology

Container class for ontologies in the DAG Edit format.

Example

c_data = File.open('component.oontology').read
go_c = Bio::GO::Ontology.new(c_data)
p go_c.bfs_shortest_path('0003673','0005632')

Attributes

header_lines[R]

Returns a Hash instance of the header lines in ontology flatfile.

id2id[R]
id2term[R]

Public Class Methods

new(str) click to toggle source

Bio::GO::Ontology.new(str) The DAG Edit format ontology data parser.

Calls superclass method Bio::Pathway::new
   # File lib/bio/db/go.rb
68 def initialize(str)
69   @id2term      = {}
70   @header_lines = {}
71   @id2id        = {}
72   adj_list = dag_edit_format_parser(str)
73   super(adj_list)
74 end
parse_goids(line) click to toggle source

Bio::GO::Ontology.parse_ogids(line)

Parsing GOID line in the DAGEdit format

GO:ID[ ; GO:ID...]
   # File lib/bio/db/go.rb
39 def self.parse_goids(line)
40   goids = []
41   loop {
42     if /^ *[$%<]\S.+?;/ =~ line
43       endpoint = line.index(';') + 1
44       line = line[endpoint..line.size]
45     elsif /^,* GO:(\d{7}),*/ =~ line
46       goids << $1.clone
47       endpoint = line.index(goids.last) + goids.last.size
48       line = line[endpoint..line.size]
49     else
50       break
51     end
52   }
53   return goids
54 end

Public Instance Methods

goid2term(goid) click to toggle source

Returns a GO_Term correspondig with the given GO_ID.

   # File lib/bio/db/go.rb
78 def goid2term(goid)
79   term = id2term[goid]
80   term = id2term[id2id[goid]] if term == nil
81   return term
82 end

Private Instance Methods

dag_edit_format_parser(str) click to toggle source

constructing adjaency list for the given ontology

    # File lib/bio/db/go.rb
 87 def dag_edit_format_parser(str)
 88   stack    = []
 89   adj_list = []
 90   
 91   str.each_line {|line|
 92     if /^!(.+?):\s+(\S.+)$/ =~ line  # Parsing head lines
 93       tag   = $1
 94       value = $2
 95       tag.gsub!(/-/,'_')
 96       next if tag == 'type'
 97       instance_eval("@header_lines['#{tag}'] = '#{value}'")
 98       next
 99     end
100     
101     case line
102     when /^( *)([$<%])(.+?) ; GO:(\d{7})(\n*)/ # GO Term ; GO:ID
103       depth = $1.length.to_i
104       rel   = $2
105       term  = $3
106       goid1 = $4
107       en    = $5
108       goids = parse_goids(line)   # GO:ID[ ; GO:ID...]
109       parse_synonyms(line)  # synonym:Term[ ; synonym:Term...]
110       stack[depth]   = goids.first
111       @id2term[goid1] = term
112       
113       next if depth == 0
114 
115       goids.each {|goid|
116         @id2term[goid] = term
117         @id2id[goid]   = goids.first
118         adj_list << Bio::Relation.new(stack[depth - 1], goid, rel)
119       }
120         
121       if en == ""
122         loop {
123           case line
124           when /^\n$/
125             break
126           when /^ *([<%]) (.+?) ; GO:(\d{7})/ # <%GO Term ; GO:ID
127             rel1  = $1
128             term1 = $2
129             goid1 = $3
130             parse_goids(line)
131             parse_synonyms(line)
132             
133             @id2term[goid1] = term1
134             goids.each {|goid|
135               adj_list << Bio::Relation.new(goid1, goid, rel1)
136             }
137           else
138             break
139           end
140         }
141       end
142     end
143   }
144   return adj_list
145 end
parse_goids(line) click to toggle source

Returns an ary of GO IDs by parsing an entry line in the DAG Edit format.

    # File lib/bio/db/go.rb
150 def parse_goids(line)
151   Ontology.parse_goids(line)
152 end
parse_synonyms(line) click to toggle source

Bio::GO::Ontology#parse_synonyms(line)

    # File lib/bio/db/go.rb
155 def parse_synonyms(line)
156   synonyms = []
157   loop {
158     if / ; synonym:(\S.+?) *[;<%\n]/ =~ line
159       synonyms << $1.clone
160       endpoint = line.index(synonyms.last) + synonyms.last.size
161       line = line[endpoint..line.size]
162     else
163       break
164     end
165   }
166   return synonyms
167 end