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

## DESCRIPTION

Bio::Nexus::CharactersBlock represents a characters nexus block.

# Example of Characters block:

Begin Characters;

     Dimensions NChar=20
                NTax=4;
     Format DataType=DNA
     Missing=x
     Gap=- MatchChar=.;
     Matrix
      fish  ACATA GAGGG TACCT CTAAG
      frog  ACTTA GAGGC TACCT CTAGC
      snake ACTCA CTGGG TACCT TTGCG
      mouse ACTCA GACGG TACCT TTGCG;

End;

## USAGE

      require 'bio/db/nexus'

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

      # Get first characters block (same methods as Nexus::DataBlock except
      # it lacks get_taxa method):
      characters_block = nexus.get_characters_blocks[ 0 ]

### Methods

get_characters_string get_characters_strings_by_name get_datatype get_gap_character get_match_character get_matrix get_missing get_number_of_characters get_number_of_taxa get_row_name get_sequence get_sequences_by_name new set_datatype set_gap_character set_match_character set_matrix set_missing set_number_of_characters set_number_of_taxa to_nexus

### Constants

MISSING | = | "Missing"
GAP | = | "Gap"
MATCHCHAR | = | "MatchChar"

### Public Class methods

new( name )

Creates a new CharactersBlock object named ‘name’.

Arguments:

- (required) name: String

[Source]

         # File lib/bio/db/nexus.rb, line 951
    951:       def initialize( name )
    952:         super( name )
    953:         @number_of_taxa = 0
    954:         @number_of_characters = 0
    955:         @data_type = String.new
    956:         @gap_character = String.new
    957:         @missing = String.new
    958:         @match_character = String.new
    959:         @matrix = NexusMatrix.new
    960:       end

### Public Instance methods

get_characters_string( row )

Returns character data as String for matrix row ‘row’.

Arguments:

- (required) row: Integer

Returns: | String

[Source]

          # File lib/bio/db/nexus.rb, line 1106
    1106:       def get_characters_string( row )
    1107:         get_matrix.get_row_string( row, "" )
    1108:       end

get_characters_strings_by_name( name )

Returns character data as String Array for matrix rows named ‘name’.

Arguments:

- (required) name: String

Returns: | Array of Strings

[Source]

          # File lib/bio/db/nexus.rb, line 1095
    1095:       def get_characters_strings_by_name( name )
    1096:         get_matrix.get_row_strings_by_name( name, "" )
    1097:       end

get_datatype()

Gets the "datatype" property.

Returns: | String

[Source]

          # File lib/bio/db/nexus.rb, line 1018
    1018:       def get_datatype
    1019:         @data_type
    1020:       end

get_gap_character()

Gets the "gap character" property.

Returns: | String

[Source]

          # File lib/bio/db/nexus.rb, line 1025
    1025:       def get_gap_character
    1026:         @gap_character
    1027:       end

get_match_character()

Gets the "match character" property.

Returns: | String

[Source]

          # File lib/bio/db/nexus.rb, line 1039
    1039:       def get_match_character
    1040:         @match_character
    1041:       end

get_matrix()

Gets the matrix.

Returns: | Bio::Nexus::NexusMatrix

[Source]

          # File lib/bio/db/nexus.rb, line 1046
    1046:       def get_matrix
    1047:         @matrix
    1048:       end

get_missing()

Gets the "missing" property.

Returns: | String

[Source]

          # File lib/bio/db/nexus.rb, line 1032
    1032:       def get_missing
    1033:         @missing
    1034:       end

get_number_of_characters()

Gets the "number of characters" property.

Returns: | Integer

[Source]

          # File lib/bio/db/nexus.rb, line 1011
    1011:       def get_number_of_characters
    1012:         @number_of_characters
    1013:       end

get_number_of_taxa()

Gets the "number of taxa" property.

Returns: | Integer

[Source]

          # File lib/bio/db/nexus.rb, line 1003
    1003:       def get_number_of_taxa
    1004:         @number_of_taxa
    1005:       end

get_row_name( row )

Returns the String in the matrix at row ‘row’ and column 0, which usually is interpreted as a sequence name (if the matrix contains molecular sequence characters).

Arguments:

- (required) row: Integer

Returns: | String

[Source]

          # File lib/bio/db/nexus.rb, line 1084
    1084:       def get_row_name( row )
    1085:         get_matrix.get_name( row )
    1086:       end

