main.nf 6.14 KB
Newer Older
Gervaise Henry's avatar
Gervaise Henry committed
1
#!/usr/bin/env nextflow
Gervaise Henry's avatar
Gervaise Henry committed
2
3
4
5
6
7
8
9
/*
main.nf
*
* --------------------------------------------------------------------------
* Licensed under MIT (https://git.biohpc.swmed.edu/BICF/Astrocyte/cellranger_mkfastq/blob/develop/LICENSE)
* --------------------------------------------------------------------------
*
*/
Gervaise Henry's avatar
Gervaise Henry committed
10

Gervaise Henry's avatar
Gervaise Henry committed
11
// Define input variables
12
params.name = "run"
13
14
params.bcl = "${baseDir}/../test_data/simple1/*.tar.gz"
params.designFile = "${baseDir}/../test_data/single1/cellranger-tiny-bcl-simple-1_2_0.csv"
Holly Ruess's avatar
Holly Ruess committed
15
16
params.outDir = "${baseDir}/output"

Gervaise Henry's avatar
Gervaise Henry committed
17
// Define list of files
Gervaise Henry's avatar
Gervaise Henry committed
18
19
tarList = Channel
  .fromPath( params.bcl )
20
bclCount = Channel
Gervaise Henry's avatar
Gervaise Henry committed
21
22
  .fromPath( params.bcl )
  .count()
Gervaise Henry's avatar
Gervaise Henry committed
23
24

// Define regular variables
Gervaise Henry's avatar
Gervaise Henry committed
25
name = params.name
26
27
28
29
designLocation = Channel
  .fromPath(params.designFile)
  .ifEmpty { exit 1, "design file not found: ${params.designFile}" }
outDir = params.outDir
Gervaise Henry's avatar
Gervaise Henry committed
30

Gervaise Henry's avatar
Gervaise Henry committed
31
32
33
34
35
// Define script files
check_designScript = Channel.fromPath("$baseDir/scripts/check_design.py")
untarBCLScript = Channel.fromPath("$baseDir/scripts/untarBCL.sh")
countDesignScript = Channel.fromPath("$baseDir/scripts/countDesign.sh")
fastqcScript = Channel.fromPath("$baseDir/scripts/fastqc.sh")
36
37
38
39
40
41
42
43
44
versionsScript = Channel.fromPath("$baseDir/scripts/generate_versions.py")
referencesScript = Channel.fromPath("$baseDir/scripts/generate_references.py")
versions_pythonScript = Channel.fromPath("$baseDir/scripts/versions_python.sh")
versions_pigzScript = Channel.fromPath("$baseDir/scripts/versions_pigz.sh")
versions_cellrangerScript = Channel.fromPath("$baseDir/scripts/versions_cellranger.sh")
versions_bcl2fastqScript = Channel.fromPath("$baseDir/scripts/versions_bcl2fastq.sh")
versions_fastqcScript = Channel.fromPath("$baseDir/scripts/versions_fastqc.sh")

// Define report files
Gervaise Henry's avatar
Gervaise Henry committed
45
multiqcConf = Channel.fromPath("${baseDir}/configs/multiqc_config.yaml")
46
47
references = Channel.fromPath("${baseDir}/../docs/references.md")

Gervaise Henry's avatar
Gervaise Henry committed
48

Gervaise Henry's avatar
Gervaise Henry committed
49
process checkDesignFile {
Holly Ruess's avatar
Holly Ruess committed
50
51

  tag "${name}"
Gervaise Henry's avatar
Gervaise Henry committed
52
53

  input:
Gervaise Henry's avatar
Gervaise Henry committed
54
    file check_designScript
55
    file versions_pythonScript
Holly Ruess's avatar
Holly Ruess committed
56
    file designLocation
Gervaise Henry's avatar
Gervaise Henry committed
57
58

  output:
Holly Ruess's avatar
Holly Ruess committed
59
60
    file("design.checked.csv") into designPaths
    file("design.checked.csv") into designCount
Gervaise Henry's avatar
Gervaise Henry committed
61
62
    //file("version_pipeline.txt") into version_pipeline
    //file("version_nextflow.txt") into version_nextflow
63
    file("version_python.txt") into version_python
Gervaise Henry's avatar
Gervaise Henry committed
64
65

  script:
Holly Ruess's avatar
Holly Ruess committed
66
67
    """
    hostname
68
    ulimit -u 16384
Holly Ruess's avatar
Holly Ruess committed
69
    ulimit -a
70
71
72
73
    noSpaceDesign=\$(echo "${designLocation}" | tr -d ' ')
    if [[ "\${noSpaceDesign}" != "${designLocation}" ]]; then
      mv "${designLocation}" "\${noSpaceDesign}"
    fi
Gervaise Henry's avatar
Gervaise Henry committed
74
    python3 check_design.py -d \${noSpaceDesign}
75
    bash versions_python.sh > version_python.txt
Holly Ruess's avatar
Holly Ruess committed
76
77
    """

Gervaise Henry's avatar
Gervaise Henry committed
78
}
79
80
81
82
/* nextflow workflow version calls that aren't compatible with nextflow 0.31.0
    echo "${workflow.manifest.version}" > version_pipeline.txt
    echo "${workflow.nextflow.version}" > version_nextflow.txt
*/
Gervaise Henry's avatar
Gervaise Henry committed
83

