Module: GO

Defined in:
lib/rbbt/sources/go.rb

Overview

This module holds helper methods to deal with the Gene Ontology files. Right now all it does is provide a translation form id to the actual names.

Constant Summary collapse

MULTIPLE_VALUE_FIELDS =
%w(is_a)
TSV_GENE_ONTOLOGY =
File.join(Persist.cachedir, 'gene_ontology')

Class Method Summary collapse

Class Method Details

.gotermsObject



47
48
49
# File 'lib/rbbt/sources/go.rb', line 47

def self.goterms
  info.keys
end

.id2ancestors(id) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/rbbt/sources/go.rb', line 60

def self.id2ancestors(id)
  if id.kind_of? Array
    info.values_at(*id).
      select{|i| ! i['is_a'].nil?}.
      collect{|i| i['is_a'].collect{|id| 
      id.match(/(GO:\d+)/)[1] if id.match(/(GO:\d+)/)
    }.compact
    }
  else
    return [] if id.nil? or info[id].nil? or info[id]['is_a'].nil?
    info[id]['is_a'].
      collect{|id| 
      id.match(/(GO:\d+)/)[1] if id.match(/(GO:\d+)/)
    }.compact
  end
end

.id2name(id) ⇒ Object



51
52
53
54
55
56
57
58
# File 'lib/rbbt/sources/go.rb', line 51

def self.id2name(id)
  if id.kind_of? Array
    info.values_at(*id).collect{|i| i['name'] if i}
  else
    return nil if info[id].nil?
    info[id]['name']
  end
end

.id2namespace(id) ⇒ Object



77
78
79
80
81
82
83
84
85
# File 'lib/rbbt/sources/go.rb', line 77

def self.id2namespace(id)
  self.init unless info
  if id.kind_of? Array
    info.values_at(*id).collect{|i| i['namespace'] if i}
  else
    return nil if info[id].nil?
    info[id]['namespace']
  end
end

.infoObject



43
44
45
# File 'lib/rbbt/sources/go.rb', line 43

def self.info
  @@info ||= self.init
end

.initObject

This method needs to be called before any translations can be made, it is called automatically the first time the id2name method is called. It loads the gene_ontology.obo file and extracts all the fields, although right now, only the name field is used.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rbbt/sources/go.rb', line 19

def self.init
  Persist.persist_tsv(nil, 'gene_ontology', {}, :persist => true) do |info|
    info.serializer = :marshal if info.respond_to? :serializer
    Rbbt.share.databases.GO.gene_ontology.read.split(/\[Term\]/).each{|term| 
      term_info = {}

      term.split(/\n/). select{|l| l =~ /:/}.each{|l| 
        key, value = l.chomp.match(/(.*?):(.*)/).values_at(1,2)
        if MULTIPLE_VALUE_FIELDS.include? key.strip
          term_info[key.strip] ||= []
          term_info[key.strip] << value.strip
        else
          term_info[key.strip] = value.strip
        end
      }

      next if term_info["id"].nil?
      info[term_info["id"]] = term_info
    }

    info
  end.tap{|o| o.unnamed = true}
end