Class: Nexml::Document::Tree

Inherits:
Nexml::DummyBase show all
Defined in:
lib/nexml/nexml_parser.rb

Overview

need to refact to allow for parent->child nodes

Instance Attribute Summary (collapse)

Attributes inherited from Nexml::DummyBase

#attributes, #text

Instance Method Summary (collapse)

Methods inherited from Nexml::DummyBase

#attribute

Constructor Details

- (Tree) initialize(opts)

Returns a new instance of Tree



257
258
259
260
261
# File 'lib/nexml/nexml_parser.rb', line 257

def initialize(opts)
  super
  @nodes = []
  @edges = []
end

Instance Attribute Details

- (Object) edges

Returns the value of attribute edges



256
257
258
# File 'lib/nexml/nexml_parser.rb', line 256

def edges
  @edges
end

- (Object) nodes

Returns the value of attribute nodes



256
257
258
# File 'lib/nexml/nexml_parser.rb', line 256

def nodes
  @nodes
end

Instance Method Details

- (Object) children_of_node(node)



270
271
272
273
274
275
276
# File 'lib/nexml/nexml_parser.rb', line 270

def children_of_node(node)
  @children = []
  @edges.each do |e|
    @children.push(self.node_by_id(e.attributes['target'])) if (e.attributes['source'] ==  node.attributes['id'])
  end
  @children 
end

- (Object) newick_string(node, string = '')

NOT WORKING - needs refactoring



286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
# File 'lib/nexml/nexml_parser.rb', line 286

def newick_string(node, string = '')
  @str = string
  nodes = self.children_of_node(node)
    nodes.each do |n|
      @str += self.otu_by_id(node.attributes['otu']).attributes['label']           
      self.newick_string(n, @str)
      @str += "," 
    end 

 #    case nodes.size
 #   when 0   
 #     @str += ""
 #   when 1 
 #    @str += ",(" 
 #   else 
 #     @str += ")"    
 #   end        
 
  @str 
end

- (Object) node_by_id(id)

make a big hash store to handle these



279
280
281
282
283
# File 'lib/nexml/nexml_parser.rb', line 279

def node_by_id(id)
  @nodes.each do |n|
    return n if n.attributes['id'] == id 
  end
end

- (Object) root_node

yuck



264
265
266
267
268
# File 'lib/nexml/nexml_parser.rb', line 264

def root_node
  @nodes.each do |n|
    return n if n.attributes['root'] 
  end 
end