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.



64
65
66
67
68
69
70
71
# File 'lib/bio-alignment/codonsequence.rb', line 64

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
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



63
64
65
# File 'lib/bio-alignment/codonsequence.rb', line 63

def id
  @id
end

#seqObject (readonly)

Returns the value of attribute seq.



63
64
65
# File 'lib/bio-alignment/codonsequence.rb', line 63

def seq
  @seq
end

Instance Method Details

#[](index) ⇒ Object



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

def [] index
  @seq[index]
end

#eachObject



77
78
79
# File 'lib/bio-alignment/codonsequence.rb', line 77

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

#to_aaObject



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

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

#to_ntObject

extra methods



87
88
89
# File 'lib/bio-alignment/codonsequence.rb', line 87

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

#to_sObject



81
82
83
# File 'lib/bio-alignment/codonsequence.rb', line 81

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