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, line 1459
def initialize( name )
  super( name ) 
  @trees      = Array.new
  @tree_names = Array.new
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, line 1550
def add_tree( tree_as_string )
  @trees.push( tree_as_string )
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, line 1542
def add_tree_name( tree_name )
  @tree_names.push( tree_name )
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, line 1514
def get_tree( i )
  newick = Bio::Newick.new( @trees[ i ] )
  tree = newick.tree
  tree
end
get_tree_names() click to toggle source

Returns an array of tree names.


Returns

Array

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

Returns an array of strings describing trees


Returns

Array

# File lib/bio/db/nexus.rb, line 1479
def get_tree_strings
  @trees  
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:

Returns

Array

# File lib/bio/db/nexus.rb, line 1496
def get_tree_strings_by_name( name )
  found_trees = Array.new
  i = 0
  @tree_names.each do | n |
    if ( n == name )
      found_trees.push( @trees[ i ] )
    end
    i += 1
  end
  found_trees
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:

Returns

Array of Bio::Newick

# File lib/bio/db/nexus.rb, line 1526
def get_trees_by_name( name )
  found_trees = Array.new
  i = 0
  @tree_names.each do | n |
    if ( n == name )
      found_trees.push( get_tree( i ) )
    end
    i += 1
  end
  found_trees
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, line 1468
def to_nexus
  trees_ary = Array.new
  for i in 0 .. @trees.length - 1
    trees_ary.push( TREE + " " + @tree_names[ i ] + "=" + @trees[ i ] )
  end
  Nexus::Util::to_nexus_helper( TREES_BLOCK, trees_ary  )
end