Class: Bio::NucleicAcid

Inherits:
Object
  • Object
show all
Defined in:
lib/bio/BIOExtensions.rb

Constant Summary collapse

IUPAC_CODES =
{

  'y'	=> 'ct',
  'r'	=> 'ag',
  'w'	=> 'at',
  's'	=> 'cg',
  'k'	=> 'gt',
  'm'	=> 'ac',

  'b'	=> 'cgt',
  'd'	=> 'agt',
  'h'	=> 'act',
  'v'	=> 'acg',

  'n'	=> 'acgt',

  'a'	=> 'a',
  't'	=> 't',
  'g'	=> 'g',
  'c'	=> 'c',
  'u'	=> 'u',

  'ct' => 'y',
  'ag' => 'r',
  'at' => 'w',
  'cg' => 's',
  'gt' => 'k',
  'ac' => 'm',

  'cgt' => 'b',
  'agt' => 'd',
  'act' => 'h',
  'acg' => 'v',

  'acgt' => 'n'
}

Class Method Summary collapse

Class Method Details

.is_unambiguous(base) ⇒ Object



41
42
43
# File 'lib/bio/BIOExtensions.rb', line 41

def self.is_unambiguous(base)
  "acgtACGT".match(base)
end

.is_valid(code, base) ⇒ Object



54
55
56
# File 'lib/bio/BIOExtensions.rb', line 54

def self.is_valid(code, base)
  IUPAC_CODES[code.downcase].chars.include? base.downcase
end

.to_IUAPC(bases) ⇒ Object



45
46
47
48
49
50
51
52
# File 'lib/bio/BIOExtensions.rb', line 45

def self.to_IUAPC(bases)    
  base = IUPAC_CODES[bases.to_s.downcase.chars.sort.uniq.join]
  if base == nil
    p "Invalid base! #{base}"
    base = 'n' #This is a patch... as one of the scripts failed here. 
  end
  base.upcase
end