class ScbiGo::GoTerm
Attributes
comment[RW]
consider[RW]
def[RW]
id[RW]
name[RW]
namespace[RW]
subset[RW]
synonym[RW]
Public Class Methods
new(go_term, gene_ontology)
click to toggle source
# File lib/scbi_go/go_term.rb, line 5 def initialize(go_term, gene_ontology) @term_type=go_term.name @gene_ontology=gene_ontology @id=go_term['id'] @name=go_term['name'] @def=go_term['def'] @namespace=go_term['namespace'] #to save is_a relation as strings, cannot save objects directly because they may be not loaded yet. @is_a_str=[] # tmp var to save a cache with is_a relation as objects @is_a=nil if go_term['is_a'].is_a?(Array) @is_a_str=go_term['is_a'] elsif !go_term['is_a'].nil? @is_a_str=[go_term['is_a']] end @subset=go_term['subset'] @comment=go_term['comment'] @consider=go_term['consider'] @synonym=go_term['synonym'] @children = [] end
Public Instance Methods
add_child(child)
click to toggle source
add another node ad child
# File lib/scbi_go/go_term.rb, line 42 def add_child(child) @children << child end
all_branches_to_top()
click to toggle source
recursive function to get all branches from myself to top of the ontology
# File lib/scbi_go/go_term.rb, line 86 def all_branches_to_top res=[] if parents.count == 0 res = [[self]] else parents.each do |parent| parent_b = parent.all_branches_to_top parent_b.each do |pb| res << pb.unshift(self) end end end return res end
ancestors()
click to toggle source
get list of ancestors for a node
# File lib/scbi_go/go_term.rb, line 73 def ancestors res=parents parents.each {|c| res += c.ancestors} return res.uniq end
base_term?()
click to toggle source
base terms have no parents
# File lib/scbi_go/go_term.rb, line 32 def base_term? return @is_a_str.count==0 end
children()
click to toggle source
# File lib/scbi_go/go_term.rb, line 54 def children @children end
descendants()
click to toggle source
get list of descendants for a node
# File lib/scbi_go/go_term.rb, line 60 def descendants res=children children.each {|c| res += c.descendants} return res.uniq end
inspect()
click to toggle source
# File lib/scbi_go/go_term.rb, line 46 def inspect "#{@term_type}:#{@id}, #{@name}, is_a: #{@is_a}" end
is_a()
click to toggle source
# File lib/scbi_go/go_term.rb, line 36 def is_a convert_is_a_to_terms! if @is_a.nil? @is_a end
parents()
click to toggle source
# File lib/scbi_go/go_term.rb, line 50 def parents is_a end
self_and_ancestors()
click to toggle source
include myself in ancestors
# File lib/scbi_go/go_term.rb, line 80 def self_and_ancestors res = [self] + self.ancestors return res.uniq end
self_and_descendants()
click to toggle source
include myself in descendants
# File lib/scbi_go/go_term.rb, line 67 def self_and_descendants res = [self] + self.descendants return res.uniq end
Private Instance Methods
convert_is_a_to_terms!()
click to toggle source
cache is_a
terms
# File lib/scbi_go/go_term.rb, line 107 def convert_is_a_to_terms! @is_a = @is_a_str.map { |ia| @gene_ontology.find_go(ia) } end