Class: Bio::NeXML::Trees

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

Constant Summary

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

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods included from Mapper

#properties

Constructor Details

- (Trees) initialize(id = nil, options = {}, &block)

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

- (Object) id

Returns the value of attribute id



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

def id
  @id
end

- (Object) label

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

- (Object) [](id)

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

- (Object) add_network



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

def add_network; end

- (Object) add_tree



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

def add_tree; end

- (Object) count 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

- (Object) create_network(int = false, options = {})



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

- (Object) create_tree(int = false, options = {})



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

- (Object) delete_network



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

def delete_network; end

- (Object) delete_tree



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

def delete_tree; end

- (Object) each(&block)

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

- (Object) each_network(&block)



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

def each_network( &block ); end

- (Object) each_network_with_id(&block)



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

def each_network_with_id( &block ); end

- (Object) each_tree(&block)



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

def each_tree( &block ); end

- (Object) each_tree_with_id(&block)



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

def each_tree_with_id( &block ); end

- (Object) get_network_by_id



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

def get_network_by_id; end

- (Object) get_tree_by_id



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

def get_tree_by_id; end

- (Boolean) has_network?(tree)

Returns:

  • (Boolean)


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

def has_network?( tree ); end

- (Boolean) has_tree?(tree)

Returns:

  • (Boolean)


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

def has_tree?( tree ); end

- (Boolean) include?(object) 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

- (Object) number_of_networks



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

def number_of_networks; end

- (Object) number_of_trees



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

def number_of_trees; end

- (Object) to_xml



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