-
Notifications
You must be signed in to change notification settings - Fork 3
/
mapping_functions.py
190 lines (156 loc) · 6.88 KB
/
mapping_functions.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
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
import os
import re
from datetime import date
def map_data_ultraflex(dest_path, logger):
"""
input: \\\\fgcz-biobeamer.uzh.ch\\Data2SAN\\p65\\Proteomics\\ULTRAFLEXTREME_1\\analytic_20200924\\D_Eris_22708
output: \\\\fgcz-biobeamer.uzh.ch\\Data2San\\p22708\\Proteomics\\ULTRAFLEXTREME_1\\analytic_20200924_D_Eris_22708\\
"""
pattern_dest = "^\\\\\\\\fgcz-biobeamer.uzh.ch\\\\Data2San\\\\p65\\\\(Proteomics|Metabolomics)\\\\[A-Z]{1,20}_[1-9]{1,1}\\\\[a-z]{1,30}_([0-9]{8,8})\\\\([A-Za-z_]+)_([0-9]{5,5})\S+$"
#"[-0-9a-zA-Z\\_\/\.]" #does not match with.
regex_dest = re.compile(pattern_dest)
match_dest = regex_dest.match(dest_path)
if match_dest:
date = match_dest.group(2)
name = match_dest.group(3)
container_id = match_dest.group(4)
order_id = "p" + container_id
dest_path = dest_path.replace("p65", order_id)
dest_path = dest_path.replace(date + "\\" + name, date + "_" + name)
dest_path = os.path.normpath(dest_path)
return dest_path
else:
logger.error("could not match : " + dest_path)
return None
def map_data_rapiflex(dest_path, logger):
"""
input: \\\\fgcz-biobeamer.uzh.ch\\Data2San\\orders\\Proteomics\\RAPIFLEX_1\\C28830_nanni_20220701\\LN_1568
output: \\\\fgcz-biobeamer.uzh.ch\\Data2San\\p28830\\Proteomics\\RAPIFLEX_1\\nanni_20201021\\N_1568
"""
pattern_dest = "^\\\\\\\\fgcz-biobeamer.uzh.ch\\\\Data2San\\\\orders\\\\(Proteomics|Metabolomics)\\\\[A-Z]{1,20}_[0-9]{1,2}\\\\(C[0-9]{3,6})_[a-z]{1,30}_[0-9]{8}\S[^%]+$"
#"[-0-9a-zA-Z\\_\/\.]" #does not match with.
regex_dest = re.compile(pattern_dest)
match_dest = regex_dest.match(dest_path)
if match_dest:
container_id = match_dest.group(2)
order_id = container_id.replace("C", "p")
dest_path = dest_path.replace("orders", order_id)
dest_path = dest_path.replace(container_id + "_", "")
dest_path = os.path.normpath(dest_path)
return dest_path
else:
return dest_path
def map_data_G2HD_2(path, logger):
"""
input:
output:
"""
pattern_dest = "^(\\\\\\\\fgcz-biobeamer.uzh.ch\\\\Data2San\\\\p[0-9]{1,4}\\\\[A-Za-z]{1,20}\\\\[A-Z0-9_]+)(\.PRO\\\\Data\\\\)([0-9]{8,8})(.+)$"
regex_dest = re.compile(pattern_dest)
match_dest = regex_dest.match(path)
if match_dest:
mg_path = match_dest.group(1)
mg_date = match_dest.group(3)
mg_folder = match_dest.group(4)
path = os.path.normpath(
"{path}\\analytic_{date}\\{date}{folder}".format(
path=mg_path,
date=mg_date,
folder=mg_folder))
return path
else:
return None
def map_data_order_QDA_G2HD(path, logger):
res = map_data_QDA(path, logger)
if res is None:
res = map_data_G2HD_2(path, logger)
if res is None:
logger.error('Could not apply mapping function to {path}. Raising exception'.format(path=path))
raise ValueError('Could not apply mapping function')
return res
def map_data_QDA(path, logger):
"""
input: '\\\\fgcz-biobeamer.fgcz-net.unizh.ch\\Data2San\\p65\\Proteomics\\QDA_1.PRO\\Data\\20201015_C22916_BSA.raw'
input: "\\fgcz-biobeamer.uzh.ch\\Data2San\p65\Proteomics\QDA_1.PRO\Data\20201021_C22959_P16G08-Atto488_1.raw"
output: "\\fgcz-biobeamer.uzh.ch\Data2San\p22959\Proteomics\QDA_1\analytic_20201021\20201021_C22959_P16G08-Atto488_1.raw
"""
pattern_dest = "^(\\\\\\\\fgcz-biobeamer.uzh.ch\\\\Data2San\\\\)(p[0-9]{1,4})(\\\\[A-Za-z]{1,20}\\\\[A-Z0-9_]+)(\.PRO\\\\Data\\\\)([0-9]{8,8})_(C[0-9]{2,5})_(.+)$"
regex_dest = re.compile(pattern_dest)
match_dest = regex_dest.match(path)
if match_dest:
mg_path_1 = match_dest.group(1)
mg_path_2 = match_dest.group(3)
mg_date = match_dest.group(5)
mg_container = match_dest.group(6)
mg_folder = match_dest.group(7)
project = mg_container.replace("C", "p")
path = os.path.normpath(
"{path1}{container}{path2}\\analytic_{date}\\{date}_{mg_container}_{folder}".format(
path1=mg_path_1,
container=project,
path2=mg_path_2,
date=mg_date,
mg_container=mg_container,
folder=mg_folder))
return path
else:
return None
def map_data_for_container(dest_path, logger):
"""
input: '\\\\fgcz-biobeamer.fgcz-net.unizh.ch\\Data2San\\20190206HM_11728_C6CYS.raw\\_PROC003.SIG'
'\\\\fgcz-biobeamer.uzh.ch\\Data2San\\orders\\Proteomics\\QEXACTIVE_1\\analytic_20200923\\20200923_004_C22687_S267154_HA-IgG__A.raw'
output: p65/Proteomics/G2HD_2/schesnov_20190000
"""
pattern_dest = "^\\\\\\\\fgcz-biobeamer.uzh.ch\\\\Data2San\\\\orders\\\\[A-Za-z]{1,20}\\\\[A-Z]{1,20}_[0-9]{1,2}\\\\analytic_[0-9]{8}[_0-9A-Za-z]*\\\\[0-9]{8}_(C[0-9]{3,6})_.+$"
regex_dest = re.compile(pattern_dest)
match_dest = regex_dest.match(dest_path)
if match_dest:
order_id = match_dest.group(1)
order_id = order_id.replace("C", "p")
dest_path = dest_path.replace("orders", order_id)
dest_path = os.path.normpath(dest_path)
return dest_path
else:
return dest_path
def map_data_analyst_tripletof_1(path, logger):
"""
input: 'p1000/Data/selevsek_20150119'
output: 'p1000/Proteomics/TRIPLETOF_1/selevsek_20150119'
"""
pattern = ".*(p[0-9]+)\\\\Data\\\\([-0-9a-zA-Z_\\\.]+)$"
regex = re.compile(pattern)
match = regex.match(path)
if match:
return os.path.normpath("{0}/Proteomics/TRIPLETOF_1/{1}".format(match.group(1), match.group(2)))
else:
logger.error('Could not apply mapping function. Raising exception')
raise ValueError('Could not apply mapping function')
return None
def map_data_analyst_qtrap_1(path, logger):
"""
input: 'p1000/Data/selevsek_20150119'
output: 'p1000/Proteomics/TRIPLETOF_1/selevsek_20150119'
"""
pattern = "(.*p[0-9]+)\\\\Data\\\\([-0-9a-zA-Z_\\\.]+)$"
regex = re.compile(pattern)
match = regex.match(path)
if match:
res = "{0}\\Proteomics\\QTRAP_1\\{1}".format(match.group(1), match.group(2))
return res
else:
logger.error('Could not apply mapping function. Raising exception')
raise ValueError('Could not apply mapping function')
return None
def test_mapping_function(logger):
'''
Test mapping
:return: nil
'''
tmp = '\\\\130.60.81.21\\Data2San\\p1001\\Data\\selevsek_20150119\\testdumm.raw'
tmp2 = '\\\\130.60.81.21\\Data2San\\p1001\\Data\\selevsek_20150119\\testdumm2.wiff'
tmp_ = map_data_analyst_qtrap_1(tmp, logger)
if tmp_ != 'p1001\\Proteomics\\QTRAP_1\\selevsek_20150119\\testdumm.raw':
print("mapping failed")
tmp2_ = map_data_analyst_qtrap_1(tmp2, logger)
if tmp2_ != 'p1001\\Proteomics\\QTRAP_1\\selevsek_20150119\\testdumm2.wiff':
print("mapping failed")