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

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

### Methods

get_matrix get_number_of_characters get_number_of_taxa get_triangle new set_matrix set_number_of_characters set_number_of_taxa set_triangle to_nexus

### Constants

TRIANGLE | = | "Triangle"

### Public Class methods

new( name )

Creates a new DistancesBlock object named ‘name’.

Arguments:

- (required) name: String

[Source]

          # File lib/bio/db/nexus.rb, line 1332
    1332:       def initialize( name )
    1333:         super( name )
    1334:         @number_of_taxa = 0
    1335:         @number_of_characters = 0
    1336:         @triangle = String.new
    1337:         @matrix = NexusMatrix.new
    1338:       end

### Public Instance methods

get_matrix()

Gets the matrix.

Returns: | Bio::Nexus::NexusMatrix

[Source]

          # File lib/bio/db/nexus.rb, line 1391
    1391:       def get_matrix
    1392:         @matrix
    1393:       end

get_number_of_characters()

Gets the "number of characters" property.

Returns: | Integer

[Source]

          # File lib/bio/db/nexus.rb, line 1377
    1377:       def get_number_of_characters
    1378:         @number_of_characters
    1379:       end

get_number_of_taxa()

Gets the "number of taxa" property.

Returns: | Integer

[Source]

          # File lib/bio/db/nexus.rb, line 1370
    1370:       def get_number_of_taxa
    1371:         @number_of_taxa
    1372:       end

get_triangle()

Gets the "triangle" property.

Returns: | String

[Source]

          # File lib/bio/db/nexus.rb, line 1384
    1384:       def get_triangle
    1385:         @triangle
    1386:       end

set_matrix( matrix )

Sets the matrix.

Arguments:

- (required) matrix: Bio::Nexus::NexusMatrix

[Source]

          # File lib/bio/db/nexus.rb, line 1423
    1423:       def set_matrix( matrix )
    1424:         @matrix = matrix
    1425:       end

set_number_of_characters( number_of_characters )

Sets the "number of characters" property.

Arguments:

- (required) number_of_characters: Integer

[Source]

          # File lib/bio/db/nexus.rb, line 1407
    1407:       def set_number_of_characters( number_of_characters )
    1408:         @number_of_characters = number_of_characters
    1409:       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 1399
    1399:       def set_number_of_taxa( number_of_taxa )
    1400:         @number_of_taxa = number_of_taxa
    1401:       end

set_triangle( triangle )

Sets the "triangle" property.

Arguments:

- (required) triangle: String

[Source]

          # File lib/bio/db/nexus.rb, line 1415
    1415:       def set_triangle( triangle )
    1416:         @triangle = triangle
    1417:       end

to_nexus()

Returns a String describing this block as nexus formatted data.

Returns: | String

[Source]

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

[Validate]