main.nf 6.19 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
name = params.name
27
28
29
designLocation = Channel
  .fromPath(params.designFile)
  .ifEmpty { exit 1, "design file not found: ${params.designFile}" }
30
mask = params.mask
31
outDir = params.outDir
Gervaise Henry's avatar
Gervaise Henry committed
32

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

Gervaise Henry's avatar
Gervaise Henry committed
50

Gervaise Henry's avatar
Gervaise Henry committed
51
process checkDesignFile {
Holly Ruess's avatar
Holly Ruess committed
52
53

  tag "${name}"
Gervaise Henry's avatar
Gervaise Henry committed
54
55

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

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

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

Gervaise Henry's avatar
Gervaise Henry committed
82
}
83
84
85
/* 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
86

87
process untarBCL {  
Holly Ruess's avatar
Holly Ruess committed
88

89
  tag "${tar.simpleName}"
Gervaise Henry's avatar
Gervaise Henry committed
90
91

  input:
Gervaise Henry's avatar
Gervaise Henry committed
92
    file untarBCLScript
93
    file versions_pigzScript
94
    each file(tar) from tarList
Gervaise Henry's avatar
Gervaise Henry committed
95
96

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

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

Gervaise Henry's avatar
Gervaise Henry committed
109
110
}

Gervaise Henry's avatar
Gervaise Henry committed
111

Gervaise Henry's avatar
Gervaise Henry committed
112
process mkfastq {
Holly Ruess's avatar
Holly Ruess committed
113

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

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

  output:
124
125
126
    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
127
    file("**/outs/fastq_path/Stats/*") into bqcPaths
128
129
    file("version_cellranger.txt") into version_cellranger
    file("version_bcl2fastq.txt") into version_bcl2fastq
Gervaise Henry's avatar
Gervaise Henry committed
130
131

  script:
Holly Ruess's avatar
Holly Ruess committed
132
133
    """
    hostname
134
135
    ulimit -u 16384
    ulimit -a
136
    cellranger mkfastq --id=mkfastq_${bcl.simpleName} --run=${bcl} --csv=${design} --ignore-dual-index ${mask}
137
138
139
140
141
    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
142
143
    """

Gervaise Henry's avatar
Gervaise Henry committed
144
}
Gervaise Henry's avatar
Gervaise Henry committed
145

Gervaise Henry's avatar
Gervaise Henry committed
146

147
if (bclCount.value == 1) {
Holly Ruess's avatar
Holly Ruess committed
148

149
  process countDesign {
Holly Ruess's avatar
Holly Ruess committed
150
151

    tag "${name}"
152
    publishDir "${outDir}/${task.process}/${name}", mode: 'copy'
153
154

    input:
Gervaise Henry's avatar
Gervaise Henry committed
155
      file countDesignScript
Holly Ruess's avatar
Holly Ruess committed
156
157
      file fastqs from cellrangerCount.collect()
      file design from designCount
158
159

    output:
Holly Ruess's avatar
Holly Ruess committed
160
      file("Cellranger_Count_Design.csv") into CountDesign
161
162

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

170
  }
Holly Ruess's avatar
Holly Ruess committed
171

172
173
}

Gervaise Henry's avatar
Gervaise Henry committed
174

175
process fastqc {
Holly Ruess's avatar
Holly Ruess committed
176

177
  tag "${bcl}"
178
179

  input:
180
181
182
183
    file fastqcScript    
    file versions_fastqcScript
    file(fastq) from fastqPaths
    each bcl from bclName
184
185

  output:
186
187
    file("*fastqc.zip") into fqcPaths mode flatten
    file("version_fastqc.txt") into version_fastqc
188
189

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

199
200
}

201

202
process versions {
Holly Ruess's avatar
Holly Ruess committed
203
204

  tag "${name}"
205
206

  input:
207
208
  file versionsScript
  file referencesScript
209
210
  file version_pipeline
  file version_nextflow
211
212
213
214
215
216
  file version_python
  file version_pigz
  file version_cellranger
  file version_bcl2fastq
  file version_fastqc
  file references
217
218

  output:
Holly Ruess's avatar
Holly Ruess committed
219
    file("*.yaml") into yamlPaths
220
221

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

230
231
}

Gervaise Henry's avatar
Gervaise Henry committed
232

Gervaise Henry's avatar
Gervaise Henry committed
233
process multiqc {
Holly Ruess's avatar
Holly Ruess committed
234
235
236

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

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

  output:
Holly Ruess's avatar
Holly Ruess committed
245
    file("multiqc_report.html") into mqcPaths
Gervaise Henry's avatar
Gervaise Henry committed
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
    export LC_ALL=C.UTF-8
    export LANG=C.UTF-8
Holly Ruess's avatar
Holly Ruess committed
254
255
256
    multiqc -c ${multiqcConf} .
    """

Gervaise Henry's avatar
Gervaise Henry committed
257
}