-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcgmlst_main.nf
More file actions
172 lines (139 loc) · 4.92 KB
/
cgmlst_main.nf
File metadata and controls
172 lines (139 loc) · 4.92 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
nextflow.enable.dsl=2
// ============================================================
// cgMLST / wgMLST pipeline using pyMLST
// Author: Mikra
// ============================================================
// -----------------------------
// Parameters and Help Section
// -----------------------------
params.species = ""
params.input = ""
params.output = "results_cgmlst"
params.help = false
params.subgraph_threshold = 5
if (params.help) {
println """
🧬 cgMLST / wgMLST pipeline — perform whole-genome MLST typing with pyMLST
Usage:
nextflow run cgmlst_main.nf --species "Salmonella enterica" --input /path/to/fasta_dir --output results_cgmlst
Required arguments:
--species Name of the bacterial species (exactly as listed below)
--input Directory containing .fa or .fasta assemblies
--output Directory where results will be stored
Example:
nextflow run cgmlst_main.nf --species "Salmonella enterica" --input ./assemblies --output ./cgmlst_out
✅ Supported species list (see full list on cgmlst.org)
------------------------------------------------------------
Acinetobacter baumannii
Bacillus anthracis
Bordetella pertussis
Brucella melitensis
Burkholderia pseudomallei
Campylobacter jejuni/coli
Clostridioides difficile
Corynebacterium diphtheriae
Enterococcus faecalis
Enterococcus faecium
Escherichia coli
Klebsiella pneumoniae
Legionella pneumophila
Listeria monocytogenes
Pseudomonas aeruginosa
Salmonella enterica
Staphylococcus aureus
Streptococcus pyogenes
Yersinia enterocolitica
------------------------------------------------------------
🔗 Visit https://cgmlst.org/ for complete scheme details.
"""
System.exit(0)
}
// -----------------------------
// Validation
// -----------------------------
if (!params.species) exit 1, "❌ Missing required parameter: --species"
if (!params.input) exit 1, "❌ Missing required parameter: --input"
if (!file(params.input).exists()) exit 1, "❌ Input folder not found: ${params.input}"
// -----------------------------
// Process: Run cgMLST with pyMLST
// -----------------------------
process cgmlst_run {
tag "${params.species}"
label 'cgmlst'
conda "envs/pymlst.yml"
publishDir "${params.output}", mode: 'copy'
output:
path "${params.output}/msa.fasta", emit: msa
path "${params.output}/subgraph.tsv"
path "${params.output}/matrix_inf.tsv"
script:
def DB_NAME = "DATABASE"
def DB_PATH = "${params.output}/${DB_NAME}"
def INPUT_DIR = file(params.input)
"""
set -euo pipefail
echo "▶ Starting cgMLST pipeline for species: ${params.species}"
echo "📂 Input directory: ${INPUT_DIR}"
echo "📁 Output directory: ${params.output}"
echo "🗃️ Database: ${DB_PATH}"
mkdir -p "${params.output}/tmp_fastas"
echo "▶ Step 1: Importing cgMLST scheme for ${params.species}"
(cd "${params.output}" && wgMLST import "${DB_NAME}" "${params.species}")
echo "▶ Step 2: Renaming fasta files (replace '-' with '_') and copying"
shopt -s nullglob
for file in "${INPUT_DIR}"/*.fa "${INPUT_DIR}"/*.fasta; do
[ -e "\$file" ] || continue
base=\$(basename "\$file")
clean="\${base//-/_}"
cp "\$file" "${params.output}/tmp_fastas/\$clean"
done
shopt -u nullglob
echo "▶ Step 3: Adding assemblies to database"
for i in "${params.output}/tmp_fastas"/*.fa "${params.output}/tmp_fastas"/*.fasta; do
[ -e "\$i" ] || continue
base=\$(basename "\$i")
base="\${base%.fa}"
base="\${base%.fasta}"
wgMLST add -s "\$base" "${DB_PATH}" "\$i"
done
echo "▶ Step 4: Calculating distance matrix"
wgMLST distance "${DB_PATH}" -o "${params.output}/matrix_inf.tsv"
echo "▶ Step 5: Creating subgraph (threshold ${params.subgraph_threshold})"
wgMLST subgraph -e group -t ${params.subgraph_threshold} \\
"${params.output}/matrix_inf.tsv" -o "${params.output}/subgraph.tsv"
echo "▶ Step 6: Generating multiple sequence alignment (MSA)"
wgMLST msa -o "${params.output}/msa.fasta" "${DB_PATH}"
echo "✅ cgMLST pipeline completed successfully for ${params.species}"
"""
}
process run_grapetree {
tag "grapetree"
conda "envs/grapetree.yml"
publishDir "${params.output}", mode: 'copy'
input:
path msa
output:
path "MSTree.tsv"
script:
"""
echo "▶ Running GrapeTree on msa.fasta"
grapetree -p ${msa} > MSTree.tsv
echo "✅ GrapeTree completed: MSTree.tsv generated"
"""
}
// -----------------------------
// Workflow definition
// -----------------------------
workflow {
cgmlst_ch=cgmlst_run()
run_grapetree(cgmlst_ch.msa)
}
// -----------------------------
// Completion message
// -----------------------------
workflow.onComplete {
println ""
println "🎉 cgMLST analysis completed successfully!"
println "📁 Results saved to: ${params.output}"
println "🔗 Visit https://cgmlst.org/ for more scheme details."
}