-
Notifications
You must be signed in to change notification settings - Fork 0
/
translator.py
executable file
·83 lines (70 loc) · 2.52 KB
/
translator.py
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env python3
# translator.py is used to translate residue numbers between
# human and mouse enac, because I am just so damn lazy.
import sys
import os
from mutator import process_fastas
from ca_bilder import make_fasta_pairs
fasta_dir = os.path.join(
os.path.split(os.path.realpath(__file__))[0],
'fastas'
)
if not os.path.exists(fasta_dir):
print(f'Put aligned fastas in {fasta_dir}')
sys.exit(1)
aligned_fastas = process_fastas(
os.path.join(fasta_dir, 'aligned*.fasta')
)
m_to_h = {
'a': make_fasta_pairs(
aligned_fastas['mouse_alpha'],
aligned_fastas['human_alpha']
),
'b': make_fasta_pairs(
aligned_fastas['mouse_beta'],
aligned_fastas['human_beta']
),
'g': make_fasta_pairs(
aligned_fastas['mouse_gamma'],
aligned_fastas['human_gamma']
)
}
h_to_m = {
'a': make_fasta_pairs(
aligned_fastas['human_alpha'],
aligned_fastas['mouse_alpha']
),
'b': make_fasta_pairs(
aligned_fastas['human_beta'],
aligned_fastas['mouse_beta']
),
'g': make_fasta_pairs(
aligned_fastas['human_gamma'],
aligned_fastas['mouse_gamma']
)
}
unaligned_fastas = {
'ha': aligned_fastas['human_alpha'],
'hb': aligned_fastas['human_beta'],
'hg': aligned_fastas['human_gamma'],
'ma': aligned_fastas['mouse_alpha'],
'mb': aligned_fastas['mouse_beta'],
'mg': aligned_fastas['mouse_gamma']
}
unaligned_fastas = {key: unaligned_fastas[key].replace('-', '') for key in unaligned_fastas}
def parse_translate(query_string:str):
q_species, q_chain, q_res_id = query_string[0].lower(), query_string[1].lower(), query_string[2:]
q_resname = unaligned_fastas[q_species + q_chain][int(q_res_id) - 1]
search_dict = h_to_m if q_species == 'h' else m_to_h
reply_species = 'h' if q_species == 'm' else 'm'
reply_id = search_dict[q_chain][q_res_id]
reply_resname = unaligned_fastas[reply_species + q_chain][int(reply_id) - 1]
print_qspecies = q_species.replace('m', 'Mouse').replace('h', 'Human')
print_rspecies = reply_species.replace('m', 'Mouse').replace('h', 'Human')
print_chain = q_chain.replace('b', '\u03B2').replace('a', '\u03B1').replace('g', '\u03B3')
print(f'{print_qspecies} {print_chain}{q_resname.upper()}{q_res_id} => {print_rspecies} {print_chain}{reply_resname.upper()}{reply_id}')
if __name__ == '__main__':
if len(sys.argv) != 2:
print('Species, chain, number: mA230 for mouse alpha 230')
sys.exit()
parse_translate(sys.argv[1])