main.nf 4.09 KB
Newer Older
Gervaise Henry's avatar
Gervaise Henry committed
1
2
3
4
5
#!/usr/bin/env nextflow

// Path to an input file, or a pattern for multiple inputs
// Note - $baseDir is the location of this workflow file main.nf

Holly Ruess's avatar
Holly Ruess committed
6

Gervaise Henry's avatar
Gervaise Henry committed
7
// Define Input variables
8
params.name = "run"
Holly Ruess's avatar
Holly Ruess committed
9
10
11
12
13
14
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
15
16

// Define List of Files
Gervaise Henry's avatar
Gervaise Henry committed
17
18
tarList = Channel
  .fromPath( params.bcl )
19
bclCount = Channel
Gervaise Henry's avatar
Gervaise Henry committed
20
21
  .fromPath( params.bcl )
  .count()
Gervaise Henry's avatar
Gervaise Henry committed
22

Holly Ruess's avatar
Holly Ruess committed
23

Gervaise Henry's avatar
Gervaise Henry committed
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
30
multiqcConf = params.multiqcConf
31
references = params.references
Gervaise Henry's avatar
Gervaise Henry committed
32

Gervaise Henry's avatar
Gervaise Henry committed
33

Gervaise Henry's avatar
Gervaise Henry committed
34
process checkDesignFile {
Holly Ruess's avatar
Holly Ruess committed
35
36
37

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

  input:
Holly Ruess's avatar
Holly Ruess committed
41
    file designLocation
Gervaise Henry's avatar
Gervaise Henry committed
42
43

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

  script:
Holly Ruess's avatar
Holly Ruess committed
48
49
50
51
52
53
    """
    hostname
    ulimit -a
    python3 ${baseDir}/scripts/check_design.py -d ${designLocation}
    """

Gervaise Henry's avatar
Gervaise Henry committed
54
55
56
57
}


process untarBCL {
Holly Ruess's avatar
Holly Ruess committed
58
59
60

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

  input:
Holly Ruess's avatar
Holly Ruess committed
64
    file tar from tarList
Gervaise Henry's avatar
Gervaise Henry committed
65
66

  output:
Holly Ruess's avatar
Holly Ruess committed
67
    file("*") into bclPaths mode flatten
Gervaise Henry's avatar
Gervaise Henry committed
68
69

  script:
Holly Ruess's avatar
Holly Ruess committed
70
71
72
73
74
75
    """
    hostname
    ulimit -a
    bash ${baseDir}/scripts/untarBCL.sh -t ${tar}
    """

Gervaise Henry's avatar
Gervaise Henry committed
76
77
}

Gervaise Henry's avatar
Gervaise Henry committed
78

Gervaise Henry's avatar
Gervaise Henry committed
79
process mkfastq {
Holly Ruess's avatar
Holly Ruess committed
80

Gervaise Henry's avatar
Gervaise Henry committed
81
  tag "${bcl.baseName}"
82
  queue '128GB,256GB,256GBv1,384GB'
Holly Ruess's avatar
Holly Ruess committed
83
  publishDir "${outDir}/${task.process}", mode: 'copy', pattern: "{*/outs/**/*.fastq.gz}"
84
  module 'cellranger/3.1.0:bcl2fastq/2.19.1'
Gervaise Henry's avatar
Gervaise Henry committed
85
86

  input:
Holly Ruess's avatar
Holly Ruess committed
87
88
    each bcl from bclPaths.collect()
    file design from designPaths
Gervaise Henry's avatar
Gervaise Henry committed
89
90

  output:
Holly Ruess's avatar
Holly Ruess committed
91
92
93
94
    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
95
96

  script:
Holly Ruess's avatar
Holly Ruess committed
97
98
99
100
101
102
    """
    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
103
}
Gervaise Henry's avatar
Gervaise Henry committed
104

Gervaise Henry's avatar
Gervaise Henry committed
105

106
if (bclCount.value == 1) {
Holly Ruess's avatar
Holly Ruess committed
107

108
  process countDesign {
Holly Ruess's avatar
Holly Ruess committed
109
110
111

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

    input:
Holly Ruess's avatar
Holly Ruess committed
114
115
      file fastqs from cellrangerCount.collect()
      file design from designCount
116
117

    output:
Holly Ruess's avatar
Holly Ruess committed
118
      file("Cellranger_Count_Design.csv") into CountDesign
119
120

    script:
Holly Ruess's avatar
Holly Ruess committed
121
122
123
124
      """
      bash ${baseDir}/scripts/countDesign.sh
      """

125
  }
Holly Ruess's avatar
Holly Ruess committed
126

127
128
}

Gervaise Henry's avatar
Gervaise Henry committed
129

130
process fastqc {
Holly Ruess's avatar
Holly Ruess committed
131
132

  tag "${bclName}"
133
  queue 'super'
Holly Ruess's avatar
Holly Ruess committed
134
  publishDir "${outDir}/misc/${task.process}/${name}/${bclName}", mode: 'copy', pattern: "{*fastqc.zip}"
Gervaise Henry's avatar
Fix    
Gervaise Henry committed
135
  module 'fastqc/0.11.5:parallel'
136
137

  input:
Holly Ruess's avatar
Holly Ruess committed
138
139
    file fastqPaths
    val bclName
140
141

  output:
Holly Ruess's avatar
Holly Ruess committed
142
    file("*fastqc.zip") into fqcPaths
143
144

  script:
Holly Ruess's avatar
Holly Ruess committed
145
146
147
148
149
150
151
    """
    hostname
    ulimit -a
    find *.fastq.gz -exec mv {} ${bclName}.{} \\;
    bash ${baseDir}/scripts/fastqc.sh
    """

152
153
154
}


155
process versions {
Holly Ruess's avatar
Holly Ruess committed
156
157
158

  tag "${name}"
  publishDir "${outDir}/misc/${task.process}/${name}", mode: 'copy'
159
  module 'python/3.6.1-2-anaconda:cellranger/3.1.0:bcl2fastq/2.19.1:fastqc/0.11.5:pandoc/2.7'
160
161
162
163

  input:

  output:
Holly Ruess's avatar
Holly Ruess committed
164
    file("*.yaml") into yamlPaths
165
166

  script:
Holly Ruess's avatar
Holly Ruess committed
167
168
169
170
171
172
173
174
175
176
    """
    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
    """

177
178
}

Gervaise Henry's avatar
Gervaise Henry committed
179

Gervaise Henry's avatar
Gervaise Henry committed
180
process multiqc {
Holly Ruess's avatar
Holly Ruess committed
181
182

  tag "${name}"
Gervaise Henry's avatar
Gervaise Henry committed
183
  queue 'super'
Holly Ruess's avatar
Holly Ruess committed
184
  publishDir "${outDir}/${task.process}/${name}", mode: 'copy', pattern: "{multiqc*}"
185
  module 'multiqc/1.7'
Gervaise Henry's avatar
Gervaise Henry committed
186
187

  input:
Holly Ruess's avatar
Holly Ruess committed
188
189
190
    file bqc name "bqc/?/*" from bqcPaths.collect()
    file fqc name "fqc/*" from fqcPaths.collect()
    file yamlPaths
Gervaise Henry's avatar
Gervaise Henry committed
191
192

  output:
Holly Ruess's avatar
Holly Ruess committed
193
    file("multiqc_report.html") into mqcPaths
Gervaise Henry's avatar
Gervaise Henry committed
194
195

  script:
Holly Ruess's avatar
Holly Ruess committed
196
197
198
199
200
201
    """
    hostname
    ulimit -a
    multiqc -c ${multiqcConf} .
    """

202
}