main.nf 6.86 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"
15
params.mask = ""
Holly Ruess's avatar
Holly Ruess committed
16
17
params.outDir = "${baseDir}/output"

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

// Define regular variables
Gervaise Henry's avatar
Gervaise Henry committed
26
pipelineVersion = "2.x.x-indev"
Gervaise Henry's avatar
Gervaise Henry committed
27
name = params.name
28
29
30
designLocation = Channel
  .fromPath(params.designFile)
  .ifEmpty { exit 1, "design file not found: ${params.designFile}" }
31
mask = params.mask
32
outDir = params.outDir
Gervaise Henry's avatar
Gervaise Henry committed
33

Gervaise Henry's avatar
Gervaise Henry committed
34
35
36
37
38
// 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")
39
40
41
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")
Gervaise Henry's avatar
Gervaise Henry committed
42
#versions_pigzScript = Channel.fromPath("$baseDir/scripts/versions_pigz.sh")
43
44
45
46
47
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
48
multiqcConf = Channel.fromPath("${baseDir}/configs/multiqc_config.yaml")
49
50
references = Channel.fromPath("${baseDir}/../docs/references.md")

Gervaise Henry's avatar
Gervaise Henry committed
51

Gervaise Henry's avatar
Gervaise Henry committed
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
/*
 * trackStart: track start of pipeline
 */
params.ci = false
process trackStart {
  script:
  """
  hostname
  ulimit -a
  export https_proxy=\${http_proxy}
 
  curl -H 'Content-Type: application/json' -X PUT -d '{ \
      "sessionId": "${workflow.sessionId}", \
      "pipeline": "cellranger_mkfastq", \
      "pipelineVersion": "${pipelineVersion}", \
      "start": "${workflow.start}", \
      "astrocyte": ${params.astrocyte}, \
      "status": "started", \
      "nextflowVersion": "${workflow.nextflow.version}",
      "ci": ${params.ci}}' \
  "https://xku43pcwnf.execute-api.us-east-1.amazonaws.com/ProdDeploy/pipeline-tracking"
  """
}


Gervaise Henry's avatar
Gervaise Henry committed
77
process checkDesignFile {
Holly Ruess's avatar
Holly Ruess committed
78
79

  tag "${name}"
Gervaise Henry's avatar
Gervaise Henry committed
80
81

  input:
Gervaise Henry's avatar
Gervaise Henry committed
82
    file check_designScript
83
    file versions_pythonScript
Holly Ruess's avatar
Holly Ruess committed
84
    file designLocation
Gervaise Henry's avatar
Gervaise Henry committed
85
86

  output:
Holly Ruess's avatar
Holly Ruess committed
87
88
    file("design.checked.csv") into designPaths
    file("design.checked.csv") into designCount
89
90
    file("version_pipeline.txt") into version_pipeline
    file("version_nextflow.txt") into version_nextflow
91
    file("version_python.txt") into version_python
Gervaise Henry's avatar
Gervaise Henry committed
92
93

  script:
Holly Ruess's avatar
Holly Ruess committed
94
95
    """
    hostname
96
    ulimit -u 16384
Holly Ruess's avatar
Holly Ruess committed
97
    ulimit -a
98
99
100
101
    noSpaceDesign=\$(echo "${designLocation}" | tr -d ' ')
    if [[ "\${noSpaceDesign}" != "${designLocation}" ]]; then
      mv "${designLocation}" "\${noSpaceDesign}"
    fi
Gervaise Henry's avatar
Gervaise Henry committed
102
    python3 check_design.py -d \${noSpaceDesign}
103
    bash versions_python.sh > version_python.txt
104
    echo "${workflow.nextflow.version}" > version_nextflow.txt
Gervaise Henry's avatar
Gervaise Henry committed
105
    echo "${pipelineVersion" > version_pipeline.txt
Holly Ruess's avatar
Holly Ruess committed
106
107
    """

Gervaise Henry's avatar
Gervaise Henry committed
108
}
109
110
111
/* nextflow workflow manifest version calls that aren't compatible with Asrcocyte
    echo "${workflow.manifest.version}" > version_pipeline.txt
*/
Gervaise Henry's avatar
Gervaise Henry committed
112

113
process untarBCL {  
Holly Ruess's avatar
Holly Ruess committed
114

115
  tag "${tar.simpleName}"
Gervaise Henry's avatar
Gervaise Henry committed
116
117

  input:
Gervaise Henry's avatar
Gervaise Henry committed
118
    file untarBCLScript
Gervaise Henry's avatar
Gervaise Henry committed
119
    #file versions_pigzScript
120
    each file(tar) from tarList
Gervaise Henry's avatar
Gervaise Henry committed
121
122

  output:
123
    file("*[!version_pigz.txt]") into bclPaths mode flatten
Gervaise Henry's avatar
Gervaise Henry committed
124
    #file("version_pigz.txt") into version_pigz
Gervaise Henry's avatar
Gervaise Henry committed
125
126

  script:
Holly Ruess's avatar
Holly Ruess committed
127
128
    """
    hostname
129
    ulimit -u 16384
Holly Ruess's avatar
Holly Ruess committed
130
    ulimit -a
131
    bash untarBCL.sh -t ${tar}
Gervaise Henry's avatar
Gervaise Henry committed
132
    #bash versions_pigz.sh > version_pigz.txt
Holly Ruess's avatar
Holly Ruess committed
133
134
    """

Gervaise Henry's avatar
Gervaise Henry committed
135
136
}

Gervaise Henry's avatar
Gervaise Henry committed
137

