Class: RbbtGraph

Inherits:
Object
  • Object
show all
Defined in:
lib/rbbt/rest/graph.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRbbtGraph

Returns a new instance of RbbtGraph.



4
5
6
7
8
9
# File 'lib/rbbt/rest/graph.rb', line 4

def initialize
  @entities = {}
  @aesthetics = {}
  @associations = {}
  @rules = {}
end

Instance Attribute Details

#aestheticsObject

Returns the value of attribute aesthetics.



2
3
4
# File 'lib/rbbt/rest/graph.rb', line 2

def aesthetics
  @aesthetics
end

#associationsObject

Returns the value of attribute associations.



2
3
4
# File 'lib/rbbt/rest/graph.rb', line 2

def associations
  @associations
end

#entitiesObject

Returns the value of attribute entities.



2
3
4
# File 'lib/rbbt/rest/graph.rb', line 2

def entities
  @entities
end

#knowledge_baseObject

Returns the value of attribute knowledge_base.



2
3
4
# File 'lib/rbbt/rest/graph.rb', line 2

def knowledge_base
  @knowledge_base
end

#rulesObject

Returns the value of attribute rules.



2
3
4
# File 'lib/rbbt/rest/graph.rb', line 2

def rules
  @rules
end

Instance Method Details

#add_aesthetic(elem, info) ⇒ Object



37
38
39
40
# File 'lib/rbbt/rest/graph.rb', line 37

def add_aesthetic(elem, info)
  @aesthetics[elem] ||= []
  @aesthetics[elem] << info
end

#add_associations(associations, type = :edge) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/rbbt/rest/graph.rb', line 11

def add_associations(associations, type = :edge)
  @associations[type] ||= []
  @associations[type].concat associations.collect{|i| i }
  @associations[type].uniq!
  if AssociationItem === associations
    add_entities associations.target, associations.target_entity_type
    add_entities associations.source, associations.source_entity_type
  end
end

#add_entities(entities, type = nil, entity_options = {}) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rbbt/rest/graph.rb', line 21

def add_entities(entities, type = nil, entity_options = {})                                                   
  type = entities.base_entity.to_s if type.nil? and AnnotatedArray === entities
  raise "No type specified and entities are not Annotated, so could not guess" if type.nil? 
  if knowledge_base
    good_entities = knowledge_base.translate(entities, type).compact.uniq
  else
    good_entities = entities
  end
  @namespace ||= entities.organism if entities.respond_to? :organism       
  if @entities[type].nil?
    @entities[type] = good_entities
  else
    @entities[type].concat good_entities
  end
end

#add_rule(elem, info) ⇒ Object



42
43
44
45
# File 'lib/rbbt/rest/graph.rb', line 42

def add_rule(elem, info)
  @rules[elem] ||= []
  @rules[elem] << info
end

#js_modelObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/rbbt/rest/graph.rb', line 48

def js_model
  js_model = {:entities => {}, :associations => {}, :aes_rules => {}, :edge_aes_rules => {}, :rules => {}, :edge_rules => {}}
  @entities.each do |type, codes|                                                                                          
    info = codes.info if codes.respond_to? :info
    info ||= {}
    js_model[:entities][type] = {:codes => codes, :entity_type => type, :info => info}
  end
  @associations.each do |type, codes|
    info = codes.info if codes.respond_to? :info
    info ||= {}
    js_model[:associations][type] = {:codes => codes, :database => type, :info => info}
  end
  @aesthetics.each do |type, info|
    aes_rule_type = (type == :node ? :aes_rules : :edge_aes_rules)
    js_model[aes_rule_type] = info
  end
  @rules.each do |type, info|
    rule_type = (type == :node ? :rules : :edge_rules)
    js_model[rule_type] = info
  end
  js_model
end