fatmacankara commited on
Commit
8d02cb5
1 Parent(s): a999cff

Create utils.py

Browse files
Files changed (1) hide show
  1. code/utils.py +70 -0
code/utils.py ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ def threeToOne(variant):
2
+ if variant == "ALA":
3
+ variant = "A"
4
+ elif variant == "ARG":
5
+ variant = "R"
6
+ elif variant == "VAL":
7
+ variant = "V"
8
+ elif variant == "GLU":
9
+ variant = "E"
10
+ elif variant == "PRO":
11
+ variant = "P"
12
+ elif variant == "LEU":
13
+ variant = "L"
14
+ elif variant == "GLY":
15
+ variant = "G"
16
+ elif variant == "ASN":
17
+ variant = "N"
18
+ elif variant == "SER":
19
+ variant = "S"
20
+ elif variant == "GLN":
21
+ variant = "Q"
22
+ elif variant == "THR":
23
+ variant = "T"
24
+ elif variant == "MET":
25
+ variant = "M"
26
+ elif variant == "LYS":
27
+ variant = "K"
28
+ elif variant == "ASP":
29
+ variant = "D"
30
+ elif variant == "ILE":
31
+ variant = "I"
32
+ elif variant == "PHE":
33
+ variant = "F"
34
+ elif variant == "TRP":
35
+ variant = "W"
36
+ elif variant == "TYR":
37
+ variant = "Y"
38
+ elif variant == "HIS":
39
+ variant = "H"
40
+ elif variant == "CYS":
41
+ variant = "C"
42
+ elif variant == 'UNK':
43
+ variant = 'X'
44
+ elif variant == 'ASX':
45
+ variant = 'O'
46
+ return (variant)
47
+
48
+
49
+
50
+ def convert_non_standard_amino_acids(sequence):
51
+ """
52
+ Convert non-standard or ambiguous amino acid codes to their closest relatives.
53
+ """
54
+
55
+ # Define a dictionary to map non-standard codes to standard amino acids
56
+ conversion_dict = {
57
+ 'B': 'D', # Aspartic Acid (D) is often used for B (Asx)
58
+ 'Z': 'E', # Glutamic Acid (E) is often used for Z (Glx)
59
+ 'X': 'A', # Alanine (A) is a common placeholder for unknown/ambiguous
60
+ 'U': 'C', # Cysteine (C) is often used for Selenocysteine (U)
61
+ 'J': 'L', # Leucine (L) is often used for J (Leu/Ile)
62
+ 'O': 'K', # Lysine (K) is often used for O (Pyrrolysine)
63
+ # '*' or 'Stop' represents a stop codon; you may replace with '' to remove
64
+ '*': '',
65
+ }
66
+
67
+ # Replace non-standard codes with their closest relatives
68
+ converted_sequence = ''.join([conversion_dict.get(aa, aa) for aa in sequence])
69
+
70
+ return converted_sequence