Class: Bio::Nexus::TaxaBlock
- Inherits:
-
GenericBlock
- Object
- GenericBlock
- Bio::Nexus::TaxaBlock
- Defined in:
- lib/bio/db/nexus.rb
Overview
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 ]
Instance Method Summary collapse
-
#add_taxon(taxon) ⇒ Object
Adds a taxon name to this block.
-
#get_number_of_taxa ⇒ Object
Gets the “number of taxa” property.
-
#get_taxa ⇒ Object
Gets the taxa of this block.
-
#initialize(name) ⇒ TaxaBlock
constructor
Creates a new TaxaBlock object named ‘name’.
-
#set_number_of_taxa(number_of_taxa) ⇒ Object
Sets the “number of taxa” property.
-
#to_nexus ⇒ Object
Returns a String describing this block as nexus formatted data.
Methods inherited from GenericBlock
#add_token, #get_name, #get_tokens, #to_s
Constructor Details
#initialize(name) ⇒ TaxaBlock
Creates a new TaxaBlock object named ‘name’.
Arguments:
-
(required) name: String
853 854 855 856 857 |
# File 'lib/bio/db/nexus.rb', line 853 def initialize( name ) super( name ) @number_of_taxa = 0 @taxa = Array.new end |
Instance Method Details
#add_taxon(taxon) ⇒ Object
Adds a taxon name to this block.
Arguments:
-
(required) taxon: String
904 905 906 |
# File 'lib/bio/db/nexus.rb', line 904 def add_taxon( taxon ) @taxa.push( taxon ) end |
#get_number_of_taxa ⇒ Object
Gets the “number of taxa” property.
- Returns
-
Integer
878 879 880 |
# File 'lib/bio/db/nexus.rb', line 878 def get_number_of_taxa @number_of_taxa end |
#get_taxa ⇒ Object
Gets the taxa of this block.
- Returns
-
Array
886 887 888 |
# File 'lib/bio/db/nexus.rb', line 886 def get_taxa @taxa end |
#set_number_of_taxa(number_of_taxa) ⇒ Object
Sets the “number of taxa” property.
Arguments:
-
(required) number_of_taxa: Integer
895 896 897 |
# File 'lib/bio/db/nexus.rb', line 895 def set_number_of_taxa( number_of_taxa ) @number_of_taxa = number_of_taxa end |
#to_nexus ⇒ Object
Returns a String describing this block as nexus formatted data.
- Returns
-
String
862 863 864 865 866 867 868 869 870 871 872 |
# File 'lib/bio/db/nexus.rb', line 862 def to_nexus line_1 = String.new line_1 << DIMENSIONS if ( Nexus::Util::larger_than_zero( get_number_of_taxa ) ) line_1 << " " << NTAX << "=" << get_number_of_taxa end line_1 << DELIMITER line_2 = String.new line_2 << TAXLABELS << " " << Nexus::Util::array_to_string( get_taxa ) << DELIMITER Nexus::Util::to_nexus_helper( TAXA_BLOCK, [ line_1, line_2 ] ) end |