Class: Bio::Nexus::DistancesBlock
- Inherits:
-
GenericBlock
- Object
- GenericBlock
- Bio::Nexus::DistancesBlock
- Defined in:
- lib/bio/db/nexus.rb
Overview
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 )
Constant Summary collapse
- TRIANGLE =
"Triangle"
Instance Method Summary collapse
-
#get_matrix ⇒ Object
Gets the matrix.
-
#get_number_of_characters ⇒ Object
Gets the “number of characters” property.
-
#get_number_of_taxa ⇒ Object
Gets the “number of taxa” property.
-
#get_triangle ⇒ Object
Gets the “triangle” property.
-
#initialize(name) ⇒ DistancesBlock
constructor
Creates a new DistancesBlock object named ‘name’.
-
#set_matrix(matrix) ⇒ Object
Sets the matrix.
-
#set_number_of_characters(number_of_characters) ⇒ Object
Sets the “number of characters” property.
-
#set_number_of_taxa(number_of_taxa) ⇒ Object
Sets the “number of taxa” property.
-
#set_triangle(triangle) ⇒ Object
Sets the “triangle” 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) ⇒ DistancesBlock
Creates a new DistancesBlock object named ‘name’.
Arguments:
-
(required) name: String
1332 1333 1334 1335 1336 1337 1338 |
# File 'lib/bio/db/nexus.rb', line 1332 def initialize( name ) super( name ) @number_of_taxa = 0 @number_of_characters = 0 @triangle = String.new @matrix = NexusMatrix.new end |
Instance Method Details
#get_matrix ⇒ Object
Gets the matrix.
- Returns
-
Bio::Nexus::NexusMatrix
1391 1392 1393 |
# File 'lib/bio/db/nexus.rb', line 1391 def get_matrix @matrix end |
#get_number_of_characters ⇒ Object
Gets the “number of characters” property.
- Returns
-
Integer
1377 1378 1379 |
# File 'lib/bio/db/nexus.rb', line 1377 def get_number_of_characters @number_of_characters end |
#get_number_of_taxa ⇒ Object
Gets the “number of taxa” property.
- Returns
-
Integer
1370 1371 1372 |
# File 'lib/bio/db/nexus.rb', line 1370 def get_number_of_taxa @number_of_taxa end |
#get_triangle ⇒ Object
Gets the “triangle” property.
- Returns
-
String
1384 1385 1386 |
# File 'lib/bio/db/nexus.rb', line 1384 def get_triangle @triangle end |
#set_matrix(matrix) ⇒ Object
Sets the matrix.
Arguments:
-
(required) matrix: Bio::Nexus::NexusMatrix
1423 1424 1425 |
# File 'lib/bio/db/nexus.rb', line 1423 def set_matrix( matrix ) @matrix = matrix end |
#set_number_of_characters(number_of_characters) ⇒ Object
Sets the “number of characters” property.
Arguments:
-
(required) number_of_characters: Integer
1407 1408 1409 |
# File 'lib/bio/db/nexus.rb', line 1407 def set_number_of_characters( number_of_characters ) @number_of_characters = number_of_characters end |
#set_number_of_taxa(number_of_taxa) ⇒ Object
Sets the “number of taxa” property.
Arguments:
-
(required) number_of_taxa: Integer
1399 1400 1401 |
# File 'lib/bio/db/nexus.rb', line 1399 def set_number_of_taxa( number_of_taxa ) @number_of_taxa = number_of_taxa end |
#set_triangle(triangle) ⇒ Object
Sets the “triangle” property.
Arguments:
-
(required) triangle: String
1415 1416 1417 |
# File 'lib/bio/db/nexus.rb', line 1415 def set_triangle( triangle ) @triangle = triangle end |
#to_nexus ⇒ Object
Returns a String describing this block as nexus formatted data.
- Returns
-
String
1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 |
# File 'lib/bio/db/nexus.rb', line 1343 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 if ( Nexus::Util::larger_than_zero( get_number_of_characters ) ) line_1 << " " << NCHAR << "=" << get_number_of_characters end line_1 << DELIMITER line_2 = String.new line_2 << FORMAT if ( Nexus::Util::longer_than_zero( get_triangle ) ) line_2 << " " << TRIANGLE << "=" << get_triangle end line_2 << DELIMITER line_3 = String.new line_3 << MATRIX Nexus::Util::to_nexus_helper( DISTANCES_BLOCK, [ line_1, line_2, line_3 ] + get_matrix.to_nexus_row_array( " " ) ) end |