Class: Bio::GO::Ontology

Inherits:
Pathway show all
Defined in:
lib/bio/db/go.rb

Overview

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')

Instance Attribute Summary collapse

Attributes inherited from Pathway

#graph, #index, #label, #relations

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Pathway

#append, #bellman_ford, #bfs_shortest_path, #breadth_first_search, #clear_relations!, #clique, #cliquishness, #common_subgraph, #delete, #depth_first_search, #dfs_topological_sort, #dijkstra, #directed, #directed?, #dump_list, #dump_matrix, #edges, #floyd_warshall, #kruskal, #nodes, #small_world, #subgraph, #to_list, #to_matrix, #to_relations, #undirected, #undirected?

Constructor Details

#initialize(str) ⇒ Ontology

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



69
70
71
72
73
74
75
# File 'lib/bio/db/go.rb', line 69

def initialize(str)
  @id2term      = {}
  @header_lines = {}
  @id2id        = {}
  adj_list = dag_edit_format_parser(str)
  super(adj_list)
end

Instance Attribute Details

#header_linesObject (readonly)

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



58
59
60
# File 'lib/bio/db/go.rb', line 58

def header_lines
  @header_lines
end

#id2idObject (readonly)

Returns the value of attribute id2id.



64
65
66
# File 'lib/bio/db/go.rb', line 64

def id2id
  @id2id
end

#id2termObject (readonly)

Returns the value of attribute id2term.



61
62
63
# File 'lib/bio/db/go.rb', line 61

def id2term
  @id2term
end

Class Method Details

.parse_goids(line) ⇒ Object

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

Parsing GOID line in the DAGEdit format

GO:ID[ ; GO:ID...]


40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/bio/db/go.rb', line 40

def self.parse_goids(line)
  goids = []
  loop {
    if /^ *[$%<]\S.+?;/ =~ line
      endpoint = line.index(';') + 1
      line = line[endpoint..line.size]
    elsif /^,* GO:(\d{7}),*/ =~ line
      goids << $1.clone
      endpoint = line.index(goids.last) + goids.last.size
      line = line[endpoint..line.size]
    else
      break
    end
  }
  return goids
end

Instance Method Details

#goid2term(goid) ⇒ Object

Returns a GO_Term correspondig with the given GO_ID.



79
80
81
82
83
# File 'lib/bio/db/go.rb', line 79

def goid2term(goid)
  term = id2term[goid]
  term = id2term[id2id[goid]] if term == nil
  return term
end