main.nf 4.41 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
11

// Define Input variables
12
params.name = "run"
Holly Ruess's avatar
Holly Ruess committed
13
14
15
16
17
18
params.bcl = "${baseDir}/../test_data/*.tar.gz"
params.designFile = "${baseDir}/../test_data/design.csv"
params.outDir = "${baseDir}/output"
params.multiqcConf = "${baseDir}/conf/multiqc_config.yaml"
params.references = "${baseDir}/../docs/references.md"

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

Gervaise Henry's avatar
Gervaise Henry committed
35

Gervaise Henry's avatar
Gervaise Henry committed
36
process checkDesignFile {
Holly Ruess's avatar
Holly Ruess committed
37
38
39

  tag "${name}"
  publishDir "${outDir}/misc/${task.process}/${name}", mode: 'copy'
40
  module 'python/3.6.1-2-anaconda'
Gervaise Henry's avatar
Gervaise Henry committed
41
42

  input:
Holly Ruess's avatar
Holly Ruess committed
43
    file designLocation
Gervaise Henry's avatar
Gervaise Henry committed
44
45

  output:
Holly Ruess's avatar
Holly Ruess committed
46
47
    file("design.checked.csv") into designPaths
    file("design.checked.csv") into designCount
Gervaise Henry's avatar
Gervaise Henry committed
48
49

  script:
Holly Ruess's avatar
Holly Ruess committed
50
51
52
    """
    hostname
    ulimit -a
53
54
55
56
57
    noSpaceDesign=\$(echo "${designLocation}" | tr -d ' ')
    if [[ "\${noSpaceDesign}" != "${designLocation}" ]]; then
      mv "${designLocation}" "\${noSpaceDesign}"
    fi
    python3 ${baseDir}/scripts/check_design.py -d \${noSpaceDesign}
Holly Ruess's avatar
Holly Ruess committed
58
59
    """

Gervaise Henry's avatar
Gervaise Henry committed
60
61
62
63
}


process untarBCL {
Holly Ruess's avatar
Holly Ruess committed
64
65
66

  tag "${tar}"
  publishDir "${outDir}/${task.process}", mode: 'copy'
67
  module 'pigz/2.4'
Gervaise Henry's avatar
Gervaise Henry committed
68
69

  input:
Holly Ruess's avatar
Holly Ruess committed
70
    file tar from tarList
Gervaise Henry's avatar
Gervaise Henry committed
71
72

  output:
Holly Ruess's avatar
Holly Ruess committed
73
    file("*") into bclPaths mode flatten
Gervaise Henry's avatar
Gervaise Henry committed
74
75

  script:
Holly Ruess's avatar
Holly Ruess committed
76
77
78
79
80
81
    """
    hostname
    ulimit -a
    bash ${baseDir}/scripts/untarBCL.sh -t ${tar}
    """

Gervaise Henry's avatar
Gervaise Henry committed
82
83
}

Gervaise Henry's avatar
Gervaise Henry committed
84

Gervaise Henry's avatar
Gervaise Henry committed
85
process mkfastq {
Holly Ruess's avatar
Holly Ruess committed
86

Gervaise Henry's avatar
Gervaise Henry committed
87
  tag "${bcl.baseName}"
88
  queue '128GB,256GB,256GBv1,384GB'
Holly Ruess's avatar
Holly Ruess committed
89
  publishDir "${outDir}/${task.process}", mode: 'copy', pattern: "{*/outs/**/*.fastq.gz}"
90
  module 'cellranger/3.1.0:bcl2fastq/2.19.1'
Gervaise Henry's avatar
Gervaise Henry committed
91
92

  input:
Holly Ruess's avatar
Holly Ruess committed
93
94
    each bcl from bclPaths.collect()
    file design from designPaths
Gervaise Henry's avatar
Gervaise Henry committed
95
96

  output:
Holly Ruess's avatar
Holly Ruess committed
97
98
99
100
    file("**/outs/**/*.fastq.gz") into fastqPaths
    file("**/outs/**/*.fastq.gz") into cellrangerCount
    file("**/outs/fastq_path/Stats/Stats.json") into bqcPaths
    val "${bcl.baseName}" into bclName
Gervaise Henry's avatar
Gervaise Henry committed
101
102

  script:
Holly Ruess's avatar
Holly Ruess committed
103
104
105
106
107
108
    """
    hostname
    ulimit -a  
    cellranger mkfastq --id=${bcl.baseName} --run=${bcl} --csv=${design} -r \$SLURM_CPUS_ON_NODE  -p \$SLURM_CPUS_ON_NODE  -w \$SLURM_CPUS_ON_NODE 
    """

Gervaise Henry's avatar
Gervaise Henry committed
109
}
Gervaise Henry's avatar
Gervaise Henry committed
110

