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:

Calls superclass method Bio::Nexus::GenericBlock.new
# File lib/bio/db/nexus.rb, line 952
def initialize( name )
  super( name )
  @number_of_taxa = 0
  @number_of_characters = 0
  @data_type = String.new
  @gap_character = String.new
  @missing = String.new
  @match_character = String.new
  @matrix = NexusMatrix.new
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, line 1107
def get_characters_string( row )
  get_matrix.get_row_string( row, "" )
end
get_characters_strings_by_name( name ) click to toggle source

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


Arguments:

Returns

Array of Strings

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

Gets the “datatype” property.


Returns

String

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

Gets the “gap character” property.


Returns

String

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

Gets the “match character” property.


Returns

String

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

Gets the matrix.


Returns

Bio::Nexus::NexusMatrix

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

Gets the “missing” property.


Returns

String

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

Gets the “number of characters” property.


Returns

Integer

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

Gets the “number of taxa” property.


Returns

Integer

# File lib/bio/db/nexus.rb, line 1004
def get_number_of_taxa
  @number_of_taxa
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, line 1085
def get_row_name( row )
  get_matrix.get_name( row )
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, line 1073
def get_sequence( row )
  create_sequence( get_characters_string( row ), get_row_name( row )  )
end
get_sequences_by_name( name ) click to toggle source

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


Arguments:

Returns

Bio::Sequence

# File lib/bio/db/nexus.rb, line 1057
def get_sequences_by_name( name )
  seq_strs = get_characters_strings_by_name( name )
  seqs = Array.new
  seq_strs.each do | seq_str |
    seqs.push( create_sequence( seq_str, name ) )
  end
  seqs
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, line 1131
def set_datatype( data_type )
  @data_type = data_type
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, line 1139
def set_gap_character( gap_character )
  @gap_character = gap_character
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, line 1155
def set_match_character( match_character )
  @match_character = match_character
end
set_matrix( matrix ) click to toggle source

Sets the matrix.


Arguments:

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

Sets the “missing” property.


Arguments:

# File lib/bio/db/nexus.rb, line 1147
def set_missing( missing )
  @missing = missing
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, line 1123
def set_number_of_characters( number_of_characters )
  @number_of_characters = number_of_characters
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, line 1115
def set_number_of_taxa( number_of_taxa )
  @number_of_taxa = number_of_taxa
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, line 967
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_datatype ) )
    line_2 << " " <<  DATATYPE << "=" << get_datatype
  end
  if ( Nexus::Util::longer_than_zero( get_missing ) )
    line_2 << " " <<  MISSING << "=" << get_missing
  end
  if ( Nexus::Util::longer_than_zero( get_gap_character ) )
    line_2 << " " <<  GAP << "=" << get_gap_character
  end
  if ( Nexus::Util::longer_than_zero( get_match_character ) )
    line_2 << " " <<  MATCHCHAR << "=" << get_match_character
  end
  line_2 << DELIMITER
  
  line_3 = String.new
  line_3 << MATRIX 
  Nexus::Util::to_nexus_helper( CHARACTERS_BLOCK, [ line_1, line_2, line_3 ] +
                                get_matrix.to_nexus_row_array  )
end