Class: Bio::NeXML::Edge

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

Overview

Edge connect two nodes of a tree or a network. An edge should have a unique id. It should have a ‘source’ and a ‘target’ node and optionally a ‘length’ may be assigned to it.

Direct Known Subclasses

FloatEdge, IntEdge, RootEdge

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 = {}) ⇒ Edge

Create a new edge.

edge = Bio::NeXML::Edge.new( 'edge1' )
edge = Bio::NeXML::Edge.new( 'edge1', :source => node1, :target => node2 )
edge = Bio::NeXML::Edge.new( 'edge1', :source => node1, :target => node2, :length => 1 )


84
85
86
87
88
89
# File 'lib/bio/db/nexml/trees.rb', line 84

def initialize( id, options = {} )
  super( length )
  @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.



66
67
68
# File 'lib/bio/db/nexml/trees.rb', line 66

def id
  @id
end

#labelObject

A human readable description.



75
76
77
# File 'lib/bio/db/nexml/trees.rb', line 75

def label
  @label
end

#sourceObject

Source of the edge.



69
70
71
# File 'lib/bio/db/nexml/trees.rb', line 69

def source
  @source
end

#targetObject

Target of the edge.



72
73
74
# File 'lib/bio/db/nexml/trees.rb', line 72

def target
  @target
end

Instance Method Details

#lengthObject

Return the length of an edge.



92
93
94
# File 'lib/bio/db/nexml/trees.rb', line 92

def length
  distance
end

#length=(length) ⇒ Object

Set the length of an edge.



97
98
99
# File 'lib/bio/db/nexml/trees.rb', line 97

def length=( length )
  self.distance = length
end

#to_xmlObject



61
62
63
# File 'lib/bio/db/nexml/trees.rb', line 61

def to_xml
  @@writer.create_node( "edge", @@writer.attributes( self, :id, :source, :target, :length, :label ) )
end