84
process untarBCL {  
Holly Ruess's avatar
Holly Ruess committed
85

86
  tag "${tar.simpleName}"
Gervaise Henry's avatar
Gervaise Henry committed
87
88

  input:
Gervaise Henry's avatar
Gervaise Henry committed
89
    file untarBCLScript
90
    file versions_pigzScript
91
    each file(tar) from tarList
Gervaise Henry's avatar
Gervaise Henry committed
92
93

  output:
94
95
    file("*[!version_pigz.txt]") into bclPaths mode flatten
    file("version_pigz.txt") into version_pigz
Gervaise Henry's avatar
Gervaise Henry committed
96
97

  script:
Holly Ruess's avatar
Holly Ruess committed
98
99
    """
    hostname
100
    ulimit -u 16384
Holly Ruess's avatar
Holly Ruess committed
101
    ulimit -a
102
103
    bash untarBCL.sh -t ${tar}
    bash versions_pigz.sh > version_pigz.txt
Holly Ruess's avatar
Holly Ruess committed
104
105
    """

Gervaise Henry's avatar
Gervaise Henry committed
106
107
}

Gervaise Henry's avatar
Gervaise Henry committed
108

Gervaise Henry's avatar
Gervaise Henry committed
109
process mkfastq {
Holly Ruess's avatar
Holly Ruess committed
110

111
  tag "${bcl.simpleName}"
Holly Ruess's avatar
Holly Ruess committed
112
  publishDir "${outDir}/${task.process}", mode: 'copy', pattern: "{*/outs/**/*.fastq.gz}"
Gervaise Henry's avatar
Gervaise Henry committed
113
114

  input:
115
116
    file versions_cellrangerScript
    file versions_bcl2fastqScript
117
    each file(bcl) from bclPaths.collect()
Holly Ruess's avatar
Holly Ruess committed
118
    file design from designPaths
Gervaise Henry's avatar
Gervaise Henry committed
119
120

  output:
121
122
123
    file("fq/${bcl.simpleName}/*.fastq.gz") into fastqPaths
    val "${bcl.simpleName}" into bclName
    file("**/outs/**/*.fastq.gz") into cellrangerCount mode flatten
Gervaise Henry's avatar
Gervaise Henry committed
124
    file("**/outs/fastq_path/Stats/*") into bqcPaths
125
126
    file("version_cellranger.txt") into version_cellranger
    file("version_bcl2fastq.txt") into version_bcl2fastq
Gervaise Henry's avatar
Gervaise Henry committed
127
128

  script:
Holly Ruess's avatar
Holly Ruess committed
129
130
    """
    hostname
131
132
    ulimit -u 16384
    ulimit -a
133
    cellranger mkfastq --id=mkfastq_${bcl.simpleName} --run=${bcl} --csv=${design} --ignore-dual-index --use-bases-mask=Y28n*,I8n*,Y*
134
135
136
137
138
    mkdir fq
    mkdir "fq/${bcl.simpleName}"
    find . -name "*.fastq.gz" -exec cp {} fq/${bcl.simpleName}/ \\;
    bash versions_cellranger.sh > version_cellranger.txt
    bash versions_bcl2fastq.sh > version_bcl2fastq.txt
Holly Ruess's avatar
Holly Ruess committed
139
140
    """

Gervaise Henry's avatar
Gervaise Henry committed
141
}
Gervaise Henry's avatar
Gervaise Henry committed
142

Gervaise Henry's avatar
Gervaise Henry committed
143

