forked from nh2tran/DeepNovo-DIA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deepnovo_config.py
417 lines (324 loc) · 13.4 KB
/
deepnovo_config.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
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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
# Copyright 2017 Hieu Tran. All Rights Reserved.
#
# DeepNovo is publicly available for non-commercial uses.
# ==============================================================================
"""TODO(nh2tran): docstring."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import numpy as np
import tensorflow as tf
# ==============================================================================
# FLAGS (options) for this app
# ==============================================================================
tf.app.flags.DEFINE_string("train_dir", # flag_name
"train", # default_value
"Training directory.") # docstring
tf.app.flags.DEFINE_integer("direction",
2,
"Set to 0/1/2 for Forward/Backward/Bi-directional.")
tf.app.flags.DEFINE_boolean("use_intensity",
True,
"Set to True to use intensity-model.")
tf.app.flags.DEFINE_boolean("shared",
False,
"Set to True to use shared weights.")
tf.app.flags.DEFINE_boolean("use_lstm",
True,
"Set to True to use lstm-model.")
tf.app.flags.DEFINE_boolean("lstm_kmer",
False,
"Set to True to use lstm model on k-mers instead of full sequence.")
tf.app.flags.DEFINE_boolean("knapsack_build",
False,
"Set to True to build knapsack matrix.")
tf.app.flags.DEFINE_boolean("train",
False,
"Set to True for training.")
tf.app.flags.DEFINE_string("train_spectrum",
"train_spectrum",
"Spectrum mgf file to train a new model.")
tf.app.flags.DEFINE_string("train_feature",
"train_feature",
"Feature csv file to train a new model.")
tf.app.flags.DEFINE_string("valid_spectrum",
"valid_spectrum",
"Spectrum mgf file for validation during training.")
tf.app.flags.DEFINE_string("valid_feature",
"valid_feature",
"Feature csv file for validation during training.")
tf.app.flags.DEFINE_boolean("test_true_feeding",
False,
"Set to True for testing.")
tf.app.flags.DEFINE_boolean("decode",
False,
"Set to True for decoding.")
tf.app.flags.DEFINE_boolean("beam_search",
False,
"Set to True for beam search.")
tf.app.flags.DEFINE_integer("beam_size",
5,
"Number of optimal paths to search during decoding.")
tf.app.flags.DEFINE_boolean("search_db",
False,
"Set to True to do a database search.")
tf.app.flags.DEFINE_boolean("search_denovo",
False,
"Set to True to do a denovo search.")
tf.app.flags.DEFINE_string("denovo_spectrum",
"denovo_spectrum",
"Spectrum mgf file to perform de novo sequencing.")
tf.app.flags.DEFINE_string("denovo_feature",
"denovo_feature",
"Feature csv file to perform de novo sequencing.")
tf.app.flags.DEFINE_boolean("search_hybrid",
False,
"Set to True to do a hybrid, db+denovo, search.")
tf.app.flags.DEFINE_boolean("test",
False,
"Set to True to test the prediction accuracy.")
tf.app.flags.DEFINE_string("target_file",
"target_file",
"Target file to calculate the prediction accuracy.")
tf.app.flags.DEFINE_string("predicted_file",
"predicted_file",
"Predicted file to calculate the prediction accuracy.")
tf.app.flags.DEFINE_boolean("header_seq",
True,
"Set to False if peptide sequence is not provided.")
tf.app.flags.DEFINE_boolean("decoy",
False,
"Set to True to search decoy database.")
tf.app.flags.DEFINE_integer("multiprocessor",
1,
"Use multi processors to read data during training.")
FLAGS = tf.app.flags.FLAGS
# ==============================================================================
# GLOBAL VARIABLES for VOCABULARY
# ==============================================================================
# Special vocabulary symbols - we always put them at the start.
_PAD = "_PAD"
_GO = "_GO"
_EOS = "_EOS"
_START_VOCAB = [_PAD, _GO, _EOS]
PAD_ID = 0
GO_ID = 1
EOS_ID = 2
vocab_reverse = ['A',
'R',
'N',
'N(Deamidation)',
'D',
#~ 'C',
'C(Carbamidomethylation)',
'E',
'Q',
'Q(Deamidation)',
'G',
'H',
'I',
'L',
'K',
'M',
'M(Oxidation)',
'F',
'P',
'S',
'T',
'W',
'Y',
'V',
]
vocab_reverse = _START_VOCAB + vocab_reverse
print("vocab_reverse ", vocab_reverse)
vocab = dict([(x, y) for (y, x) in enumerate(vocab_reverse)])
print("vocab ", vocab)
vocab_size = len(vocab_reverse)
print("vocab_size ", vocab_size)
# ==============================================================================
# GLOBAL VARIABLES for THEORETICAL MASS
# ==============================================================================
mass_H = 1.0078
mass_H2O = 18.0106
mass_NH3 = 17.0265
mass_N_terminus = 1.0078
mass_C_terminus = 17.0027
mass_CO = 27.9949
mass_AA = {'_PAD': 0.0,
'_GO': mass_N_terminus-mass_H,
'_EOS': mass_C_terminus+mass_H,
'A': 71.03711, # 0
'R': 156.10111, # 1
'N': 114.04293, # 2
'N(Deamidation)': 115.02695,
'D': 115.02694, # 3
#~ 'C(Carbamidomethylation)': 103.00919, # 4
'C(Carbamidomethylation)': 160.03065, # C(+57.02)
#~ 'C(Carbamidomethylation)': 161.01919, # C(+58.01) # orbi
'E': 129.04259, # 5
'Q': 128.05858, # 6
'Q(Deamidation)': 129.0426,
'G': 57.02146, # 7
'H': 137.05891, # 8
'I': 113.08406, # 9
'L': 113.08406, # 10
'K': 128.09496, # 11
'M': 131.04049, # 12
'M(Oxidation)': 147.0354,
'F': 147.06841, # 13
'P': 97.05276, # 14
'S': 87.03203, # 15
'T': 101.04768, # 16
'W': 186.07931, # 17
'Y': 163.06333, # 18
'V': 99.06841, # 19
}
mass_ID = [mass_AA[vocab_reverse[x]] for x in range(vocab_size)]
mass_ID_np = np.array(mass_ID, dtype=np.float32)
mass_AA_min = mass_AA["G"] # 57.02146
# ==============================================================================
# GLOBAL VARIABLES for PRECISION, RESOLUTION, temp-Limits of MASS & LEN
# ==============================================================================
# if change, need to re-compile cython_speedup << NO NEED
#~ SPECTRUM_RESOLUTION = 10 # bins for 1.0 Da = precision 0.1 Da
#~ SPECTRUM_RESOLUTION = 20 # bins for 1.0 Da = precision 0.05 Da
#~ SPECTRUM_RESOLUTION = 40 # bins for 1.0 Da = precision 0.025 Da
SPECTRUM_RESOLUTION = 50 # bins for 1.0 Da = precision 0.02 Da
#~ SPECTRUM_RESOLUTION = 100 # bins for 1.0 Da = precision 0.01 Da
print("SPECTRUM_RESOLUTION ", SPECTRUM_RESOLUTION)
# if change, need to re-compile cython_speedup << NO NEED
WINDOW_SIZE = 10 # 10 bins
print("WINDOW_SIZE ", WINDOW_SIZE)
MZ_MAX = 3000.0
MZ_SIZE = int(MZ_MAX * SPECTRUM_RESOLUTION) # 30k
KNAPSACK_AA_RESOLUTION = 10000 # 0.0001 Da
mass_AA_min_round = int(round(mass_AA_min * KNAPSACK_AA_RESOLUTION)) # 57.02146
KNAPSACK_MASS_PRECISION_TOLERANCE = 100 # 0.01 Da
num_position = 0
PRECURSOR_MASS_PRECISION_TOLERANCE = 0.01
# ONLY for accuracy evaluation
AA_MATCH_PRECISION = 0.1
# skip (x > MZ_MAX,MAX_LEN)
MAX_LEN = 50 if FLAGS.decode else 30
print("MAX_LEN ", MAX_LEN)
# We use a number of buckets and pad to the closest one for efficiency.
_buckets = [12,22,32,42,52] if FLAGS.decode else [12, 22, 32]
print("_buckets ", _buckets)
# ==============================================================================
# HYPER-PARAMETERS of the NEURAL NETWORKS
# ==============================================================================
num_ion = 8 # 2
print("num_ion ", num_ion)
l2_weight = 0.0
print("l2_weight ", l2_weight)
embedding_size = 512
print("embedding_size ", embedding_size)
num_layers = 1
num_units = 512
print("num_layers ", num_layers)
print("num_units ", num_units)
keep_conv = 0.75
keep_dense = 0.5
print("keep_conv ", keep_conv)
print("keep_dense ", keep_dense)
batch_size = 32
print("batch_size ", batch_size)
epoch_stop = 49 + 10#10 # 50 # 31800*32/(counter_train = 20568)
print("epoch_stop ", epoch_stop)
train_stack_size = 500 # 3000 # 5000
valid_stack_size = 1500#1000 # 3000 # 5000
test_stack_size = 5000
decode_stack_size = 1000 # 3000
print("train_stack_size ", train_stack_size)
print("valid_stack_size ", valid_stack_size)
print("test_stack_size ", test_stack_size)
print("decode_stack_size ", decode_stack_size)
steps_per_checkpoint = 10 # 100 # 2 # 4 # 200
random_test_batches = 10
print("steps_per_checkpoint ", steps_per_checkpoint)
print("random_test_batches ", random_test_batches)
max_gradient_norm = 5.0
print("max_gradient_norm ", max_gradient_norm)
# DIA model parameters
neighbor_size = 5 # allow up to ? spectra, including the main spectrum
dia_window = 20.0 # the window size of MS2 scan in Dalton
focal_loss = True
# ==============================================================================
# DB SEARCH PARAMETERS
# ==============================================================================
data_format = "mgf"
cleavage_rule = "trypsin"
num_missed_cleavage = 2
fixed_mod_list = ['C']
var_mod_list = ['N', 'Q', 'M']
num_mod = 3
precursor_mass_tolerance = 0.01 # Da
precursor_mass_ppm = 15.0/1000000 # ppm (20 better) # instead of absolute 0.01 Da
topk_output = 1
# ==============================================================================
# INPUT/OUTPUT FILES
# ==============================================================================
# pre-built knapsack matrix
knapsack_file = "knapsack.npy"
# train/valid/test files
input_spectrum_file_train = FLAGS.train_spectrum
input_feature_file_train = FLAGS.train_feature
input_spectrum_file_valid = FLAGS.valid_spectrum
input_feature_file_valid = FLAGS.valid_feature
input_spectrum_file_test = "data.training/dia.pecan.plasma.2018_03_29/testing_gs.spectrum.mgf"
input_feature_file_test = "data.training/dia.pecan.plasma.2018_03_29/testing_gs.feature.csv"
# denovo files
denovo_input_spectrum_file = FLAGS.denovo_spectrum
denovo_input_feature_file = FLAGS.denovo_feature
denovo_output_file = denovo_input_feature_file + ".deepnovo_denovo"
# db files
#~ db_fasta_file = "data/uniprot_sprot.human.db_decoy.fasta"
#~ db_input_spectrum_file = "data.training/dia.pecan.hela.2018_03_29/testing.spectrum.mgf"
#~ db_input_feature_file = "data.training/dia.abrf.2018_03_27/testing.feature.csv.2k"
#~ db_output_file = db_input_feature_file + ".deepnovo_db"
#~ if FLAGS.decoy:
#~ db_output_file += ".decoy"
# hybrid files
#~ hybrid_fasta_file = "data/uniprot_sprot.human.db_decoy.fasta"
#~ hybrid_input_spectrum_file = "data.training/dia.abrf.2018_03_27/prediction.spectrum.mgf"
#~ hybrid_input_feature_file = "data.training/dia.abrf.2018_03_27/prediction.feature.csv.part1"
#~ hybrid_denovo_file = hybrid_input_feature_file + ".deepnovo_hybrid_denovo"
#~ hybrid_output_file = hybrid_input_feature_file + ".deepnovo_hybrid"
#~ if FLAGS.decoy:
#~ hybrid_output_file += ".decoy"
# test accuracy files
predicted_format = "deepnovo"
target_file = FLAGS.target_file
predicted_file = FLAGS.predicted_file
# ~ predicted_file = "data.training/dia.pecan.plasma.2018_03_29/testing_plasma.unlabeled.csv.deepnovo_denovo.top90"
#~ predicted_format = "peaks"
#~ target_file = "data.training/dia.urine.2018_04_23/testing_gs.feature.csv"
#~ predicted_file = "data.training/dia.urine.2018_04_23/peaks.denovo.csv.uti"
accuracy_file = predicted_file + ".accuracy"
denovo_only_file = predicted_file + ".denovo_only"
scan2fea_file = predicted_file + ".scan2fea"
multifea_file = predicted_file + ".multifea"
# ==============================================================================
# ==============================================================================
# feature file column format
col_feature_id = 0
col_precursor_mz = 1
col_precursor_charge = 2
col_rt_mean = 3
col_raw_sequence = 4
col_scan_list = 5
col_ms1_list = 6
col_feature_area = 7
col_num = 8
# predicted file column format
pcol_feature_id = 0
pcol_feature_area = 1
pcol_sequence = 2
pcol_score = 3
pcol_position_score = 4
pcol_precursor_mz = 5
pcol_precursor_charge = 6
pcol_protein_id = 7
pcol_scan_list_middle = 8
pcol_scan_list_original = 9
pcol_score_max = 10