class Bio::Nexus::TreesBlock

DESCRIPTION

Bio::Nexus::TreesBlock represents a trees nexus block.

Example of Trees block:

Begin Trees;

Tree best=(fish,(frog,(snake, mouse)));
Tree other=(snake,(frog,( fish, mouse)));

End;

USAGE

require 'bio/db/nexus'

# Create a new parser:
nexus = Bio::Nexus.new( nexus_data_as_string )

Get trees block(s):   
trees_block = nexus.get_trees_blocks[ 0 ]
# Get first tree named "best" as String:
string_fish = trees_block.get_tree_strings_by_name( "best" )[ 0 ]
# Get first tree named "best" as Bio::Db::Newick object:
tree_fish = trees_block.get_trees_by_name( "best" )[ 0 ]
# Get first tree as Bio::Db::Newick object:
tree_first = trees_block.get_tree( 0 )

Constants

TREE

Public Class Methods

new( name ) click to toggle source
Calls superclass method Bio::Nexus::GenericBlock::new
     # File lib/bio/db/nexus.rb
1459 def initialize( name )
1460   super( name ) 
1461   @trees      = Array.new
1462   @tree_names = Array.new
1463 end

Public Instance Methods

add_tree( tree_as_string ) click to toggle source

Adds a tree to this block.


Arguments:

  • (required) tree_as_string: String

     # File lib/bio/db/nexus.rb
1550 def add_tree( tree_as_string )
1551   @trees.push( tree_as_string )
1552 end
add_tree_name( tree_name ) click to toggle source

Adds a tree name to this block.


Arguments:

  • (required) tree_name: String

     # File lib/bio/db/nexus.rb
1542 def add_tree_name( tree_name )
1543   @tree_names.push( tree_name )
1544 end
get_tree( i ) click to toggle source

Returns tree i (same order as in nexus data) as newick parsed tree object.


Arguments:

  • (required) i: Integer

Returns

Bio::Newick

     # File lib/bio/db/nexus.rb
1514 def get_tree( i )
1515   newick = Bio::Newick.new( @trees[ i ] )
1516   tree = newick.tree
1517   tree
1518 end
get_tree_names() click to toggle source

Returns an array of tree names.


Returns

Array

     # File lib/bio/db/nexus.rb
1486 def get_tree_names
1487   @tree_names 
1488 end
get_tree_strings() click to toggle source

Returns an array of strings describing trees


Returns

Array

     # File lib/bio/db/nexus.rb
1479 def get_tree_strings
1480   @trees  
1481 end
get_tree_strings_by_name( name ) click to toggle source

Returns an array of strings describing trees for which name matches the tree name.


Arguments:

  • (required) name: String

Returns

Array

     # File lib/bio/db/nexus.rb
1496 def get_tree_strings_by_name( name )
1497   found_trees = Array.new
1498   i = 0
1499   @tree_names.each do | n |
1500     if ( n == name )
1501       found_trees.push( @trees[ i ] )
1502     end
1503     i += 1
1504   end
1505   found_trees
1506 end
get_trees_by_name( name ) click to toggle source

Returns an array of newick parsed tree objects for which name matches the tree name.


Arguments:

  • (required) name: String

Returns

Array of Bio::Newick

     # File lib/bio/db/nexus.rb
1526 def get_trees_by_name( name )
1527   found_trees = Array.new
1528   i = 0
1529   @tree_names.each do | n |
1530     if ( n == name )
1531       found_trees.push( get_tree( i ) )
1532     end
1533     i += 1
1534   end
1535   found_trees
1536 end
to_nexus() click to toggle source

Returns a String describing this block as nexus formatted data.


Returns

String

     # File lib/bio/db/nexus.rb
1468 def to_nexus
1469   trees_ary = Array.new
1470   for i in 0 .. @trees.length - 1
1471     trees_ary.push( TREE + " " + @tree_names[ i ] + "=" + @trees[ i ] )
1472   end
1473   Nexus::Util::to_nexus_helper( TREES_BLOCK, trees_ary  )
1474 end