| Class | Bio::Nexus::CharactersBlock |
| In: |
lib/bio/db/nexus.rb
|
| Parent: | GenericBlock |
Bio::Nexus::CharactersBlock represents a characters nexus block.
Begin Characters;
Dimensions NChar=20
NTax=4;
Format DataType=DNA
Missing=x
Gap=- MatchChar=.;
Matrix
fish ACATA GAGGG TACCT CTAAG
frog ACTTA GAGGC TACCT CTAGC
snake ACTCA CTGGG TACCT TTGCG
mouse ACTCA GACGG TACCT TTGCG;
End;
require 'bio/db/nexus' # Create a new parser: nexus = Bio::Nexus.new( nexus_data_as_string ) # Get first characters block (same methods as Nexus::DataBlock except # it lacks get_taxa method): characters_block = nexus.get_characters_blocks[ 0 ]
| MISSING | = | "Missing" |
| GAP | = | "Gap" |
| MATCHCHAR | = | "MatchChar" |
Creates a new CharactersBlock object named ‘name’.
Arguments:
# File lib/bio/db/nexus.rb, line 951
951: def initialize( name )
952: super( name )
953: @number_of_taxa = 0
954: @number_of_characters = 0
955: @data_type = String.new
956: @gap_character = String.new
957: @missing = String.new
958: @match_character = String.new
959: @matrix = NexusMatrix.new
960: end
Gets the matrix.
| Returns: | Bio::Nexus::NexusMatrix |
# File lib/bio/db/nexus.rb, line 1046
1046: def get_matrix
1047: @matrix
1048: end
Gets the "number of characters" property.
| Returns: | Integer |
# File lib/bio/db/nexus.rb, line 1011
1011: def get_number_of_characters
1012: @number_of_characters
1013: end
Gets the "number of taxa" property.
| Returns: | Integer |
# File lib/bio/db/nexus.rb, line 1003
1003: def get_number_of_taxa
1004: @number_of_taxa
1005: end
Returns the String in the matrix at row ‘row’ and column 0, which usually is interpreted as a sequence name (if the matrix contains molecular sequence characters).
Arguments:
| Returns: | String |
# File lib/bio/db/nexus.rb, line 1084
1084: def get_row_name( row )
1085: get_matrix.get_name( row )
1086: end
Returns the characters in the matrix at row ‘row’ as Bio::Sequence object. Column 0 of the matrix is set as the definition of the Bio::Sequence object.
Arguments:
| Returns: | Bio::Sequence |
# File lib/bio/db/nexus.rb, line 1072
1072: def get_sequence( row )
1073: create_sequence( get_characters_string( row ), get_row_name( row ) )
1074: end
Returns character data as Bio::Sequence object Array for matrix rows named ‘name’.
Arguments:
| Returns: | Bio::Sequence |
# File lib/bio/db/nexus.rb, line 1056
1056: def get_sequences_by_name( name )
1057: seq_strs = get_characters_strings_by_name( name )
1058: seqs = Array.new
1059: seq_strs.each do | seq_str |
1060: seqs.push( create_sequence( seq_str, name ) )
1061: end
1062: seqs
1063: end
Sets the matrix.
Arguments:
# File lib/bio/db/nexus.rb, line 1162
1162: def set_matrix( matrix )
1163: @matrix = matrix
1164: end
Sets the "number of characters" property.
Arguments:
# File lib/bio/db/nexus.rb, line 1122
1122: def set_number_of_characters( number_of_characters )
1123: @number_of_characters = number_of_characters
1124: end
Sets the "number of taxa" property.
Arguments:
# File lib/bio/db/nexus.rb, line 1114
1114: def set_number_of_taxa( number_of_taxa )
1115: @number_of_taxa = number_of_taxa
1116: end
Returns a String describing this block as nexus formatted data.
| Returns: | String |
# File lib/bio/db/nexus.rb, line 966
966: def to_nexus
967: line_1 = String.new
968: line_1 << DIMENSIONS
969: if ( Nexus::Util::larger_than_zero( get_number_of_taxa ) )
970: line_1 << " " << NTAX << "=" << get_number_of_taxa
971: end
972: if ( Nexus::Util::larger_than_zero( get_number_of_characters ) )
973: line_1 << " " << NCHAR << "=" << get_number_of_characters
974: end
975: line_1 << DELIMITER
976:
977: line_2 = String.new
978: line_2 << FORMAT
979: if ( Nexus::Util::longer_than_zero( get_datatype ) )
980: line_2 << " " << DATATYPE << "=" << get_datatype
981: end
982: if ( Nexus::Util::longer_than_zero( get_missing ) )
983: line_2 << " " << MISSING << "=" << get_missing
984: end
985: if ( Nexus::Util::longer_than_zero( get_gap_character ) )
986: line_2 << " " << GAP << "=" << get_gap_character
987: end
988: if ( Nexus::Util::longer_than_zero( get_match_character ) )
989: line_2 << " " << MATCHCHAR << "=" << get_match_character
990: end
991: line_2 << DELIMITER
992:
993: line_3 = String.new
994: line_3 << MATRIX
995: Nexus::Util::to_nexus_helper( CHARACTERS_BLOCK, [ line_1, line_2, line_3 ] +
996: get_matrix.to_nexus_row_array )
997: end