144
if (bclCount.value == 1) {
Holly Ruess's avatar
Holly Ruess committed
145

146
  process countDesign {
Holly Ruess's avatar
Holly Ruess committed
147
148

    tag "${name}"
149
    publishDir "${outDir}/${task.process}/${name}", mode: 'copy'
150
151

    input:
Gervaise Henry's avatar
Gervaise Henry committed
152
      file countDesignScript
Holly Ruess's avatar
Holly Ruess committed
153
154
      file fastqs from cellrangerCount.collect()
      file design from designCount
155
156

    output:
Holly Ruess's avatar
Holly Ruess committed
157
      file("Cellranger_Count_Design.csv") into CountDesign
158
159

    script:
Holly Ruess's avatar
Holly Ruess committed
160
      """
161
162
163
      hostname
      ulimit -u 16384
      ulimit -a
Gervaise Henry's avatar
Gervaise Henry committed
164
      bash countDesign.sh
Holly Ruess's avatar
Holly Ruess committed
165
166
      """

167
  }
Holly Ruess's avatar
Holly Ruess committed
168

169
170
}

Gervaise Henry's avatar
Gervaise Henry committed
171

172
process fastqc {
Holly Ruess's avatar
Holly Ruess committed
173

174
  tag "${bcl}"
175
176

  input:
177
178
179
180
    file fastqcScript    
    file versions_fastqcScript
    file(fastq) from fastqPaths
    each bcl from bclName
181
182

  output:
183
184
    file("*fastqc.zip") into fqcPaths mode flatten
    file("version_fastqc.txt") into version_fastqc
185
186

  script:
Holly Ruess's avatar
Holly Ruess committed
187
188
    """
    hostname
189
    ulimit -u 16384
Holly Ruess's avatar
Holly Ruess committed
190
    ulimit -a
191
    find *.fastq.gz -exec mv {} ${bcl}.{} \\;
Gervaise Henry's avatar
Gervaise Henry committed
192
    bash fastqc.sh
193
    bash versions_fastqc.sh > version_fastqc.txt
Holly Ruess's avatar
Holly Ruess committed
194
195
    """

196
197
}

198

199
process versions {
Holly Ruess's avatar
Holly Ruess committed
200
201

  tag "${name}"
202
203

  input:
204
205
  file versionsScript
  file referencesScript
Gervaise Henry's avatar
Gervaise Henry committed
206
207
  //file version_pipeline
  //file version_nextflow
208
209
210
211
212
213
  file version_python
  file version_pigz
  file version_cellranger
  file version_bcl2fastq
  file version_fastqc
  file references
214
215

  output:
Holly Ruess's avatar
Holly Ruess committed
216
    file("*.yaml") into yamlPaths
217
218

  script:
Holly Ruess's avatar
Holly Ruess committed
219
220
    """
    hostname
221
    ulimit -u 16384
Holly Ruess's avatar
Holly Ruess committed
222
    ulimit -a
223
224
    python3 generate_versions.py -f version_*.txt -o versions
    python3 generate_references.py -r ${references} -o references
Holly Ruess's avatar
Holly Ruess committed
225
226
    """

227
228
}

Gervaise Henry's avatar
Gervaise Henry committed
229

Gervaise Henry's avatar
Gervaise Henry committed
230
process multiqc {
Holly Ruess's avatar
Holly Ruess committed
231
232
233

  tag "${name}"
  publishDir "${outDir}/${task.process}/${name}", mode: 'copy', pattern: "{multiqc*}"
Gervaise Henry's avatar
Gervaise Henry committed
234
235

  input:
236
    file multiqcConf
Holly Ruess's avatar
Holly Ruess committed
237
    file bqc name "bqc/?/*" from bqcPaths.collect()
238
    file fqc name "fqc/?/*" from fqcPaths.collect()
Holly Ruess's avatar
Holly Ruess committed
239
    file yamlPaths
Gervaise Henry's avatar
Gervaise Henry committed
240
241

  output:
Holly Ruess's avatar
Holly Ruess committed
242
    file("multiqc_report.html") into mqcPaths
Gervaise Henry's avatar
Gervaise Henry committed
243
244

  script:
Holly Ruess's avatar
Holly Ruess committed
245
246
    """
    hostname
247
    ulimit -u 16384
Holly Ruess's avatar
Holly Ruess committed
248
    ulimit -a
249
250
    export LC_ALL=C.UTF-8
    export LANG=C.UTF-8
Holly Ruess's avatar
Holly Ruess committed
251
252
253
    multiqc -c ${multiqcConf} .
    """

Gervaise Henry's avatar
Gervaise Henry committed
254
}