Class: Bio::NeXML::Trees

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

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 = nil, options = {}, &block) ⇒ Trees

Create a trees object.



578
579
580
581
582
# 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

Instance Attribute Details

#idObject

Returns the value of attribute id.



565
566
567
# File 'lib/bio/db/nexml/trees.rb', line 565

def id
  @id
end

#labelObject

Returns the value of attribute label.



566
567
568
# File 'lib/bio/db/nexml/trees.rb', line 566

def label
  @label
end

Instance Method Details

#<<(object) ⇒ Object

Add a tree or a network to self.



591
592
593
594
595
596
597
598
599
# 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) ⇒ Object

Fetch a tree or a network by id.



614
615
616
617
# File 'lib/bio/db/nexml/trees.rb', line 614

def []( id )
  get_tree_by_id( id ) ||
    get_network_by_id( id )
end

#add_treeObject

Add a tree to self.



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

def add_tree; end

#countObject Also known as: length

Returns total number of trees and networks.



638
639
640
# File 'lib/bio/db/nexml/trees.rb', line 638

def count
  number_of_trees + number_of_networks
end

#create_network(int = false, options = {}) ⇒ Object



558
559
560
561
562
563
# 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 = {}) ⇒ Object



551
552
553
554
555
556
# 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_treeObject

Delete a tree from self.



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

def delete_tree; end

#each(&block) ⇒ Object

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



658
659
660
# File 'lib/bio/db/nexml/trees.rb', line 658

def each( &block )
  @trees.merge( @networks ).each( &block )
end

#each_tree(&block) ⇒ Object

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



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

def each_tree( &block ); end

#has_network?(tree) ⇒ Boolean

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

Returns:

  • (Boolean)


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

def has_network?( tree ); end

#has_tree?(tree) ⇒ Boolean

Returns true if tree is containes in self.

Returns:

  • (Boolean)


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

def has_tree?( tree ); end

#include?(object) ⇒ Boolean Also known as: has?

Returns:

  • (Boolean)


625
626
627
628
# File 'lib/bio/db/nexml/trees.rb', line 625

def include?( object )
  has_tree?( object ) ||
    has_network?( object )
end

#number_of_treesObject

Returns the number of trees contained in self.



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

def number_of_trees; end

#to_xmlObject



537
538
539
540
541
542
543
544
545
546
547
548
549
# 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