Repository navigation
Expand file tree
/
Copy pathexample.nf
More file actions
107 lines (82 loc) · 2.64 KB
/
Copy pathexample.nf
File metadata and controls
107 lines (82 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
nextflow.enable.dsl=2
params.samples = ['sample_ctrl', 'sample_trt1', 'sample_trt2']
params.outdir = 'results'
process SIMULATE_MATRIX {
tag "${sample_id}"
cpus 1
input:
val sample_id
output:
tuple val(sample_id), path("${sample_id}_matrix.csv")
script:
"""
echo "barcode,feature,count" > ${sample_id}_matrix.csv
for i in {1..200}; do
echo "CELL\$((RANDOM % 10)),FEATURE\$((RANDOM % 20)),\$((RANDOM % 100))" >> ${sample_id}_matrix.csv
done
"""
}
process EXTRACT_BARCODES {
tag "${sample_id}"
publishDir "${params.outdir}", mode: 'copy', saveAs: { filename -> "${sample_id}/${filename}" }
input:
tuple val(sample_id), path(matrix_csv)
output:
tuple val(sample_id), path("${sample_id}_barcodes.tsv")
script:
"""
awk -F',' 'NR>1 {print \$1}' ${matrix_csv} | sort | uniq -c | awk '{print \$2 "\t" \$1}' > ${sample_id}_barcodes.tsv
"""
}
process AGGREGATE_FEATURES {
tag "${sample_id}"
input:
tuple val(sample_id), path(matrix_csv)
output:
tuple val(sample_id), path("${sample_id}_features.tsv")
script:
"""
awk -F',' 'NR>1 {print \$2, \$3}' ${matrix_csv} | sort | awk '{a[\$1]+=\$2} END {for (i in a) print i "\t" a[i]}' > ${sample_id}_features.tsv
"""
}
process COMPILE_SAMPLE_STATS {
tag "${sample_id}"
publishDir "${params.outdir}", mode: 'copy', saveAs: { filename -> "${sample_id}/${filename}" }
input:
tuple val(sample_id), path(barcodes), path(features)
output:
path "${sample_id}_summary.txt"
script:
"""
echo "=== ${sample_id} ===" > ${sample_id}_summary.txt
echo "Top 3 Barcodes by Appearance:" >> ${sample_id}_summary.txt
sort -k2,2nr ${barcodes} | head -n 3 >> ${sample_id}_summary.txt
echo "" >> ${sample_id}_summary.txt
echo "Top 3 Features by Count:" >> ${sample_id}_summary.txt
sort -k2,2nr ${features} | head -n 3 >> ${sample_id}_summary.txt
"""
}
process GENERATE_RUN_REPORT {
publishDir "${params.outdir}", mode: 'copy'
input:
path summaries
output:
path "run_report.txt"
script:
"""
echo "PIPELINE EXECUTION REPORT" > run_report.txt
echo "=========================" >> run_report.txt
date >> run_report.txt
echo "" >> run_report.txt
cat ${summaries} >> run_report.txt
"""
}
workflow {
sample_ch = Channel.fromList(params.samples)
matrix_ch = SIMULATE_MATRIX(sample_ch)
barcode_ch = EXTRACT_BARCODES(matrix_ch)
feature_ch = AGGREGATE_FEATURES(matrix_ch)
merged_stats_ch = barcode_ch.join(feature_ch)
summary_ch = COMPILE_SAMPLE_STATS(merged_stats_ch)
GENERATE_RUN_REPORT(summary_ch.collect())
}