Gervaise Henry's avatar
Gervaise Henry committed
138
process mkfastq {
Holly Ruess's avatar
Holly Ruess committed
139

140
  tag "${bcl.simpleName}"
Holly Ruess's avatar
Holly Ruess committed
141
  publishDir "${outDir}/${task.process}", mode: 'copy', pattern: "{*/outs/**/*.fastq.gz}"
Gervaise Henry's avatar
Gervaise Henry committed
142
143

  input:
144
145
    file versions_cellrangerScript
    file versions_bcl2fastqScript
146
    each file(bcl) from bclPaths.collect()
Holly Ruess's avatar
Holly Ruess committed
147
    file design from designPaths
Gervaise Henry's avatar
Gervaise Henry committed
148
149

  output:
150
151
152
    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
153
    file("**/outs/fastq_path/Stats/*") into bqcPaths
154
155
    file("version_cellranger.txt") into version_cellranger
    file("version_bcl2fastq.txt") into version_bcl2fastq
Gervaise Henry's avatar
Gervaise Henry committed
156
157

  script:
Holly Ruess's avatar
Holly Ruess committed
158
159
    """
    hostname
160
161
    ulimit -u 16384
    ulimit -a
162
    cellranger mkfastq --id=mkfastq_${bcl.simpleName} --run=${bcl} --csv=${design} --ignore-dual-index ${mask}
163
164
165
166
167
    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
168
169
    """

Gervaise Henry's avatar
Gervaise Henry committed
170
}
Gervaise Henry's avatar
Gervaise Henry committed
171

Gervaise Henry's avatar
Gervaise Henry committed
172

173
if (bclCount.value == 1) {
Holly Ruess's avatar
Holly Ruess committed
174

175
  process countDesign {
Holly Ruess's avatar
Holly Ruess committed
176
177

    tag "${name}"
178
    publishDir "${outDir}/${task.process}/${name}", mode: 'copy'
179
180

    input:
Gervaise Henry's avatar
Gervaise Henry committed
181
      file countDesignScript
Holly Ruess's avatar
Holly Ruess committed
182
183
      file fastqs from cellrangerCount.collect()
      file design from designCount
184
185

    output:
Holly Ruess's avatar
Holly Ruess committed
186
      file("Cellranger_Count_Design.csv") into CountDesign
187
188

    script:
Holly Ruess's avatar
Holly Ruess committed
189
      """
190
191
192
      hostname
      ulimit -u 16384
      ulimit -a
Gervaise Henry's avatar
Gervaise Henry committed
193
      bash countDesign.sh
Holly Ruess's avatar
Holly Ruess committed
194
195
      """

196
  }
Holly Ruess's avatar
Holly Ruess committed
197

198
199
}

Gervaise Henry's avatar
Gervaise Henry committed
200

201
process fastqc {
Holly Ruess's avatar
Holly Ruess committed
202

203
  tag "${bcl}"
204
205

  input:
206
207
208
209
    file fastqcScript    
    file versions_fastqcScript
    file(fastq) from fastqPaths
    each bcl from bclName
210
211

  output:
212
213
    file("*fastqc.zip") into fqcPaths mode flatten
    file("version_fastqc.txt") into version_fastqc
214
215

  script:
Holly Ruess's avatar
Holly Ruess committed
216
217
    """
    hostname
218
    ulimit -u 16384
Holly Ruess's avatar
Holly Ruess committed
219
    ulimit -a
220
    find *.fastq.gz -exec mv {} ${bcl}.{} \\;
Gervaise Henry's avatar
Gervaise Henry committed
221
    bash fastqc.sh
222
    bash versions_fastqc.sh > version_fastqc.txt
Holly Ruess's avatar
Holly Ruess committed
223
224
    """

225
226
}

227

228
process versions {
Holly Ruess's avatar
Holly Ruess committed
229
230

  tag "${name}"
231
232

  input:
233
234
  file versionsScript
  file referencesScript
235
236
  file version_pipeline
  file version_nextflow
237
238
239
240
241
242
  file version_python
  file version_pigz
  file version_cellranger
  file version_bcl2fastq
  file version_fastqc
  file references
243
244

  output:
Holly Ruess's avatar
Holly Ruess committed
245
    file("*.yaml") into yamlPaths
246
247

  script:
Holly Ruess's avatar
Holly Ruess committed
248
249
    """
    hostname
250
    ulimit -u 16384
Holly Ruess's avatar
Holly Ruess committed
251
    ulimit -a
252
253
    python3 generate_versions.py -f version_*.txt -o versions
    python3 generate_references.py -r ${references} -o references
Holly Ruess's avatar
Holly Ruess committed
254
255
    """

256
257
}

Gervaise Henry's avatar
Gervaise Henry committed
258

Gervaise Henry's avatar
Gervaise Henry committed
259
process multiqc {
Holly Ruess's avatar
Holly Ruess committed
260
261
262

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

  input:
265
    file multiqcConf
Holly Ruess's avatar
Holly Ruess committed
266
    file bqc name "bqc/?/*" from bqcPaths.collect()
267
    file fqc name "fqc/?/*" from fqcPaths.collect()
Holly Ruess's avatar
Holly Ruess committed
268
    file yamlPaths
Gervaise Henry's avatar
Gervaise Henry committed
269
270

  output:
Holly Ruess's avatar
Holly Ruess committed
271
    file("multiqc_report.html") into mqcPaths
Gervaise Henry's avatar
Gervaise Henry committed
272
273

  script:
Holly Ruess's avatar
Holly Ruess committed
274
275
    """
    hostname
276
    ulimit -u 16384
Holly Ruess's avatar
Holly Ruess committed
277
    ulimit -a
278
279
    export LC_ALL=C.UTF-8
    export LANG=C.UTF-8
Holly Ruess's avatar
Holly Ruess committed
280
281
282
    multiqc -c ${multiqcConf} .
    """

Gervaise Henry's avatar
Gervaise Henry committed
283
}