-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.nf
executable file
·314 lines (258 loc) · 7.62 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
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
#!/usr/bin/env nextflow
def helpMessage() {
log.info"""
=======================
demultiplexing pipeline
=======================
This pipeline runs Souporcell/Vireo.
The parameters you need to input are:
--SAMPLEFILE /full/path/to/sample/file
-K k-value
This file should be a tsv with 3 columns: SAMPLEID\t/PATH/TO/BAM/\t/PATH/TO/BARCODES
Each line should only contain information on a single sample.
An example can be seen here: https://github.com/cellgeni/nf-demultiplex/blob/main/examples/samples.txt
----------
souporcell
----------
Souporcell uses a common variants file by default, to use a known genotypes vcf please use:
--known_genotypes true
The default reference fasta used is: GRCh38_v32_modified (2020A)
The default common variants vcf used is: filtered_2p_1kgenomes_GRCh38
To change these defaults input:
--soc_fasta /path/to/reference/fasta
--soc_vcf /path/to/vcf
-----
vireo
-----
The default reference vcf is: genome1K.phase3.SNP_AF5e2.chr1toX.hg38
To change this default input:
--snp_vcf /path/to/vcf
""".stripIndent()
}
def errorMessage() {
log.info"""
====================
demultiplexing error
====================
You failed to provide the --SAMPLEFILE or --K parameter
Please provide this parameter as follows:
--SAMPLEFILE /full/path/to/sample/file
--K donor-number
The pipeline has exited with error status 1.
""".stripIndent()
exit 1
}
process get_data {
label 'get_data'
input:
tuple val(id), val(bam_path), val(barcodes_path), val(K)
output:
tuple val(id), path('*barcodes.tsv'), path('*bam'), path('*bam.bai'), val(K)
shell:
'''
if "!{params.bam_on_irods}"; then
iget -f -v -K "!{bam_path}" "!{id}.bam"
iget -f -v -K "!{bam_path}.bai" "!{id}.bam.bai"
else
ln -s "!{bam_path}" "!{id}.bam"
ln -s "!{bam_path}.bai" "!{id}.bam.bai"
fi
if "!{params.barcodes_on_irods}"; then
iget -f -v -K "!{barcodes_path}" "!{id}.barcodes.tsv.gz"
gunzip -f "!{id}.barcodes.tsv.gz"
else
ln -s "!{barcodes_path}" "!{id}.barcodes.tsv.gz"
gunzip -f "!{id}.barcodes.tsv.gz"
fi
'''
}
process run_cellsnp {
label 'vireo'
publishDir "${params.outdir}/vireo/cellsnp", mode: 'copy'
input:
tuple val(name), path(barcodes), path(bam), path(index), val(K)
output:
val(name)
path("*cellsnp")
val(K)
shell:
'''
!{projectDir}/bin/cellsnp.sh !{name} !{barcodes} !{bam} !{params.snp_vcf}
'''
}
process run_vireo {
label 'vireo'
publishDir "${params.outdir}/vireo", mode: 'copy'
input:
val(name)
path(cellsnp)
val(K)
output:
path("*vireo"), emit: output
shell:
'''
!{projectDir}/bin/vireo.sh !{name} !{cellsnp} !{K}
'''
}
process run_souporcell {
publishDir "${params.outdir}/souporcell", mode: 'copy'
input:
tuple val(name), path(barcodes), path(bam), path(index), val(K)
output:
path(name), emit: output
shell:
'''
!{projectDir}/bin/souporcell.sh !{name} !{barcodes} !{bam} !{params.known_genotypes} !{params.soc_vcf} !{params.soc_fasta} !{K} !{params.skip_remap} !{params.no_umi}
!{projectDir}/bin/soup_qc.sh !{name}
'''
}
process run_shared_samples {
publishDir "${params.outdir}/souporcell/shared_samples", mode: 'copy'
input:
path(name)
path(samplefile)
output:
path('map*'), emit: mapping
shell:
'''
!{projectDir}/bin/shared_samples.sh !{samplefile}
'''
}
process quantify_shared_samples {
publishDir "${params.outdir}/souporcell/shared_samples", mode: 'copy'
input:
path(mapping)
output:
path('quantification')
shell:
'''
mkdir -p quantification/clusters
for shared in map*; do
#Get sample id from shared sample file name
sample=`echo $shared | cut -f 2 -d .`
#Extract cluster comparison tsv from shared samples file
tail -n +6 $shared > "quantification/clusters/${sample}.cluster"
done
cd quantification
mkdir -p loss-tables
for comparison in clusters/*.cluster; do
sample=`echo $comparison | cut -f 2 -d / | cut -f 1 -d .`
python !{projectDir}/bin/shared-samples-quant.py --input $comparison --sample $sample
done
echo -e "experiment1_cluster\texperiment2_cluster\tloss\tsample_id" > total.tsv
cat loss-tables/* >> total.tsv
'''
}
process group_shared_samples {
label 'rscript'
publishDir "${params.outdir}/souporcell", mode: 'copy'
input:
path(shared_samples, stageAs: "shared_samples/*")
path(souporcell, stageAs: "souporcell/*")
path(samplefile)
output:
path('group_samples')
shell:
'''
Rscript !{projectDir}/bin/group_genotypes.R shared_samples souporcell !{samplefile} !{params.ngenomes}
'''
}
process compare_methods {
label 'rscript'
publishDir "${params.outdir}/compare_methods", mode: 'copy'
input:
path(souporcell, stageAs: "souporcell/*")
path(vireo, stageAs: "vireo/*")
path(samplefile)
output:
path('soc2vir*')
shell:
'''
Rscript !{projectDir}/bin/compare_methods.R !{samplefile}
'''
}
process get_gex_data {
label 'get_data'
input:
path(samplefile)
output:
path('out/*')
shell:
'''
mkdir out
# load expression data
if "!{params.barcodes_on_irods}"; then
cmd='iget'
else
cmd='cp'
fi
while read name bam b n;
do
${cmd} -r $(dirname $bam)/filtered_feature_bc_matrix out/${name}
done < !{samplefile}
'''
}
process check_sex {
label 'rscript'
publishDir "${params.outdir}/", mode: 'copy'
input:
path(souporcell, stageAs: "souporcell/*")
path(vireo, stageAs: "vireo/*")
path(gex, stageAs: "gex/*")
path(samplefile)
output:
path('sex')
shell:
'''
Rscript !{projectDir}/bin/check_sex.R !{samplefile}
'''
}
workflow vireo {
if (params.HELP) {
helpMessage()
exit 0
}
else {
ch_sample_list = params.SAMPLEFILE != null ? Channel.fromPath(params.SAMPLEFILE) : errorMessage()
ch_sample_list | flatMap{ it.readLines() } | map { it -> [ it.split()[0], it.split()[1], it.split()[2], it.split()[3]] } | get_data | set { ch_data }
ch_data_vireo = ch_data.filter { it[4].toInteger() > 1}
run_cellsnp(ch_data_vireo) | run_vireo
}
}
workflow souporcell {
if (params.HELP) {
helpMessage()
exit 0
}
else {
ch_sample_list = params.SAMPLEFILE != null ? Channel.fromPath(params.SAMPLEFILE) : errorMessage()
ch_sample_list | flatMap{ it.readLines() } | map { it -> [ it.split()[0], it.split()[1], it.split()[2], it.split()[3] ] } | get_data | run_souporcell
ch_soc = run_souporcell.out.output | collect
run_shared_samples(ch_soc, ch_sample_list)
group_shared_samples(run_shared_samples.out.mapping,ch_soc,ch_sample_list)
}
}
workflow all {
if (params.HELP) {
helpMessage()
exit 0
}
else {
ch_sample_list = params.SAMPLEFILE != null ? Channel.fromPath(params.SAMPLEFILE) : errorMessage()
ch_sample_list | flatMap{ it.readLines() } | map { it -> [ it.split()[0], it.split()[1], it.split()[2] , it.split()[3] ] } | get_data | set { ch_data }
ch_data_vireo = ch_data.filter { it[4].toInteger() > 1}
run_cellsnp(ch_data_vireo) | run_vireo
run_souporcell(ch_data)
ch_soc = run_souporcell.out.output | collect
ch_vir = run_vireo.out.output | collect
run_shared_samples(ch_soc, ch_sample_list)
// quantify_shared_samples is older version of group_shared_samples and probably should be depricated
quantify_shared_samples(run_shared_samples.out.mapping)
group_shared_samples(run_shared_samples.out.mapping,ch_soc,ch_sample_list)
compare_methods(ch_soc, ch_vir, ch_sample_list)
if(params.check_sex){
get_gex_data(ch_sample_list)
check_sex(ch_soc, ch_vir, get_gex_data.out, ch_sample_list)
}
}
}