main.nf 3.21 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
14
15

// Define List of Files
tarList = Channel.fromPath( params.bcl )

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

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

  input:

29
  file designLocation
Gervaise Henry's avatar
Gervaise Henry committed
30
31
32

  output:

33
  file("design.checked.csv") into designPaths
Gervaise Henry's avatar
Gervaise Henry committed
34
35
36
37

  script:

  """
38
39
  hostname
  ulimit -a
40
  python3 $baseDir/scripts/check_design.py -d $designLocation
Gervaise Henry's avatar
Gervaise Henry committed
41
42
43
44
45
46
  """
}


process untarBCL {
  tag "$tar"
47
  publishDir "$outDir/${task.process}", mode: 'copy'
48
  module 'pigz/2.4'
Gervaise Henry's avatar
Gervaise Henry committed
49
50
51
52
53
54
55

  input:

  file tar from tarList

  output:

56
  file("*") into bclPaths mode flatten
Gervaise Henry's avatar
Gervaise Henry committed
57
58
59
60

  script:

  """
61
62
  hostname
  ulimit -a
63
64
  name=`echo ${tar} | rev | cut -f1 -d '.' | rev`;
  if [ "\${name}" == "gz" ];
65
66
  then tar -xvf $tar -I pigz;
  else tar -xvf $tar;
67
  fi;
Gervaise Henry's avatar
Gervaise Henry committed
68
69
70
  """
}

71

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

  input:

80
81
  each bcl from bclPaths.collect()
  file design from designPaths
Gervaise Henry's avatar
Gervaise Henry committed
82
83
84

  output:

85
  file("**/outs/**/*.fastq.gz") into fastqPaths
86
  file("**/outs/fastq_path/Stats/Stats.json") into bqcPaths
87
  val "${bcl.baseName}" into bclName
Gervaise Henry's avatar
Gervaise Henry committed
88
89
90
91

  script:

  """
92
93
  hostname
  ulimit -a
94
  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
95
96
  """
}
Gervaise Henry's avatar
Gervaise Henry committed
97

98
process fastqc {
99
  tag "$bclName"
100
  queue 'super'
Gervaise Henry's avatar
Gervaise Henry committed
101
  publishDir "$outDir/misc/${task.process}/$name/$bclName", mode: 'copy', pattern: "{*fastqc.zip}"
Gervaise Henry's avatar
Fix    
Gervaise Henry committed
102
  module 'fastqc/0.11.5:parallel'
103
104

  input:
105
  file fastqPaths
Gervaise Henry's avatar
Gervaise Henry committed
106
  val bclName
107
108
109

  output:

110
  file("*fastqc.zip") into fqcPaths
111
112
113
114
115
116

  script:

  """
  hostname
  ulimit -a
117
  find *.fastq.gz -exec mv {} $bclName.{} \\;
118
  bash $baseDir/scripts/fastqc.sh
119
  
120
121
122
123
  """
}


124
process versions {
Gervaise Henry's avatar
Gervaise Henry committed
125
126
  tag "$name"
  publishDir "$outDir/misc/${task.process}/$name", mode: 'copy'
127
  module 'python/3.6.1-2-anaconda:cellranger/3.0.2:bcl2fastq/2.19.1:fastqc/0.11.5'
128
129
130
131
132
133
134
135
136
137
138
139
140

  input:

  output:

  file("*.yaml") into yamlPaths

  script:

  """
  hostname
  ulimit -a
  echo $workflow.nextflow.version > version_nextflow.txt
141
142
  sh $baseDir/scripts/versions_mkfastq.sh
  bash $baseDir/scripts/versions_fastqc.sh
143
144
145
146
  python3 $baseDir/scripts/generate_versions.py -f version_*.txt -o versions
  """
}

Gervaise Henry's avatar
Gervaise Henry committed
147
process multiqc {
Gervaise Henry's avatar
Gervaise Henry committed
148
  tag "$name"
Gervaise Henry's avatar
Gervaise Henry committed
149
  queue 'super'
150
  publishDir "$outDir/${task.process}/$name", mode: 'copy', pattern: "{multiqc*}"
151
  module 'multiqc/1.7'
Gervaise Henry's avatar
Gervaise Henry committed
152
153
154

  input:

155
  file bqc name "bqc/?/*" from bqcPaths.collect()
156
  file fqc name "fqc/*" from fqcPaths.collect()
157
  file yamlPaths
Gervaise Henry's avatar
Gervaise Henry committed
158
159
160

  output:

161
  file("*") into mqcPaths
Gervaise Henry's avatar
Gervaise Henry committed
162
163
164
165
166
167

  script:

  """
  hostname
  ulimit -a
Gervaise Henry's avatar
Gervaise Henry committed
168
  multiqc . -c $baseDir/conf/multiqc_config.yaml 
Gervaise Henry's avatar
Gervaise Henry committed
169
170
  """
}