Class: Bio::BioAlignment::Codon

Inherits:
Object
  • Object
show all
Includes:
State
Defined in:
lib/bio-alignment/codonsequence.rb

Overview

Codon element for the matrix, used by CodonSequence.

Constant Summary collapse

GAP =
'---'
UNDEFINED =
'XXX'

Instance Attribute Summary collapse

Attributes included from State

#state

Instance Method Summary collapse

Constructor Details

#initialize(codon, codon_table = 1) ⇒ Codon

Returns a new instance of Codon.



15
16
17
18
19
20
# File 'lib/bio-alignment/codonsequence.rb', line 15

def initialize codon, codon_table = 1
  @codon = codon
  @codon_table = codon_table
  @codon.freeze
  @codon_table.freeze
end

Instance Attribute Details

#codon_tableObject (readonly)

Returns the value of attribute codon_table.



12
13
14
# File 'lib/bio-alignment/codonsequence.rb', line 12

def codon_table
  @codon_table
end

Instance Method Details

#==(other) ⇒ Object



38
39
40
# File 'lib/bio-alignment/codonsequence.rb', line 38

def == other
  @codon == other.to_s
end

#gap?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/bio-alignment/codonsequence.rb', line 22

def gap?
  @codon == GAP
end

#to_aaObject

lazily convert to Amino acid (once only)



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/bio-alignment/codonsequence.rb', line 43

def to_aa
  aa = translate
  if not aa
    if gap?
      return '-'
    elsif undefined?
      return UNDEFINED
    else
      raise 'What?'
    end
  end
  aa
end

#to_sObject



34
35
36
# File 'lib/bio-alignment/codonsequence.rb', line 34

def to_s
  @codon
end

#undefined?Boolean

Returns:

  • (Boolean)


26
27
28
29
30
31
32
# File 'lib/bio-alignment/codonsequence.rb', line 26

def undefined?
  aa = translate
  if aa == nil and not gap?
    return true
  end
  false
end