| Class | Bio::Nexus::TreesBlock |
| In: |
lib/bio/db/nexus.rb
|
| Parent: | GenericBlock |
Bio::Nexus::TreesBlock represents a trees nexus block.
Begin Trees;
Tree best=(fish,(frog,(snake, mouse))); Tree other=(snake,(frog,( fish, mouse)));
End;
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 )
| TREE | = | "Tree" |
# 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
Returns tree i (same order as in nexus data) as newick parsed tree object.
Arguments:
| Returns: | Bio::Newick |
# 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 |
# 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 |
# 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 |
# 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 |
# 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 |
# 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