Gervaise Henry's avatar
Gervaise Henry committed
111

112
if (bclCount.value == 1) {
Holly Ruess's avatar
Holly Ruess committed
113

114
  process countDesign {
Holly Ruess's avatar
Holly Ruess committed
115
116
117

    tag "${name}"
    publishDir "${outDir}/misc/${task.process}/${name}", mode: 'copy'
118
119

    input:
Holly Ruess's avatar
Holly Ruess committed
120
121
      file fastqs from cellrangerCount.collect()
      file design from designCount
122
123

    output:
Holly Ruess's avatar
Holly Ruess committed
124
      file("Cellranger_Count_Design.csv") into CountDesign
125
126

    script:
Holly Ruess's avatar
Holly Ruess committed
127
128
129
130
      """
      bash ${baseDir}/scripts/countDesign.sh
      """

131
  }
Holly Ruess's avatar
Holly Ruess committed
132

133
134
}

Gervaise Henry's avatar
Gervaise Henry committed
135

136
process fastqc {
Holly Ruess's avatar
Holly Ruess committed
137
138

  tag "${bclName}"
139
  queue 'super'
Holly Ruess's avatar
Holly Ruess committed
140
  publishDir "${outDir}/misc/${task.process}/${name}/${bclName}", mode: 'copy', pattern: "{*fastqc.zip}"
Gervaise Henry's avatar
Fix    
Gervaise Henry committed
141
  module 'fastqc/0.11.5:parallel'
142
143

  input:
Holly Ruess's avatar
Holly Ruess committed
144
145
    file fastqPaths
    val bclName
146
147

  output:
Holly Ruess's avatar
Holly Ruess committed
148
    file("*fastqc.zip") into fqcPaths
149
150

  script:
Holly Ruess's avatar
Holly Ruess committed
151
152
153
154
155
156
157
    """
    hostname
    ulimit -a
    find *.fastq.gz -exec mv {} ${bclName}.{} \\;
    bash ${baseDir}/scripts/fastqc.sh
    """

158
159
160
}


161
process versions {
Holly Ruess's avatar
Holly Ruess committed
162
163
164

  tag "${name}"
  publishDir "${outDir}/misc/${task.process}/${name}", mode: 'copy'
165
  module 'python/3.6.1-2-anaconda:cellranger/3.1.0:bcl2fastq/2.19.1:fastqc/0.11.5:pandoc/2.7'
166
167
168
169

  input:

  output:
Holly Ruess's avatar
Holly Ruess committed
170
    file("*.yaml") into yamlPaths
171
172

  script:
Holly Ruess's avatar
Holly Ruess committed
173
174
175
176
177
178
179
180
181
182
    """
    hostname
    ulimit -a
    echo ${workflow.nextflow.version} > version_nextflow.txt
    bash ${baseDir}/scripts/versions_mkfastq.sh
    bash ${baseDir}/scripts/versions_fastqc.sh
    python3 ${baseDir}/scripts/generate_versions.py -f version_*.txt -o versions
    python3 ${baseDir}/scripts/generate_references.py -r ${references} -o references
    """

183
184
}

Gervaise Henry's avatar
Gervaise Henry committed
185

Gervaise Henry's avatar
Gervaise Henry committed
186
process multiqc {
Holly Ruess's avatar
Holly Ruess committed
187
188

  tag "${name}"
Gervaise Henry's avatar
Gervaise Henry committed
189
  queue 'super'
Holly Ruess's avatar
Holly Ruess committed
190
  publishDir "${outDir}/${task.process}/${name}", mode: 'copy', pattern: "{multiqc*}"
191
  module 'multiqc/1.7'
Gervaise Henry's avatar
Gervaise Henry committed
192
193

  input:
Holly Ruess's avatar
Holly Ruess committed
194
195
196
    file bqc name "bqc/?/*" from bqcPaths.collect()
    file fqc name "fqc/*" from fqcPaths.collect()
    file yamlPaths
Gervaise Henry's avatar
Gervaise Henry committed
197
198

  output:
Holly Ruess's avatar
Holly Ruess committed
199
    file("multiqc_report.html") into mqcPaths
Gervaise Henry's avatar
Gervaise Henry committed
200
201

  script:
Holly Ruess's avatar
Holly Ruess committed
202
203
204
205
206
207
    """
    hostname
    ulimit -a
    multiqc -c ${multiqcConf} .
    """

208
}