Class: Bioinform::ComplementableAlphabet
- Inherits:
-
Object
- Object
- Bioinform::ComplementableAlphabet
- Defined in:
- lib/bioinform/alphabet.rb
Overview
alphabets for DNA/RNA (which do have complements)
Instance Attribute Summary collapse
-
#alphabet ⇒ Object
readonly
Returns the value of attribute alphabet.
-
#complement_alphabet ⇒ Object
readonly
Returns the value of attribute complement_alphabet.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #complement_index(index) ⇒ Object
- #complement_letter(letter) ⇒ Object
- #each_letter(&block) ⇒ Object
- #each_letter_index(&block) ⇒ Object
- #index_by_letter(letter) ⇒ Object
-
#initialize(alphabet, complements) ⇒ ComplementableAlphabet
constructor
ComplementableAlphabet.new(, [:T,:G,:C,:A]).
- #letter_by_index(index) ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(alphabet, complements) ⇒ ComplementableAlphabet
ComplementableAlphabet.new(, [:T,:G,:C,:A])
10 11 12 13 14 15 16 17 18 |
# File 'lib/bioinform/alphabet.rb', line 10 def initialize(alphabet, complements) @alphabet = alphabet.map{|letter| letter.upcase.to_sym } @complement_alphabet = complements.map{|letter| letter.upcase.to_sym } @complements_by_letters = Support.various_key_value_case_types( Hash[ @alphabet.zip(@complement_alphabet) ] ) @index_by_letter = Support.various_key_case_types(Support.element_indices(@alphabet)) raise Error, "Complement's complement should be original letter" unless valid? end |
Instance Attribute Details
#alphabet ⇒ Object (readonly)
Returns the value of attribute alphabet.
7 8 9 |
# File 'lib/bioinform/alphabet.rb', line 7 def alphabet @alphabet end |
#complement_alphabet ⇒ Object (readonly)
Returns the value of attribute complement_alphabet.
7 8 9 |
# File 'lib/bioinform/alphabet.rb', line 7 def complement_alphabet @complement_alphabet end |
Instance Method Details
#==(other) ⇒ Object
57 58 59 |
# File 'lib/bioinform/alphabet.rb', line 57 def ==(other) @alphabet == other.alphabet && @complement_alphabet == other.complement_alphabet end |
#complement_index(index) ⇒ Object
52 53 54 55 |
# File 'lib/bioinform/alphabet.rb', line 52 def complement_index(index) letter = @complement_alphabet[index] || raise(Error, "Unknown letter-index #{index}") @index_by_letter[letter] end |
#complement_letter(letter) ⇒ Object
48 49 50 |
# File 'lib/bioinform/alphabet.rb', line 48 def complement_letter(letter) @complements_by_letters[letter] || raise(Error, "Unknown letter #{letter}") end |
#each_letter(&block) ⇒ Object
32 33 34 |
# File 'lib/bioinform/alphabet.rb', line 32 def each_letter(&block) @alphabet.each(&block) end |
#each_letter_index(&block) ⇒ Object
36 37 38 |
# File 'lib/bioinform/alphabet.rb', line 36 def each_letter_index(&block) @alphabet.each_index(&block) end |
#index_by_letter(letter) ⇒ Object
44 45 46 |
# File 'lib/bioinform/alphabet.rb', line 44 def index_by_letter(letter) @index_by_letter[letter] || raise(Error, "Unknown letter #{letter}") end |
#letter_by_index(index) ⇒ Object
40 41 42 |
# File 'lib/bioinform/alphabet.rb', line 40 def letter_by_index(index) @alphabet[index] || raise(Error, "Unknown letter-index #{index}") end |
#size ⇒ Object
28 29 30 |
# File 'lib/bioinform/alphabet.rb', line 28 def size @alphabet.size end |