-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.nf
202 lines (133 loc) · 7.63 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
nextflow.enable.dsl=2
/*
========================================================================================
eQTL-Detect
NOTE - Before running the script please take care of the input and output paths
========================================================================================
*/
log.info """\
==============================================================================================================
eQTL-DETECT [ *** SNP ---> Expression *** ]
==============================================================================================================
starIndex : ${params.starindex}
fasta : ${params.fasta}
gtf : ${params.gtf}
Input_reads paired : ${params.pairedreads}
Input_reads single : ${params.singlereads}
SampleInfo : ${params.corresponding_SampleInfo}
output : ${params.outdir}
CountMatrices : ${params.countMatrices}
Bam_input_files : ${params.bamIpfiles}
Geno_input_files : ${params.genoIpfiles}
==============================================================================================================
"""
.stripIndent()
/*
========================================================================================
Channel objects declared in nextflow.config
========================================================================================
*/
// Channels from tsv files
Channel.fromPath(params.genoIpfiles)
.ifEmpty { error "Cannot find countmatices file in: ${params.genoIpfiles}" }
.splitCsv(header: true, sep: '\t')
.map { row -> tuple(row.chromosome, file(row.vcfFile)) }
.set {genotype_input_ch}
Channel.fromPath(params.pairedreads)
.ifEmpty { error "Cannot find countmatices file in: ${params.pairedreads}" }
.splitCsv(header: true, sep: '\t')
.map{row -> tuple(row.sampleId, file(row.read1), file(row.read2))}
.set { read_pairs_ch }
Channel.fromPath(params.bamIpfiles)
.ifEmpty { error "Cannot find countmatices file in: ${params.bamIpfiles}" }
.splitCsv(header: true, sep: '\t')
.map { row -> tuple(row.sampleId, file(row.stringTieBam)) }
.set {stringtie_ip_di}
Channel.fromPath(params.bamIpfiles)
.ifEmpty { error "Cannot find countmatices file in: ${params.bamIpfiles}" }
.splitCsv(header: true, sep: '\t')
.map { row -> tuple(row.sampleId, file(row.leafcutterBam)) }
.set {leafcutter_ip_di}
Channel.fromPath(params.bamIpfiles)
.ifEmpty { error "Cannot find countmatices file in: ${params.bamIpfiles}" }
.splitCsv(header: true, sep: '\t')
.map { row -> tuple(row.sampleId, file(row.leafcutterBai)) }
.set {leafcutter_ip_idx}
Channel.fromPath(params.countMatrices)
.ifEmpty { error "Cannot find countmatices file in: ${params.countMatrices}" }
.splitCsv(header: true, sep: '\t')
.map{row -> tuple(row.count_matrices, file(row.gene_count_matrix), file(row.transcript_count_matrix), file(row.splice_count_matrix),file(row.splice_count_pcs))}
.set { count_matrices_ch }
// single channel objects
fasta = Channel.fromPath(params.fasta)
gtf = Channel.fromPath(params.gtf)
sample_info_ch = Channel.fromPath(params.corresponding_SampleInfo)
/*
========================================================================================
Parameters declared in nextflow.config
========================================================================================
*/
anchor_length_ch = params.anchor_length
intron_length_minimum_ch = params.intron_length_minimum
intron_length_maximum_ch = params.intron_length_maximum
phenotype_PCs_sQTL_ch = params.phenotype_PCs_sQTL
nominal_cis_ch = params.cis_nominal
permutations_cis_ch = params.cis_permutations
fdr_rate_cis_ch = params.cis_FDR
threshold_trans_ch = params.trans_threshold
permutations_trans_ch = params.trans_permutations
genotype_pcs_ch = params.genotype_pcs
phenotype_PCs_cis = params.phenotype_PCs_cis
phenotype_PCs_trans = params.phenotype_Pcs_trans
/*
========================================================================================
Modules
========================================================================================
*/
include { makeSTARindex } from './modules_dsl2/Reference_Index'
include {tissuewise_extractGenotype} from './modules_dsl2/Tissuewise_Extract_Merge_Genotypes'
include { genotypeStratificationPCA } from './modules_dsl2/GenotypePCs'
/*
========================================================================================
Sub-Workflows
========================================================================================
*/
include {PAIREDEND_END_READS} from "./subworkflows/pairedEndReads.nf"
include {SINGLE_END_READS} from "./subworkflows/singleEndReads.nf"
include {QUANTIFICATION_AND_MERGE_EXPRESSION_COUNTS} from "./subworkflows/QuantifcationExpressionCounts"
include {ciseQTL_workflow} from "./subworkflows/cis-eQTL_Sub-Wf"
include {transeQTL_workflow} from "./subworkflows/trans-eQTL_Sub-Wf"
workflow {
main:
if ( params.countMatrices_input ) {
tissuewise_extractGenotype(genotype_input_ch,sample_info_ch.collect())
commonSampleIds_ch = tissuewise_extractGenotype.out.genoVcfData_ch
norm_Ge_count_ch = count_matrices_ch.map {it[1]}
norm_Tr_count_ch = count_matrices_ch.map {it[2]}
splice_count_ch = count_matrices_ch.map {it[3]}
splice_pc_ch = count_matrices_ch.map {it[4]}
}
else {
makeSTARindex(fasta,gtf)
if(params.pairedEnd_reads){
PAIREDEND_END_READS(read_pairs_ch, gtf, makeSTARindex.out, anchor_length_ch, intron_length_minimum_ch, intron_length_maximum_ch, stringtie_ip_di, leafcutter_ip_di, leafcutter_ip_idx)
stringtie_ip_ch = PAIREDEND_END_READS.out.stringtie_ip
leafcutter_bamtojunc_ip_ch = PAIREDEND_END_READS.out.leafcutter_bamtojunc_ip
}
if (params.sigleEnd_reads){
SINGLE_END_READS(single_endReads_ch, gtf, makeSTARindex.out, anchor_length_ch, intron_length_minimum_ch, intron_length_maximum_ch, stringtie_ip_di, leafcutter_ip_di, leafcutter_ip_idx)
stringtie_ip_ch = SINGEL_END_READS.out.stringtie_ip
leafcutter_bamtojunc_ip_ch = SINGEL_END_READS.out.leafcutter_bamtojunc_ip
}
QUANTIFICATION_AND_MERGE_EXPRESSION_COUNTS(stringtie_ip_ch,leafcutter_bamtojunc_ip_ch, gtf, anchor_length_ch, intron_length_minimum_ch, intron_length_maximum_ch, genotype_input_ch, sample_info_ch, phenotype_PCs_sQTL_ch)
commonSampleIds_ch = QUANTIFICATION_AND_MERGE_EXPRESSION_COUNTS.out.commonSampleIds
norm_Tr_count_ch = QUANTIFICATION_AND_MERGE_EXPRESSION_COUNTS.out.norm_Tr_count
norm_Ge_count_ch = QUANTIFICATION_AND_MERGE_EXPRESSION_COUNTS.out.norm_Ge_count
splice_pc_ch = QUANTIFICATION_AND_MERGE_EXPRESSION_COUNTS.out.splice_pc
splice_count_ch = QUANTIFICATION_AND_MERGE_EXPRESSION_COUNTS.out.splice_Count
}
genotypeStratificationPCA(genotype_input_ch, genotype_pcs_ch)
ciseQTL_workflow(genotypeStratificationPCA.out,commonSampleIds_ch,norm_Tr_count_ch,norm_Ge_count_ch,splice_pc_ch,splice_count_ch,phenotype_PCs_cis,nominal_cis_ch,permutations_cis_ch,fdr_rate_cis_ch)
transeQTL_workflow(genotypeStratificationPCA.out,commonSampleIds_ch,norm_Tr_count_ch,norm_Ge_count_ch,splice_pc_ch,splice_count_ch,phenotype_PCs_trans,threshold_trans_ch,permutations_trans_ch)
}
/* ****END****** */