-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathThreeLetters.jl
64 lines (57 loc) · 1.14 KB
/
ThreeLetters.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const _res2three = [
"ALA",
"ARG",
"ASN",
"ASP",
"CYS",
"GLN",
"GLU",
"GLY",
"HIS",
"ILE",
"LEU",
"LYS",
"MET",
"PHE",
"PRO",
"SER",
"THR",
"TRP",
"TYR",
"VAL",
" ",
"XAA",
]
"""
This function returns the three letter name of the `Residue`.
```jldoctest
julia> using MIToS.MSA
julia> residue2three(Residue('G'))
"GLY"
```
"""
function residue2three(res::Residue)
int_res = Int(res)
if int_res == 21 || !isvalid(res)
# GAP
throw(ErrorException("Residue($(int_res)) has not three letter name."))
end
_res2three[int_res]
end
"""
It takes a three letter residue name and returns the corresponding `Residue`.
If the name isn't in the MIToS dictionary, a `XAA` is returned.
```jldoctest
julia> using MIToS.MSA
julia> three2residue("ALA")
A
```
"""
function three2residue(res::String)
if length(res) == 3
get(_three2res, uppercase(res), XAA)
else
throw(ErrorException("The residue name should have 3 letters."))
end
end
const _three2res = convert(Dict{String,Residue}, THREE2ONE) # THREE2ONE from MIToS.Utils