-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathprepare_diann_parameters.py
More file actions
executable file
·109 lines (95 loc) · 3.68 KB
/
prepare_diann_parameters.py
File metadata and controls
executable file
·109 lines (95 loc) · 3.68 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/env python
import re
import click
from sdrf_pipelines.openms.unimod import UnimodDatabase
CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])
@click.group(context_settings=CONTEXT_SETTINGS)
def cli():
pass
@click.command('generate')
@click.option("--enzyme", "-e", help="")
@click.option("--fix_mod", "-f", help="")
@click.option("--var_mod", "-v", help="")
@click.option("--precursor_tolerence", "-p", help="")
@click.option("--precursor_tolerence_unit", "-pu", help="")
@click.option("--fragment_tolerence", "-fr", help="")
@click.option("--fragment_tolerence_unit", "-fu", help="")
@click.pass_context
def generate_cfg(ctx, enzyme, fix_mod, var_mod, precursor_tolerence, precursor_tolerence_unit, fragment_tolerence, fragment_tolerence_unit):
cut = enzyme_cut(enzyme)
unimod_database = UnimodDatabase()
fix_ptm, var_ptm = convert_mod(unimod_database, fix_mod, var_mod)
var_ptm_str = " --var-mod "
fix_ptm_str = " --fixed-mod "
diann_fix_ptm = ""
diann_var_ptm = ""
for mod in fix_ptm:
diann_fix_ptm += (fix_ptm_str + mod)
for mod in var_ptm:
diann_var_ptm += (var_ptm_str + mod)
with open("diann_config.cfg", "w") as f:
f.write("--cut " + cut + diann_fix_ptm + diann_var_ptm)
def convert_mod(unimod_database, fix_mod, var_mod):
pattern = re.compile("\((.*?)\)")
var_ptm = []
fix_ptm = []
if fix_mod != "":
for mod in fix_mod.split(","):
tag = 0
for m in unimod_database.modifications:
if m.get_name() == mod.split(" ")[0]:
diann_mod = m.get_name() + "," + str(m._delta_mono_mass)
tag = 1
break
if tag == 0:
print("Warning: Currently only supported unimod modifications for DIA pipeline. Skipped: " + mod)
continue
site = re.findall(pattern, " ".join(mod.split(" ")[1:]))[0]
if site == "Protein N-term":
site = "*n"
elif site == "N-term":
site = "n"
if "TMT" in diann_mod or "Label" in diann_mod or "iTRAQ" in diann_mod or "mTRAQ" in diann_mod:
fix_ptm.append(diann_mod + "," + site + "," + "label")
else:
fix_ptm.append(diann_mod + "," + site)
if var_mod != "":
for mod in var_mod.split(","):
tag = 0
for m in unimod_database.modifications:
if m.get_name() == mod.split(" ")[0]:
diann_mod = m.get_name() + "," + str(m._delta_mono_mass)
tag = 1
break
if tag == 0:
print("Warning: Currently only supported unimod modifications for DIA pipeline. Skipped: " + mod)
continue
site = re.findall(pattern, " ".join(mod.split(" ")[1:]))[0]
if site == "Protein N-term":
site = "*n"
elif site == "N-term":
site = "n"
if "TMT" in diann_mod or "Label" in diann_mod or "iTRAQ" in diann_mod or "mTRAQ" in diann_mod:
var_ptm.append(diann_mod + "," + site + "," + "label")
else:
var_ptm.append(diann_mod + "," + site)
return fix_ptm, var_ptm
def enzyme_cut(enzyme):
if enzyme == "Trypsin":
cut = "K*,R*,!*P"
elif enzyme == "Trypsin/P":
cut = "K*,R*,*P"
elif enzyme == "Arg-C":
cut = "R*,!*P"
elif enzyme == "Asp-N":
cut = "*B,*D"
elif enzyme == "Chymotrypsin":
cut = "F*,W*,Y*,L*,!*P"
elif enzyme == "Lys-C":
cut="K*,!*P"
else:
cut = "--cut"
return cut
cli.add_command(generate_cfg)
if __name__ == "__main__":
cli()