main.nf 5.92 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
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
    bash versions_python.sh > version_python.txt
Holly Ruess's avatar
Holly Ruess committed
75
76
    """

Gervaise Henry's avatar
Gervaise Henry committed
77
}
78
79
80
81
/* 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
82

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

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

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

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

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

Gervaise Henry's avatar
Gervaise Henry committed
104
105
}

Gervaise Henry's avatar
Gervaise Henry committed
106

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

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

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

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

  script:
Holly Ruess's avatar
Holly Ruess committed
127
128
129
    """
    hostname
    ulimit -a  
130
131
132
133
134
135
    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
136
137
    """

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

Gervaise Henry's avatar
Gervaise Henry committed
140

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

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

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

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

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

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

161
  }
Holly Ruess's avatar
Holly Ruess committed
162

163
164
}

Gervaise Henry's avatar
Gervaise Henry committed
165

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

168
  tag "${bcl}"
169
170

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

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

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

189
190
}

191

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

  tag "${name}"
195
196

  input:
197
198
  file versionsScript
  file referencesScript
Gervaise Henry's avatar
Gervaise Henry committed
199
200
  //file version_pipeline
  //file version_nextflow
201
202
203
204
205
206
  file version_python
  file version_pigz
  file version_cellranger
  file version_bcl2fastq
  file version_fastqc
  file references
207
208

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

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

219
220
}

Gervaise Henry's avatar
Gervaise Henry committed
221

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

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

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

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

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

Gervaise Henry's avatar
Gervaise Henry committed
245
}