Class: ScbiGo::GoTerm

Inherits:
Object
  • Object
show all
Defined in:
lib/scbi_go/go_term.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#commentObject

Returns the value of attribute comment.



3
4
5
# File 'lib/scbi_go/go_term.rb', line 3

def comment
  @comment
end

#considerObject

Returns the value of attribute consider.



3
4
5
# File 'lib/scbi_go/go_term.rb', line 3

def consider
  @consider
end

#defObject

Returns the value of attribute def.



3
4
5
# File 'lib/scbi_go/go_term.rb', line 3

def def
  @def
end

#idObject

Returns the value of attribute id.



3
4
5
# File 'lib/scbi_go/go_term.rb', line 3

def id
  @id
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/scbi_go/go_term.rb', line 3

def name
  @name
end

#namespaceObject

Returns the value of attribute namespace.



3
4
5
# File 'lib/scbi_go/go_term.rb', line 3

def namespace
  @namespace
end

#subsetObject

Returns the value of attribute subset.



3
4
5
# File 'lib/scbi_go/go_term.rb', line 3

def subset
  @subset
end

#synonymObject

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_topObject

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

#ancestorsObject

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

Returns:

  • (Boolean)


32
33
34
# File 'lib/scbi_go/go_term.rb', line 32

def base_term?
  return @is_a_str.count==0
end

#childrenObject



54
55
56
# File 'lib/scbi_go/go_term.rb', line 54

def children
  @children
end

#descendantsObject

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

#inspectObject



46
47
48
# File 'lib/scbi_go/go_term.rb', line 46

def inspect
	"#{@term_type}:#{@id}, #{@name}, is_a: #{@is_a}"
end

#is_aObject



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

#parentsObject



50
51
52
# File 'lib/scbi_go/go_term.rb', line 50

def parents
  is_a
end

#self_and_ancestorsObject

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_descendantsObject

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