class Bio::Nexus::DataBlock

DESCRIPTION

Bio::Nexus::DataBlock represents a data nexus block. A data block is a Bio::Nexus::CharactersBlock with the added capability to store taxa names.

Example of Data block:

Begin Data;

Dimensions ntax=5 nchar=14;
Format Datatype=RNA gap=# MISSING=x MatchChar=^;
TaxLabels ciona cow [comment] ape 'purple urchin' "green lizard";
Matrix
 taxon_1 A- CCGTCGA-GTTA
 taxon_2 T- CCG-CGA-GATA
 taxon_3 A- C-GTCGA-GATA
 taxon_4 A- CCTCGA--GTTA
 taxon_5 T- CGGTCGT-CTTA;

End;

USAGE

require 'bio/db/nexus'

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

# Get first data block:
data_block = nexus.get_data_blocks[ 0 ]
# Get first characters name:
seq_name = data_block.get_row_name( 0 )
# Get first characters row named "taxon_2" as Bio::Sequence sequence:
seq_tax_2 = data_block.get_sequences_by_name( "taxon_2" )[ 0 ]
# Get third characters row as Bio::Sequence sequence:
seq_2 = data_block.get_sequence( 2 )
# Get first characters row named "taxon_3" as String:
string_tax_3 = data_block.get_characters_strings_by_name( "taxon_3" )
# Get name of first taxon:
taxon_0 = data_block.get_taxa[ 0 ]
# Get characters matrix as Bio::Nexus::NexusMatrix (names are in column 0)
characters_matrix = data_block.get_matrix

Public Class Methods

new( name ) click to toggle source

Creates a new DataBlock object named 'name'.


Arguments:

  • (required) name: String

Calls superclass method Bio::Nexus::CharactersBlock::new
     # File lib/bio/db/nexus.rb
1233 def initialize( name )
1234   super( name )
1235   @taxa = Array.new
1236 end

Public Instance Methods

add_taxon( taxon ) click to toggle source

Adds a taxon name to this block.


Arguments:

  • (required) taxon: String

     # File lib/bio/db/nexus.rb
1289 def add_taxon( taxon )
1290   @taxa.push( taxon )
1291 end
get_taxa() click to toggle source

Gets the taxa of this block.


Returns

Array

     # File lib/bio/db/nexus.rb
1281 def get_taxa
1282   @taxa
1283 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
1241 def to_nexus
1242   line_1 = String.new
1243   line_1 << DIMENSIONS  
1244   if ( Nexus::Util::larger_than_zero( get_number_of_taxa ) )
1245     line_1 << " " <<  NTAX << "=" << get_number_of_taxa
1246   end
1247   if ( Nexus::Util::larger_than_zero( get_number_of_characters ) )
1248     line_1 << " " <<  NCHAR << "=" << get_number_of_characters
1249   end
1250   line_1 << DELIMITER
1251   
1252   line_2 = String.new
1253   line_2 << FORMAT  
1254   if ( Nexus::Util::longer_than_zero( get_datatype ) )
1255     line_2 << " " <<  DATATYPE << "=" << get_datatype
1256   end
1257   if ( Nexus::Util::longer_than_zero( get_missing ) )
1258     line_2 << " " <<  MISSING << "=" << get_missing
1259   end
1260   if ( Nexus::Util::longer_than_zero( get_gap_character ) )
1261     line_2 << " " <<  GAP << "=" << get_gap_character
1262   end
1263   if ( Nexus::Util::longer_than_zero( get_match_character ) )
1264     line_2 << " " <<  MATCHCHAR << "=" << get_match_character
1265   end
1266   line_2 << DELIMITER
1267   
1268   line_3 = String.new
1269   line_3 << TAXLABELS << " " << Nexus::Util::array_to_string( get_taxa )
1270   line_3 << DELIMITER
1271   
1272   line_4 = String.new
1273   line_4 << MATRIX 
1274   Nexus::Util::to_nexus_helper( DATA_BLOCK, [ line_1, line_2, line_3, line_4 ] +
1275                                 get_matrix.to_nexus_row_array  )
1276 end