main.nf 3.73 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
  dL=`echo "$designLocation" | tr -d ' '`
41
42
43
44
  if [ `dirname "$designLocation"` != `dirname "\$dL"` ]
  then echo "Error: Spaces Found in Design Directory Path"
  exit 5
  elif [ `basename "$designLocation"` != `basename "\$dL"` ] 
45
46
47
  then mv "$designLocation" "\$dL"
  fi
  python3 "$baseDir/scripts/check_design.py" -d "\$dL"
Gervaise Henry's avatar
Gervaise Henry committed
48
49
50
51
52
53
  """
}


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

  input:

  file tar from tarList

  output:

63
  file("*") into bclPaths mode flatten
Gervaise Henry's avatar
Gervaise Henry committed
64
65
66
67

  script:

  """
68
69
  hostname
  ulimit -a
70
71
  
  tar_no=`echo "${tar}" | tr -d ' '`
72
73
74
75
76
  if [ `dirname "${tar}"` != `dirname "\${tar_no}"` ]
  then echo "Error: Spaces Found in BCL Directory Path"
  exit 5
  elif [ `basename "${tar}"` != `basename "\$dL"` ]
  then mv "${tar}" "\${tar_no}"
77
78
  fi

79
80
  name=`echo ${tar} | rev | cut -f1 -d '.' | rev`;
  if [ "\${name}" == "gz" ];
81
82
  then tar -xvf "\$tar_no" -I pigz;
  else tar -xvf "\$tar_no";
83
  fi;
Gervaise Henry's avatar
Gervaise Henry committed
84
85
86
  """
}

87

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

  input:

96
97
  each bcl from bclPaths.collect()
  file design from designPaths
Gervaise Henry's avatar
Gervaise Henry committed
98
99
100

  output:

101
  file("**/outs/**/*.fastq.gz") into fastqPaths
102
  file("**/outs/fastq_path/Stats/Stats.json") into bqcPaths
103
  val "${bcl.baseName}" into bclName
Gervaise Henry's avatar
Gervaise Henry committed
104
105
106
107

  script:

  """
108
109
  hostname
  ulimit -a
110
  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
111
112
  """
}
Gervaise Henry's avatar
Gervaise Henry committed
113

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
  """
}