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

## 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 ]

### Methods

add_taxon get_number_of_taxa get_taxa new set_number_of_taxa to_nexus

### Public Class methods

new( name )

Creates a new TaxaBlock object named ‘name’.

Arguments:

- (required) name: String

[Source]

         # File lib/bio/db/nexus.rb, line 853
    853:       def initialize( name )
    854:         super( name )
    855:         @number_of_taxa = 0
    856:         @taxa = Array.new
    857:       end

### Public Instance methods

add_taxon( taxon )

Adds a taxon name to this block.

Arguments:

- (required) taxon: String

[Source]

         # File lib/bio/db/nexus.rb, line 904
    904:       def add_taxon( taxon )
    905:         @taxa.push( taxon )
    906:       end

get_number_of_taxa()

Gets the "number of taxa" property.

Returns: | Integer

[Source]

         # File lib/bio/db/nexus.rb, line 878
    878:       def get_number_of_taxa
    879:         @number_of_taxa
    880:       end

get_taxa()

Gets the taxa of this block.

Returns: | Array

[Source]

         # File lib/bio/db/nexus.rb, line 886
    886:       def get_taxa
    887:         @taxa
    888:       end

set_number_of_taxa( number_of_taxa )

Sets the "number of taxa" property.

Arguments:

- (required) number_of_taxa: Integer

[Source]

         # File lib/bio/db/nexus.rb, line 895
    895:       def set_number_of_taxa( number_of_taxa )
    896:         @number_of_taxa = number_of_taxa
    897:       end

to_nexus()

Returns a String describing this block as nexus formatted data.

Returns: | String

[Source]

         # File lib/bio/db/nexus.rb, line 862
    862:       def to_nexus
    863:         line_1 = String.new
    864:         line_1 << DIMENSIONS
    865:         if ( Nexus::Util::larger_than_zero( get_number_of_taxa  ) )
    866:           line_1 << " " <<  NTAX << "=" << get_number_of_taxa
    867:         end
    868:         line_1 << DELIMITER
    869:         line_2 = String.new
    870:         line_2 << TAXLABELS << " " << Nexus::Util::array_to_string( get_taxa ) << DELIMITER
    871:         Nexus::Util::to_nexus_helper( TAXA_BLOCK, [ line_1, line_2 ] )
    872:       end

[Validate]