Method: Bio::Pathway#subgraph

Defined in:
lib/bio/pathway.rb

#subgraph(list = nil) ⇒ Object

Select labeled nodes and generate subgraph

This method select some nodes and returns new Bio::Pathway object consists of selected nodes only. If the list of the nodes (as Array) is assigned as the argument, use the list to select the nodes from the graph. If no argument is assigned, internal property of the graph @label is used to select the nodes.

hash = { 'a' => 'secret', 'b' => 'important', 'c' => 'important' }
g.label = hash
g.subgraph
list = [ 'a', 'b', 'c' ]
 g.subgraph(list)


278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
# File 'lib/bio/pathway.rb', line 278

def subgraph(list = nil)
  if list
    @label.clear
    list.each do |node|
      @label[node] = true
    end
  end
  sub_graph = Pathway.new([], @undirected)
  @graph.each do |from, hash|
    next unless @label[from]
    hash.each do |to, relation|
      next unless @label[to]
      sub_graph.append(Relation.new(from, to, relation))
    end
  end
  return sub_graph
end