class Bio::Nexus

DESCRIPTION

Bio::Nexus is a parser for nexus formatted data. It contains classes and constants enabling the representation and processing of nexus data.

USAGE

# Parsing a nexus formatted string str:
nexus = Bio::Nexus.new( nexus_str )

# Obtaining of the nexus blocks as array of GenericBlock or
# any of its subclasses (such as DistancesBlock):
blocks = nexus.get_blocks

# Getting a block by name:
my_blocks = nexus.get_blocks_by_name( "my_block" )

# Getting distance blocks:
distances_blocks = nexus.get_distances_blocks

# Getting trees blocks:
trees_blocks = nexus.get_trees_blocks

# Getting data blocks:
data_blocks = nexus.get_data_blocks

# Getting characters blocks:
character_blocks = nexus.get_characters_blocks

# Getting taxa blocks:
taxa_blocks = nexus.get_taxa_blocks

Constants

BEGIN_BLOCK
BEGIN_COMMENT
BEGIN_NEXUS
CHARACTERS
CHARACTERS_BLOCK
DATA
DATATYPE
DATA_BLOCK
DELIMITER
DIMENSIONS
DISTANCES
DISTANCES_BLOCK
DOUBLE_QUOTE
END_BLOCK
END_COMMENT
END_OF_LINE
FORMAT
INDENTENTION
MATRIX
NCHAR
NTAX
SINGLE_QUOTE
TAXA
TAXA_BLOCK
TAXLABELS
TREES
TREES_BLOCK

Public Class Methods

new( nexus_str ) click to toggle source

Creates a new nexus parser for ‘nexus_str’.


Arguments:

  • (required) nexus_str: String - nexus formatted data

    # File lib/bio/db/nexus.rb
177 def initialize( nexus_str )
178   @blocks             = Array.new
179   @current_cmd        = nil
180   @current_subcmd     = nil
181   @current_block_name = nil
182   @current_block      = nil
183   parse( nexus_str )
184 end

Public Instance Methods

get_blocks() click to toggle source

Returns an Array of all blocks found in the String ‘nexus_str’ set via Bio::Nexus.new( nexus_str ).


Returns

Array of GenericBlocks or any of its subclasses

    # File lib/bio/db/nexus.rb
192 def get_blocks
193   @blocks
194 end
get_blocks_by_name( name ) click to toggle source

A convenience methods which returns an array of all nexus blocks for which the name equals ‘name’ found in the String ‘nexus_str’ set via Bio::Nexus.new( nexus_str ).


Arguments:

  • (required) name: String

Returns

Array of GenericBlocks or any of its subclasses

    # File lib/bio/db/nexus.rb
204 def get_blocks_by_name( name )
205   found_blocks = Array.new
206   @blocks.each do | block |
207     if ( name == block.get_name )
208       found_blocks.push( block )
209     end
210   end
211   found_blocks
212 end
get_characters_blocks() click to toggle source

A convenience methods which returns an array of all characters blocks.


Returns

Array of CharactersBlocks

    # File lib/bio/db/nexus.rb
228 def get_characters_blocks
229   get_blocks_by_name( CHARACTERS_BLOCK.chomp( ";").downcase )
230 end
get_data_blocks() click to toggle source

A convenience methods which returns an array of all data blocks.


Returns

Array of DataBlocks

    # File lib/bio/db/nexus.rb
219 def get_data_blocks
220   get_blocks_by_name( DATA_BLOCK.chomp( ";").downcase )
221 end
get_distances_blocks() click to toggle source

A convenience methods which returns an array of all distances blocks.


Returns

Array of DistancesBlock

    # File lib/bio/db/nexus.rb
246 def get_distances_blocks
247   get_blocks_by_name( DISTANCES_BLOCK.chomp( ";").downcase )
248 end
get_taxa_blocks() click to toggle source

A convenience methods which returns an array of all taxa blocks.


Returns

Array of TaxaBlocks

    # File lib/bio/db/nexus.rb
255 def get_taxa_blocks
256   get_blocks_by_name( TAXA_BLOCK.chomp( ";").downcase )
257 end
get_trees_blocks() click to toggle source

A convenience methods which returns an array of all trees blocks.


Returns

Array of TreesBlocks

    # File lib/bio/db/nexus.rb
237 def get_trees_blocks
238   get_blocks_by_name( TREES_BLOCK.chomp( ";").downcase )
239 end
to_s() click to toggle source

Returns a String listing how many of each blocks it parsed.


Returns

String

    # File lib/bio/db/nexus.rb
263 def to_s
264   str = String.new
265   if get_blocks.length < 1
266     str << "empty"
267   else 
268     str << "number of blocks: " << get_blocks.length.to_s
269     if get_characters_blocks.length > 0
270       str << " [characters blocks: " << get_characters_blocks.length.to_s << "] "
271     end  
272     if get_data_blocks.length > 0
273       str << " [data blocks: " << get_data_blocks.length.to_s << "] "
274     end
275     if get_distances_blocks.length > 0
276       str << " [distances blocks: " << get_distances_blocks.length.to_s << "] "
277     end  
278     if get_taxa_blocks.length > 0
279       str << " [taxa blocks: " << get_taxa_blocks.length.to_s << "] "
280     end    
281     if get_trees_blocks.length > 0
282       str << " [trees blocks: " << get_trees_blocks.length.to_s << "] "
283     end        
284   end
285   str
286 end
Also aliased as: to_str
to_str()
Alias for: to_s