main.nf 3.89 KB
Newer Older
Gervaise Henry's avatar
Gervaise Henry committed
1
2
3
4
5
6
#!/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

// Define Input variables
7
params.name = "run"
Venkat Malladi's avatar
Venkat Malladi committed
8
params.bcl = "$baseDir/../test_data/*.tar.gz"
Gervaise Henry's avatar
Gervaise Henry committed
9
params.designFile = "$baseDir/../test_data/design.csv"
10
params.outDir = "$baseDir/output"
11
params.multiqcConf = "$baseDir/conf/multiqc_config.yaml"
12
params.references = "$baseDir/../docs/references.md"
Gervaise Henry's avatar
Gervaise Henry committed
13
14
15

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

// Define regular variables
Gervaise Henry's avatar
Gervaise Henry committed
21
name = params.name
22
23
24
25
designLocation = Channel
  .fromPath(params.designFile)
  .ifEmpty { exit 1, "design file not found: ${params.designFile}" }
outDir = params.outDir
26
multiqcConf = params.multiqcConf
27
references = params.references
Gervaise Henry's avatar
Gervaise Henry committed
28
29

process checkDesignFile {
Gervaise Henry's avatar
Gervaise Henry committed
30
31
  tag "$name"
  publishDir "$outDir/misc/${task.process}/$name", mode: 'copy'
32
  module 'python/3.6.1-2-anaconda'
Gervaise Henry's avatar
Gervaise Henry committed
33
34

  input:
35
  file designLocation
Gervaise Henry's avatar
Gervaise Henry committed
36
37

  output:
38
  file("design.checked.csv") into designPaths
39
  file("design.checked.csv") into designCount
Gervaise Henry's avatar
Gervaise Henry committed
40
41
42

  script:
  """
43
44
  hostname
  ulimit -a
45
  python3 "$baseDir/scripts/check_design.py" -d "$designLocation"
Gervaise Henry's avatar
Gervaise Henry committed
46
47
48
49
50
51
  """
}


process untarBCL {
  tag "$tar"
52
  publishDir "$outDir/${task.process}", mode: 'copy'
53
  module 'pigz/2.4'
Gervaise Henry's avatar
Gervaise Henry committed
54
55
56
57
58

  input:
  file tar from tarList

  output:
59
  file("*") into bclPaths mode flatten
Gervaise Henry's avatar
Gervaise Henry committed
60
61
62

  script:
  """
63
64
  hostname
  ulimit -a
Jeremy Mathews's avatar
Jeremy Mathews committed
65
  bash "$baseDir/scripts/untarBCL.sh" -t "$tar"
Gervaise Henry's avatar
Gervaise Henry committed
66
67
68
69
70
  """
}

process mkfastq {
  tag "${bcl.baseName}"
71
  queue '128GB,256GB,256GBv1,384GB'
Gervaise Henry's avatar
Fix    
Gervaise Henry committed
72
  publishDir "$outDir/${task.process}", mode: 'copy', pattern: "{*/outs/**/*.fastq.gz}"
73
  module 'cellranger/3.0.2:bcl2fastq/2.19.1'
Gervaise Henry's avatar
Gervaise Henry committed
74
75

  input:
76
77
  each bcl from bclPaths.collect()
  file design from designPaths
Gervaise Henry's avatar
Gervaise Henry committed
78
79

  output:
80
  file("**/outs/**/*.fastq.gz") into fastqPaths
81
  file("**/outs/**/*.fastq.gz") into cellrangerCount
82
  file("**/outs/fastq_path/Stats/Stats.json") into bqcPaths
83
  val "${bcl.baseName}" into bclName
Gervaise Henry's avatar
Gervaise Henry committed
84
85
86

  script:
  """
87
  hostname
88
  ulimit -a  
89
  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
90
91
  """
}
Gervaise Henry's avatar
Gervaise Henry committed
92

93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
if (bclCount.value == 1) {
  process countDesign {
    tag "$name"
    publishDir "$outDir/misc/${task.process}/$name", mode: 'copy'

    input:
    file fastqs from cellrangerCount.collect()
    file design from designCount

    output:
    file("Cellranger_Count_Design.csv") into CountDesign

    script:
    """
    bash "$baseDir/scripts/countDesign.sh"
    """
  }
}

112
process fastqc {
113
  tag "$bclName"
114
  queue 'super'
Gervaise Henry's avatar
Gervaise Henry committed
115
  publishDir "$outDir/misc/${task.process}/$name/$bclName", mode: 'copy', pattern: "{*fastqc.zip}"
Gervaise Henry's avatar
Fix    
Gervaise Henry committed
116
  module 'fastqc/0.11.5:parallel'
117
118

  input:
119
  file fastqPaths
Gervaise Henry's avatar
Gervaise Henry committed
120
  val bclName
121
122

  output:
123
  file("*fastqc.zip") into fqcPaths
124
125
126
127
128

  script:
  """
  hostname
  ulimit -a
129
  find *.fastq.gz -exec mv {} $bclName.{} \\;
130
  bash "$baseDir/scripts/fastqc.sh"
131
  
132
133
134
135
  """
}


136
process versions {
Gervaise Henry's avatar
Gervaise Henry committed
137
138
  tag "$name"
  publishDir "$outDir/misc/${task.process}/$name", mode: 'copy'
139
  module 'python/3.6.1-2-anaconda:cellranger/3.0.2:bcl2fastq/2.19.1:fastqc/0.11.5:pandoc/2.7'
140
141
142
143
144
145
146
147
148
149
150

  input:

  output:
  file("*.yaml") into yamlPaths

  script:
  """
  hostname
  ulimit -a
  echo $workflow.nextflow.version > version_nextflow.txt
151
152
153
  bash "$baseDir/scripts/versions_mkfastq.sh"
  bash "$baseDir/scripts/versions_fastqc.sh"
  python3 "$baseDir/scripts/generate_versions.py" -f version_*.txt -o versions
154
  python3 "$baseDir/scripts/generate_references.py" -r "$references" -o references
155
156
157
  """
}

Gervaise Henry's avatar
Gervaise Henry committed
158
process multiqc {
Gervaise Henry's avatar
Gervaise Henry committed
159
  tag "$name"
Gervaise Henry's avatar
Gervaise Henry committed
160
  queue 'super'
161
  publishDir "$outDir/${task.process}/$name", mode: 'copy', pattern: "{multiqc*}"
162
  module 'multiqc/1.7'
Gervaise Henry's avatar
Gervaise Henry committed
163
164

  input:
165
  file bqc name "bqc/?/*" from bqcPaths.collect()
166
  file fqc name "fqc/*" from fqcPaths.collect()
167
  file yamlPaths
Gervaise Henry's avatar
Gervaise Henry committed
168
169

  output:
170
  file("multiqc_report.html") into mqcPaths
Gervaise Henry's avatar
Gervaise Henry committed
171
172
173
174
175

  script:
  """
  hostname
  ulimit -a
176
  multiqc -c $multiqcConf .
Gervaise Henry's avatar
Gervaise Henry committed
177
  """
178
}