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.



68
69
70
71
72
73
74
75
# File 'lib/bio-alignment/codonsequence.rb', line 68

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.



67
68
69
# File 'lib/bio-alignment/codonsequence.rb', line 67

def id
  @id
end

#seqObject (readonly)

Returns the value of attribute seq.



67
68
69
# File 'lib/bio-alignment/codonsequence.rb', line 67

def seq
  @seq
end

Instance Method Details

#<<(codon) ⇒ Object



107
108
109
# File 'lib/bio-alignment/codonsequence.rb', line 107

def << codon
  @seq << codon
end

#[](index) ⇒ Object



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

def [] index
  @seq[index]
end

#eachObject



85
86
87
# File 'lib/bio-alignment/codonsequence.rb', line 85

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

#empty_copyObject



103
104
105
# File 'lib/bio-alignment/codonsequence.rb', line 103

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

#lengthObject



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

def length
  @seq.length
end

#to_aaObject



99
100
101
# File 'lib/bio-alignment/codonsequence.rb', line 99

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

#to_ntObject

extra methods



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

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

#to_sObject



89
90
91
# File 'lib/bio-alignment/codonsequence.rb', line 89

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