Class: Mapper::CodonGray
Overview
Gray-coded representation. This representation modifies the standard GE mapping with the Gray transcription.
See wwwilson.wordpress.com/files/2009/01/search-neutral-evol-and-mapping.pdf
Instance Attribute Summary
Attributes inherited from CodonMod
Instance Method Summary (collapse)
-
- (Object) bit_size=(bit_size)
Set the number of bits per codon.
-
- (Object) generate(numof_choices, index, dummy = nil)
Create the codon from the index of the choice and number of choices.
-
- (CodonGray) initialize(bits = 8)
constructor
Initialise a codon representation.
-
- (Object) interpret(numof_choices, codon, dummy = nil)
Interpret the codon given a number of choices.
-
- (Object) raw_read(codon)
Read a raw codon value.
Methods inherited from CodonMod
#mutate_bit, #rand_gen, #valid_codon?
Constructor Details
- (CodonGray) initialize(bits = 8)
Initialise a codon representation. bits is the number of bits per one codon.
15 16 17 18 |
# File '../lib/codon_gray.rb', line 15 def initialize( bits=8 ) super self.bit_size = bits end |
Instance Method Details
- (Object) bit_size=(bit_size)
Set the number of bits per codon.
21 22 23 24 25 26 27 28 29 30 31 32 |
# File '../lib/codon_gray.rb', line 21 def bit_size= bit_size super x = ['0','1'] (bit_size-1).times do y = (x.map { |i| '0'+i }).concat( x.reverse.map { |i| '1'+i } ) x=y end @gray = x.map { |i| i.to_i(2) } @reverse = [] @gray.each_with_index { |g,i| @reverse[g] = i } end |
- (Object) generate(numof_choices, index, dummy = nil)
Create the codon from the index of the choice and number of choices. See CodonMod#generate.
42 43 44 |
# File '../lib/codon_gray.rb', line 42 def generate( numof_choices, index, dummy=nil ) @gray[super] end |
- (Object) interpret(numof_choices, codon, dummy = nil)
Interpret the codon given a number of choices. See CodonMod#interpret.
36 37 38 |
# File '../lib/codon_gray.rb', line 36 def interpret( numof_choices, codon, dummy=nil ) super( numof_choices, @reverse[codon] ) end |
- (Object) raw_read(codon)
Read a raw codon value
47 48 49 |
# File '../lib/codon_gray.rb', line 47 def raw_read codon @reverse[codon] end |