Class: Bio::BioAlignment::CodonSequence
- Inherits:
-
Object
- Object
- Bio::BioAlignment::CodonSequence
- Includes:
- Enumerable
- Defined in:
- lib/bio-alignment/codonsequence.rb
Overview
A CodonSequence supports the concept of codons (triple nucleotides) for an alignment. A codon table number can be passed in for translation of nucleotide sequences. This is the same table used in BioRuby.
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#seq ⇒ Object
readonly
Returns the value of attribute seq.
Instance Method Summary collapse
- #<<(codon) ⇒ Object
- #[](index) ⇒ Object
- #each ⇒ Object
- #empty_copy ⇒ Object
-
#initialize(id, seq, options = { :codon_table => 1 }) ⇒ CodonSequence
constructor
A new instance of CodonSequence.
- #length ⇒ Object
- #to_aa ⇒ Object
-
#to_elements ⇒ Object
Return Sequence (string) as an Elements object.
-
#to_nt ⇒ Object
extra methods.
-
#to_s ⇒ Object
Output codon style.
Constructor Details
#initialize(id, seq, options = { :codon_table => 1 }) ⇒ CodonSequence
Returns a new instance of CodonSequence.
75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/bio-alignment/codonsequence.rb', line 75 def initialize id, seq, = { :codon_table => 1 } @id = id @seq = [] @codon_table = [:codon_table] seq.scan(/\S\S\S/).each do | codon | @seq << Codon.new(codon, @codon_table) end @id.freeze @codon_table.freeze # @seq is not immutable, as we can add new codes to the list end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
74 75 76 |
# File 'lib/bio-alignment/codonsequence.rb', line 74 def id @id end |
#seq ⇒ Object (readonly)
Returns the value of attribute seq.
74 75 76 |
# File 'lib/bio-alignment/codonsequence.rb', line 74 def seq @seq end |
Instance Method Details
#<<(codon) ⇒ Object
118 119 120 |
# File 'lib/bio-alignment/codonsequence.rb', line 118 def << codon @seq << codon end |
#[](index) ⇒ Object
87 88 89 |
# File 'lib/bio-alignment/codonsequence.rb', line 87 def [] index @seq[index] end |
#each ⇒ Object
95 96 97 |
# File 'lib/bio-alignment/codonsequence.rb', line 95 def each @seq.each { | codon | yield codon } end |
#empty_copy ⇒ Object
114 115 116 |
# File 'lib/bio-alignment/codonsequence.rb', line 114 def empty_copy CodonSequence.new(@id,"") end |
#length ⇒ Object
91 92 93 |
# File 'lib/bio-alignment/codonsequence.rb', line 91 def length @seq.length end |
#to_aa ⇒ Object
110 111 112 |
# File 'lib/bio-alignment/codonsequence.rb', line 110 def to_aa @seq.map { |codon| codon.to_aa }.join('') end |
#to_elements ⇒ Object
Return Sequence (string) as an Elements object
123 124 125 |
# File 'lib/bio-alignment/codonsequence.rb', line 123 def to_elements self end |
#to_nt ⇒ Object
extra methods
106 107 108 |
# File 'lib/bio-alignment/codonsequence.rb', line 106 def to_nt @seq.map { |codon| codon.to_s }.join('') end |
#to_s ⇒ Object
Output codon style
100 101 102 |
# File 'lib/bio-alignment/codonsequence.rb', line 100 def to_s @seq.map { |codon| codon.to_s }.join(' ') end |