Class: IUPAC
- Inherits:
-
String
show all
- Defined in:
- lib/sequence_logo/ytilib/iupac.rb
Constant Summary
collapse
- CODE =
{"A" => "A", "C" => "C", "G" => "G", "T" => "T",
"AG" => "R", "CT" => "Y", "GT" => "K", "AC" => "M",
"CG" => "S", "AT" => "W", "CGT" => "B", "AGT" => "D", "ACT" => "H", "ACG" => "V", "ACGT" => "N"}
- REVCODE =
CODE.invert
Instance Method Summary
collapse
Methods inherited from String
#prev, #prev!, #revcomp, #revcomp!, #to_id
Constructor Details
#initialize(words) ⇒ IUPAC
Returns a new instance of IUPAC.
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/sequence_logo/ytilib/iupac.rb', line 11
def initialize(words)
if words.is_a?(Array)
iupac = (0...words[0].size).collect { |i|
(0...words.size).collect { |j| words[j][i,1] }.uniq.sort.inject("") { |cola, letter| cola += letter }
}.inject("") { |iup, cola|
checkerr("bad letter set #{cola}") { !CODE.has_key?(cola) }
iup += CODE[cola]
}
super(iupac)
elsif words.is_a?(IUPAC)
super(words)
elsif words.is_a?(String)
checkerr("word #{words} has strange characters") { words.tr('ACGTURYKMSWBDHVN', '').size > 0 }
super(words)
end
end
|
Instance Method Details
#==(iupac) ⇒ Object
28
29
30
31
|
# File 'lib/sequence_logo/ytilib/iupac.rb', line 28
def ==(iupac)
return false if self.size != iupac.size
(0...self.size).inject(true) { |result, i| result &= IUPACOM[self[i,1]][iupac[i,1]] }
end
|
#compl ⇒ Object
Also known as:
comp, complement
50
51
52
|
# File 'lib/sequence_logo/ytilib/iupac.rb', line 50
def compl
return self.tr("ACGTRYKMSWBDHVN", "TGCAYRMKSWVHDBN")
end
|
#compl! ⇒ Object
Also known as:
comp!, complement!
54
55
56
57
|
# File 'lib/sequence_logo/ytilib/iupac.rb', line 54
def compl!
self.tr!("ACGTRYKMSWBDHVN", "TGCAYRMKSWVHDBN")
return self
end
|
7
8
9
|
# File 'lib/sequence_logo/ytilib/iupac.rb', line 7
def dup
IUPAC.new(self)
end
|
#include?(iupac) ⇒ Boolean
42
43
44
45
46
47
48
|
# File 'lib/sequence_logo/ytilib/iupac.rb', line 42
def include?(iupac)
return false if self.size < iupac.size || !iupac.is_a?(IUPAC)
(0..self.size-iupac.size).each { |i|
return i if IUPAC.new(self[i,iupac.size]) == iupac
}
return false
end
|
#merge(iupac) ⇒ Object
33
34
35
36
37
38
39
40
|
# File 'lib/sequence_logo/ytilib/iupac.rb', line 33
def merge(iupac)
return nil if self.size != iupac.size
res = (0...self.size).inject("") { |res, i|
merges = REVCODE[self[i,1]].split(//).concat(REVCODE[iupac[i,1]].split(//)).uniq.sort.inject("") { |s, c| s += c}
res << CODE[merges]
}
return IUPAC.new(res)
end
|
60
61
62
|
# File 'lib/sequence_logo/ytilib/iupac.rb', line 60
def reverse
return IUPAC.new(reverse_string)
end
|
#reverse_string ⇒ Object
59
|
# File 'lib/sequence_logo/ytilib/iupac.rb', line 59
alias reverse_string reverse
|