Class: Bio::NeXML::Node

Inherits:
Tree::Node
  • Object
show all
Includes:
Mapper
Defined in:
lib/bio/db/nexml/trees.rb

Overview

Node represents a node of a Tree or a Network. A node must have a unique id. It may optionally have a human readable ‘label’ and may link to an ‘otu’.

Constant Summary collapse

@@writer =
Bio::NeXML::Writer.new

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Mapper

#properties

Constructor Details

#initialize(id, options = {}) ⇒ Node

Create a new otu. Passing an ‘id’ is a must. While ‘label’ and ‘otu’ may be passed as an optional hash.

node = Bio::NeXML::Node.new( 'node1' )
node = Bio::NeXML::Node.new( 'node1', :label => 'A node' )
node = Bio::NeXML::Node.new( 'node1', :label => 'A node', :otu => otu )


36
37
38
39
40
41
# File 'lib/bio/db/nexml/trees.rb', line 36

def initialize( id, options = {} )
  super( id )
  @id = id
  properties( options ) unless options.empty?
  block.arity < 1 ? instance_eval( &block ) : block.call( self ) if block_given?
end

Instance Attribute Details

#idObject

A file level unique identifier.



17
18
19
# File 'lib/bio/db/nexml/trees.rb', line 17

def id
  @id
end

#labelObject

A human readable description.



23
24
25
# File 'lib/bio/db/nexml/trees.rb', line 23

def label
  @label
end

#rootObject

Stores a boolean value to indicate a root node.



20
21
22
# File 'lib/bio/db/nexml/trees.rb', line 20

def root
  @root
end

Instance Method Details

#otuObject

Return the otu to which the node links to.



44
# File 'lib/bio/db/nexml/trees.rb', line 44

def otu; end

#root?Boolean

Returns true if the node is a root node; false otherwise.

Returns:

  • (Boolean)


50
51
52
# File 'lib/bio/db/nexml/trees.rb', line 50

def root?
  root
end

#to_xmlObject



12
13
14
# File 'lib/bio/db/nexml/trees.rb', line 12

def to_xml
  @@writer.create_node( "node", @@writer.attributes( self, :id, :otu, :root, :label ) )
end