Class: ScbiGo::GoTerm
- Inherits:
-
Object
- Object
- ScbiGo::GoTerm
- Defined in:
- lib/scbi_go/go_term.rb
Instance Attribute Summary collapse
-
#comment ⇒ Object
Returns the value of attribute comment.
-
#consider ⇒ Object
Returns the value of attribute consider.
-
#def ⇒ Object
Returns the value of attribute def.
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#namespace ⇒ Object
Returns the value of attribute namespace.
-
#subset ⇒ Object
Returns the value of attribute subset.
-
#synonym ⇒ Object
Returns the value of attribute synonym.
Instance Method Summary collapse
-
#add_child(child) ⇒ Object
add another node ad child.
-
#all_branches_to_top ⇒ Object
recursive function to get all branches from myself to top of the ontology.
-
#ancestors ⇒ Object
get list of ancestors for a node.
-
#base_term? ⇒ Boolean
base terms have no parents.
- #children ⇒ Object
-
#descendants ⇒ Object
get list of descendants for a node.
-
#initialize(go_term, gene_ontology) ⇒ GoTerm
constructor
A new instance of GoTerm.
- #inspect ⇒ Object
- #is_a ⇒ Object
- #parents ⇒ Object
-
#self_and_ancestors ⇒ Object
include myself in ancestors.
-
#self_and_descendants ⇒ Object
include myself in descendants.
Constructor Details
#initialize(go_term, gene_ontology) ⇒ GoTerm
Returns a new instance of GoTerm.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# 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 |
Instance Attribute Details
#comment ⇒ Object
Returns the value of attribute comment.
3 4 5 |
# File 'lib/scbi_go/go_term.rb', line 3 def comment @comment end |
#consider ⇒ Object
Returns the value of attribute consider.
3 4 5 |
# File 'lib/scbi_go/go_term.rb', line 3 def consider @consider end |
#def ⇒ Object
Returns the value of attribute def.
3 4 5 |
# File 'lib/scbi_go/go_term.rb', line 3 def def @def end |
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'lib/scbi_go/go_term.rb', line 3 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/scbi_go/go_term.rb', line 3 def name @name end |
#namespace ⇒ Object
Returns the value of attribute namespace.
3 4 5 |
# File 'lib/scbi_go/go_term.rb', line 3 def namespace @namespace end |
#subset ⇒ Object
Returns the value of attribute subset.
3 4 5 |
# File 'lib/scbi_go/go_term.rb', line 3 def subset @subset end |
#synonym ⇒ Object
Returns the value of attribute synonym.
3 4 5 |
# File 'lib/scbi_go/go_term.rb', line 3 def synonym @synonym end |
Instance Method Details
#add_child(child) ⇒ Object
add another node ad child
42 43 44 |
# File 'lib/scbi_go/go_term.rb', line 42 def add_child(child) @children << child end |
#all_branches_to_top ⇒ Object
recursive function to get all branches from myself to top of the ontology
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# 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 ⇒ Object
get list of ancestors for a node
73 74 75 76 77 |
# 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? ⇒ Boolean
base terms have no parents
32 33 34 |
# File 'lib/scbi_go/go_term.rb', line 32 def base_term? return @is_a_str.count==0 end |
#children ⇒ Object
54 55 56 |
# File 'lib/scbi_go/go_term.rb', line 54 def children @children end |
#descendants ⇒ Object
get list of descendants for a node
60 61 62 63 64 |
# File 'lib/scbi_go/go_term.rb', line 60 def descendants res=children children.each {|c| res += c.descendants} return res.uniq end |
#inspect ⇒ Object
46 47 48 |
# File 'lib/scbi_go/go_term.rb', line 46 def inspect "#{@term_type}:#{@id}, #{@name}, is_a: #{@is_a}" end |
#is_a ⇒ Object
36 37 38 39 |
# 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 ⇒ Object
50 51 52 |
# File 'lib/scbi_go/go_term.rb', line 50 def parents is_a end |
#self_and_ancestors ⇒ Object
include myself in ancestors
80 81 82 83 |
# File 'lib/scbi_go/go_term.rb', line 80 def self_and_ancestors res = [self] + self.ancestors return res.uniq end |
#self_and_descendants ⇒ Object
include myself in descendants
67 68 69 70 |
# File 'lib/scbi_go/go_term.rb', line 67 def self_and_descendants res = [self] + self.descendants return res.uniq end |