Module: SSW::DNA

Defined in:
lib/ssw/dna.rb

Constant Summary collapse

Elements =
%w[A C G T N].freeze
DNA2INT =
{ 'A' => 0, 'a' => 0,
'C' => 1, 'c' => 1,
'G' => 2, 'g' => 2,
'T' => 3, 't' => 3,
'N' => 4, 'n' => 4 }.freeze
INT2DNA =
{ 0 => 'A', 1 => 'C', 2 => 'G', 3 => 'T', 4 => 'N' }.freeze
DNARC =

reverse complement

{ 'A' => 'T',
'C' => 'G',
'G' => 'C',
'T' => 'A',
'N' => 'N',
'a' => 'T',
'c' => 'G',
'g' => 'C',
't' => 'A',
'n' => 'N' }.freeze

Class Method Summary collapse

Class Method Details

.from_int_array(arr) ⇒ Object

Parameters:

  • int (Array)

    array

Raises:

  • (ArgumentError)


39
40
41
42
43
44
45
# File 'lib/ssw/dna.rb', line 39

def from_int_array(arr)
  raise ArgumentError, 'arr must be an Array' unless arr.is_a? Array

  arr.map do |i|
    INT2DNA[i] || 'N'
  end.join
end

.revcomp(seq) ⇒ Object



47
48
49
50
51
# File 'lib/ssw/dna.rb', line 47

def revcomp(seq)
  seq.each_char.map do |base|
    DNARC[base]
  end.join.reverse
end

.to_int_array(seq) ⇒ Object

Parameters:

  • seq (String)

Raises:

  • (ArgumentError)


30
31
32
33
34
35
36
# File 'lib/ssw/dna.rb', line 30

def to_int_array(seq)
  raise ArgumentError, 'seq must be a string' unless seq.is_a? String

  seq.each_char.map do |base|
    DNA2INT[base] || DNA2INT['N']
  end
end