class Bio::NeXML::Characters
A character state matrix. This class is analogous to the characters element of NeXML
.
Attributes
format[RW]
A characters block holds a single format definition
id[RW]
An id should be uniquely scoped in an NeXML
file. It need not be unique globally. It is a compulsory attribute.
label[RW]
A human readable description. Its usage is optional.
matrix[RW]
A characters block holds a single matrix definition
Public Class Methods
new( id, options = {} )
click to toggle source
# File lib/bio/db/nexml/matrix.rb, line 821 def initialize( id, options = {} ) @id = id self.create_format self.create_matrix properties( options ) unless options.empty? block.arity < 1 ? instance_eval( &block ) : block.call( self ) if block_given? end
Public Instance Methods
add_format( format )
click to toggle source
# File lib/bio/db/nexml/matrix.rb, line 829 def add_format( format ) @format = format end
add_matrix( matrix )
click to toggle source
# File lib/bio/db/nexml/matrix.rb, line 833 def add_matrix( matrix ) @matrix = matrix end
create_format( options = {} )
click to toggle source
# File lib/bio/db/nexml/matrix.rb, line 855 def create_format( options = {} ) format = Format.new( options ) states = format.create_states lookup_table = self.lookup state_for_symbol = {} lookup_table.keys.each do |key| if lookup_table[key].length == 1 state = states.create_state( :symbol => key ) state_for_symbol[key] = state end end lookup_table.keys.each do |key| if lookup_table[key].length != 1 state = states.create_state( :symbol => key, :ambiguity => :uncertain ) lookup_table[key].each do |symbol| state.add_member( state_for_symbol[symbol] ) end end end add_format format format end
create_matrix( options = {} )
click to toggle source
# File lib/bio/db/nexml/matrix.rb, line 844 def create_matrix( options = {} ) matrix = nil if self.class.name =~ /Seqs$/ matrix = SeqMatrix.new( options ) else matrix = CellMatrix.new( options ) end add_matrix matrix matrix end
create_raw( string, row = nil )
click to toggle source
# File lib/bio/db/nexml/matrix.rb, line 878 def create_raw( string, row = nil ) matrix = self.matrix format = self.format if row == nil row = matrix.create_row end if row.kind_of? SeqRow sequence = Sequence.new sequence.value = join_sequence split_sequence string row.add_sequence( sequence ) end if row.kind_of? CellRow split_seq = split_sequence string pos = 0 states = format.states.first split_seq.each do |symbol| char = format.chars[pos] if char == nil char = format.create_char( states ) end state = states.get_state_by_symbol( symbol ) if state == nil state = states.create_state( symbol ) end cell = Cell.new char, state row.add_cell cell pos += 1 end end row end
join_sequence( array )
click to toggle source
# File lib/bio/db/nexml/matrix.rb, line 914 def join_sequence( array ) array.join end
split_sequence( string )
click to toggle source
# File lib/bio/db/nexml/matrix.rb, line 910 def split_sequence( string ) string.split(//) end
to_xml()
click to toggle source
# File lib/bio/db/nexml/matrix.rb, line 837 def to_xml node = @@writer.create_node( "characters", @@writer.attributes( self, :id, :"xsi:type", :otus, :label ) ) node << self.format.to_xml node << self.matrix.to_xml node end