Class: Nucleotide::Translate

Inherits:
Object
  • Object
show all
Includes:
Bio::Big::TranslationAdapter
Defined in:
lib/bigbio/sequence/translate.rb

Constant Summary

Constants included from Bio::Big::TranslationAdapter

Bio::Big::TranslationAdapter::VALID_FRAME_VALUES

Instance Method Summary collapse

Methods included from Bio::Big::TranslationAdapter

pre_translate, translate, translation_table

Constructor Details

#initialize(table) ⇒ Translate

Table can be either an id (integer) or a Biolib::Emboss TrnTable



13
14
15
16
17
18
19
20
# File 'lib/bigbio/sequence/translate.rb', line 13

def initialize table 
  table = 0 if table == nil
  if table.kind_of? Numeric
    @trn_table = Bio::Big::TranslationAdapter.translation_table(table)
  else
    @trn_table = table
  end
end

Instance Method Details

#aa_6_frames(seq) ⇒ Object

Return all six reading frames as an Array - ordered as frames [1,2,3,-1,-2,-3] with as tuples [frame, AAsequence].

Note that the nucleotide sequence does not get modified.



27
28
29
30
31
32
33
34
35
36
# File 'lib/bigbio/sequence/translate.rb', line 27

def aa_6_frames seq
  res = []
  # remove white space
  seq = seq.gsub(/\s/,'')
  [1,2,3,-1,-2,-3].each do | frame |
    aa = Bio::Big::TranslationAdapter.translate(@trn_table,frame,seq)
    res.push({:frame => frame, :sequence => aa})
  end
  res
end

#aa_forward_frames(seq) ⇒ Object

Return all forward reading frames as an Array - ordered as frames [1,2,3] with as tuples [frame, AAsequence]



40
41
42
43
44
45
46
47
48
49
# File 'lib/bigbio/sequence/translate.rb', line 40

def aa_forward_frames seq
  res = []
  # remove white space
  seq = seq.gsub(/\s/,'')
  [1,2,3].each do | frame |
    aa = Bio::Big::TranslationAdapter.translate(@trn_table,frame,seq)
    res.push({:frame => frame, :sequence => aa})
  end
  res
end