-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnf_library_search_modules.nf
More file actions
296 lines (233 loc) · 7.15 KB
/
nf_library_search_modules.nf
File metadata and controls
296 lines (233 loc) · 7.15 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
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
params.TOOL_FOLDER = "$moduleDir/bin/library_search"
params.publishdir = "./nf_output"
process searchDataGNPS {
//publishDir "./nf_output", mode: 'copy'
conda "$params.TOOL_FOLDER/conda_env.yml"
cache 'lenient'
input:
tuple file(input_library), file(input_spectrum), val(input_path), val(full_path)
val pm_tolerance
val fragment_tolerance
val topk
val library_min_cosine
val library_min_matched_peaks
val analog_search
val filter_precursor
val filter_window
output:
file 'search_results/*' optional true
"""
mkdir -p search_results
python $params.TOOL_FOLDER/library_search_wrapper.py \
$input_spectrum \
$input_library \
search_results \
$params.TOOL_FOLDER/convert \
$params.TOOL_FOLDER/main_execmodule.allcandidates \
--pm_tolerance "$pm_tolerance" \
--fragment_tolerance "$fragment_tolerance" \
--topk $topk \
--library_min_cosine $library_min_cosine \
--library_min_matched_peaks $library_min_matched_peaks \
--analog_search "$analog_search" \
--full_relative_query_path "$full_path" \
--filter_precursor "$filter_precursor" \
--filter_window "$filter_window"
"""
}
process searchDataGNPSIndexed {
//publishDir "./nf_output", mode: 'copy'
conda "$params.TOOL_FOLDER/conda_env.yml"
cache 'lenient'
input:
tuple file(input_library), file(input_spectrum), val(input_path), val(full_path)
val pm_tolerance
val fragment_tolerance
val topk
val library_min_cosine
val library_min_matched_peaks
val analog_search
val filter_precursor
val filter_window
output:
file 'search_results/*' optional true
"""
mkdir -p search_results
# Addressing race condition for symlinks in NextFlow for GNPS2
sleep 1
python $params.TOOL_FOLDER/library_search_indexed.py \
$input_spectrum \
$input_library \
search_results \
$params.TOOL_FOLDER/convert \
$params.TOOL_FOLDER/main_execmodule.allcandidates \
--pm_tolerance "$pm_tolerance" \
--fragment_tolerance "$fragment_tolerance" \
--topk $topk \
--library_min_cosine $library_min_cosine \
--library_min_matched_peaks $library_min_matched_peaks \
--analog_search "$analog_search" \
--full_relative_query_path "$full_path"\
--filter_precursor "$filter_precursor" \
--filter_window "$filter_window"
"""
}
process searchDataGNPSNew{
publishDir params.publishdir, mode: 'copy'
conda "$params.TOOL_FOLDER/conda_env_gnps_new.yml"
cache 'lenient'
input:
tuple file(input_library), file(input_spectrum)
val search_algorithm
val analog_search
val analog_max_shift
val pm_tolerance
val fragment_tolerance
val library_min_similarity
val library_min_matched_peaks
val peak_transformation
val unmatched_penalty_factor
output:
file 'search_results/*' optional true
"""
mkdir -p search_results
python $params.TOOL_FOLDER/gnps_new/main_search.py \
--gnps_lib_mgf $input_library \
--qry_file $input_spectrum \
--algorithm $search_algorithm \
--analog_search $analog_search \
--analog_max_shift $analog_max_shift \
--pm_tol $pm_tolerance \
--frag_tol $fragment_tolerance \
--min_score $library_min_similarity \
--min_matched_peak $library_min_matched_peaks \
--peak_transformation $peak_transformation \
--unmatched_penalty_factor $unmatched_penalty_factor
"""
}
process searchDataBlink {
//publishDir "./nf_output", mode: 'copy'
conda "$params.TOOL_FOLDER/blink/environment.yml"
input:
each file(input_library)
each file(input_spectrum)
val blink_ionization
val blink_minpredict
val fragment_tolerance
output:
file 'search_results/*.csv' optional true
script:
def randomFilename = UUID.randomUUID().toString()
def input_spectrum_abs = input_spectrum.toRealPath()
def input_library_abs = input_library.toRealPath()
"""
mkdir -p search_results
echo $workDir
previous_cwd=\$(pwd)
echo \$previous_cwd
cd $params.TOOL_FOLDER/blink && python -m blink.blink_cli \
"$input_spectrum_abs" \
$input_library_abs \
\$previous_cwd/search_results/${randomFilename}.csv \
$params.TOOL_FOLDER/blink/models/positive_random_forest.pickle \
$params.TOOL_FOLDER/blink/models/negative_random_forest.pickle \
$blink_ionization \
--min_predict $blink_minpredict \
--mass_diffs 0 14.0157 12.000 15.9949 2.01565 27.9949 26.0157 18.0106 30.0106 42.0106 1.9792 17.00284 24.000 13.97925 1.00794 40.0313 \
--tolerance $fragment_tolerance
"""
}
process formatBlinkResults {
conda "$params.TOOL_FOLDER/conda_env.yml"
input:
path input_file
output:
path '*.tsv'
"""
python $params.TOOL_FOLDER/format_blink.py \
$input_file \
${input_file}.tsv
"""
}
process chunkResults {
conda "$params.TOOL_FOLDER/conda_env.yml"
cache 'lenient'
input:
path to_merge, stageAs: './results/*' // To avoid naming collisions
val topk
output:
path "batched_results.tsv" optional true
"""
python $params.TOOL_FOLDER/tsv_merger.py \
results \
batched_results.tsv \
--topk $topk
"""
}
// Use a separate process to merge all the batched results
process mergeResults {
publishDir params.publishdir, mode: 'copy'
conda "$params.TOOL_FOLDER/conda_env.yml"
cache 'lenient'
input:
path 'batched_results.tsv', stageAs: './results/batched_results*.tsv' // Will automatically number inputs to avoid name collisions
val topk
output:
path 'merged_results.tsv'
"""
python $params.TOOL_FOLDER/tsv_merger.py \
results \
merged_results.tsv \
--topk $topk
"""
}
process librarygetGNPSAnnotations {
publishDir params.publishdir, mode: 'copy'
cache 'lenient'
conda "$params.TOOL_FOLDER/conda_env.yml"
input:
path "merged_results.tsv"
path "library_summary.tsv"
val topk
val filtertostructures
val forceoffline
output:
path 'merged_results_with_gnps.tsv'
"""
python $params.TOOL_FOLDER/getGNPS_library_annotations.py \
merged_results.tsv \
merged_results_with_gnps.tsv \
--librarysummary library_summary.tsv \
--topk $topk \
--filtertostructures $filtertostructures \
--forceoffline $forceoffline
"""
}
process filtertop1Annotations {
publishDir params.publishdir, mode: 'copy'
cache 'lenient'
conda "$params.TOOL_FOLDER/conda_env.yml"
input:
path "merged_results_with_gnps.tsv"
output:
path 'merged_results_with_gnps_top1.tsv'
"""
python $params.TOOL_FOLDER/filter_top1_hits.py \
merged_results_with_gnps.tsv \
merged_results_with_gnps_top1.tsv
"""
}
process summaryLibrary {
//publishDir params.publishdir, mode: 'copy'
cache 'lenient'
conda "$params.TOOL_FOLDER/conda_env.yml"
input:
path library_file
output:
path '*.tsv'
"""
python $params.TOOL_FOLDER/library_summary.py \
$library_file \
${library_file}.tsv
"""
}