class Bio::Nexus::TaxaBlock

DESCRIPTION

Bio::Nexus::TaxaBlock represents a taxa nexus block.

Example of Taxa block:

Begin Taxa;

Dimensions NTax=4;
TaxLabels fish [comment] 'african frog' "rat snake" 'red mouse';

End;

USAGE

require 'bio/db/nexus'

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

# Get first taxa block:
taxa_block = nexus.get_taxa_blocks[ 0 ]
# Get number of taxa:
number_of_taxa = taxa_block.get_number_of_taxa.to_i
# Get name of first taxon:
first_taxon = taxa_block.get_taxa[ 0 ]

Public Class Methods

new( name ) click to toggle source

Creates a new TaxaBlock object named ‘name’.


Arguments:

  • (required) name: String

Calls superclass method Bio::Nexus::GenericBlock::new
    # File lib/bio/db/nexus.rb
854 def initialize( name )
855   super( name )
856   @number_of_taxa = 0
857   @taxa = Array.new
858 end

Public Instance Methods

add_taxon( taxon ) click to toggle source

Adds a taxon name to this block.


Arguments:

  • (required) taxon: String

    # File lib/bio/db/nexus.rb
905 def add_taxon( taxon )
906   @taxa.push( taxon )
907 end
get_number_of_taxa() click to toggle source

Gets the “number of taxa” property.


Returns

Integer

    # File lib/bio/db/nexus.rb
879 def get_number_of_taxa
880   @number_of_taxa
881 end
get_taxa() click to toggle source

Gets the taxa of this block.


Returns

Array

    # File lib/bio/db/nexus.rb
887 def get_taxa
888   @taxa
889 end
set_number_of_taxa( number_of_taxa ) click to toggle source

Sets the “number of taxa” property.


Arguments:

  • (required) number_of_taxa: Integer

    # File lib/bio/db/nexus.rb
896 def set_number_of_taxa( number_of_taxa )
897   @number_of_taxa = number_of_taxa
898 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
863 def to_nexus
864   line_1 = String.new
865   line_1 << DIMENSIONS 
866   if ( Nexus::Util::larger_than_zero( get_number_of_taxa  ) )
867     line_1 << " " <<  NTAX << "=" << get_number_of_taxa
868   end
869   line_1 << DELIMITER
870   line_2 = String.new
871   line_2 << TAXLABELS << " " << Nexus::Util::array_to_string( get_taxa ) << DELIMITER
872   Nexus::Util::to_nexus_helper( TAXA_BLOCK, [ line_1, line_2 ] )
873 end