-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmain.py
More file actions
249 lines (231 loc) · 7.02 KB
/
Copy pathmain.py
File metadata and controls
249 lines (231 loc) · 7.02 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
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
#!/usr/bin/env python3
import argparse
import configparser
import sys
import os
import platform
import numpy as np
# modules
from PCprophet import io_ as io
from PCprophet import collapse as collapse
from PCprophet import generate_features_v2 as generate_features
from PCprophet import hypothesis as hypothesis
from PCprophet import map_to_database as map_to_database
from PCprophet import merge as merge
from PCprophet import differential as differential
from PCprophet import predict as predict
from PCprophet import plots as plots
from PCprophet import validate_input as validate
class ParserHelper(argparse.ArgumentParser):
def error(self, message):
sys.stderr.write('error: %s\n' % message)
self.print_help()
sys.exit(2)
# TODO check os
def get_os():
return platform.system()
def create_config():
'''
parse command line and create .ini file for configuration
'''
parser = ParserHelper(description='Protein Complex Prophet argument')
parser.add_argument(
'-db',
help='protein complex database from CORUM or ppi network in STRING format',
dest='database',
action='store',
default='coreComplexes.txt',
)
# maybe better to add function for generating a dummy sample id?
parser.add_argument(
'-sid',
help='sample ids file',
dest='sample_ids',
default='sample_ids.txt',
action='store',
)
parser.add_argument(
'-output',
help='outfile folder path',
dest='out_folder',
default=r'./Output',
action='store',
)
# TODO change tmp to Output/tmp check resource_path important for windows
parser.add_argument(
'-cal',
help='calibration file no headers tab delimited fractiosn to mw in KDa',
dest='calibration',
default='None',
action='store',
)
parser.add_argument(
'-mw_uniprot',
help='Molecular weight from uniprot',
dest='mwuni',
default='None',
action='store',
)
parser.add_argument(
'-is_ppi',
help='is the -db a protein protein interaction database',
dest='is_ppi',
action='store',
default='False',
choices=['True', 'False'],
)
parser.add_argument(
'-a',
help='use all fractions [1,X]',
dest='all_fract',
action='store',
default='all',
)
parser.add_argument(
'-ma',
help='merge using all complexes or reference only',
dest='merge',
action='store',
choices=['all', 'reference'],
default='all',
)
parser.add_argument(
'-fdr',
help='false discovery rate for novel complexes',
dest='fdr',
action='store',
default=0.5,
type=float,
)
parser.add_argument(
'-co',
help='collapse mode',
choices=['GO', 'CAL', 'SUPER', 'PROB', 'NONE'],
dest='collapse',
default='GO',
action='store',
)
parser.add_argument(
'-sc',
help='score for missing proteins in differential analysis',
dest='score_missing',
action='store',
default=0.5,
type=float,
)
parser.add_argument(
'-mult',
help='Multi processing feature generation',
dest='multi',
action='store',
default='True',
choices=['True', 'False'],
)
parser.add_argument('-w', dest='weight_pred', help='LEGACY', action='store', default=1, type=float)
parser.add_argument('-v', dest='verbose', help='Verbose', action='store', default=1)
parser.add_argument('-skip',
dest='skip',
help='Skip feature generation and complex prediction step',action='store',
default=False)
args = parser.parse_args()
# deal with numpy warnings and so on
if args.verbose == 0:
np.seterr(all='ignore')
else:
pass
# print them
# create config file
config = configparser.ConfigParser()
config['GLOBAL'] = {
'db': args.database,
'sid': args.sample_ids,
'go_obo': io.resource_path('go-basic.obo'),
'sp_go': io.resource_path('tmp_GO_sp_only.txt'),
'output': args.out_folder,
'cal': args.calibration,
'mw': args.mwuni,
'temp': r'./tmp',
'mult': args.multi,
'skip': args.skip
}
config['PREPROCESS'] = {
'is_ppi': args.is_ppi,
'all_fract': args.all_fract,
'merge': args.merge,
}
config['POSTPROCESS'] = {'fdr': args.fdr, 'collapse_mode': args.collapse}
config['DIFFERENTIAL'] = {
'score_missing': args.score_missing,
'weight_pred': args.weight_pred,
'fold_change': '-5,-2,2,5',
'correlation': '0.3,0.9',
'ratio': '-2,-0.5,0.5,2',
'shift': '-10,-5,5,10',
'weight_fold_change': 1,
'weight_correlation': 0.75,
'weight_ratio': 0.25,
'weight_shift': 0.5,
}
# create config ini file for backup
with open('ProphetConfig.conf', 'w') as conf:
config.write(conf)
return config
def preprocessing(infile, config):
#validate.InputTester(infile, 'in').test_file()
map_to_database.runner(
infile=infile,
db=config['GLOBAL']['db'],
is_ppi=config['PREPROCESS']['is_ppi'],
use_fr=config['PREPROCESS']['all_fract'],
)
hypothesis.runner(
infile=infile,
hypothesis=config['PREPROCESS']['merge'],
use_fr=config['PREPROCESS']['all_fract'],
)
# # sample specific folder
tmp_folder = io.file2folder(infile, prefix=config['GLOBAL']['temp'])
merge.runner(base=tmp_folder, mergemode=config['PREPROCESS']['merge'])
generate_features.runner(
tmp_folder,
config['GLOBAL']['go_obo'],
config['GLOBAL']['sp_go'],
config['GLOBAL']['mult']
)
predict.runner(tmp_folder)
return True
def main():
config = create_config()
validate.InputTester(config['GLOBAL']['db'], 'db').test_file()
validate.InputTester(config['GLOBAL']['sid'], 'ids').test_file()
files = io.read_sample_ids(config['GLOBAL']['sid'])
files = [os.path.abspath(x) for x in files.keys()]
# skip feature generation
if config['GLOBAL']['skip'] == 'False':
[preprocessing(infile, config) for infile in files]
collapse.runner(
config['GLOBAL']['temp'],
config['GLOBAL']['sid'],
config['GLOBAL']['cal'],
config['GLOBAL']['mw'],
config['POSTPROCESS']['fdr'],
config['POSTPROCESS']['collapse_mode'],
)
combined_file = os.path.join(config['GLOBAL']['temp'], 'combined.txt')
differential.runner(
combined_file,
config['GLOBAL']['sid'],
config['GLOBAL']['output'],
config['GLOBAL']['temp'],
)
plots.runner(
config['GLOBAL']['temp'],
config['GLOBAL']['output'],
config['POSTPROCESS']['fdr'],
config['GLOBAL']['sid'],
)
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
pass