-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpparse.py
106 lines (91 loc) · 3.72 KB
/
pparse.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
'''
Email: pengyaping21@mails.ucas.ac.cn
Author: pengyaping21
LastEditors: pengyaping21
Date: 2022-06-28 12:07:49
LastEditTime: 2024-11-27 14:38:04
FilePath: \pChem-main\pparse.py
Description: Do not edit
'''
from utils import parameter_pick, parameter_modify, parameter_file_read, pfind_path_find
import os
import shutil
def parameter_select(cfg_path):
parameter_dict = {}
parameter_dict['msmspath'] = []
with open(cfg_path, 'r', encoding='utf-8') as f:
lines = f.readlines()
for line in lines:
if 'msmstype' in line:
parameter_dict['msmstype'] = parameter_pick(line)
if 'msmspath' in line:
parameter_dict['msmspath'].append(parameter_pick(line))
if 'output_path' in line:
parameter_dict['output_path'] = parameter_pick(line)
return parameter_dict
def data_preprocess(cfg_path, current_path):
pparse_file_path = os.path.join(current_path, 'bin')
pfind_file_path = os.path.join(pparse_file_path, 'pFind')
pparse_file_path = os.path.join(pparse_file_path, 'pParse')
pparse_exe_path = os.path.join(pparse_file_path, 'pParse.exe')
parameter_dict = parameter_file_read(cfg_path)
pparse_output_path = os.path.join(os.path.join(
parameter_dict['output_path'], 'source'), 'pParse')
if not os.path.exists(pparse_output_path):
os.makedirs(pparse_output_path)
# 对raw文件进行预处理
for msms_path in parameter_dict['msms_path']:
_, t_msms_path = msms_path.split('=')
t_msms_path = t_msms_path[:-1]
'''
cmd = pparse_exe_path + ' -D ' + t_msms_path + ' -O ' + pparse_output_path
# 切换环境
os.chdir(pparse_file_path)
receive = os.system(cmd)
print(receive)
'''
cmd = pparse_exe_path + ' -D ' + t_msms_path + ' -O ' + pparse_output_path
# 切换环境
os.chdir(pparse_file_path)
receive = os.system(cmd)
print(receive)
pf2_list = os.listdir(pparse_output_path)
pf2_name_list = []
for pf2 in pf2_list:
if pf2[-4:] == '.pf2':
pf2_name_list.append(os.path.join(pparse_output_path, pf2))
print(parameter_dict['msms_path'])
print(pf2_name_list)
for msms_path in parameter_dict['msms_path']:
_, t_msms_path = msms_path.split('=')
shutil.copy2(t_msms_path[:-1], os.path.join(pparse_output_path, os.path.basename(t_msms_path[:-1])))
parameter_dict['msmstype'] = 'PF2'
# assert len(parameter_dict['msms_path']) == len(pf2_name_list)
if len(parameter_dict['msms_path']) != len(pf2_name_list):
print('number of pf2 not equal to msms_path, there may be exist bug.')
pf2_path_list = []
i = 0
for msms_path in parameter_dict['msms_path']:
prefix, _ = msms_path.split('=')
pf2_path_list.append(prefix + '=' + pf2_name_list[i] + '\n')
i += 1
while i < len(pf2_name_list):
pf2_path_list.append('msmspath' + str(i+1)+'='+pf2_name_list[i] + '\n')
i += 1
parameter_dict['msms_path'] = pf2_path_list
# print(parameter_dict)
parameter_dict['close_mass_diff_number'] = 100
parameter_dict['msms_num'] = len(pf2_name_list)
# pyp: 可测试这里的mass_calibration是否对精度计算有作用
parameter_dict['mass_calibration'] = 'True'
# target_path = [os.getcwd()]
# print(parameter_dict)
#pfind_path_find(parameter_dict['pfind_install_path'], target_path)
# parameter_dict['pfind_install_path'] = target_path[1]
parameter_dict['pfind_install_path'] = pfind_file_path
print(parameter_dict)
return parameter_dict
if __name__ == "__main__":
current_path = os.getcwd()
cfg_path = os.path.join(current_path, 'pChem.cfg')
data_preprocess(cfg_path, current_path)