-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.nf
More file actions
218 lines (176 loc) · 7 KB
/
main.nf
File metadata and controls
218 lines (176 loc) · 7 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
#!/usr/bin/env nextflow
/*
* MIT License
*
* Copyright (c) 2020 Daniel Malzl
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
def helpMessage() {
log.info"""
================================================================
geneIS-nf
================================================================
DESCRIPTION
Reproducible annotation of initiation sites with genetic features
Usage:
nextflow run dmalzl/geneIS-nf
Options:
--masterTable tab-separated file containing the genomic coordinates and
names of the mapped initiation sites with header row and
first four columns being chr, start, end, name (same as BED)
including quantification results
--txDb file containing annotation database for a current genetic annotation
can be generated with the GenomicFeatures Bioconductor package
ideally use refGene table for generation
--email email address to use to fetch genesymbols from EntrezIds
--xCol column of masterTable holding quantification for x-axis of plots
--yCol column of masterTable holding quantification for y-axis of plots
--axMin minimum value of axes of final plots (Default: 0)
--axMax maximum value of axes of final plots (Default: 8)
--foldChange adds diagonal lines in distance of foldChange to plot
--filePrefix prefix to use for output files (Default: ISgene)
--outputDir name of the directory to save results to (Default: results)
Authors:
Daniel Malzl (daniel.malzl@imp.ac.at)
""".stripIndent()
}
params.help = false
if (params.help) {
helpMessage()
exit 0
}
if (params.masterTable) {
if (!file(params.masterTable).exists()) {
exit 1, "--masterTable was specified but does not exist"
}
} else {
exit 1, "--masterTable is requried but was not set!"
}
if (params.txDb) {
if (!file(params.txDb).exists()) {
exit 1, "--txDb was specified but does not exist"
}
} else {
exit 1, "--txDb is required but was not set!"
}
if (!params.email) {
exit 1, "--email needs to be set"
}
log.info ""
log.info " parameters"
log.info " ======================"
log.info " masterTable : ${params.masterTable}"
log.info " txDb : ${params.txDb}"
log.info " email : ${params.email}"
log.info " xCol : ${params.xCol}"
log.info " yCol : ${params.yCol}"
log.info " axMin : ${params.axMin}"
log.info " axMax : ${params.axMax}"
log.info " filePrefix : ${params.filePrefix}"
log.info " outputDir : ${params.outputDir}"
log.info " ======================"
log.info ""
inputChannel = Channel
.fromList([[params.filePrefix,
file(params.masterTable),
file(params.txDb)]])
process computeGeneAnnotation {
tag { filePrefix }
input:
set val(filePrefix), file(masterTable), file(txDb) from inputChannel
output:
set val(filePrefix), file("${filePrefix}.chipseeker.tsv"), file(masterTable) into resultsGeneAnnotation
shell:
'''
cut -f 1,2,3,4 !{masterTable} | tail -n +2 > master.tmp.bed
annotateIniSites.R master.tmp.bed !{txDb} !{filePrefix}.chipseeker.tsv
'''
}
process mapEntrezIds {
tag { filePrefix }
publishDir path: "${params.outputDir}",
mode: "copy",
overwrite: "true",
pattern: "*.chipseeker.mapped.tsv"
publishDir path: "${params.outputDir}",
mode: "copy",
overwrite: "true",
pattern: "entrezEntries*"
input:
set val(filePrefix), file(annotation), file(masterTable) from resultsGeneAnnotation
output:
set val(filePrefix), file("${filePrefix}.chipseeker.mapped.tsv"), file(masterTable) into resultsMapEntrez
set file("entrezEntries.txt"), file("entrezEntries.txt.ids") into entrezResults
shell:
'''
mapentrez.py -a !{annotation} \
--email !{params.email} \
-m entrezEntries.txt \
-o !{filePrefix}.chipseeker.mapped.tsv
'''
}
process extendMasterTable {
tag { filePrefix }
publishDir path: "${params.outputDir}",
mode: "copy",
overwrite: "true",
pattern: "${filePrefix}.master.tsv"
input:
set val(filePrefix), file(mappedAnnotation), file(masterTable) from resultsMapEntrez
output:
set val(filePrefix), file("${filePrefix}.master.tsv"), file("${filePrefix}.master.tsv.plotTable") into resultsExtendMaster
shell:
'''
annotateMasterTable.py -mt !{masterTable} -a !{mappedAnnotation} -o !{filePrefix}.master.tsv
'''
}
process plotting {
tag { filePrefix }
publishDir path: "${params.outputDir}",
mode: "copy",
overwrite: "true",
pattern: "*.pdf"
input:
set val(filePrefix), file(masterTable), file(plotTable) from resultsExtendMaster
output:
set file("${filePrefix}.Promoter.pdf"), file("${filePrefix}.Exon.pdf"), file("${filePrefix}.Intron.pdf"), file("${filePrefix}.Intergenic.pdf") into resultsPlotting
shell:
'''
for geneFeature in Promoter Exon Intron Intergenic;
do
datashader.py -mt !{plotTable} \
--xcol !{params.xCol} --ycol !{params.yCol} \
--xmin !{params.axMin} --xmax !{params.axMax} \
--ymin !{params.axMin} --ymax !{params.axMax} \
--subsetColumn ${geneFeature} \
--xlabel "!{params.xCol} log2(RPM)" \
--ylabel "!{params.yCol} log2(RPM)" \
--density F T \
--colormaps Grey,Grey coolwarm \
--foldchange !{params.foldChange} \
--plotmethod mesh \
--figwidth 6 --figheight 6 \
-o !{filePrefix}.${geneFeature}.pdf \
--xbins 200 --ybins 200 \
--labels rest $geneFeature \
--plotCounts
done
'''
}