get_sequence( row )

Returns the characters in the matrix at row ‘row’ as Bio::Sequence object. Column 0 of the matrix is set as the definition of the Bio::Sequence object.

Arguments:

- (required) row: Integer

Returns: | Bio::Sequence

[Source]

          # File lib/bio/db/nexus.rb, line 1072
    1072:       def get_sequence( row )
    1073:         create_sequence( get_characters_string( row ), get_row_name( row )  )
    1074:       end

get_sequences_by_name( name )

Returns character data as Bio::Sequence object Array for matrix rows named ‘name’.

Arguments:

- (required) name: String

Returns: | Bio::Sequence

[Source]

          # File lib/bio/db/nexus.rb, line 1056
    1056:       def get_sequences_by_name( name )
    1057:         seq_strs = get_characters_strings_by_name( name )
    1058:         seqs = Array.new
    1059:         seq_strs.each do | seq_str |
    1060:           seqs.push( create_sequence( seq_str, name ) )
    1061:         end
    1062:         seqs
    1063:       end

set_datatype( data_type )

Sets the "data type" property.

Arguments:

- (required) data_type: String

[Source]

          # File lib/bio/db/nexus.rb, line 1130
    1130:       def set_datatype( data_type )
    1131:         @data_type = data_type
    1132:       end

set_gap_character( gap_character )

Sets the "gap character" property.

Arguments:

- (required) gap_character: String

[Source]

          # File lib/bio/db/nexus.rb, line 1138
    1138:       def set_gap_character( gap_character )
    1139:         @gap_character = gap_character
    1140:       end

set_match_character( match_character )

Sets the "match character" property.

Arguments:

- (required) match_character: String

[Source]

          # File lib/bio/db/nexus.rb, line 1154
    1154:       def set_match_character( match_character )
    1155:         @match_character = match_character
    1156:       end

set_matrix( matrix )

Sets the matrix.

Arguments:

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

[Source]

          # File lib/bio/db/nexus.rb, line 1162
    1162:       def set_matrix( matrix )
    1163:         @matrix = matrix
    1164:       end

set_missing( missing )

Sets the "missing" property.

Arguments:

- (required) missing: String

[Source]

          # File lib/bio/db/nexus.rb, line 1146
    1146:       def set_missing( missing )
    1147:         @missing = missing
    1148:       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 1122
    1122:       def set_number_of_characters( number_of_characters )
    1123:         @number_of_characters = number_of_characters
    1124:       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 1114
    1114:       def set_number_of_taxa( number_of_taxa )
    1115:         @number_of_taxa = number_of_taxa
    1116:       end

to_nexus()

Returns a String describing this block as nexus formatted data.

Returns: | String

[Source]

         # File lib/bio/db/nexus.rb, line 966
    966:       def to_nexus
    967:         line_1 = String.new
    968:         line_1 << DIMENSIONS
    969:         if ( Nexus::Util::larger_than_zero( get_number_of_taxa ) )
    970:           line_1 << " " <<  NTAX << "=" << get_number_of_taxa
    971:         end
    972:         if ( Nexus::Util::larger_than_zero( get_number_of_characters ) )
    973:           line_1 << " " <<  NCHAR << "=" << get_number_of_characters
    974:         end
    975:         line_1 << DELIMITER
    976:
    977:         line_2 = String.new
    978:         line_2 << FORMAT
    979:         if ( Nexus::Util::longer_than_zero( get_datatype ) )
    980:           line_2 << " " <<  DATATYPE << "=" << get_datatype
    981:         end
    982:         if ( Nexus::Util::longer_than_zero( get_missing ) )
    983:           line_2 << " " <<  MISSING << "=" << get_missing
    984:         end
    985:         if ( Nexus::Util::longer_than_zero( get_gap_character ) )
    986:           line_2 << " " <<  GAP << "=" << get_gap_character
    987:         end
    988:         if ( Nexus::Util::longer_than_zero( get_match_character ) )
    989:           line_2 << " " <<  MATCHCHAR << "=" << get_match_character
    990:         end
    991:         line_2 << DELIMITER
    992:
    993:         line_3 = String.new
    994:         line_3 << MATRIX
    995:         Nexus::Util::to_nexus_helper( CHARACTERS_BLOCK, [ line_1, line_2, line_3 ] +
    996:                                       get_matrix.to_nexus_row_array  )
    997:       end

[Validate]