Class | Bio::Nexus::DataBlock |
In: |
lib/bio/db/nexus.rb
|
Parent: | CharactersBlock |
Bio::Nexus::DataBlock represents a data nexus block. A data block is a Bio::Nexus::CharactersBlock with the added capability to store taxa names.
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;
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
Gets the taxa of this block.
Returns: | Array |
# File lib/bio/db/nexus.rb, line 1280 1280: def get_taxa 1281: @taxa 1282: end
Returns a String describing this block as nexus formatted data.
Returns: | String |
# File lib/bio/db/nexus.rb, line 1240 1240: def to_nexus 1241: line_1 = String.new 1242: line_1 << DIMENSIONS 1243: if ( Nexus::Util::larger_than_zero( get_number_of_taxa ) ) 1244: line_1 << " " << NTAX << "=" << get_number_of_taxa 1245: end 1246: if ( Nexus::Util::larger_than_zero( get_number_of_characters ) ) 1247: line_1 << " " << NCHAR << "=" << get_number_of_characters 1248: end 1249: line_1 << DELIMITER 1250: 1251: line_2 = String.new 1252: line_2 << FORMAT 1253: if ( Nexus::Util::longer_than_zero( get_datatype ) ) 1254: line_2 << " " << DATATYPE << "=" << get_datatype 1255: end 1256: if ( Nexus::Util::longer_than_zero( get_missing ) ) 1257: line_2 << " " << MISSING << "=" << get_missing 1258: end 1259: if ( Nexus::Util::longer_than_zero( get_gap_character ) ) 1260: line_2 << " " << GAP << "=" << get_gap_character 1261: end 1262: if ( Nexus::Util::longer_than_zero( get_match_character ) ) 1263: line_2 << " " << MATCHCHAR << "=" << get_match_character 1264: end 1265: line_2 << DELIMITER 1266: 1267: line_3 = String.new 1268: line_3 << TAXLABELS << " " << Nexus::Util::array_to_string( get_taxa ) 1269: line_3 << DELIMITER 1270: 1271: line_4 = String.new 1272: line_4 << MATRIX 1273: Nexus::Util::to_nexus_helper( DATA_BLOCK, [ line_1, line_2, line_3, line_4 ] + 1274: get_matrix.to_nexus_row_array ) 1275: end