class Bio::Nexus::CharactersBlock

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 ]

Constants

GAP
MATCHCHAR
MISSING

Public Class Methods

new( name ) click to toggle source

Creates a new CharactersBlock object named 'name'.


Arguments:

  • (required) name: String

Calls superclass method Bio::Nexus::GenericBlock::new
    # File lib/bio/db/nexus.rb
952 def initialize( name )
953   super( name )
954   @number_of_taxa = 0
955   @number_of_characters = 0
956   @data_type = String.new
957   @gap_character = String.new
958   @missing = String.new
959   @match_character = String.new
960   @matrix = NexusMatrix.new
961 end

Public Instance Methods

get_characters_string( row ) click to toggle source

Returns character data as String for matrix row 'row'.


Arguments:

  • (required) row: Integer

Returns

String

     # File lib/bio/db/nexus.rb
1107 def get_characters_string( row )
1108   get_matrix.get_row_string( row, "" )
1109 end
get_characters_strings_by_name( name ) click to toggle source

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


Arguments:

  • (required) name: String

Returns

Array of Strings

     # File lib/bio/db/nexus.rb
1096 def get_characters_strings_by_name( name )
1097   get_matrix.get_row_strings_by_name( name, "" )
1098 end
get_datatype() click to toggle source

Gets the “datatype” property.


Returns

String

     # File lib/bio/db/nexus.rb
1019 def get_datatype
1020   @data_type
1021 end
get_gap_character() click to toggle source

Gets the “gap character” property.


Returns

String

     # File lib/bio/db/nexus.rb
1026 def get_gap_character
1027   @gap_character
1028 end
get_match_character() click to toggle source

Gets the “match character” property.


Returns

String

     # File lib/bio/db/nexus.rb
1040 def get_match_character 
1041   @match_character 
1042 end
get_matrix() click to toggle source

Gets the matrix.


Returns

Bio::Nexus::NexusMatrix

     # File lib/bio/db/nexus.rb
1047 def get_matrix
1048   @matrix 
1049 end
get_missing() click to toggle source

Gets the “missing” property.


Returns

String

     # File lib/bio/db/nexus.rb
1033 def get_missing
1034   @missing
1035 end
get_number_of_characters() click to toggle source

Gets the “number of characters” property.


Returns

Integer

     # File lib/bio/db/nexus.rb
1012 def get_number_of_characters
1013   @number_of_characters
1014 end
get_number_of_taxa() click to toggle source

Gets the “number of taxa” property.


Returns

Integer

     # File lib/bio/db/nexus.rb
1004 def get_number_of_taxa
1005   @number_of_taxa
1006 end
get_row_name( row ) click to toggle source

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

     # File lib/bio/db/nexus.rb
1085 def get_row_name( row )
1086   get_matrix.get_name( row )
1087 end
get_sequence( row ) click to toggle source

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

     # File lib/bio/db/nexus.rb
1073 def get_sequence( row )
1074   create_sequence( get_characters_string( row ), get_row_name( row )  )
1075 end
get_sequences_by_name( name ) click to toggle source

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


Arguments:

  • (required) name: String

Returns

Bio::Sequence

     # File lib/bio/db/nexus.rb
1057 def get_sequences_by_name( name )
1058   seq_strs = get_characters_strings_by_name( name )
1059   seqs = Array.new
1060   seq_strs.each do | seq_str |
1061     seqs.push( create_sequence( seq_str, name ) )
1062   end
1063   seqs
1064 end
set_datatype( data_type ) click to toggle source

Sets the “data type” property.


Arguments:

  • (required) data_type: String

     # File lib/bio/db/nexus.rb
1131 def set_datatype( data_type )
1132   @data_type = data_type
1133 end
set_gap_character( gap_character ) click to toggle source

Sets the “gap character” property.


Arguments:

  • (required) gap_character: String

     # File lib/bio/db/nexus.rb
1139 def set_gap_character( gap_character )
1140   @gap_character = gap_character
1141 end
set_match_character( match_character ) click to toggle source

Sets the “match character” property.


Arguments:

  • (required) match_character: String

     # File lib/bio/db/nexus.rb
1155 def set_match_character( match_character )
1156   @match_character = match_character
1157 end
set_matrix( matrix ) click to toggle source

Sets the matrix.


Arguments:

     # File lib/bio/db/nexus.rb
1163 def set_matrix( matrix )
1164   @matrix = matrix
1165 end
set_missing( missing ) click to toggle source

Sets the “missing” property.


Arguments:

  • (required) missing: String

     # File lib/bio/db/nexus.rb
1147 def set_missing( missing )
1148   @missing = missing
1149 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
1123 def set_number_of_characters( number_of_characters )
1124   @number_of_characters = number_of_characters
1125 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
1115 def set_number_of_taxa( number_of_taxa )
1116   @number_of_taxa = number_of_taxa
1117 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
967 def to_nexus
968   line_1 = String.new
969   line_1 << DIMENSIONS  
970   if ( Nexus::Util::larger_than_zero( get_number_of_taxa ) )
971     line_1 << " " <<  NTAX << "=" << get_number_of_taxa
972   end
973   if ( Nexus::Util::larger_than_zero( get_number_of_characters ) )
974     line_1 << " " <<  NCHAR << "=" << get_number_of_characters
975   end
976   line_1 << DELIMITER
977   
978   line_2 = String.new
979   line_2 << FORMAT  
980   if ( Nexus::Util::longer_than_zero( get_datatype ) )
981     line_2 << " " <<  DATATYPE << "=" << get_datatype
982   end
983   if ( Nexus::Util::longer_than_zero( get_missing ) )
984     line_2 << " " <<  MISSING << "=" << get_missing
985   end
986   if ( Nexus::Util::longer_than_zero( get_gap_character ) )
987     line_2 << " " <<  GAP << "=" << get_gap_character
988   end
989   if ( Nexus::Util::longer_than_zero( get_match_character ) )
990     line_2 << " " <<  MATCHCHAR << "=" << get_match_character
991   end
992   line_2 << DELIMITER
993   
994   line_3 = String.new
995   line_3 << MATRIX 
996   Nexus::Util::to_nexus_helper( CHARACTERS_BLOCK, [ line_1, line_2, line_3 ] +
997                                 get_matrix.to_nexus_row_array  )
998 end