main.nf 6.89 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 = ""
Gervaise Henry's avatar
Gervaise Henry committed
16
params.astrocyte = false
Holly Ruess's avatar
Holly Ruess committed
17
18
params.outDir = "${baseDir}/output"

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

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

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

Gervaise Henry's avatar
Gervaise Henry committed
52

Gervaise Henry's avatar
Gervaise Henry committed
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
/*
 * 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
78
process checkDesignFile {
Holly Ruess's avatar
Holly Ruess committed
79
80

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

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

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

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

Gervaise Henry's avatar
Gervaise Henry committed
109
}
110
111
112
/* 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
113

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

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

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

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

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

Gervaise Henry's avatar
Gervaise Henry committed
136
137
}

Gervaise Henry's avatar
Gervaise Henry committed
138

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

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

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

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

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

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

Gervaise Henry's avatar
Gervaise Henry committed
173

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

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

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

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

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

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

197
  }
Holly Ruess's avatar
Holly Ruess committed
198

199
200
}

Gervaise Henry's avatar
Gervaise Henry committed
201

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

204
  tag "${bcl}"
205
206

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

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

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

226
227
}

228

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

  tag "${name}"
232
233

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

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

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

257
258
}

Gervaise Henry's avatar
Gervaise Henry committed
259

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

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

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

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

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

Gervaise Henry's avatar
Gervaise Henry committed
284
}