Class: Bio::BioAlignment::CodonSequence

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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, options = { :codon_table => 1 }
  @id = id
  @seq = []
  @codon_table = options[: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

#idObject (readonly)

Returns the value of attribute id.



74
75
76
# File 'lib/bio-alignment/codonsequence.rb', line 74

def id
  @id
end

#seqObject (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

#eachObject



95
96
97
# File 'lib/bio-alignment/codonsequence.rb', line 95

def each
  @seq.each { | codon | yield codon }
end

#empty_copyObject



114
115
116
# File 'lib/bio-alignment/codonsequence.rb', line 114

def empty_copy
  CodonSequence.new(@id,"")
end

#lengthObject



91
92
93
# File 'lib/bio-alignment/codonsequence.rb', line 91

def length
  @seq.length
end

#to_aaObject



110
111
112
# File 'lib/bio-alignment/codonsequence.rb', line 110

def to_aa
  @seq.map { |codon| codon.to_aa }.join('')
end

#to_elementsObject

Return Sequence (string) as an Elements object



123
124
125
# File 'lib/bio-alignment/codonsequence.rb', line 123

def to_elements
  self
end

#to_ntObject

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_sObject

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