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 1458 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 1549 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 1541 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
# File lib/bio/db/nexus.rb, line 1513 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 1485 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 1478 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:
-
(required) name: String
- Returns
-
Array
# File lib/bio/db/nexus.rb, line 1495 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:
-
(required) name: String
- Returns
-
Array of Bio::Newick
# File lib/bio/db/nexus.rb, line 1525 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
# File lib/bio/db/nexus.rb, line 1467 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