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, line 177
def initialize( nexus_str )
  @blocks             = Array.new
  @current_cmd        = nil
  @current_subcmd     = nil
  @current_block_name = nil
  @current_block      = nil
  parse( nexus_str )
end

Public Instance Methods

get_blocks() click to toggle source

Returns an Array of all blocks found in the String 'nexus_str' set via ::new( nexus_str ).


Returns

Array of GenericBlocks or any of its subclasses

# File lib/bio/db/nexus.rb, line 192
def get_blocks
  @blocks
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 ::new( nexus_str ).


Arguments:

Returns

Array of GenericBlocks or any of its subclasses

# File lib/bio/db/nexus.rb, line 204
def get_blocks_by_name( name )
  found_blocks = Array.new
  @blocks.each do | block |
    if ( name == block.get_name )
      found_blocks.push( block )
    end
  end
  found_blocks
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, line 228
def get_characters_blocks
  get_blocks_by_name( CHARACTERS_BLOCK.chomp( ";").downcase )
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, line 219
def get_data_blocks
  get_blocks_by_name( DATA_BLOCK.chomp( ";").downcase )
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, line 246
def get_distances_blocks
  get_blocks_by_name( DISTANCES_BLOCK.chomp( ";").downcase )
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, line 255
def get_taxa_blocks
  get_blocks_by_name( TAXA_BLOCK.chomp( ";").downcase )
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, line 237
def get_trees_blocks
  get_blocks_by_name( TREES_BLOCK.chomp( ";").downcase )
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, line 263
def to_s
  str = String.new
  if get_blocks.length < 1
    str << "empty"
  else 
    str << "number of blocks: " << get_blocks.length.to_s
    if get_characters_blocks.length > 0
      str << " [characters blocks: " << get_characters_blocks.length.to_s << "] "
    end  
    if get_data_blocks.length > 0
      str << " [data blocks: " << get_data_blocks.length.to_s << "] "
    end
    if get_distances_blocks.length > 0
      str << " [distances blocks: " << get_distances_blocks.length.to_s << "] "
    end  
    if get_taxa_blocks.length > 0
      str << " [taxa blocks: " << get_taxa_blocks.length.to_s << "] "
    end    
    if get_trees_blocks.length > 0
      str << " [trees blocks: " << get_trees_blocks.length.to_s << "] "
    end        
  end
  str
end
Also aliased as: to_str
to_str()
Alias for: to_s