Class Bio::Nexus
In: lib/bio/db/nexus.rb
Parent: Object

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

Methods

Classes and Modules

Class Bio::Nexus::CharactersBlock
Class Bio::Nexus::DataBlock
Class Bio::Nexus::DistancesBlock
Class Bio::Nexus::GenericBlock
Class Bio::Nexus::NexusMatrix
Class Bio::Nexus::NexusParseError
Class Bio::Nexus::TaxaBlock
Class Bio::Nexus::TreesBlock
Class Bio::Nexus::Util

Constants

END_OF_LINE = "\n"
INDENTENTION = " "
DOUBLE_QUOTE = "\""
SINGLE_QUOTE = "'"
BEGIN_NEXUS = "#NEXUS"
DELIMITER = ";"
BEGIN_BLOCK = "Begin"
END_BLOCK = "End" + DELIMITER
BEGIN_COMMENT = "["
END_COMMENT = "]"
TAXA = "Taxa"
CHARACTERS = "Characters"
DATA = "Data"
DISTANCES = "Distances"
TREES = "Trees"
TAXA_BLOCK = TAXA + DELIMITER
CHARACTERS_BLOCK = CHARACTERS + DELIMITER
DATA_BLOCK = DATA + DELIMITER
DISTANCES_BLOCK = DISTANCES + DELIMITER
TREES_BLOCK = TREES + DELIMITER
DIMENSIONS = "Dimensions"
FORMAT = "Format"
NTAX = "NTax"
NCHAR = "NChar"
DATATYPE = "DataType"
TAXLABELS = "TaxLabels"
MATRIX = "Matrix"

Public Class methods

Creates a new nexus parser for ‘nexus_str’.


Arguments:

  • (required) nexus_str: String - nexus formatted data

[Source]

     # File lib/bio/db/nexus.rb, line 177
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

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

[Source]

     # File lib/bio/db/nexus.rb, line 192
192:     def get_blocks
193:       @blocks
194:     end

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:

Returns:Array of GenericBlocks or any of its subclasses

[Source]

     # File lib/bio/db/nexus.rb, line 204
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

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


Returns:Array of CharactersBlocks

[Source]

     # File lib/bio/db/nexus.rb, line 228
228:     def get_characters_blocks
229:       get_blocks_by_name( CHARACTERS_BLOCK.chomp( ";").downcase )
230:     end

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


Returns:Array of DataBlocks

[Source]

     # File lib/bio/db/nexus.rb, line 219
219:     def get_data_blocks
220:       get_blocks_by_name( DATA_BLOCK.chomp( ";").downcase )
221:     end

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


Returns:Array of DistancesBlock

[Source]

     # File lib/bio/db/nexus.rb, line 246
246:     def get_distances_blocks
247:       get_blocks_by_name( DISTANCES_BLOCK.chomp( ";").downcase )
248:     end

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


Returns:Array of TaxaBlocks

[Source]

     # File lib/bio/db/nexus.rb, line 255
255:     def get_taxa_blocks
256:       get_blocks_by_name( TAXA_BLOCK.chomp( ";").downcase )
257:     end

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


Returns:Array of TreesBlocks

[Source]

     # File lib/bio/db/nexus.rb, line 237
237:     def get_trees_blocks
238:       get_blocks_by_name( TREES_BLOCK.chomp( ";").downcase )
239:     end

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


Returns:String

[Source]

     # File lib/bio/db/nexus.rb, line 263
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
to_str()

Alias for to_s

[Validate]