Bio::Nexus is a parser for nexus formatted data. It contains classes and constants enabling the representation and processing of nexus data.
# 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
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
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, line 192 def get_blocks @blocks 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:
(required) name: String
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
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
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
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
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
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
Returns a String listing how many of each blocks it parsed.
Returns |
# 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
Generated with the Darkfish Rdoc Generator 2.