Class: Bio::NeXML::Trees
- Inherits:
-
Object
- Object
- Bio::NeXML::Trees
- Includes:
- Mapper
- Defined in:
- lib/bio/db/nexml/trees.rb
Constant Summary
- @@writer =
Bio::NeXML::Writer.new
Instance Attribute Summary (collapse)
-
- (Object) id
Returns the value of attribute id.
-
- (Object) label
Returns the value of attribute label.
Instance Method Summary (collapse)
-
- (Object) <<(object)
Add a tree or a network to self.
-
- (Object) [](id)
Fetch a tree or a network by id.
- - (Object) add_network
- - (Object) add_tree
-
- (Object) count
(also: #length)
Returns total number of trees and networks.
- - (Object) create_network(int = false, options = {})
- - (Object) create_tree(int = false, options = {})
- - (Object) delete_network
- - (Object) delete_tree
-
- (Object) each(&block)
Iterate over each element.
- - (Object) each_network(&block)
- - (Object) each_network_with_id(&block)
- - (Object) each_tree(&block)
- - (Object) each_tree_with_id(&block)
- - (Object) get_network_by_id
- - (Object) get_tree_by_id
- - (Boolean) has_network?(tree)
- - (Boolean) has_tree?(tree)
- - (Boolean) include?(object) (also: #has?)
-
- (Trees) initialize(id = nil, options = {}, &block)
constructor
Create a trees object.
- - (Object) number_of_networks
- - (Object) number_of_trees
- - (Object) to_xml
Methods included from Mapper
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, = {}, &block ) @id = id properties( ) unless .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, = {} ) type = int ? Bio::NeXML::IntNetwork : Bio::NeXML::FloatNetwork network = type.new( Bio::NeXML.generate_id( type ), ) 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, = {} ) type = int ? Bio::NeXML::IntTree : Bio::NeXML::FloatTree tree = type.new( Bio::NeXML.generate_id( type ), ) 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)
623 |
# File 'lib/bio/db/nexml/trees.rb', line 623 def has_network?( tree ); end |
- (Boolean) has_tree?(tree)
620 |
# File 'lib/bio/db/nexml/trees.rb', line 620 def has_tree?( tree ); end |
- (Boolean) include?(object) Also known as: has?
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 |