main.nf 3.72 KB
Newer Older
Gervaise Henry's avatar
Gervaise Henry committed
1
#!/usr/bin/env nextflow
Gervaise Henry's avatar
Gervaise Henry committed
2
3
4
5
6
7
8
9
/*
main.nf
*
* --------------------------------------------------------------------------
* Licensed under MIT (https://git.biohpc.swmed.edu/BICF/Astrocyte/cellranger_mkfastq/blob/develop/LICENSE)
* --------------------------------------------------------------------------
*
*/
Gervaise Henry's avatar
Gervaise Henry committed
10
11

// Define Input variables
12
params.name = "run"
Holly Ruess's avatar
Holly Ruess committed
13
14
15
16
17
18
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
19
// Define List of Files
Gervaise Henry's avatar
Gervaise Henry committed
20
21
tarList = Channel
  .fromPath( params.bcl )
22
bclCount = Channel
Gervaise Henry's avatar
Gervaise Henry committed
23
24
  .fromPath( params.bcl )
  .count()
Gervaise Henry's avatar
Gervaise Henry committed
25
26

// Define regular variables
Gervaise Henry's avatar
Gervaise Henry committed
27
name = params.name
28
29
30
31
designLocation = Channel
  .fromPath(params.designFile)
  .ifEmpty { exit 1, "design file not found: ${params.designFile}" }
outDir = params.outDir
32
multiqcConf = params.multiqcConf
33
references = params.references
Gervaise Henry's avatar
Gervaise Henry committed
34

Gervaise Henry's avatar
Gervaise Henry committed
35

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

  tag "${name}"
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
    """
    hostname
    ulimit -a
51
52
53
54
55
    noSpaceDesign=\$(echo "${designLocation}" | tr -d ' ')
    if [[ "\${noSpaceDesign}" != "${designLocation}" ]]; then
      mv "${designLocation}" "\${noSpaceDesign}"
    fi
    python3 ${baseDir}/scripts/check_design.py -d \${noSpaceDesign}
Holly Ruess's avatar
Holly Ruess committed
56
57
    """

Gervaise Henry's avatar
Gervaise Henry committed
58
59
60
61
}


process untarBCL {
Holly Ruess's avatar
Holly Ruess committed
62
63

  tag "${tar}"
Gervaise Henry's avatar
Gervaise Henry committed
64
65

  input:
Holly Ruess's avatar
Holly Ruess committed
66
    file tar from tarList
Gervaise Henry's avatar
Gervaise Henry committed
67
68

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

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

Gervaise Henry's avatar
Gervaise Henry committed
78
79
}

Gervaise Henry's avatar
Gervaise Henry committed
80

Gervaise Henry's avatar
Gervaise Henry committed
81
process mkfastq {
Holly Ruess's avatar
Holly Ruess committed
82

Gervaise Henry's avatar
Gervaise Henry committed
83
  tag "${bcl.baseName}"
Holly Ruess's avatar
Holly Ruess committed
84
  publishDir "${outDir}/${task.process}", mode: 'copy', pattern: "{*/outs/**/*.fastq.gz}"
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
    file("**/outs/**/*.fastq.gz") into fastqPaths
    file("**/outs/**/*.fastq.gz") into cellrangerCount
Gervaise Henry's avatar
Gervaise Henry committed
93
    file("**/outs/fastq_path/Stats/*") into bqcPaths
Holly Ruess's avatar
Holly Ruess committed
94
    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
    """
    hostname
    ulimit -a  
100
    cellranger mkfastq --id=${bcl.baseName} --run=${bcl} --csv=${design}
Holly Ruess's avatar
Holly Ruess committed
101
102
    """

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

    tag "${name}"
111
    publishDir "${outDir}/${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
134

  input:
Holly Ruess's avatar
Holly Ruess committed
135
136
    file fastqPaths
    val bclName
137
138

  output:
Holly Ruess's avatar
Holly Ruess committed
139
    file("*fastqc.zip") into fqcPaths
140
141

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

149
150
}

151
/*
152
process versions {
Holly Ruess's avatar
Holly Ruess committed
153
154

  tag "${name}"
155
156
157
158

  input:

  output:
Holly Ruess's avatar
Holly Ruess committed
159
    file("*.yaml") into yamlPaths
160
161

  script:
Holly Ruess's avatar
Holly Ruess committed
162
163
164
165
166
167
168
169
170
171
    """
    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
    """

172
173
}

Gervaise Henry's avatar
Gervaise Henry committed
174

Gervaise Henry's avatar
Gervaise Henry committed
175
process multiqc {
Holly Ruess's avatar
Holly Ruess committed
176
177
178

  tag "${name}"
  publishDir "${outDir}/${task.process}/${name}", mode: 'copy', pattern: "{multiqc*}"
Gervaise Henry's avatar
Gervaise Henry committed
179
180

  input:
Holly Ruess's avatar
Holly Ruess committed
181
182
183
    file bqc name "bqc/?/*" from bqcPaths.collect()
    file fqc name "fqc/*" from fqcPaths.collect()
    file yamlPaths
Gervaise Henry's avatar
Gervaise Henry committed
184
185

  output:
Holly Ruess's avatar
Holly Ruess committed
186
    file("multiqc_report.html") into mqcPaths
Gervaise Henry's avatar
Gervaise Henry committed
187
188

  script:
Holly Ruess's avatar
Holly Ruess committed
189
190
191
192
193
194
    """
    hostname
    ulimit -a
    multiqc -c ${multiqcConf} .
    """

195
}
196
*/