-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.nf
executable file
·226 lines (203 loc) · 11.6 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
#!/usr/bin/env nextflow
/*
*# Author: Paul Donovan
*# Email: pauldonovandonegal@gmail.com
*/
nextflow.enable.dsl = 2
// Set default parameters
params.species = 'human'
//params.skip = "no"
params.all_plots = false
//params.remove = "no"
params.layout = null
params.input_dir = null
params.output_dir = "Results"
params.min_read_length = 16
params.version = false
params.help = false
// Print message for user
def helpMessage() {
log.info """\
===========
tsRNAsearch
===========
Usage: Single file analysis:
nextflow run tsRNAsearch --species mouse --input_dir tsRNAsearch/ExampleData --output_dir Results
Usage: Multi file analysis:
nextflow run tsRNAsearch --species mouse --input_dir tsRNAsearch/ExampleData --output_dir Results
Usage: Group comparison analysis:
nextflow run tsRNAsearch --species mouse --input_dir tsRNAsearch/ExampleData --output_dir Results --layout tsRNAsearch/additional-files/Example_Layout.csv
Single file analysis mandatory arguments:
Output directory: ${params.output_dir}
Input directory with file (/path/to/file): ${params.input_dir}
Multi file analysis (no group comparison) mandatory arguments:
Output directory: ${params.output_dir}
Input directory with file (/path/to/file): ${params.input_dir}
Group comparison analysis mandatory arguments:
Output directory: ${params.output_dir}
Input directory of files (/path/to/files): ${params.input_dir}
Other arguments:
Species (human/mouse/rat): ${params.species}
Minimum read length: ${params.min_read_length}
Print help" ${params.help}
"""
}
// Pipeline version
version="Version: tsRNAsearch 1.02"
// Print message for user
def versionMessage() {
log.info """\
${version}
"""
}
// Show help message and quit
if (params.help) {
helpMessage()
versionMessage()
exit 0
}
// Show version and quit
if (params.version) {
versionMessage()
exit 0
}
// Input parameter error catching
if(!params.input_dir){
exit 1, "Error: No input provided. Provide --input_dir to pipeline"
}
// If input_dir is absolute path, do nothing. Otherwise, add launch dir working dir to path
//if(params.input_dir.startsWith("/")){
// inputdir = "$params.input_dir"
//} else {
// inputdir = "$launchDir/$params.input_dir"
//}
// If output_dir is absolute path, do nothing. Otherwise, add launch dir working dir to path
if(params.output_dir.startsWith("/")){
outputdir = "$params.output_dir"
} else {
outputdir = "$launchDir/$params.output_dir"
}
// If layout is absolute path, do nothing. Otherwise, add launch dir working dir to path
if(params.layout){
if(params.layout.startsWith("/")){
layoutfile = "$params.layout"
} else {
layoutfile = "$launchDir/$params.layout"
}
}
// Load modules (these inherit the params above if the default params are also declared in the modules)
include { PREPARE_TRNA_GTF } from './modules/prepare_trna_gtf'
include { PREPARE_NCRNA_GTF } from './modules/prepare_ncrna_gtf'
//include { FASTQC } from './modules/fastqc'
//include { MULTIQC } from './modules/multiqc'
include { MAKE_STAR_DB } from './modules/star_genome-generate'
include { TRIM_READS } from './modules/trim_galore'
include { STAR_ALIGN } from './modules/star_align'
include { BAM_COLLAPSE } from './modules/bam_collapse'
include { ADD_EMPTY_COUNTS } from './modules/add_empty_counts'
include { BAM_SPLIT } from './modules/bam_split'
include { FEATURE_COUNT_NCRNA } from './modules/count_features_ncrna'
include { FEATURE_COUNT_TRNA } from './modules/count_features_trna'
include { SUM_COUNTS } from './modules/sum_counts'
include { GENERATE_TRNA_DEPTH_FILES } from './modules/generate_trna_depth_files'
include { GENERATE_MULTIMAPPER_TRNA_DEPTH_FILES } from './modules/generate_multimapper_trna_depth_files'
include { GENERATE_NCRNA_DEPTH_FILES } from './modules/generate_ncrna_depth_files'
include { GENERATE_DEPTHFILE_STATS } from './modules/generate_depthfile_stats'
include { PLOT_TRNA_ALIGNMENT_LENGTH } from './modules/plot_trna_alignment_length'
include { PLOT_NCRNA_ALL_PLOTS } from './modules/plot_ncrna_all_plots'
include { PLOT_TRNA_ALL_PLOTS } from './modules/plot_trna_all_plots'
//include { PLOT_TRNA_SINGLE_SAMPLE_ANALYSIS } from './modules/plot_trna_single_sample_analysis'
include { PLOT_TRNA_ALL_DEPTH_PLOTS } from './modules/plot_trna_all_depth_plots'
include { RAW_COUNTS_TO_PROPORTIONS } from './modules/raw_counts_to_proportions'
include { RAW_COUNTS_TO_NORM_COUNTS } from './modules/raw_counts_to_norm_counts'
include { COUNTS_TO_COLLAPSED_COUNTS } from './modules/counts_to_collapsed_counts'
include { PREDICT_TSRNA_TYPE } from './modules/predict_tsrna_type'
include { PREDICT_TSRNA_TYPE_GROUPS } from './modules/predict_tsrna_type_groups'
include { GENERATE_RESULTS_PDF } from './modules/generate_results_pdf'
include { GENERATE_RESULTS_PDF_GROUPS } from './modules/generate_results_pdf_groups'
include { DESEQ2 } from './modules/deseq2'
include { COMBINE_DEPTHFILES } from './modules/combine_depthfiles'
include { DATA_TRANSFORMATIONS } from './modules/data_transformations'
include { DISTRIBUTION_SCORE } from './modules/distribution_score'
include { SLOPE_SCORE } from './modules/slope_score'
include { CLEAVAGE_SCORE } from './modules/cleavage_score'
include { FISHERS_METHOD } from './modules/fishers_method'
include { RESULTS_TABLE } from './modules/results_table'
include { COMBINED_SCORE } from './modules/combined_score'
include { PLOT_TSRNA_LENGTHS } from './modules/plot_tsrna_lengths'
include { PLOT_ALL_NCRNAS } from './modules/plot_all_ncrnas'
include { PLOT_TRNAS } from './modules/plot_trnas'
include { PLOT_NCRNAS } from './modules/plot_ncrnas'
include { VENN_DIAGRAM } from './modules/venn_diagram'
include { GENERATE_COUNT_DATAFRAME } from './modules/generate_count_dataframe'
include { STACKED_BARPLOTS } from './modules/stacked_barplots'
include { BARPLOTS } from './modules/barplots'
include { ORGANISE_RESULTS } from './modules/organise_results'
include { ORGANISE_RESULTS_GROUPS } from './modules/organise_results_groups'
include { PUBLISH_FILES } from './modules/publish_files'
workflow {
main:
// Define channels
fastq_channel = Channel.fromPath( ["$params.input_dir/*.fastq.gz", "$params.input_dir/*.fq.gz"] ) //, "$params.input_file"] )
PREPARE_TRNA_GTF(params.species)
PREPARE_NCRNA_GTF(params.species)
TRIM_READS(fastq_channel, "$params.min_read_length")
MAKE_STAR_DB("$projectDir/DBs/${params.species}_tRNAs-and-ncRNAs-and-lookalikes.fa") // Run process to generate DB
STAR_ALIGN(TRIM_READS.out.trimmed_reads, MAKE_STAR_DB.out.star_index)
BAM_COLLAPSE(STAR_ALIGN.out.bam)
ADD_EMPTY_COUNTS(BAM_COLLAPSE.out.tRNA_almost_mapped_count, "$projectDir/additional-files/${params.species}_empty_tRNA.count")
BAM_SPLIT(BAM_COLLAPSE.out.collapsedbam)
FEATURE_COUNT_TRNA(BAM_SPLIT.out.bam_tRNA, PREPARE_TRNA_GTF.out.tRNA_gtf)
FEATURE_COUNT_NCRNA(BAM_SPLIT.out.bam_ncRNA, PREPARE_NCRNA_GTF.out.ncRNA_gtf)
SUM_COUNTS(FEATURE_COUNT_TRNA.out.counts.collect(), FEATURE_COUNT_NCRNA.out.counts.collect(), ADD_EMPTY_COUNTS.out.filled_multi_counts.collect())
GENERATE_TRNA_DEPTH_FILES(BAM_SPLIT.out.bam_tRNA, PREPARE_TRNA_GTF.out.tRNA_gtf, PREPARE_NCRNA_GTF.out.ncRNA_gtf)
GENERATE_MULTIMAPPER_TRNA_DEPTH_FILES(BAM_COLLAPSE.out.tRNA_almost_mapped_txt, PREPARE_TRNA_GTF.out.tRNA_gtf, PREPARE_NCRNA_GTF.out.ncRNA_gtf)
GENERATE_NCRNA_DEPTH_FILES(BAM_SPLIT.out.bam_ncRNA, PREPARE_TRNA_GTF.out.tRNA_gtf, PREPARE_NCRNA_GTF.out.ncRNA_gtf)
GENERATE_DEPTHFILE_STATS(GENERATE_TRNA_DEPTH_FILES.out.depth_files.mix(GENERATE_NCRNA_DEPTH_FILES.out.depth_files))
RAW_COUNTS_TO_PROPORTIONS(FEATURE_COUNT_TRNA.out.counts, BAM_COLLAPSE.out.tRNA_almost_mapped_count, SUM_COUNTS.out.sum_counts)
RAW_COUNTS_TO_NORM_COUNTS(SUM_COUNTS.out.all_counts.flatten(), PREPARE_TRNA_GTF.out.tRNA_gtf, PREPARE_NCRNA_GTF.out.ncRNA_gtf)
COUNTS_TO_COLLAPSED_COUNTS(SUM_COUNTS.out.all_counts.flatten().mix(RAW_COUNTS_TO_NORM_COUNTS.out.tpm_count))
PREDICT_TSRNA_TYPE(GENERATE_TRNA_DEPTH_FILES.out.collect(), GENERATE_MULTIMAPPER_TRNA_DEPTH_FILES.out.collect())
//MULTIQC(FASTQC.out.collect())
// Plot things
PLOT_TRNA_ALIGNMENT_LENGTH(BAM_SPLIT.out.bam_tRNA)
PLOT_TRNA_ALL_PLOTS(GENERATE_TRNA_DEPTH_FILES.out.depth_files, PREPARE_TRNA_GTF.out.tRNA_gtf)
GENERATE_RESULTS_PDF(PLOT_TRNA_ALIGNMENT_LENGTH.out.pdf.collect(), \
PLOT_TRNA_ALL_PLOTS.out.pdfs.collect(), \
SUM_COUNTS.out.sum_counts)
if (params.all_plots){
PLOT_NCRNA_ALL_PLOTS(GENERATE_NCRNA_DEPTH_FILES.out.depth_files, PREPARE_NCRNA_GTF.out.ncRNA_gtf)
}
// END OF INDIVIDUAL FILE ANALYSIS
// START OF GROUP COMPARISON
if (params.layout){
DESEQ2(COUNTS_TO_COLLAPSED_COUNTS.out.collapsed_count.collect(), "$layoutfile", PREPARE_NCRNA_GTF.out.ncRNA_gtf)
DATA_TRANSFORMATIONS("$layoutfile", \
GENERATE_TRNA_DEPTH_FILES.out.depth_files.collect(), \
GENERATE_NCRNA_DEPTH_FILES.out.depth_files.collect(), \
GENERATE_MULTIMAPPER_TRNA_DEPTH_FILES.out.depth_files.collect(), \
SUM_COUNTS.out.sum_counts)
DISTRIBUTION_SCORE(DATA_TRANSFORMATIONS.out.ncrna_stddev, DATA_TRANSFORMATIONS.out.trna_stddev, PREPARE_NCRNA_GTF.out.ncRNA_gtf)
SLOPE_SCORE(DATA_TRANSFORMATIONS.out.depth_means, "$layoutfile", PREPARE_NCRNA_GTF.out.ncRNA_gtf)
CLEAVAGE_SCORE(DATA_TRANSFORMATIONS.out.depth_means, "$layoutfile", PREPARE_NCRNA_GTF.out.ncRNA_gtf)
FISHERS_METHOD(DATA_TRANSFORMATIONS.out.depthfiles, "$layoutfile", PREPARE_NCRNA_GTF.out.ncRNA_gtf)
RESULTS_TABLE(FISHERS_METHOD.out.pvalues, DISTRIBUTION_SCORE.out.combined_features, CLEAVAGE_SCORE.out.combined_features, DESEQ2.out.csvs, SLOPE_SCORE.out.combined_features, "$layoutfile")
COMBINED_SCORE(RESULTS_TABLE.out.tsv, "$layoutfile")
PLOT_TSRNA_LENGTHS(PLOT_TRNA_ALIGNMENT_LENGTH.out.txt.collect(), "$layoutfile")
if (params.all_plots){
PLOT_ALL_NCRNAS(DATA_TRANSFORMATIONS.out.ncrna_depth, "$layoutfile", PREPARE_NCRNA_GTF.out.ncRNA_gtf)
}
PLOT_TRNAS(DATA_TRANSFORMATIONS.out.depthfiles, COMBINED_SCORE.out.top_features, "$layoutfile")
PLOT_NCRNAS(DATA_TRANSFORMATIONS.out.ncrna_depth, COMBINED_SCORE.out.top_features, "$layoutfile", PREPARE_NCRNA_GTF.out.ncRNA_gtf)
VENN_DIAGRAM(FISHERS_METHOD.out.top_features, DISTRIBUTION_SCORE.out.top_features, CLEAVAGE_SCORE.out.top_features, DESEQ2.out.txt, SLOPE_SCORE.out.top_features, "$layoutfile")
GENERATE_COUNT_DATAFRAME(COUNTS_TO_COLLAPSED_COUNTS.out.collect())
STACKED_BARPLOTS(RAW_COUNTS_TO_PROPORTIONS.out.collect())
BARPLOTS(GENERATE_COUNT_DATAFRAME.out, "$layoutfile", PREPARE_NCRNA_GTF.out.ncRNA_gtf)
PREDICT_TSRNA_TYPE_GROUPS(DATA_TRANSFORMATIONS.out.depth_means, "$layoutfile")
GENERATE_RESULTS_PDF_GROUPS(DESEQ2.out.pdfs, STACKED_BARPLOTS.out, BARPLOTS.out, VENN_DIAGRAM.out.pdf, COMBINED_SCORE.out.pdfs, PLOT_TRNAS.out, PLOT_NCRNAS.out, "$layoutfile")
ORGANISE_RESULTS_GROUPS("$outputdir", SUM_COUNTS.out.sum_counts, GENERATE_RESULTS_PDF_GROUPS.out.pdf)
PUBLISH_FILES("$outputdir", DESEQ2.out.pdfs, STACKED_BARPLOTS.out, BARPLOTS.out, VENN_DIAGRAM.out.pdf, COMBINED_SCORE.out.pdfs, PLOT_TRNAS.out, PLOT_NCRNAS.out, "$layoutfile", DESEQ2.out.csvs, VENN_DIAGRAM.out.tsvs, COMBINED_SCORE.out.all_txt_output)
} else {
ORGANISE_RESULTS("$outputdir", SUM_COUNTS.out.sum_counts, GENERATE_RESULTS_PDF.out.pdf, RAW_COUNTS_TO_PROPORTIONS.out.collect())
}
}