Module: Mapper::ConstantsInGenotype
- Included in:
- DepthLocusEmbConsts
- Defined in:
- ../lib/mapper_constants.rb
Overview
See Mapper::DepthLocusEmbConsts for details.
Defined Under Namespace
Classes: EmbeddedConstantData
Instance Attribute Summary (collapse)
-
- (Object) embedded
readonly
Returns the value of attribute embedded.
Instance Method Summary (collapse)
- - (Object) embedded_constants=(config)
- - (Object) modify_expansion_base(exp, genome)
- - (Object) modify_expansion_generate(exp, genome)
Instance Attribute Details
- (Object) embedded (readonly)
Returns the value of attribute embedded
23 24 25 |
# File '../lib/mapper_constants.rb', line 23 def @embedded end |
Instance Method Details
- (Object) embedded_constants=(config)
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File '../lib/mapper_constants.rb', line 25 def config @embedded = {} config.each_pair do |name,params| raise "ConstantsInGenotype: missing min for constant '#{name}'" unless params.has_key? 'min' min = params['min'] raise "ConstantsInGenotype: missing max for constant '#{name}'" unless params.has_key? 'max' max = params['max'] codons = params.has_key?('codons') ? params['codons'] : 1 type = (min.integer? and max.integer?) ? Integer : Float size = 2 ** (@codon.bit_size * codons) step = (max - min).to_f / (size-1) @embedded[name] = EmbeddedConstantData.new( type, codons, min, step ) end end |
- (Object) modify_expansion_base(exp, genome)
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File '../lib/mapper_constants.rb', line 43 def modify_expansion_base( exp, genome ) return unless defined? @embedded exp.each do |token| next unless token.type == :literal found = @embedded.fetch( token.data, nil ) next if found.nil? index = 0 found.codons.times do index <<= @codon.bit_size position = @used_length.divmod( genome.size ).last @used_length += 1 index += @codon.raw_read genome.at(position) end token.data = found.mapping(index).to_s end end |
- (Object) modify_expansion_generate(exp, genome)
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File '../lib/mapper_constants.rb', line 64 def modify_expansion_generate( exp, genome ) return unless defined? @embedded exp.each do |token| next unless token.type == :literal found = @embedded.fetch( token.data, nil ) next if found.nil? index = 0 found.codons.times do index <<= @codon.bit_size value = @codon.rand_gen index += value genome.push value end token.data = found.mapping(index).to_s end end |