main.nf 5.79 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"
Holly Ruess's avatar
Holly Ruess committed
13
14
15
16
params.bcl = "${baseDir}/../test_data/*.tar.gz"
params.designFile = "${baseDir}/../test_data/design.csv"
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
45
46
47
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
multiqcConf = Channel.fromPath("${baseDir}/conf/multiqc_config.yaml")
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
61
62
63
    file("version_pipeline.txt") into version_pipeline
    file("version_nextflow.txt") into version_nextflow
    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
68
    """
    hostname
    ulimit -a
69
70
71
72
    noSpaceDesign=\$(echo "${designLocation}" | tr -d ' ')
    if [[ "\${noSpaceDesign}" != "${designLocation}" ]]; then
      mv "${designLocation}" "\${noSpaceDesign}"
    fi
Gervaise Henry's avatar
Gervaise Henry committed
73
    python3 check_design.py -d \${noSpaceDesign}
74
75
76
    echo "${workflow.manifest.version}" > version_pipeline.txt
    echo "${workflow.nextflow.version}"> version_nextflow.txt
    bash versions_python.sh > version_python.txt
Holly Ruess's avatar
Holly Ruess committed
77
78
    """

Gervaise Henry's avatar
Gervaise Henry committed
79
80
81
}


82
process untarBCL {  
Holly Ruess's avatar
Holly Ruess committed
83

84
  tag "${tar.simpleName}"
Gervaise Henry's avatar
Gervaise Henry committed
85
86

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

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

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

Gervaise Henry's avatar
Gervaise Henry committed
103
104
}

Gervaise Henry's avatar
Gervaise Henry committed
105

Gervaise Henry's avatar
Gervaise Henry committed
106
process mkfastq {
Holly Ruess's avatar
Holly Ruess committed
107

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

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

  output:
118
119
120
    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
121
    file("**/outs/fastq_path/Stats/*") into bqcPaths
122
123
    file("version_cellranger.txt") into version_cellranger
    file("version_bcl2fastq.txt") into version_bcl2fastq
Gervaise Henry's avatar
Gervaise Henry committed
124
125

  script:
Holly Ruess's avatar
Holly Ruess committed
126
127
128
    """
    hostname
    ulimit -a  
129
130
131
132
133
134
    cellranger mkfastq --id=mkfastq_${bcl.simpleName} --run=${bcl} --csv=${design}
    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
135
136
    """

Gervaise Henry's avatar
Gervaise Henry committed
137
}
Gervaise Henry's avatar
Gervaise Henry committed
138

Gervaise Henry's avatar
Gervaise Henry committed
139

140
if (bclCount.value == 1) {
Holly Ruess's avatar
Holly Ruess committed
141

142
  process countDesign {
Holly Ruess's avatar
Holly Ruess committed
143
144

    tag "${name}"
145
    publishDir "${outDir}/${task.process}/${name}", mode: 'copy'
146
147

    input:
Gervaise Henry's avatar
Gervaise Henry committed
148
      file countDesignScript
Holly Ruess's avatar
Holly Ruess committed
149
150
      file fastqs from cellrangerCount.collect()
      file design from designCount
151
152

    output:
Holly Ruess's avatar
Holly Ruess committed
153
      file("Cellranger_Count_Design.csv") into CountDesign
154
155

    script:
Holly Ruess's avatar
Holly Ruess committed
156
      """
Gervaise Henry's avatar
Gervaise Henry committed
157
      bash countDesign.sh
Holly Ruess's avatar
Holly Ruess committed
158
159
      """

160
  }
Holly Ruess's avatar
Holly Ruess committed
161

162
163
}

Gervaise Henry's avatar
Gervaise Henry committed
164

165
process fastqc {
Holly Ruess's avatar
Holly Ruess committed
166

167
  tag "${bcl}"
168
169

  input:
170
171
172
173
    file fastqcScript    
    file versions_fastqcScript
    file(fastq) from fastqPaths
    each bcl from bclName
174
175

  output:
176
177
    file("*fastqc.zip") into fqcPaths mode flatten
    file("version_fastqc.txt") into version_fastqc
178
179

  script:
Holly Ruess's avatar
Holly Ruess committed
180
181
182
    """
    hostname
    ulimit -a
183
    find *.fastq.gz -exec mv {} ${bcl}.{} \\;
Gervaise Henry's avatar
Gervaise Henry committed
184
    bash fastqc.sh
185
    bash versions_fastqc.sh > version_fastqc.txt
Holly Ruess's avatar
Holly Ruess committed
186
187
    """

188
189
}

190

191
process versions {
Holly Ruess's avatar
Holly Ruess committed
192
193

  tag "${name}"
194
195

  input:
196
197
198
199
200
201
202
203
204
205
  file versionsScript
  file referencesScript
  file version_pipeline
  file version_nextflow
  file version_python
  file version_pigz
  file version_cellranger
  file version_bcl2fastq
  file version_fastqc
  file references
206
207

  output:
Holly Ruess's avatar
Holly Ruess committed
208
    file("*.yaml") into yamlPaths
209
210

  script:
Holly Ruess's avatar
Holly Ruess committed
211
212
213
    """
    hostname
    ulimit -a
214
215
    python3 generate_versions.py -f version_*.txt -o versions
    python3 generate_references.py -r ${references} -o references
Holly Ruess's avatar
Holly Ruess committed
216
217
    """

218
219
}

Gervaise Henry's avatar
Gervaise Henry committed
220

Gervaise Henry's avatar
Gervaise Henry committed
221
process multiqc {
Holly Ruess's avatar
Holly Ruess committed
222
223
224

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

  input:
227
    file multiqcConf
Holly Ruess's avatar
Holly Ruess committed
228
    file bqc name "bqc/?/*" from bqcPaths.collect()
229
    file fqc name "fqc/?/*" from fqcPaths.collect()
Holly Ruess's avatar
Holly Ruess committed
230
    file yamlPaths
Gervaise Henry's avatar
Gervaise Henry committed
231
232

  output:
Holly Ruess's avatar
Holly Ruess committed
233
    file("multiqc_report.html") into mqcPaths
Gervaise Henry's avatar
Gervaise Henry committed
234
235

  script:
Holly Ruess's avatar
Holly Ruess committed
236
237
238
    """
    hostname
    ulimit -a
239
240
    export LC_ALL=C.UTF-8
    export LANG=C.UTF-8
Holly Ruess's avatar
Holly Ruess committed
241
242
243
    multiqc -c ${multiqcConf} .
    """

244
}