-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.nf
188 lines (147 loc) · 4.51 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
def errorMessage() {
log.info"""
====================
please provide input parameters --SAMPLEFILE or --BARCODEFILE
====================
""".stripIndent()
exit 1
}
process make_ref {
publishDir "${params.outdir}/", mode: 'copy'
input:
path gtf
output:
path('segments.csv')
path('gtf.rds')
path('segments.sajr')
path('functional_annotation')
shell:
'''
java -Xmx10G -jar !{projectDir}/bin/sajr.ss.jar \
gff2sajr !{projectDir}/bin/sajr.config \
-ann_foreign=!{gtf} \
-ann_out=segments.sajr
Rscript !{projectDir}/bin/prepare_reference.R !{gtf} segments.sajr
'''
}
process get_data {
input:
tuple val(id), val(bam_path)
output:
tuple val(id),path('*bam'),path('*bam.bai')
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
'''
}
process run_sajr {
publishDir "${params.outdir}/sajr/", mode: 'copy', pattern: "${id}"
input:
tuple val(id), path(bam_path), path(bam_path_id), val(strand), path(ref)
output:
tuple path(id), val(id), path(bam_path), path(bam_path_id), val(strand)
shell:
'''
mkdir !{id}
java -Xmx60G -jar !{projectDir}/bin/sajr.ss.jar \
count_reads !{projectDir}/bin/sajr.config \
-batch_in=!{bam_path}\
-batch_out=!{id}/!{id} \
-ann_in=!{ref}/segments.sajr \
-stranded=!{strand} \
-count_only_border_reads=true
gzip !{id}/*
'''
}
process combine_sajr_output {
label "pseudobulk"
input:
path(samples)
path(barcodes)
path(ref)
val(n_samples)
output:
path('rds'), emit: rds
shell:
'''
Rscript !{projectDir}/bin/combine_sajr_output.R !{samples} !{barcodes} !{ref} !{projectDir}/bin !{params.ncores}
'''
}
process remake_pseudobulk {
label "pseudobulk"
input:
path(samples)
path(barcodes)
path(ref)
val(n_samples)
output:
path('rds'), emit: rds
shell:
'''
Rscript !{projectDir}/bin/remake_pseudobulk.R !{samples} !{barcodes} !{params.preprocessed_rds} !{ref} !{projectDir}/bin !{params.ncores}
'''
}
process postprocess {
publishDir "${params.outdir}/", mode: 'copy'
input:
path(rds)
path(samples)
path(barcodes)
path(ref)
val(n_samples)
output:
path('rds'), emit: rds
path('examples.pdf')
shell:
'''
Rscript !{projectDir}/bin/postprocess.R !{rds} !{params.mincells} !{params.minsamples} !{samples} !{barcodes} !{ref} !{projectDir}/bin !{params.ncores}
'''
}
process generate_summary {
publishDir "${params.outdir}/", mode: 'copy'
input:
path(rds)
output:
path('summary.html')
shell:
'''
cp !{projectDir}/bin/summary.Rmd .
cp !{projectDir}/bin/sajr_utils.R .
Rscript -e "wd=getwd();rmarkdown::render('summary.Rmd',
output_file = 'summary.html',
clean = TRUE)"
'''
}
workflow {
ch_barcodes = Channel.fromPath(params.BARCODEFILE)
ch_ref = Channel.fromPath(params.ref)
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] ] } | get_data | set { ch_data }
ch_data = ch_data.combine(Channel.of(-1,1))
ch_data = ch_data.combine(ch_ref)
ch_data | run_sajr | set {sajr_outs}
sajrout_path_file = sajr_outs.collectFile{item -> ["sajr_outs.txt", item[0].toString() + " " + item[1] + " " + item[2] + " " + item[3] + " " + item[4] + "\n"]}
combine_sajr_output(sajrout_path_file,ch_barcodes,ch_ref,sajr_outs.count())
bam_path_file = ch_data.collectFile{item -> ["bam_paths.txt", item[0].toString() + " " + item[1] + "\n"]}
postprocess(combine_sajr_output.out.rds,bam_path_file,ch_barcodes,ch_ref,ch_sample_list.countLines())
generate_summary(postprocess.out.rds)
}
workflow repseudobulk {
ch_barcodes = Channel.fromPath(params.BARCODEFILE)
ch_ref = Channel.fromPath(params.ref)
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] ] } | get_data | set { ch_data }
bam_path_file = ch_data.collectFile{item -> ["bam_paths.txt", item[0].toString() + " " + item[1] + "\n"]}
remake_pseudobulk(ch_sample_list,Channel.fromPath(params.BARCODEFILE),ch_ref,ch_sample_list.countLines())
postprocess(remake_pseudobulk.out.rds,bam_path_file,ch_barcodes,ch_ref,ch_sample_list.countLines())
generate_summary(postprocess.out.rds)
}
workflow reference {
make_ref(params.gtf)
}