-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.nf
executable file
·201 lines (148 loc) · 5.01 KB
/
main.nf
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
#!/usr/bin/env nextflow
process runSetup {
input:
val organism
val census_version
output:
path "scvi-human-${census_version}/"
script:
"""
python $projectDir/bin/setup.py --organism ${organism} --census_version ${census_version}
"""
}
process mapQuery {
input:
val model_path
path relabel_q
path query_file
val batch_key
val join_key
output:
path "${query_file.toString().replace('.h5ad','_processed.h5ad')}"
script:
"""
python $projectDir/bin/process_query.py \\
--model_path ${model_path} \\
--relabel_path ${relabel_q} \\
--query_path ${query_file} \\
--batch_key ${batch_key} \\
--join_key ${join_key}
"""
}
// process getRefs {
// input:
// val organism
// val census_version
// val subsample_ref
// val relabel_r
// output:
// path "refs/*.h5ad", emit: ref_paths
// script:
// """
// # Run the python script to generate the files
// python $projectDir/bin/get_refs.py --organism ${organism} --census_version ${census_version} --subsample_ref ${subsample_ref} --relabel_path ${relabel_r}
// # After running the python script, all .h5ad files will be saved in the refs/ directory inside a work directory
// """
// }
process rfClassify {
publishDir "${params.outdir}", mode: "copy"
input:
val tree_file
val query_path
path ref_path
val ref_keys
val cutoff
output:
path "f1_results/*f1.scores.tsv", emit: f1_score_channel // Match TSV files in f1_results
path "roc/*.tsv", emit: auc_channel
path "roc/**"
path "confusion/**"
path "probs/**"
path "probs/*tsv"
path "predicted_meta/*tsv"
// publish:
script:
"""
python $projectDir/bin/rfc_classify.py --tree_file ${tree_file} --query_path ${query_path} --ref_path ${ref_path} --ref_keys ${ref_keys} \\
--cutoff ${cutoff}
"""
}
process plot_auc_dist {
publishDir "${params.outdir}", mode: "copy"
input:
file auc
output:
path "dists/*distribution.png" // Wildcard to capture all relevant output files
script:
"""
python $projectDir/bin/plot_auc_dist.py --roc_paths ${auc}
"""
}
process plot_f1_results {
publishDir "${params.outdir}", mode: "copy"
input:
val ref_keys
val cutoff
file f1_scores
output:
path "f1_plots/*png" // Wildcard to capture all relevant output files
script:
"""
python $projectDir/bin/plot_f1_results.py --ref_keys ${ref_keys} --cutoff ${cutoff} --f1_results ${f1_scores}
"""
}
// Workflow definition
workflow {
// Call the setup process to download the model
model_path = runSetup(params.organism, params.census_version)
Channel.fromPath(params.query)
.set{ query_paths }
Channel.fromPath(params.refs)
// .collect()
.set { ref_paths }
processed_query = mapQuery(model_path, params.relabel_q, query_paths, params.batch_key, params.join_key)
// Pass each file in ref_paths to rfc_classify using one query file at a time
rfClassify(params.tree_file, processed_query.first(), ref_paths, params.ref_keys.join(' '), params.cutoff)
// Collect all individual output files into a single channel
auc = rfClassify.out.auc_channel
f1_scores = rfClassify.out.f1_score_channel
plot_auc_dist(auc.flatten().toList())
// Plot f1 score heatmaps using a list of file names from the f1 score channel
plot_f1_results(params.ref_keys.join(' '), params.cutoff, f1_scores.flatten().toList())
}
workflow.onComplete {
println "Successfully completed"
/*
// This bit cannot be run interactively????, only try when sending as pipeline
jsonStr = JsonOutput.toJson(params)
file("${params.outdir}/params.json").text = JsonOutput.prettyPrint(jsonStr)
*/
println ( workflow.success ?
"""
===============================================================================
Pipeline execution summary
-------------------------------------------------------------------------------
Run as : ${workflow.commandLine}
Started at : ${workflow.start}
Completed at: ${workflow.complete}
Duration : ${workflow.duration}
Success : ${workflow.success}
workDir : ${workflow.workDir}
Config files: ${workflow.configFiles}
exit status : ${workflow.exitStatus}
--------------------------------------------------------------------------------
================================================================================
""".stripIndent() : """
Failed: ${workflow.errorReport}
exit status : ${workflow.exitStatus}
""".stripIndent()
)
}
workflow.onError = {
println "Error: something went wrong, check the pipeline log at '.nextflow.log"
}
/*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
THE END
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/