Class Bio::Nexus::TreesBlock
In: lib/bio/db/nexus.rb
Parent: GenericBlock

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 )

Methods

Constants

TREE = "Tree"

Public Class methods

[Source]

      # File lib/bio/db/nexus.rb, line 1458
1458:       def initialize( name )
1459:         super( name ) 
1460:         @trees      = Array.new
1461:         @tree_names = Array.new
1462:       end

Public Instance methods

Adds a tree to this block.


Arguments:

  • (required) tree_as_string: String

[Source]

      # File lib/bio/db/nexus.rb, line 1549
1549:       def add_tree( tree_as_string )
1550:         @trees.push( tree_as_string )
1551:       end

Adds a tree name to this block.


Arguments:

  • (required) tree_name: String

[Source]

      # File lib/bio/db/nexus.rb, line 1541
1541:       def add_tree_name( tree_name )
1542:         @tree_names.push( tree_name )
1543:       end

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


Arguments:

  • (required) i: Integer
Returns:Bio::Newick

[Source]

      # File lib/bio/db/nexus.rb, line 1513
1513:       def get_tree( i )
1514:         newick = Bio::Newick.new( @trees[ i ] )
1515:         tree = newick.tree
1516:         tree
1517:       end

Returns an array of tree names.


Returns:Array

[Source]

      # File lib/bio/db/nexus.rb, line 1485
1485:       def get_tree_names
1486:         @tree_names 
1487:       end

Returns an array of strings describing trees


Returns:Array

[Source]

      # File lib/bio/db/nexus.rb, line 1478
1478:       def get_tree_strings
1479:         @trees  
1480:       end

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


Arguments:

Returns:Array

[Source]

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

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


Arguments:

Returns:Array of Bio::Newick

[Source]

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

Returns a String describing this block as nexus formatted data.


Returns:String

[Source]

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

[Validate]