main.nf 3.65 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"
Gervaise Henry's avatar
Gervaise Henry committed
11
12
13

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

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

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

  input:

32
  file designLocation
Gervaise Henry's avatar
Gervaise Henry committed
33
34
35

  output:

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

  script:

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


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

  input:

  file tar from tarList

  output:

60
  file("*") into bclPaths mode flatten
Gervaise Henry's avatar
Gervaise Henry committed
61
62
63
64

  script:

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

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

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

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

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

95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
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"
    """
  }
}

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

  input:
121
  file fastqPaths
Gervaise Henry's avatar
Gervaise Henry committed
122
  val bclName
123
124
125

  output:

126
  file("*fastqc.zip") into fqcPaths
127
128
129
130
131
132

  script:

  """
  hostname
  ulimit -a
133
  find *.fastq.gz -exec mv {} $bclName.{} \\;
134
  bash "$baseDir/scripts/fastqc.sh"
135
  
136
137
138
139
  """
}


140
process versions {
Gervaise Henry's avatar
Gervaise Henry committed
141
142
  tag "$name"
  publishDir "$outDir/misc/${task.process}/$name", mode: 'copy'
143
  module 'python/3.6.1-2-anaconda:cellranger/3.0.2:bcl2fastq/2.19.1:fastqc/0.11.5'
144
145
146
147
148
149
150
151
152
153
154
155
156

  input:

  output:

  file("*.yaml") into yamlPaths

  script:

  """
  hostname
  ulimit -a
  echo $workflow.nextflow.version > version_nextflow.txt
157
158
159
  bash "$baseDir/scripts/versions_mkfastq.sh"
  bash "$baseDir/scripts/versions_fastqc.sh"
  python3 "$baseDir/scripts/generate_versions.py" -f version_*.txt -o versions
160
161
162
  """
}

Gervaise Henry's avatar
Gervaise Henry committed
163
process multiqc {
Gervaise Henry's avatar
Gervaise Henry committed
164
  tag "$name"
Gervaise Henry's avatar
Gervaise Henry committed
165
  queue 'super'
166
  publishDir "$outDir/${task.process}/$name", mode: 'copy', pattern: "{multiqc*}"
167
  module 'multiqc/1.7'
Gervaise Henry's avatar
Gervaise Henry committed
168
169
170

  input:

171
  file bqc name "bqc/?/*" from bqcPaths.collect()
172
  file fqc name "fqc/*" from fqcPaths.collect()
173
  file yamlPaths
Gervaise Henry's avatar
Gervaise Henry committed
174
175
176

  output:

177
  file("*") into mqcPaths
Gervaise Henry's avatar
Gervaise Henry committed
178
179
180
181
182
183

  script:

  """
  hostname
  ulimit -a
184
  multiqc . -c "$baseDir/conf/multiqc_config.yaml"
Gervaise Henry's avatar
Gervaise Henry committed
185
186
  """
}