class Bio::NeXML::Trees

Attributes

id[RW]
label[RW]

Public Class Methods

new( id = nil, options = {}, &block ) click to toggle source

Create a trees object.

# File lib/bio/db/nexml/trees.rb, line 578
def initialize( id = nil, options = {}, &block )
  @id = id
  properties( options ) unless options.empty?
  block.arity < 1 ? instance_eval( &block ) : block.call( self ) if block_given?
end

Public Instance Methods

<<( object ) click to toggle source

Add a tree or a network to self.

# File lib/bio/db/nexml/trees.rb, line 591
def <<( object )
  case object
  when Network
    add_network( object )
  when Tree
    add_tree( object )
  end
  self
end
[]( id ) click to toggle source

Fetch a tree or a network by id.

# File lib/bio/db/nexml/trees.rb, line 614
def []( id )
  get_tree_by_id( id ) ||
    get_network_by_id( id )
end
add_network() click to toggle source

Add a networ to self.

# File lib/bio/db/nexml/trees.rb, line 588
def add_network; end
add_tree() click to toggle source

Add a tree to self.

# File lib/bio/db/nexml/trees.rb, line 585
def add_tree; end
count() click to toggle source

Returns total number of trees and networks.

# File lib/bio/db/nexml/trees.rb, line 638
def count
  number_of_trees + number_of_networks
end
Also aliased as: length
create_network( int = false, options = {} ) click to toggle source
# File lib/bio/db/nexml/trees.rb, line 558
def create_network( int = false, options = {} )
  type = int ? Bio::NeXML::IntNetwork : Bio::NeXML::FloatNetwork
  network = type.new( Bio::NeXML.generate_id( type ), options )
  self << network
  network
end
create_tree( int = false, options = {} ) click to toggle source
# File lib/bio/db/nexml/trees.rb, line 551
def create_tree( int = false, options = {} )
  type = int ? Bio::NeXML::IntTree : Bio::NeXML::FloatTree
  tree = type.new( Bio::NeXML.generate_id( type ), options )
  self << tree
  tree
end
delete_network() click to toggle source

Delete a network from self.

# File lib/bio/db/nexml/trees.rb, line 605
def delete_network; end
delete_tree() click to toggle source

Delete a tree from self.

# File lib/bio/db/nexml/trees.rb, line 602
def delete_tree; end
each( &block ) click to toggle source

Iterate over each element. Returns an Enumerator if no block is given.

# File lib/bio/db/nexml/trees.rb, line 658
def each( &block )
  @trees.merge( @networks ).each( &block )
end
each_network( &block ) click to toggle source

Iterate over each network. Returns an Enumerator if no block is given.

# File lib/bio/db/nexml/trees.rb, line 651
def each_network( &block ); end
each_network_with_id( &block ) click to toggle source

Iterate over each network passing the id and the tree itself to the block. Returns an Enumerator if no block is given.

# File lib/bio/db/nexml/trees.rb, line 655
def each_network_with_id( &block ); end
each_tree( &block ) click to toggle source

Iterate over each tree. Returns an Enumerator if no block is given.

# File lib/bio/db/nexml/trees.rb, line 644
def each_tree( &block ); end
each_tree_with_id( &block ) click to toggle source

Iterate over each tree passing the id and the tree itself to the block. Returns an Enumerator if no block is given.

# File lib/bio/db/nexml/trees.rb, line 648
def each_tree_with_id( &block ); end
get_network_by_id() click to toggle source

Fetch a network by id.

# File lib/bio/db/nexml/trees.rb, line 611
def get_network_by_id; end
get_tree_by_id() click to toggle source

Fetch a tree by id.

# File lib/bio/db/nexml/trees.rb, line 608
def get_tree_by_id; end
has?( object )
Alias for: include?
has_network?( tree ) click to toggle source

Returns true if the given network is containes in self; false otherwise.

# File lib/bio/db/nexml/trees.rb, line 623
def has_network?( tree ); end
has_tree?( tree ) click to toggle source

Returns true if tree is containes in self.

# File lib/bio/db/nexml/trees.rb, line 620
def has_tree?( tree ); end
include?( object ) click to toggle source
# File lib/bio/db/nexml/trees.rb, line 625
def include?( object )
  has_tree?( object ) ||
    has_network?( object )
end
Also aliased as: has?
length()
Alias for: count
number_of_networks() click to toggle source

Returns the number of networks contained in self.

# File lib/bio/db/nexml/trees.rb, line 635
def number_of_networks; end
number_of_trees() click to toggle source

Returns the number of trees contained in self.

# File lib/bio/db/nexml/trees.rb, line 632
def number_of_trees; end
to_xml() click to toggle source
# File lib/bio/db/nexml/trees.rb, line 537
def to_xml
  node = @@writer.create_node( "trees", @@writer.attributes( self, :id, :label, :otus ) )

  self.each_tree do |tree|
    node << tree.to_xml
  end

  self.each_network do |network|
    node << network.to_xml
  end

  node
end