class Bio::Nexus::DistancesBlock

DESCRIPTION

Bio::Nexus::DistancesBlock represents a distances nexus block.

Example of Distances block:

Begin Distances;

Dimensions nchar=20 ntax=5;
Format Triangle=Upper;
Matrix
 taxon_1 0.0 1.0 2.0 4.0 7.0
 taxon_2 1.0 0.0 3.0 5.0 8.0
 taxon_3 3.0 4.0 0.0 6.0 9.0
 taxon_4 7.0 3.0 1.0 0.0 9.5
 taxon_5 1.2 1.3 1.4 1.5 0.0;

End;

USAGE

require 'bio/db/nexus'

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

# Get distances block(s):
distances_blocks = nexus.get_distances_blocks
# Get matrix as Bio::Nexus::NexusMatrix object:
matrix = distances_blocks[ 0 ].get_matrix
# Get value (column 0 are names):
val = matrix.get_value( 1, 5 )

Constants

TRIANGLE

Public Class Methods

new( name ) click to toggle source

Creates a new DistancesBlock object named ‘name’.


Arguments:

  • (required) name: String

Calls superclass method Bio::Nexus::GenericBlock::new
     # File lib/bio/db/nexus.rb
1333 def initialize( name )
1334   super( name )        
1335   @number_of_taxa = 0
1336   @number_of_characters = 0
1337   @triangle = String.new
1338   @matrix = NexusMatrix.new
1339 end

Public Instance Methods

get_matrix() click to toggle source

Gets the matrix.


Returns

Bio::Nexus::NexusMatrix

     # File lib/bio/db/nexus.rb
1392 def get_matrix
1393   @matrix
1394 end
get_number_of_characters() click to toggle source

Gets the “number of characters” property.


Returns

Integer

     # File lib/bio/db/nexus.rb
1378 def get_number_of_characters
1379   @number_of_characters
1380 end
get_number_of_taxa() click to toggle source

Gets the “number of taxa” property.


Returns

Integer

     # File lib/bio/db/nexus.rb
1371 def get_number_of_taxa
1372   @number_of_taxa
1373 end
get_triangle() click to toggle source

Gets the “triangle” property.


Returns

String

     # File lib/bio/db/nexus.rb
1385 def get_triangle
1386   @triangle
1387 end
set_matrix( matrix ) click to toggle source

Sets the matrix.


Arguments:

     # File lib/bio/db/nexus.rb
1424 def set_matrix( matrix )
1425   @matrix = matrix
1426 end
set_number_of_characters( number_of_characters ) click to toggle source

Sets the “number of characters” property.


Arguments:

  • (required) number_of_characters: Integer

     # File lib/bio/db/nexus.rb
1408 def set_number_of_characters( number_of_characters )
1409   @number_of_characters = number_of_characters
1410 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
1400 def set_number_of_taxa( number_of_taxa )
1401   @number_of_taxa = number_of_taxa
1402 end
set_triangle( triangle ) click to toggle source

Sets the “triangle” property.


Arguments:

  • (required) triangle: String

     # File lib/bio/db/nexus.rb
1416 def set_triangle( triangle )
1417   @triangle = triangle
1418 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
1344 def to_nexus
1345   line_1 = String.new
1346   line_1 << DIMENSIONS  
1347   if ( Nexus::Util::larger_than_zero( get_number_of_taxa ) )
1348     line_1 << " " <<  NTAX << "=" << get_number_of_taxa
1349   end
1350   if ( Nexus::Util::larger_than_zero( get_number_of_characters ) )
1351     line_1 << " " <<  NCHAR << "=" << get_number_of_characters
1352   end
1353   line_1 << DELIMITER
1354   
1355   line_2 = String.new
1356   line_2 << FORMAT  
1357   if ( Nexus::Util::longer_than_zero( get_triangle ) )
1358     line_2 << " " << TRIANGLE << "=" << get_triangle
1359   end
1360   line_2 << DELIMITER
1361   
1362   line_3 = String.new
1363   line_3 << MATRIX 
1364   Nexus::Util::to_nexus_helper( DISTANCES_BLOCK, [ line_1, line_2, line_3 ] +
1365                                 get_matrix.to_nexus_row_array( " " ) )
1366 end