Repository: genomic-medicine-sweden/jasen
Pull request #417: 387 implement post mapping qc for long reads
Author: login: Emkago
Created: 2025-03-19T14:14:48Z | Merged: 2025-03-28T13:43:24Z

# Description
_##Remove elements in cursive as needed.##_

Add mapping of LR to the reference and post mapping QC.

_Summary of the changes made:_
- added Minimap2 module to map LR sequences to the reference genome
- created Mmi index for all the species
- renamed `referenceGenomeIdx` to `referenceGenomeFai` and added variable `referenceGenomeMmi` for Minimap2 index
- added samtools coverage function to extract stats after mapping with Minimap2

## Primary function of PR
- [ ] Hotfix
- [x] Minor functionality improvement
- [ ] Major functionality improvement / New type of analysis
- [ ] Backward-breaking functionality

# Testing
I have tested it on S. aureus workflow with Nanopore test data.

# Sign-offs
- [ ] Code reviewed by @octocat
- [ ] Code tested by @octocat



Diff:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c34f11c2..ac3695bf 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,18 +8,27 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 ## [Unreleased]
 
 ### Added
-- Added missing tools to S. aureus subworkflow tool list
 
+- Added missing tools to S. aureus subworkflow tool list
 - Added spyogenes bed file representing cgmlst targets
 - Added `prodigal` image download to container `Makefile`
+- Added module for mapping long reads with Minimap2
+- Added Minimap2 refence index `referenceGenomeMmi` for all species
+- Added `samtools_coverage` to get stats from mapping long reads to the reference and assembly
+- Added `minimap2_align_assembly`
+- Added `minimap2_index` for assembly indexing
 
 ### Fixed
+- Fixed stub-run for S.aureus ONT workflow
 
 ### Changed
 
 - Changed spyogenes genome from `GCF_000006785.2` to `GCF_005164585.1`
 - Updated `check_taxon` method to include spyogenes
 - Changed ptf downloading to generation of ptf via prodigal for `ecoli` & `spyogenes`
+- Renamed index created by BWA from `referenceGenomeIdx` to `referenceGenomeFai`
+- Renamed `bwa_mem_dedup` to `bwa_mem_assembly`
+- Split `samtools_sort` into two modules
 
 ## [1.0.0]
 
diff --git a/Makefile b/Makefile
index 37a3206a..6c6628bd 100644
--- a/Makefile
+++ b/Makefile
@@ -335,6 +335,7 @@ $(ASSETS_DIR)/virulencefinder_db/stx.name: | check-and-reinit-git-submodules
 saureus_all: saureus_download_reference \
 	saureus_faidx_reference \
 	saureus_bwaidx_reference \
+	saureus_minimap2idx_reference \
 	saureus_download_prodigal_training_file \
 	saureus_download_cgmlst_schema \
 	saureus_unpack_cgmlst_schema \
@@ -374,6 +375,13 @@ $(SAUR_GENOMES_DIR)/$(SAUR_REFSEQ_ACC).fasta.bwt: $(SAUR_GENOMES_DIR)/$(SAUR_REF
 	&& apptainer exec --bind $(MNT_ROOT) $(CONTAINER_DIR)/bwakit.sif \
 		bwa index $$(basename $<) |& tee -a $(INSTALL_LOG)
 
+saureus_minimap2idx_reference: $(SAUR_GENOMES_DIR)/$(SAUR_REFSEQ_ACC).mmi
+
+$(SAUR_GENOMES_DIR)/$(SAUR_REFSEQ_ACC).mmi: $(SAUR_GENOMES_DIR)/$(SAUR_REFSEQ_ACC).fasta
+	$(call log_message,"Indexing S. aureus reference genome using minimap2...")
+	cd $(SAUR_GENOMES_DIR) \
+	&& apptainer exec --bind $(MNT_ROOT) $(CONTAINER_DIR)/minimap2.sif \
+		minimap2 -d $@ $< |& tee -a $(INSTALL_LOG)
 
 saureus_download_prodigal_training_file: $(PRODIGAL_TRAINING_DIR)/Staphylococcus_aureus.trn
 
@@ -429,6 +437,7 @@ $(SAUR_CGMLST_DIR)/alleles_rereffed: | $(SAUR_CGMLST_DIR)/alleles/unpacking.done
 ecoli_all: ecoli_download_reference \
 	ecoli_faidx_reference \
 	ecoli_bwaidx_reference \
+	ecoli_minimap2idx_reference \
 	ecoli_generate_prodigal_training_file \
 	ecoli_download_wgmlst_schema \
 	ecoli_prep_ecoli_cgmlst_schema
@@ -469,6 +478,15 @@ $(ECOLI_GENOMES_DIR)/$(ECOLI_REFSEQ_ACC).fasta.bwt: $(ECOLI_GENOMES_DIR)/$(ECOLI
 		bwa index $$(basename $<) |& tee -a $(INSTALL_LOG)
 
 
+ecoli_minimap2idx_reference: $(ECOLI_GENOMES_DIR)/$(ECOLI_REFSEQ_ACC).mmi
+
+$(ECOLI_GENOMES_DIR)/$(ECOLI_REFSEQ_ACC).mmi: $(ECOLI_GENOMES_DIR)/$(ECOLI_REFSEQ_ACC).fasta
+	$(call log_message,"Indexing E. coli genome using minimap2...")
+	cd $(ECOLI_GENOMES_DIR) \
+	&& apptainer exec --bind $(MNT_ROOT) $(CONTAINER_DIR)/minimap2.sif \
+		minimap2 -d $@ $< |& tee -a $(INSTALL_LOG)
+
+
 ecoli_generate_prodigal_training_file: $(PRODIGAL_TRAINING_DIR)/Escherichia_coli.trn
 
 $(PRODIGAL_TRAINING_DIR)/Escherichia_coli.trn:
@@ -541,6 +559,7 @@ $(ECOLI_CGMLST_DIR)/alleles_rereffed: | $(ECOLI_CGMLST_DIR)/alleles/unpacking.do
 kpneumoniae_all: kpneumoniae_download_reference \
 	kpneumoniae_faidx_reference \
 	kpneumoniae_bwaidx_reference \
+	kpneumoniae_minimap2idx_reference \
 	kpneumoniae_download_prodigal_training_file \
 	kpneumoniae_download_cgmlst_schema \
 	kpneumoniae_unpack_cgmlst_schema \
@@ -581,6 +600,14 @@ $(KPNEU_GENOMES_DIR)/$(KPNEU_REFSEQ_ACC).fasta.bwt: $(KPNEU_GENOMES_DIR)/$(KPNEU
 	&& apptainer exec --bind $(MNT_ROOT) $(CONTAINER_DIR)/bwakit.sif \
 		bwa index $$(basename $<) |& tee -a $(INSTALL_LOG)
 
+kpneumoniae_minimap2idx_reference: $(KPNEU_GENOMES_DIR)/$(KPNEU_REFSEQ_ACC).mmi
+
+$(KPNEU_GENOMES_DIR)/$(KPNEU_REFSEQ_ACC).mmi: $(KPNEU_GENOMES_DIR)/$(KPNEU_REFSEQ_ACC).fasta
+	$(call log_message,"Indexing K. pneumoniae genome using minimap2...")
+	cd $(KPNEU_GENOMES_DIR) \
+	&& apptainer exec --bind $(MNT_ROOT) $(CONTAINER_DIR)/minimap2.sif \
+		minimap2 -d $@ $< |& tee -a $(INSTALL_LOG)
+
 
 kpneumoniae_download_prodigal_training_file: $(PRODIGAL_TRAINING_DIR)/Klebsiella_pneumoniae.trn
 
@@ -639,6 +666,7 @@ $(KPNEU_CGMLST_DIR)/alleles_rereffed: | $(KPNEU_CGMLST_DIR)/alleles/unpacking.do
 spyogenes_all: spyogenes_download_reference \
 	spyogenes_faidx_reference \
 	spyogenes_bwaidx_reference \
+	spyogenes_minimap2idx_reference \
 	spyogenes_generate_prodigal_training_file \
 	spyogenes_download_cgmlst_schema \
 	spyogenes_unpack_cgmlst_schema \
@@ -680,6 +708,15 @@ $(SPYO_GENOMES_DIR)/$(SPYO_REFSEQ_ACC).fasta.bwt: $(SPYO_GENOMES_DIR)/$(SPYO_REF
 		bwa index $$(basename $<) |& tee -a $(INSTALL_LOG)
 
 
+spyogenes_minimap2idx_reference: $(SPYO_GENOMES_DIR)/$(SPYO_REFSEQ_ACC).mmi
+
+$(SPYO_GENOMES_DIR)/$(SPYO_REFSEQ_ACC).mmi: $(SPYO_GENOMES_DIR)/$(SPYO_REFSEQ_ACC).fasta
+	$(call log_message,"Indexing S. pyogenes genome using minimap2...")
+	cd $(SPYO_GENOMES_DIR) \
+	&& apptainer exec --bind $(MNT_ROOT) $(CONTAINER_DIR)/minimap2.sif \
+		minimap2 -d $@ $< |& tee -a $(INSTALL_LOG)
+
+
 spyogenes_generate_prodigal_training_file: $(PRODIGAL_TRAINING_DIR)/Streptococcus_pyogenes.trn
 
 $(PRODIGAL_TRAINING_DIR)/Streptococcus_pyogenes.trn:
@@ -785,7 +822,13 @@ MTUBE_TBDB_DIR := $(ASSETS_DIR)/tbdb
 MTUBE_TB_INFO_DIR := $(ASSETS_DIR)/tb_info
 MTUBE_REFSEQ_ACC := GCF_000195955.2
 
-mtuberculosis_all: mtuberculosis_download_reference mtuberculosis_faidx_reference mtuberculosis_bwaidx_reference mtuberculosis_converged_who_fohm_tbdb mtuberculosis_bgzip_bed mtuberculosis_index_bed
+mtuberculosis_all: mtuberculosis_download_reference \
+	mtuberculosis_faidx_reference \
+	mtuberculosis_bwaidx_reference \
+	mtuberculosis_miniamp2idx_reference \
+	mtuberculosis_converged_who_fohm_tbdb \
+	mtuberculosis_bgzip_bed \
+	mtuberculosis_index_bed
 
 mtuberculosis_download_reference: $(MTUBE_GENOMES_DIR)/$(MTUBE_REFSEQ_ACC).fasta
 
@@ -814,6 +857,15 @@ $(MTUBE_GENOMES_DIR)/$(MTUBE_REFSEQ_ACC).fasta.bwt: $(MTUBE_GENOMES_DIR)/$(MTUBE
 	&& apptainer exec --bind $(MNT_ROOT) $(CONTAINER_DIR)/bwakit.sif \
 		bwa index $$(basename $<) |& tee -a $(INSTALL_LOG)
 
+mtuberculosis_minimap2idx_reference: $(MTUBE_GENOMES_DIR)/$(MTUBE_REFSEQ_ACC).mmi
+
+$(MTUBE_GENOMES_DIR)/$(MTUBE_REFSEQ_ACC).mmi: $(MTUBE_GENOMES_DIR)/$(MTUBE_REFSEQ_ACC).fasta
+	$(call log_message,"Indexing M. tuberculosis genome using minimap2...")
+	cd $(MTUBE_GENOMES_DIR) \
+	&& apptainer exec --bind $(MNT_ROOT) $(CONTAINER_DIR)/minimap2.sif \
+		minimap2 -d $@ $< |& tee -a $(INSTALL_LOG)
+
+
 mtuberculosis_converged_who_fohm_tbdb: $(MTUBE_TBDB_DIR)/converged_who_fohm_tbdb.variables.json
 
 $(MTUBE_TBDB_DIR)/converged_who_fohm_tbdb.variables.json: $(MTUBE_TB_INFO_DIR)/csv/converged_who_fohm_tbdb.csv
@@ -906,6 +958,18 @@ check_bwa:
 		echo "[!] FAILED check for bwa: Indexes do not exist in $(SAUR_GENOMES_DIR)" |& tee -a $(INSTALL_LOG); \
 	fi
 
+check_minimap2:
+	@cd $(SCRIPT_DIR) \
+	&& ref=$(SAUR_GENOMES_DIR)/$(SAUR_REFSEQ_ACC).fasta; \
+		refmmi=$${ref}.mmi \
+	&& if [[ -f $$ref \
+		&& -f $${refmmi} \
+	]]; then \
+		echo "[✓] PASSED check for minimap2: Indexes exist in $(SAUR_GENOMES_DIR)" |& tee -a $(INSTALL_LOG); \
+	else \
+		echo "[!] FAILED check for minimap2: Indexes do not exist in $(SAUR_GENOMES_DIR)" |& tee -a $(INSTALL_LOG); \
+	fi
+
 # -----------------------------
 # Check BlastDB
 # -----------------------------
diff --git a/configs/nextflow.base.config b/configs/nextflow.base.config
index ff31cd16..317f4cf7 100644
--- a/configs/nextflow.base.config
+++ b/configs/nextflow.base.config
@@ -39,7 +39,8 @@ profiles {
 		params.speciesDir = 'saureus'
 		params.mlstScheme = 'saureus'
 		params.referenceGenome = "${params.root}/assets/genomes/staphylococcus_aureus/GCF_000012045.1.fasta"
-		params.referenceGenomeIdx = "${params.root}/assets/genomes/staphylococcus_aureus/GCF_000012045.1.fasta.fai"
+		params.referenceGenomeFai = "${params.root}/assets/genomes/staphylococcus_aureus/GCF_000012045.1.fasta.fai"
+		params.referenceGenomeMmi = "${params.root}/assets/genomes/staphylococcus_aureus/GCF_000012045.1.mmi"
 		params.referenceGenomeGff = "${params.root}/assets/genomes/staphylococcus_aureus/GCF_000012045.1.gff"
 		params.chewbbacaDb = "${params.root}/assets/cgmlst/staphylococcus_aureus/alleles_rereffed"
 		params.coreLociBed = "${params.root}/assets/cgmlst/staphylococcus_aureus/bed/GCF_000012045.1.bed"
@@ -54,7 +55,8 @@ profiles {
 		params.speciesDir = 'ecoli'
 		params.mlstScheme = 'ecoli_achtman_4'
 		params.referenceGenome = "${params.root}/assets/genomes/escherichia_coli/GCF_000005845.2.fasta"
-		params.referenceGenomeIdx = "${params.root}/assets/genomes/escherichia_coli/GCF_000005845.2.fasta.fai"
+		params.referenceGenomeFai = "${params.root}/assets/genomes/escherichia_coli/GCF_000005845.2.fasta.fai"
+		params.referenceGenomeMmi = "${params.root}/assets/genomes/escherichia_coli/GCF_000005845.2.mmi"
 		params.referenceGenomeGff = "${params.root}/assets/genomes/escherichia_coli/GCF_000005845.2.gff"
 		// params.chewbbacaDb = "${params.root}/assets/cgmlst/escherichia_coli/alleles_rereffed"
 		// params.coreLociBed = "${params.root}/assets/cgmlst/escherichia_coli/bed/GCF_000005845.2.bed"
@@ -73,7 +75,8 @@ profiles {
 		params.speciesDir = 'kpneumoniae'
 		params.mlstScheme = 'klebsiella'
 		params.referenceGenome = "${params.root}/assets/genomes/klebsiella_pneumoniae/GCF_000240185.1.fasta"
-		params.referenceGenomeIdx = "${params.root}/assets/genomes/klebsiella_pneumoniae/GCF_000240185.1.fasta.fai"
+		params.referenceGenomeFai = "${params.root}/assets/genomes/klebsiella_pneumoniae/GCF_000240185.1.fasta.fai"
+		params.referenceGenomeMmi = "${params.root}/assets/genomes/klebsiella_pneumoniae/GCF_000240185.1.mmi"
 		params.referenceGenomeGff = "${params.root}/assets/genomes/klebsiella_pneumoniae/GCF_000240185.1.gff"
 		params.chewbbacaDb = "${params.root}/assets/cgmlst/klebsiella_pneumoniae/alleles_rereffed"
 		params.coreLociBed = "${params.root}/assets/cgmlst/klebsiella_pneumoniae/bed/GCF_000240185.1.bed"
@@ -89,7 +92,8 @@ profiles {
 		params.resistantLociName = 'resistance_loci'
 		params.gradingLociName = 'grading_loci'
 		params.referenceGenome = "${params.root}/assets/genomes/mycobacterium_tuberculosis/GCF_000195955.2.fasta"
-		params.referenceGenomeIdx = "${params.root}/assets/genomes/mycobacterium_tuberculosis/GCF_000195955.2.fasta.fai"
+		params.referenceGenomeFai = "${params.root}/assets/genomes/mycobacterium_tuberculosis/GCF_000195955.2.fasta.fai"
+		params.referenceGenomeMmi = "${params.root}/assets/genomes/mycobacterium_tuberculosis/GCF_000195955.2.mmi"
 		params.referenceGenomeGff = "${params.root}/assets/genomes/mycobacterium_tuberculosis/GCF_000195955.2.gff"
 		params.coreLociBed = "${params.root}/assets/cgmlst/mycobacterium_tuberculosis/bed/GCF_000195955.2.bed"
 		params.tbGradingRulesBed = "${params.root}/assets/tb_info/bed/tb_grading_rules.bed"
@@ -103,7 +107,8 @@ profiles {
 		params.speciesDir = 'spyogenes'
 		params.mlstScheme = 'spyogenes'
 		params.referenceGenome = "${params.root}/assets/genomes/streptococcus_pyogenes/GCF_005164585.1.fasta"
-		params.referenceGenomeIdx = "${params.root}/assets/genomes/streptococcus_pyogenes/GCF_005164585.1.fasta.fai"
+		params.referenceGenomeFai = "${params.root}/assets/genomes/streptococcus_pyogenes/GCF_005164585.1.fasta.fai"
+		params.referenceGenomeMmi = "${params.root}/assets/genomes/streptococcus_pyogenes/GCF_005164585.1.mmi"
 		params.referenceGenomeGff = "${params.root}/assets/genomes/streptococcus_pyogenes/GCF_005164585.1.gff"
 		params.chewbbacaDb = "${params.root}/assets/cgmlst/streptococcus_pyogenes/alleles_rereffed"
 		params.coreLociBed = "${params.root}/assets/cgmlst/streptococcus_pyogenes/bed/GCF_005164585.1.bed"
@@ -118,7 +123,8 @@ profiles {
 		params.speciesDir = 'streptococcus'
 		params.mlstScheme = null
 		params.referenceGenome = null
-		params.referenceGenomeIdx = null
+		params.referenceGenomeFai = null
+		params.referenceGenomeMmi = null
 		params.referenceGenomeGff = null
 		params.chewbbacaDb = "${params.root}/assets/cgmlst/streptococcus/alleles_rereffed"
 		params.shigapassDb = null
@@ -185,7 +191,7 @@ process {
 		ext.args = "-M"
 		ext.when = { params.species != "mycobacterium tuberculosis" }
 	}
-	withName: bwa_mem_dedup {
+	withName: bwa_mem_assembly {
 		container = "${params.containerDir}/bwakit.sif"
 		cpus = 16
 		memory = '20.GB'
@@ -284,6 +290,21 @@ process {
 		publishDir = [ path: "${params.outdir}/${params.speciesDir}/medaka", mode: 'copy', overwrite: true ]
 		ext.args = "-t 40 --bacteria"
 	}
+	withName: minimap2_align_assembly {
+		cpus = 4
+		memory = '12.GB'
+		container = "${params.containerDir}/minimap2.sif"
+		ext.args = "-a -x map-ont"
+	}
+	withName: minimap2_align_ref {
+		cpus = 4
+		memory = '12.GB'
+		container = "${params.containerDir}/minimap2.sif"
+		ext.args = "-a -x map-ont"
+	}
+	withName: minimap2_index {
+		container = "${params.containerDir}/minimap2.sif"
+	}
 	withName: mlst {
 		container = "${params.containerDir}/mlst.sif"
 		publishDir = [ path: "${params.outdir}/${params.speciesDir}/mlst", mode: 'copy', overwrite: true ]
@@ -317,6 +338,10 @@ process {
 		ext.nanopore_args = "--nanopore --ignore_indels --ignore_stop_codons"
 		ext.when = { params.species != "mycobacterium tuberculosis" }
 	}
+	withName: samtools_coverage {
+		container = "${params.containerDir}/samtools.sif"
+		publishDir = [ path: "${params.outdir}/${params.speciesDir}/postalignqc", mode: 'copy', overwrite: true ]
+	}
 	withName: samtools_index_assembly {
 		cpus = 16
 		memory = '2.GB'
@@ -330,6 +355,17 @@ process {
 		publishDir = [ path: "${params.outdir}/${params.speciesDir}/${params.bamDir}", mode: 'copy', overwrite: true ]
 		ext.when = { params.referenceGenome && params.species != "mycobacterium tuberculosis" }
 	}
+	withName: samtools_sort_assembly {
+		cpus = 16
+		memory = '20.GB'
+		container = "${params.containerDir}/samtools.sif"
+	}
+	withName: samtools_sort_ref {
+		cpus = 16
+		memory = '20.GB'
+		container = "${params.containerDir}/samtools.sif"
+		publishDir = [ path: "${params.outdir}/${params.speciesDir}/${params.bamDir}", mode: 'copy', overwrite: true ]
+	}
 	withName: save_analysis_metadata {
 		container = "${params.containerDir}/bonsai-prp.sif"
 		publishDir = [ path: "${params.outdir}/${params.speciesDir}/analysis_metadata", mode: 'copy', overwrite: true ]
diff --git a/configs/nextflow.ci.config b/configs/nextflow.ci.config
index edde7639..de908135 100644
--- a/configs/nextflow.ci.config
+++ b/configs/nextflow.ci.config
@@ -37,7 +37,8 @@ profiles {
 		params.speciesDir = 'saureus'
 		params.mlstScheme = 'saureus'
 		params.referenceGenome = "${params.root}/assets/genomes/staphylococcus_aureus/GCF_000012045.1.fasta"
-		params.referenceGenomeIdx = "${params.root}/assets/genomes/staphylococcus_aureus/GCF_000012045.1.fasta.fai"
+		params.referenceGenomeFai = "${params.root}/assets/genomes/staphylococcus_aureus/GCF_000012045.1.fasta.fai"
+		params.referenceGenomeMmi = "${params.root}/assets/genomes/staphylococcus_aureus/GCF_000012045.1.mmi"
 		params.referenceGenomeGff = "${params.root}/assets/genomes/staphylococcus_aureus/GCF_000012045.1.gff"
 		params.chewbbacaDb = "${params.root}/assets/cgmlst/staphylococcus_aureus/alleles_rereffed"
 		params.coreLociBed = "${params.root}/assets/cgmlst/staphylococcus_aureus/bed/GCF_000012045.1.bed"
@@ -52,7 +53,8 @@ profiles {
 		params.speciesDir = 'ecoli'
 		params.mlstScheme = 'ecoli_achtman_4'
 		params.referenceGenome = "${params.root}/assets/genomes/escherichia_coli/GCF_000005845.2.fasta"
-		params.referenceGenomeIdx = "${params.root}/assets/genomes/escherichia_coli/GCF_000005845.2.fasta.fai"
+		params.referenceGenomeFai = "${params.root}/assets/genomes/escherichia_coli/GCF_000005845.2.fasta.fai"
+		params.referenceGenomeMmi = "${params.root}/assets/genomes/escherichia_coli/GCF_000005845.2.mmi"
 		params.referenceGenomeGff = "${params.root}/assets/genomes/escherichia_coli/GCF_000005845.2.gff"
 		// params.chewbbacaDb = "${params.root}/assets/cgmlst/escherichia_coli/alleles_rereffed"
 		// params.coreLociBed = "${params.root}/assets/cgmlst/escherichia_coli/bed/GCF_000005845.2.bed"
@@ -71,7 +73,8 @@ profiles {
 		params.speciesDir = 'kpneumoniae'
 		params.mlstScheme = 'klebsiella'
 		params.referenceGenome = "${params.root}/assets/genomes/klebsiella_pneumoniae/GCF_000240185.1.fasta"
-		params.referenceGenomeIdx = "${params.root}/assets/genomes/klebsiella_pneumoniae/GCF_000240185.1.fasta.fai"
+		params.referenceGenomeFai = "${params.root}/assets/genomes/klebsiella_pneumoniae/GCF_000240185.1.fasta.fai"
+		params.referenceGenomeMmi = "${params.root}/assets/genomes/klebsiella_pneumoniae/GCF_000240185.1.mmi"
 		params.referenceGenomeGff = "${params.root}/assets/genomes/klebsiella_pneumoniae/GCF_000240185.1.gff"
 		params.chewbbacaDb = "${params.root}/assets/cgmlst/klebsiella_pneumoniae/alleles_rereffed"
 		params.coreLociBed = "${params.root}/assets/cgmlst/klebsiella_pneumoniae/bed/GCF_000240185.1.bed"
@@ -87,7 +90,8 @@ profiles {
 		params.resistantLociName = 'resistance_loci'
 		params.gradingLociName = 'grading_loci'
 		params.referenceGenome = "${params.root}/assets/genomes/mycobacterium_tuberculosis/GCF_000195955.2.fasta"
-		params.referenceGenomeIdx = "${params.root}/assets/genomes/mycobacterium_tuberculosis/GCF_000195955.2.fasta.fai"
+		params.referenceGenomeFai = "${params.root}/assets/genomes/mycobacterium_tuberculosis/GCF_000195955.2.fasta.fai"
+		params.referenceGenomeMmi = "${params.root}/assets/genomes/mycobacterium_tuberculosis/GCF_000195955.2.mmi"
 		params.referenceGenomeGff = "${params.root}/assets/genomes/mycobacterium_tuberculosis/GCF_000195955.2.gff"
 		params.coreLociBed = "${params.root}/assets/cgmlst/mycobacterium_tuberculosis/bed/GCF_000195955.2.bed"
 		params.tbGradingRulesBed = "${params.root}/assets/tb_info/bed/tb_grading_rules.bed"
@@ -101,7 +105,8 @@ profiles {
 		params.speciesDir = 'spyogenes'
 		params.mlstScheme = 'spyogenes'
 		params.referenceGenome = "${params.root}/assets/genomes/streptococcus_pyogenes/GCF_005164585.1.fasta"
-		params.referenceGenomeIdx = "${params.root}/assets/genomes/streptococcus_pyogenes/GCF_005164585.1.fasta.fai"
+		params.referenceGenomeFai = "${params.root}/assets/genomes/streptococcus_pyogenes/GCF_005164585.1.fasta.fai"
+		params.referenceGenomeMmi = "${params.root}/assets/genomes/streptococcus_pyogenes/GCF_005164585.1.mmi"
 		params.referenceGenomeGff = "${params.root}/assets/genomes/streptococcus_pyogenes/GCF_005164585.1.gff"
 		params.chewbbacaDb = "${params.root}/assets/cgmlst/streptococcus_pyogenes/alleles_rereffed"
 		params.coreLociBed = "${params.root}/assets/cgmlst/streptococcus_pyogenes/bed/GCF_005164585.1.bed"
@@ -116,7 +121,8 @@ profiles {
 		params.speciesDir = 'streptococcus'
 		params.mlstScheme = null
 		params.referenceGenome = null
-		params.referenceGenomeIdx = null
+		params.referenceGenomeFai = null
+		params.referenceGenomeMmi = null
 		params.referenceGenomeGff = null
 		params.chewbbacaDb = "${params.root}/assets/cgmlst/streptococcus/alleles_rereffed"
 		params.shigapassDb = null
@@ -168,7 +174,7 @@ process {
 		ext.args = "-M"
 		ext.when = { params.species != "mycobacterium tuberculosis" }
 	}
-	withName: bwa_mem_dedup {
+	withName: bwa_mem_assembly {
 		container = "${params.containerDir}/bwakit.sif"
 		cpus = 4
 		memory = '12.GB'
@@ -261,12 +267,27 @@ process {
 	}
 	withName: medaka {
 		container = "${params.containerDir}/medaka.sif"
-		cpus = 20
-		memory = '32.GB'
+		cpus = 4
+		memory = '12.GB'
 		time=2.h
 		publishDir = [ path: "${params.outdir}/${params.speciesDir}/medaka", mode: 'copy', overwrite: true ]
 		ext.args = "-t 40 --bacteria"
 	}
+	withName: minimap2_align_assembly {
+		cpus = 4
+		memory = '12.GB'
+		container = "${params.containerDir}/minimap2.sif"
+		ext.args = "-a -x map-ont"
+	}
+	withName: minimap2_align_ref {
+		cpus = 4
+		memory = '12.GB'
+		container = "${params.containerDir}/minimap2.sif"
+		ext.args = "-a -x map-ont"
+	}
+	withName: minimap2_index {
+		container = "${params.containerDir}/minimap2.sif"
+	}
 	withName: mlst {
 		container = "${params.containerDir}/mlst.sif"
 		publishDir = [ path: "${params.outdir}/${params.speciesDir}/mlst", mode: 'copy', overwrite: true ]
@@ -300,6 +321,10 @@ process {
 		ext.nanopore_args = "--nanopore --ignore_indels --ignore_stop_codons"
 		ext.when = { params.species != "mycobacterium tuberculosis" }
 	}
+	withName: samtools_coverage {
+		container = "${params.containerDir}/samtools.sif"
+		publishDir = [ path: "${params.outdir}/${params.speciesDir}/postalignqc", mode: 'copy', overwrite: true ]
+	}
 	withName: samtools_index_assembly {
 		cpus = 4
 		memory = '2.GB'
@@ -313,6 +338,17 @@ process {
 		publishDir = [ path: "${params.outdir}/${params.speciesDir}/${params.bamDir}", mode: 'copy', overwrite: true ]
 		ext.when = { params.referenceGenome && params.species != "mycobacterium tuberculosis" }
 	}
+	withName: samtools_sort_assembly {
+		cpus = 4
+		memory = '12.GB'
+		container = "${params.containerDir}/samtools.sif"
+	}
+	withName: samtools_sort_ref {
+		cpus = 4
+		memory = '12.GB'
+		container = "${params.containerDir}/samtools.sif"
+		publishDir = [ path: "${params.outdir}/${params.speciesDir}/${params.bamDir}", mode: 'copy', overwrite: true ]
+	}
 	withName: save_analysis_metadata {
 		container = "${params.containerDir}/bonsai-prp.sif"
 		publishDir = [ path: "${params.outdir}/${params.speciesDir}/analysis_metadata", mode: 'copy', overwrite: true ]
diff --git a/configs/nextflow.cmd.config b/configs/nextflow.cmd.config
index c94a5698..f71b6173 100644
--- a/configs/nextflow.cmd.config
+++ b/configs/nextflow.cmd.config
@@ -79,7 +79,8 @@ profiles {
 		params.mlstScheme = 'saureus'
 		params.symlinkDir = "/access/jasen/saureus/"
 		params.referenceGenome = "${params.root}/assets/genomes/staphylococcus_aureus/GCF_000012045.1.fasta"
-		params.referenceGenomeIdx = "${params.root}/assets/genomes/staphylococcus_aureus/GCF_000012045.1.fasta.fai"
+		params.referenceGenomeFai = "${params.root}/assets/genomes/staphylococcus_aureus/GCF_000012045.1.fasta.fai"
+		params.referenceGenomeMmi = "${params.root}/assets/genomes/staphylococcus_aureus/GCF_000012045.1.mmi"
 		params.referenceGenomeGff = "${params.root}/assets/genomes/staphylococcus_aureus/GCF_000012045.1.gff"
 		params.chewbbacaDb = "${params.root}/assets/cgmlst/staphylococcus_aureus/alleles_rereffed"
 		params.coreLociBed = "${params.root}/assets/cgmlst/staphylococcus_aureus/bed/GCF_000012045.1.bed"
@@ -95,7 +96,8 @@ profiles {
 		params.mlstScheme = 'ecoli_achtman_4'
 		params.symlinkDir = "/access/jasen/ecoli/"
 		params.referenceGenome = "${params.root}/assets/genomes/escherichia_coli/GCF_000005845.2.fasta"
-		params.referenceGenomeIdx = "${params.root}/assets/genomes/escherichia_coli/GCF_000005845.2.fasta.fai"
+		params.referenceGenomeFai = "${params.root}/assets/genomes/escherichia_coli/GCF_000005845.2.fasta.fai"
+		params.referenceGenomeMmi = "${params.root}/assets/genomes/escherichia_coli/GCF_000005845.2.mmi"
 		params.referenceGenomeGff = "${params.root}/assets/genomes/escherichia_coli/GCF_000005845.2.gff"
 		// params.chewbbacaDb = "${params.root}/assets/cgmlst/escherichia_coli/alleles_rereffed"
 		// params.coreLociBed = "${params.root}/assets/cgmlst/escherichia_coli/bed/GCF_000005845.2.bed"
@@ -115,7 +117,8 @@ profiles {
 		params.mlstScheme = 'klebsiella'
 		params.symlinkDir = "/access/jasen/kpneumoniae/"
 		params.referenceGenome = "${params.root}/assets/genomes/klebsiella_pneumoniae/GCF_000240185.1.fasta"
-		params.referenceGenomeIdx = "${params.root}/assets/genomes/klebsiella_pneumoniae/GCF_000240185.1.fasta.fai"
+		params.referenceGenomeFai = "${params.root}/assets/genomes/klebsiella_pneumoniae/GCF_000240185.1.fasta.fai"
+		params.referenceGenomeMmi = "${params.root}/assets/genomes/klebsiella_pneumoniae/GCF_000240185.1.mmi"
 		params.referenceGenomeGff = "${params.root}/assets/genomes/klebsiella_pneumoniae/GCF_000240185.1.gff"
 		params.chewbbacaDb = "${params.root}/assets/cgmlst/klebsiella_pneumoniae/alleles_rereffed"
 		params.coreLociBed = "${params.root}/assets/cgmlst/klebsiella_pneumoniae/bed/GCF_000240185.1.bed"
@@ -131,7 +134,8 @@ profiles {
 		params.gradingLociName = 'grading_loci'
 		params.symlinkDir = "/access/jasen/mtuberculosis/"
 		params.referenceGenome = "${params.root}/assets/genomes/mycobacterium_tuberculosis/GCF_000195955.2.fasta"
-		params.referenceGenomeIdx = "${params.root}/assets/genomes/mycobacterium_tuberculosis/GCF_000195955.2.fasta.fai"
+		params.referenceGenomeFai = "${params.root}/assets/genomes/mycobacterium_tuberculosis/GCF_000195955.2.fasta.fai"
+		params.referenceGenomeMmi = "${params.root}/assets/genomes/mycobacterium_tuberculosis/GCF_000195955.2.mmi"
 		params.referenceGenomeGff = "${params.root}/assets/genomes/mycobacterium_tuberculosis/GCF_000195955.2.gff"
 		params.coreLociBed = "${params.root}/assets/cgmlst/mycobacterium_tuberculosis/bed/GCF_000195955.2.bed"
 		params.tbGradingRulesBed = "${params.root}/assets/tb_info/bed/tb_grading_rules.bed"
@@ -146,7 +150,8 @@ profiles {
 		params.mlstScheme = 'spyogenes'
 		params.symlinkDir = "/access/jasen/spyogenes/"
 		params.referenceGenome = "${params.root}/assets/genomes/streptococcus_pyogenes/GCF_005164585.1.fasta"
-		params.referenceGenomeIdx = "${params.root}/assets/genomes/streptococcus_pyogenes/GCF_005164585.1.fasta.fai"
+		params.referenceGenomeFai = "${params.root}/assets/genomes/streptococcus_pyogenes/GCF_005164585.1.fasta.fai"
+		params.referenceGenomeMmi = "${params.root}/assets/genomes/streptococcus_pyogenes/GCF_005164585.1.mmi"
 		params.referenceGenomeGff = "${params.root}/assets/genomes/streptococcus_pyogenes/GCF_005164585.1.gff"
 		params.chewbbacaDb = "${params.root}/assets/cgmlst/streptococcus_pyogenes/alleles_rereffed"
 		params.coreLociBed = "${params.root}/assets/cgmlst/streptococcus_pyogenes/bed/GCF_005164585.1.bed"
@@ -161,7 +166,8 @@ profiles {
 		params.speciesDir = 'streptococcus'
 		params.mlstScheme = null
 		params.referenceGenome = null
-		params.referenceGenomeIdx = null
+		params.referenceGenomeFai = null
+		params.referenceGenomeMmi = null
 		params.referenceGenomeGff = null
 		params.chewbbacaDb = "${params.root}/assets/cgmlst/streptococcus/alleles_rereffed"
 		params.shigapassDb = null
@@ -215,7 +221,7 @@ process {
 		ext.args = "-M"
 		ext.when = { params.species != "mycobacterium tuberculosis" }
 	}
-	withName: bwa_mem_dedup {
+	withName: bwa_mem_assembly {
 		container = "https://depot.galaxyproject.org/singularity/bwakit:0.7.17.dev1--hdfd78af_1"
 		cpus = 16
 		memory = '20.GB'
@@ -314,6 +320,21 @@ process {
 		publishDir = [ path: "${params.outdir}/${params.speciesDir}/medaka", mode: 'copy', overwrite: true ]
 		ext.args = "-t 40 --bacteria"
 	}
+	withName: minimap2_align_assembly {
+		cpus = 4
+		memory = '12.GB'
+		container = "${params.containerDir}/minimap2.sif"
+		ext.args = "-a -x map-ont"
+	}
+	withName: minimap2_align_ref {
+		cpus = 4
+		memory = '12.GB'
+		container = "${params.containerDir}/minimap2.sif"
+		ext.args = "-a -x map-ont"
+	}
+	withName: minimap2_index {
+		container = "${params.containerDir}/minimap2.sif"
+	}
 	withName: mlst {
 		container = "https://depot.galaxyproject.org/singularity/mlst:2.23.0--hdfd78af_1"
 		publishDir = [ path: "${params.outdir}/${params.speciesDir}/mlst", mode: 'copy', overwrite: true ]
@@ -347,6 +368,10 @@ process {
 		ext.nanopore_args = "--nanopore --ignore_indels --ignore_stop_codons"
 		ext.when = { params.species != "mycobacterium tuberculosis" }
 	}
+	withName: samtools_coverage {
+		container = "https://depot.galaxyproject.org/singularity/samtools:1.17--h00cdaf9_0"
+		publishDir = [ path: "${params.outdir}/${params.speciesDir}/postalignqc", mode: 'copy', overwrite: true ]
+	}
 	withName: samtools_index_assembly {
 		cpus = 16
 		memory = '2.GB'
@@ -360,6 +385,17 @@ process {
 		publishDir = [ path: "${params.outdir}/${params.speciesDir}/${params.bamDir}", mode: 'copy', overwrite: true ]
 		ext.when = { params.referenceGenome && params.species != "mycobacterium tuberculosis" }
 	}
+	withName: samtools_sort_assembly {
+		cpus = 16
+		memory = '20.GB'
+		container = "https://depot.galaxyproject.org/singularity/samtools:1.17--h00cdaf9_0"
+	}
+	withName: samtools_sort_ref {
+		cpus = 16
+		memory = '20.GB'
+		container = "https://depot.galaxyproject.org/singularity/samtools:1.17--h00cdaf9_0"
+		publishDir = [ path: "${params.outdir}/${params.speciesDir}/${params.bamDir}", mode: 'copy', overwrite: true ]
+	}
 	withName: save_analysis_metadata {
 		container = "${params.bonsaiPrpSif}"
 		publishDir = [ path: "${params.outdir}/${params.speciesDir}/analysis_metadata", mode: 'copy', overwrite: true ]
diff --git a/configs/nextflow.ngp.config b/configs/nextflow.ngp.config
index 03731b53..362ae238 100644
--- a/configs/nextflow.ngp.config
+++ b/configs/nextflow.ngp.config
@@ -60,7 +60,8 @@ profiles {
 		params.speciesDir = 'saureus'
 		params.mlstScheme = 'saureus'
 		params.referenceGenome = "${params.root}/assets/genomes/staphylococcus_aureus/GCF_000012045.1.fasta"
-		params.referenceGenomeIdx = "${params.root}/assets/genomes/staphylococcus_aureus/GCF_000012045.1.fasta.fai"
+		params.referenceGenomeFai = "${params.root}/assets/genomes/staphylococcus_aureus/GCF_000012045.1.fasta.fai"
+		params.referenceGenomeMmi = "${params.root}/assets/genomes/staphylococcus_aureus/GCF_000012045.1.mmi"
 		params.referenceGenomeGff = "${params.root}/assets/genomes/staphylococcus_aureus/GCF_000012045.1.gff"
 		params.chewbbacaDb = "${params.root}/assets/cgmlst/staphylococcus_aureus/alleles_rereffed"
 		params.coreLociBed = "${params.root}/assets/cgmlst/staphylococcus_aureus/bed/GCF_000012045.1.bed"
@@ -75,7 +76,8 @@ profiles {
 		params.speciesDir = 'ecoli'
 		params.mlstScheme = 'ecoli_achtman_4'
 		params.referenceGenome = "${params.root}/assets/genomes/escherichia_coli/GCF_000005845.2.fasta"
-		params.referenceGenomeIdx = "${params.root}/assets/genomes/escherichia_coli/GCF_000005845.2.fasta.fai"
+		params.referenceGenomeFai = "${params.root}/assets/genomes/escherichia_coli/GCF_000005845.2.fasta.fai"
+		params.referenceGenomeMmi = "${params.root}/assets/genomes/escherichia_coli/GCF_000005845.2.mmi"
 		params.referenceGenomeGff = "${params.root}/assets/genomes/escherichia_coli/GCF_000005845.2.gff"
 		// params.chewbbacaDb = "${params.root}/assets/cgmlst/escherichia_coli/alleles_rereffed"
 		// params.coreLociBed = "${params.root}/assets/cgmlst/escherichia_coli/bed/GCF_000005845.2.bed"
@@ -94,7 +96,8 @@ profiles {
 		params.speciesDir = 'kpneumoniae'
 		params.mlstScheme = 'klebsiella'
 		params.referenceGenome = "${params.root}/assets/genomes/klebsiella_pneumoniae/GCF_000240185.1.fasta"
-		params.referenceGenomeIdx = "${params.root}/assets/genomes/klebsiella_pneumoniae/GCF_000240185.1.fasta.fai"
+		params.referenceGenomeFai = "${params.root}/assets/genomes/klebsiella_pneumoniae/GCF_000240185.1.fasta.fai"
+		params.referenceGenomeMmi = "${params.root}/assets/genomes/klebsiella_pneumoniae/GCF_000240185.1.mmi"
 		params.referenceGenomeGff = "${params.root}/assets/genomes/klebsiella_pneumoniae/GCF_000240185.1.gff"
 		params.chewbbacaDb = "${params.root}/assets/cgmlst/klebsiella_pneumoniae/alleles_rereffed"
 		params.coreLociBed = "${params.root}/assets/cgmlst/klebsiella_pneumoniae/bed/GCF_000240185.1.bed"
@@ -110,7 +113,8 @@ profiles {
 		params.resistantLociName = 'resistance_loci'
 		params.gradingLociName = 'grading_loci'
 		params.referenceGenome = "${params.root}/assets/genomes/mycobacterium_tuberculosis/GCF_000195955.2.fasta"
-		params.referenceGenomeIdx = "${params.root}/assets/genomes/mycobacterium_tuberculosis/GCF_000195955.2.fasta.fai"
+		params.referenceGenomeFai = "${params.root}/assets/genomes/mycobacterium_tuberculosis/GCF_000195955.2.fasta.fai"
+		params.referenceGenomeMmi = "${params.root}/assets/genomes/mycobacterium_tuberculosis/GCF_000195955.2.mmi"
 		params.referenceGenomeGff = "${params.root}/assets/genomes/mycobacterium_tuberculosis/GCF_000195955.2.gff"
 		params.coreLociBed = "${params.root}/assets/cgmlst/mycobacterium_tuberculosis/bed/GCF_000195955.2.bed"
 		params.tbGradingRulesBed = "${params.root}/assets/tb_info/bed/tb_grading_rules.bed"
@@ -124,7 +128,8 @@ profiles {
 		params.speciesDir = 'spyogenes'
 		params.mlstScheme = 'spyogenes'
 		params.referenceGenome = "${params.root}/assets/genomes/streptococcus_pyogenes/GCF_005164585.1.fasta"
-		params.referenceGenomeIdx = "${params.root}/assets/genomes/streptococcus_pyogenes/GCF_005164585.1.fasta.fai"
+		params.referenceGenomeFai = "${params.root}/assets/genomes/streptococcus_pyogenes/GCF_005164585.1.fasta.fai"
+		params.referenceGenomeMmi = "${params.root}/assets/genomes/streptococcus_pyogenes/GCF_005164585.1.mmi"
 		params.referenceGenomeGff = "${params.root}/assets/genomes/streptococcus_pyogenes/GCF_005164585.1.gff"
 		params.chewbbacaDb = "${params.root}/assets/cgmlst/streptococcus_pyogenes/alleles_rereffed"
 		params.coreLociBed = "${params.root}/assets/cgmlst/streptococcus_pyogenes/bed/GCF_005164585.1.bed"
@@ -139,7 +144,8 @@ profiles {
 		params.speciesDir = 'streptococcus'
 		params.mlstScheme = null
 		params.referenceGenome = null
-		params.referenceGenomeIdx = null
+		params.referenceGenomeFai = null
+		params.referenceGenomeMmi = null
 		params.referenceGenomeGff = null
 		params.chewbbacaDb = "${params.root}/assets/cgmlst/streptococcus/alleles_rereffed"
 		params.shigapassDb = null
@@ -193,7 +199,7 @@ process {
 		ext.args = "-M"
 		ext.when = { params.species != "mycobacterium tuberculosis" }
 	}
-	withName: bwa_mem_dedup {
+	withName: bwa_mem_assembly {
 		container = "${params.containerDir}/bwakit.sif"
 		cpus = params.cpus_large
 		memory = params.mem_large
@@ -294,6 +300,21 @@ process {
 		publishDir = [ path: "${params.outdir}/${params.speciesDir}/medaka", mode: 'copy', overwrite: true ]
 		ext.args = "-t 40 --bacteria"
 	}
+	withName: minimap2_align_assembly {
+		cpus = 4
+		memory = '12.GB'
+		container = "${params.containerDir}/minimap2.sif"
+		ext.args = "-a -x map-ont"
+	}
+	withName: minimap2_align_ref {
+		cpus = 4
+		memory = '12.GB'
+		container = "${params.containerDir}/minimap2.sif"
+		ext.args = "-a -x map-ont"
+	}
+	withName: minimap2_index {
+		container = "${params.containerDir}/minimap2.sif"
+	}
 	withName: mlst {
 		container = "${params.containerDir}/mlst.sif"
 		publishDir = [ path: "${params.outdir}/${params.speciesDir}/mlst", mode: 'copy', overwrite: true ]
@@ -329,6 +350,10 @@ process {
 		ext.nanopore_args = "--nanopore --ignore_indels --ignore_stop_codons"
 		ext.when = { params.species != "mycobacterium tuberculosis" }
 	}
+	withName: samtools_coverage {
+		container = "${params.containerDir}/samtools.sif"
+		publishDir = [ path: "${params.outdir}/${params.speciesDir}/postalignqc", mode: 'copy', overwrite: true ]
+	}
 	withName: samtools_index_assembly {
 		cpus = params.cpus_large
 		memory = params.mem_large
@@ -342,6 +367,17 @@ process {
 		publishDir = [ path: "${params.outdir}/${params.speciesDir}/${params.bamDir}", mode: 'copy', overwrite: true ]
 		ext.when = { params.referenceGenome && params.species != "mycobacterium tuberculosis" }
 	}
+	withName: samtools_sort_assembly {
+		cpus = 16
+		memory = '20.GB'
+		container = "${params.containerDir}/samtools.sif"
+	}
+	withName: samtools_sort_ref {
+		cpus = 16
+		memory = '20.GB'
+		container = "${params.containerDir}/samtools.sif"
+		publishDir = [ path: "${params.outdir}/${params.speciesDir}/${params.bamDir}", mode: 'copy', overwrite: true ]
+	}
 	withName: save_analysis_metadata {
 		container = "${params.containerDir}/bonsai-prp.sif"
 		publishDir = [ path: "${params.outdir}/${params.speciesDir}/analysis_metadata", mode: 'copy', overwrite: true ]
diff --git a/container/Makefile b/container/Makefile
index 379c0809..876493b6 100644
--- a/container/Makefile
+++ b/container/Makefile
@@ -30,9 +30,10 @@ remote_containers := ncbi-amrfinderplus.sif \
 					htslib.sif \
 					kraken2.sif \
 					medaka.sif \
-					nanoplot.sif \
+					minimap2.sif \
 					mlst.sif \
 					mykrobe.sif \
+					nanoplot.sif \
 					perl-json.sif \
 					prodigal.sif \
 					quast.sif \
@@ -68,6 +69,7 @@ URL_hostile := https://depot.galaxyproject.org/singularity/hostile:2.0.0--pyhdfd
 URL_htslib := https://depot.galaxyproject.org/singularity/htslib:1.21--h566b1c6_1
 URL_kraken2 := https://depot.galaxyproject.org/singularity/kraken2:2.1.2--pl5321h9f5acd7_3
 URL_medaka := https://depot.galaxyproject.org/singularity/medaka:2.0.1--py39hf77f13f_0
+URL_minimap2 := https://depot.galaxyproject.org/singularity/minimap2:2.28--h577a1d6_4
 URL_mlst := https://depot.galaxyproject.org/singularity/mlst:2.23.0--hdfd78af_1
 URL_mykrobe := https://depot.galaxyproject.org/singularity/mykrobe:0.12.2--py39h70e0db4_0
 URL_nanoplot := https://depot.galaxyproject.org/singularity/nanoplot:1.43.0--pyhdfd78af_1
diff --git a/docs/source/workflows/escherichia_coli_sw.csv b/docs/source/workflows/escherichia_coli_sw.csv
index cb599793..bd659977 100644
--- a/docs/source/workflows/escherichia_coli_sw.csv
+++ b/docs/source/workflows/escherichia_coli_sw.csv
@@ -8,6 +8,7 @@ flye,2.9.3,https://depot.galaxyproject.org/singularity/flye:2.9.3--py39hd65a603_
 freebayes,1.3.6,https://depot.galaxyproject.org/singularity/freebayes:1.3.6--hbfe0e7f_2
 hostile,2.0.0,https://depot.galaxyproject.org/singularity/hostile:2.0.0--pyhdfd78af_0
 kraken2,2.1.2,https://depot.galaxyproject.org/singularity/kraken2:2.1.2--pl5321h9f5acd7_3
+minimiap2,2.28,https://depot.galaxyproject.org/singularity/minimap2:2.28--h577a1d6_4
 medaka,2.0.1,https://depot.galaxyproject.org/singularity/medaka:2.0.1--py39hf77f13f_0
 mlst,2.23.0,https://depot.galaxyproject.org/singularity/mlst:2.23.0--hdfd78af_1
 nanoplot,1.43.0,https://depot.galaxyproject.org/singularity/nanoplot:1.43.0--pyhdfd78af_1
diff --git a/docs/source/workflows/klebsiella_pneumoniae_sw.csv b/docs/source/workflows/klebsiella_pneumoniae_sw.csv
index cb599793..bd659977 100644
--- a/docs/source/workflows/klebsiella_pneumoniae_sw.csv
+++ b/docs/source/workflows/klebsiella_pneumoniae_sw.csv
@@ -8,6 +8,7 @@ flye,2.9.3,https://depot.galaxyproject.org/singularity/flye:2.9.3--py39hd65a603_
 freebayes,1.3.6,https://depot.galaxyproject.org/singularity/freebayes:1.3.6--hbfe0e7f_2
 hostile,2.0.0,https://depot.galaxyproject.org/singularity/hostile:2.0.0--pyhdfd78af_0
 kraken2,2.1.2,https://depot.galaxyproject.org/singularity/kraken2:2.1.2--pl5321h9f5acd7_3
+minimiap2,2.28,https://depot.galaxyproject.org/singularity/minimap2:2.28--h577a1d6_4
 medaka,2.0.1,https://depot.galaxyproject.org/singularity/medaka:2.0.1--py39hf77f13f_0
 mlst,2.23.0,https://depot.galaxyproject.org/singularity/mlst:2.23.0--hdfd78af_1
 nanoplot,1.43.0,https://depot.galaxyproject.org/singularity/nanoplot:1.43.0--pyhdfd78af_1
diff --git a/docs/source/workflows/mycobacterium_tuberculosis_sw.csv b/docs/source/workflows/mycobacterium_tuberculosis_sw.csv
index 822e1b11..2e820867 100644
--- a/docs/source/workflows/mycobacterium_tuberculosis_sw.csv
+++ b/docs/source/workflows/mycobacterium_tuberculosis_sw.csv
@@ -3,6 +3,7 @@ bracken,2.8,https://depot.galaxyproject.org/singularity/bracken:2.8--py39hc16433
 bwa,0.7.17-r1188,https://depot.galaxyproject.org/singularity/bwakit:0.7.17.dev1--hdfd78af_1
 flye,2.9.3,https://depot.galaxyproject.org/singularity/flye:2.9.3--py39hd65a603_0
 hostile,2.0.0,https://depot.galaxyproject.org/singularity/hostile:2.0.0--pyhdfd78af_0
+minimiap2,2.28,https://depot.galaxyproject.org/singularity/minimap2:2.28--h577a1d6_4
 medaka,2.0.1,https://depot.galaxyproject.org/singularity/medaka:2.0.1--py39hf77f13f_0
 mykrobe,0.12.2,https://depot.galaxyproject.org/singularity/mykrobe:0.12.2--py39h70e0db4_0
 nanoplot,1.43.0,https://depot.galaxyproject.org/singularity/nanoplot:1.43.0--pyhdfd78af_1
diff --git a/docs/source/workflows/staphylococcus_aureus_sw.csv b/docs/source/workflows/staphylococcus_aureus_sw.csv
index f375568f..a25addc0 100644
--- a/docs/source/workflows/staphylococcus_aureus_sw.csv
+++ b/docs/source/workflows/staphylococcus_aureus_sw.csv
@@ -8,6 +8,7 @@ flye,2.9.3,https://depot.galaxyproject.org/singularity/flye:2.9.3--py39hd65a603_
 freebayes,1.3.6,https://depot.galaxyproject.org/singularity/freebayes:1.3.6--hbfe0e7f_2
 hostile,2.0.0,https://depot.galaxyproject.org/singularity/hostile:2.0.0--pyhdfd78af_0
 kraken2,2.1.2,https://depot.galaxyproject.org/singularity/kraken2:2.1.2--pl5321h9f5acd7_3
+minimiap2,2.28,https://depot.galaxyproject.org/singularity/minimap2:2.28--h577a1d6_4
 medaka,2.0.1,https://depot.galaxyproject.org/singularity/medaka:2.0.1--py39hf77f13f_0
 mlst,2.23.0,https://depot.galaxyproject.org/singularity/mlst:2.23.0--hdfd78af_1
 nanoplot,1.43.0,https://depot.galaxyproject.org/singularity/nanoplot:1.43.0--pyhdfd78af_1
diff --git a/docs/source/workflows/streptococcus_pyogenes_sw.csv b/docs/source/workflows/streptococcus_pyogenes_sw.csv
index dc7054d2..33f48640 100644
--- a/docs/source/workflows/streptococcus_pyogenes_sw.csv
+++ b/docs/source/workflows/streptococcus_pyogenes_sw.csv
@@ -9,6 +9,7 @@ flye,2.9.3,https://depot.galaxyproject.org/singularity/flye:2.9.3--py39hd65a603_
 freebayes,1.3.6,https://depot.galaxyproject.org/singularity/freebayes:1.3.6--hbfe0e7f_2
 hostile,2.0.0,https://depot.galaxyproject.org/singularity/hostile:2.0.0--pyhdfd78af_0
 kraken2,2.1.2,https://depot.galaxyproject.org/singularity/kraken2:2.1.2--pl5321h9f5acd7_3
+minimiap2,2.28,https://depot.galaxyproject.org/singularity/minimap2:2.28--h577a1d6_4
 medaka,2.0.1,https://depot.galaxyproject.org/singularity/medaka:2.0.1--py39hf77f13f_0
 mlst,2.23.0,https://depot.galaxyproject.org/singularity/mlst:2.23.0--hdfd78af_1
 nanoplot,1.43.0,https://depot.galaxyproject.org/singularity/nanoplot:1.43.0--pyhdfd78af_1
diff --git a/docs/source/workflows/streptococcus_sw.csv b/docs/source/workflows/streptococcus_sw.csv
index dc7054d2..33f48640 100644
--- a/docs/source/workflows/streptococcus_sw.csv
+++ b/docs/source/workflows/streptococcus_sw.csv
@@ -9,6 +9,7 @@ flye,2.9.3,https://depot.galaxyproject.org/singularity/flye:2.9.3--py39hd65a603_
 freebayes,1.3.6,https://depot.galaxyproject.org/singularity/freebayes:1.3.6--hbfe0e7f_2
 hostile,2.0.0,https://depot.galaxyproject.org/singularity/hostile:2.0.0--pyhdfd78af_0
 kraken2,2.1.2,https://depot.galaxyproject.org/singularity/kraken2:2.1.2--pl5321h9f5acd7_3
+minimiap2,2.28,https://depot.galaxyproject.org/singularity/minimap2:2.28--h577a1d6_4
 medaka,2.0.1,https://depot.galaxyproject.org/singularity/medaka:2.0.1--py39hf77f13f_0
 mlst,2.23.0,https://depot.galaxyproject.org/singularity/mlst:2.23.0--hdfd78af_1
 nanoplot,1.43.0,https://depot.galaxyproject.org/singularity/nanoplot:1.43.0--pyhdfd78af_1
diff --git a/nextflow-modules/modules/bwa/main.nf b/nextflow-modules/modules/bwa/main.nf
index 6a588e31..dc941c21 100644
--- a/nextflow-modules/modules/bwa/main.nf
+++ b/nextflow-modules/modules/bwa/main.nf
@@ -3,18 +3,18 @@ process bwa_index {
   scratch params.scratch
 
   input:
-    tuple val(sample_id), path(reference)
+    tuple val(sample_id), path(fasta), val(platform)
 
   output:
-    tuple val(sample_id), path("${reference}.*"), emit: idx
-    path "*versions.yml"                        , emit: versions
+    tuple val(sample_id), path("${fasta}.*"), emit: index
+    path "*versions.yml"                    , emit: versions
 
   when:
-    task.ext.when
+    task.ext.when && platform == "illumina"
 
   script:
     """
-    bwa index ${reference} ${reference.baseName}/${reference}
+    bwa index ${fasta} ${fasta.baseName}/${fasta}
 
     cat <<-END_VERSIONS > ${sample_id}_${task.process}_versions.yml
     ${task.process}:
@@ -26,11 +26,11 @@ process bwa_index {
 
   stub:
     """
-    touch ${reference}.amb
-    touch ${reference}.ann
-    touch ${reference}.bwt
-    touch ${reference}.pac
-    touch ${reference}.sa
+    touch ${fasta}.amb
+    touch ${fasta}.ann
+    touch ${fasta}.bwt
+    touch ${fasta}.pac
+    touch ${fasta}.sa
 
     cat <<-END_VERSIONS > ${sample_id}_${task.process}_versions.yml
     ${task.process}:
@@ -46,15 +46,15 @@ process bwa_mem {
   scratch params.scratch
 
   input:
-    tuple val(sample_id), path(reads)
+    tuple val(sample_id), path(reads), val(platform)
     path referenceIdx
 
   output:
     tuple val(sample_id), path(output), emit: bam
-    path "*versions.yml"             , emit: versions
+    path "*versions.yml"              , emit: versions
 
   when:
-    task.ext.when
+    task.ext.when && platform == "illumina"
 
   script:
     def args = task.ext.args ?: ''
diff --git a/nextflow-modules/modules/freebayes/main.nf b/nextflow-modules/modules/freebayes/main.nf
index 9c5b1f59..a46237df 100644
--- a/nextflow-modules/modules/freebayes/main.nf
+++ b/nextflow-modules/modules/freebayes/main.nf
@@ -4,7 +4,7 @@ process freebayes {
 
   input:
     tuple val(sample_id), path(assembly)
-    tuple path(bam), path(bai) 
+    tuple val(sample_id), path(bam), path(bai) 
 
   output:
     tuple val(sample_id), path(output), emit: vcf
diff --git a/nextflow-modules/modules/minimap2/main.nf b/nextflow-modules/modules/minimap2/main.nf
new file mode 100644
index 00000000..1117cb89
--- /dev/null
+++ b/nextflow-modules/modules/minimap2/main.nf
@@ -0,0 +1,88 @@
+process minimap2_align {
+  tag "${sample_id}"
+  scratch params.scratch
+
+  input:
+    tuple val(sample_id), path(reads), val(platform)
+    path referenceGenomeMmi
+
+  output:
+    tuple val(sample_id), path(output), emit: sam
+    path "*versions.yml"              , emit: versions
+
+  when:
+    platform == "nanopore"
+
+  script:
+    def args = task.ext.args ?: ''
+    def process = task.process.tokenize(':')[-1]
+    output = "${sample_id}_${process}.sam"
+    """
+    minimap2 ${args} ${referenceGenomeMmi} ${reads} > ${output}
+    
+    cat <<-END_VERSIONS > ${sample_id}_${process}_versions.yml
+    ${task.process}:
+     minimap2:
+      version: \$(echo \$(minimap2 --version 2>&1))
+      container: ${task.container}
+    END_VERSIONS
+    """
+
+  stub:
+    def process = task.process.tokenize(':')[-1]
+    output = "${sample_id}_${process}.sam"
+    """
+    touch "${output}"
+
+    cat <<-END_VERSIONS > ${sample_id}_${task.process}_versions.yml
+    ${task.process}:
+     minimap2:
+      version: \$(echo \$(minimap2 --version 2>&1))
+      container: ${task.container}
+    END_VERSIONS
+    """
+}
+
+process minimap2_index {
+  tag "${sample_id}"
+  scratch params.scratch
+
+  input:
+    tuple val(sample_id), path(fasta), val(platform)
+
+  output:
+    tuple val(sample_id), path("*.mmi"), emit: index
+    path "*versions.yml"               , emit: versions
+
+  when:
+    platform == "nanopore"
+
+  script:
+    def args = task.ext.args ?: ''
+    """
+    minimap2 \\
+        -t ${task.cpus} \\
+        -d ${fasta.baseName}.mmi \\
+        ${args} \\
+        ${fasta}
+
+    cat <<-END_VERSIONS > ${sample_id}_${task.process}_versions.yml
+    ${task.process}:
+     minimap2:
+      version: \$(echo \$(minimap2 --version 2>&1))
+      container: ${task.container}
+    END_VERSIONS
+    """
+
+  stub:
+    """
+    touch ${fasta.baseName}.mmi
+
+    cat <<-END_VERSIONS > ${sample_id}_${task.process}_versions.yml
+    ${task.process}:
+     minimap2:
+      version: \$(echo \$(minimap2 --version 2>&1))
+      container: ${task.container}
+    END_VERSIONS
+    """
+}
diff --git a/nextflow-modules/modules/prp/main.nf b/nextflow-modules/modules/prp/main.nf
index 884f50d1..72cc241e 100644
--- a/nextflow-modules/modules/prp/main.nf
+++ b/nextflow-modules/modules/prp/main.nf
@@ -5,7 +5,8 @@ process create_analysis_result {
   input:
     tuple val(sample_id), path(quast), path(postalignqc), path(mlst), path(cgmlst), path(amr), path(resistance), path(resfinderMeta), path(serotype), path(serotypefinderMeta), path(virulence), path(virulencefinderMeta), path(shigapass), path(emmtyper), path(bam), path(bai), path(runInfo), path(vcf), path(mykrobe), path(tbprofiler), path(bracken)
     path reference_genome
-    path reference_genome_idx
+    path reference_genome_fai
+    path reference_genome_mmi
     path reference_genome_gff
 
   output:
diff --git a/nextflow-modules/modules/samtools/main.nf b/nextflow-modules/modules/samtools/main.nf
index b7146c96..5bd1f7c9 100644
--- a/nextflow-modules/modules/samtools/main.nf
+++ b/nextflow-modules/modules/samtools/main.nf
@@ -55,9 +55,9 @@ process samtools_sort {
     path "*versions.yml"              , emit: versions
 
   script:
-    output = "${sample_id}.bam"
+    output = "${input.baseName}.bam"
     """
-    samtools sort -@ ${task.cpus} -o ${output} ${input}
+    samtools sort -@ ${task.cpus} -O bam -o ${output} ${input}
 
     cat <<-END_VERSIONS > ${sample_id}_${task.process}_versions.yml
     ${task.process}:
@@ -68,8 +68,9 @@ process samtools_sort {
     """
 
   stub:
+    output = "${input.baseName}.bam"
     """
-    touch ${sample_id}.bam
+    touch "${output}"
 
     cat <<-END_VERSIONS > ${sample_id}_${task.process}_versions.yml
     ${task.process}:
@@ -158,3 +159,42 @@ process samtools_faidx {
     END_VERSIONS
     """
 }
+
+process samtools_coverage {
+  tag "${sample_id}"
+  scratch params.scratch
+
+  input:
+    tuple val(sample_id), path(input)
+
+  output:
+    tuple val(sample_id), path(output), emit: txt
+    path "*versions.yml"              , emit: versions
+
+  script:
+    def args = task.ext.args ?: ''
+    output = "${input.baseName}_mapcoverage.txt"
+    """
+    samtools coverage -o ${output} ${args} ${input}
+
+    cat <<-END_VERSIONS > ${sample_id}_${task.process}_versions.yml
+        ${task.process}:
+        samtools:
+          version: \$(echo \$(samtools --version 2>&1) | sed 's/^.*samtools //; s/Using.*\$//')
+          container: ${task.container}
+        END_VERSIONS
+    """
+
+  stub:
+  output = "${input.baseName}_mapcoverage.txt"
+    """
+    touch "${output}"
+
+    cat <<-END_VERSIONS > ${sample_id}_${task.process}_versions.yml
+    ${task.process}:
+     samtools:
+      version: \$(echo \$(samtools --version 2>&1) | sed 's/^.*samtools //; s/Using.*\$//')
+      container: ${task.container}
+    END_VERSIONS
+    """
+}
diff --git a/nextflow-modules/modules/skesa/main.nf b/nextflow-modules/modules/skesa/main.nf
index f5c3baf8..901fe2bf 100644
--- a/nextflow-modules/modules/skesa/main.nf
+++ b/nextflow-modules/modules/skesa/main.nf
@@ -3,7 +3,7 @@ process skesa {
   scratch params.scratch
 
   input:
-    tuple val(sample_id), path(reads), val(platform) 
+    tuple val(sample_id), path(reads), val(platform)
 
   output:
     tuple val(sample_id), path(output), emit: fasta
diff --git a/workflows/bacterial_base.nf b/workflows/bacterial_base.nf
index 36bb3070..756d4f37 100644
--- a/workflows/bacterial_base.nf
+++ b/workflows/bacterial_base.nf
@@ -2,32 +2,36 @@
 
 nextflow.enable.dsl=2
 
-include { get_meta                              } from '../methods/get_sample_data.nf'
-include { get_reads                             } from '../methods/get_sample_data.nf'
-include { get_seqrun_meta                       } from '../methods/get_seqrun_meta.nf'
-include { assembly_trim_clean                   } from '../nextflow-modules/modules/clean/main.nf'
-include { bwa_mem as bwa_mem_ref                } from '../nextflow-modules/modules/bwa/main.nf'
-include { fastqc                                } from '../nextflow-modules/modules/fastqc/main.nf'
-include { flye                                  } from '../nextflow-modules/modules/flye/main.nf'
-include { hostile                               } from '../nextflow-modules/modules/hostile/main.nf'
-include { medaka                                } from '../nextflow-modules/modules/medaka/main.nf'
-include { nanoplot                              } from '../nextflow-modules/modules/nanoplot/main.nf'
-include { post_align_qc                         } from '../nextflow-modules/modules/prp/main.nf'
-include { quast                                 } from '../nextflow-modules/modules/quast/main.nf'
-include { samtools_index as samtools_index_ref  } from '../nextflow-modules/modules/samtools/main.nf'
-include { save_analysis_metadata                } from '../nextflow-modules/modules/meta/main.nf'
-include { seqtk_sample                          } from '../nextflow-modules/modules/seqtk/main.nf'
-include { ska_build                             } from '../nextflow-modules/modules/ska/main.nf'
-include { skesa                                 } from '../nextflow-modules/modules/skesa/main.nf'
-include { sourmash                              } from '../nextflow-modules/modules/sourmash/main.nf'
-include { spades_illumina                       } from '../nextflow-modules/modules/spades/main.nf'
-include { spades_iontorrent                     } from '../nextflow-modules/modules/spades/main.nf'
+include { get_meta                                   } from '../methods/get_sample_data.nf'
+include { get_reads                                  } from '../methods/get_sample_data.nf'
+include { get_seqrun_meta                            } from '../methods/get_seqrun_meta.nf'
+include { assembly_trim_clean                        } from '../nextflow-modules/modules/clean/main.nf'
+include { bwa_mem as bwa_mem_ref                     } from '../nextflow-modules/modules/bwa/main.nf'
+include { fastqc                                     } from '../nextflow-modules/modules/fastqc/main.nf'
+include { flye                                       } from '../nextflow-modules/modules/flye/main.nf'
+include { hostile                                    } from '../nextflow-modules/modules/hostile/main.nf'
+include { medaka                                     } from '../nextflow-modules/modules/medaka/main.nf'
+include { nanoplot                                   } from '../nextflow-modules/modules/nanoplot/main.nf'
+include { minimap2_align as minimap2_align_ref       } from '../nextflow-modules/modules/minimap2/main.nf'       
+include { post_align_qc                              } from '../nextflow-modules/modules/prp/main.nf'
+include { quast                                      } from '../nextflow-modules/modules/quast/main.nf'
+include { samtools_index as samtools_index_ref       } from '../nextflow-modules/modules/samtools/main.nf'
+include { samtools_coverage as samtools_coverage_ref } from '../nextflow-modules/modules/samtools/main.nf'
+include { samtools_sort as samtools_sort_ref         } from '../nextflow-modules/modules/samtools/main.nf'
+include { save_analysis_metadata                     } from '../nextflow-modules/modules/meta/main.nf'
+include { seqtk_sample                               } from '../nextflow-modules/modules/seqtk/main.nf'
+include { ska_build                                  } from '../nextflow-modules/modules/ska/main.nf'
+include { skesa                                      } from '../nextflow-modules/modules/skesa/main.nf'
+include { sourmash                                   } from '../nextflow-modules/modules/sourmash/main.nf'
+include { spades_illumina                            } from '../nextflow-modules/modules/spades/main.nf'
+include { spades_iontorrent                          } from '../nextflow-modules/modules/spades/main.nf'
 
 workflow CALL_BACTERIAL_BASE {
     take:
         coreLociBed
         referenceGenome
         referenceGenomeDir
+        referenceGenomeMmi
         inputSamples
         targetSampleSize
     
@@ -96,23 +100,31 @@ workflow CALL_BACTERIAL_BASE {
         // evaluate assembly quality 
         quast(ch_assembly, referenceGenome)
 
-        // qc processing
+        // qc processing - short read
         fastqc(ch_reads_w_meta)
-        bwa_mem_ref(ch_reads, referenceGenomeDir)
-        samtools_index_ref(bwa_mem_ref.out.bam)
+        bwa_mem_ref(ch_reads_w_meta, referenceGenomeDir)
 
         post_align_qc(bwa_mem_ref.out.bam, referenceGenome, coreLociBed)
 
+        // qc processing - long read
         nanoplot(ch_reads_w_meta)
+        minimap2_align_ref(ch_reads_w_meta, referenceGenomeMmi)
+        samtools_sort_ref(minimap2_align_ref.out.sam)
+        samtools_coverage_ref(samtools_sort_ref.out.bam)
 
-        sourmash(ch_assembly)
+        samtools_sort_ref.out.bam.mix(bwa_mem_ref.out.bam).set{ ch_ref_bam }
+
+        samtools_index_ref(ch_ref_bam)
 
+        // signature
+        sourmash(ch_assembly)
         ska_build(ch_reads)
 
         ch_versions = ch_versions.mix(bwa_mem_ref.out.versions)
         ch_versions = ch_versions.mix(fastqc.out.versions)
         ch_versions = ch_versions.mix(flye.out.versions)
         ch_versions = ch_versions.mix(medaka.out.versions)
+        ch_versions = ch_versions.mix(minimap2_align_ref.out.versions)
         ch_versions = ch_versions.mix(nanoplot.out.versions)
         ch_versions = ch_versions.mix(quast.out.versions)
         ch_versions = ch_versions.mix(samtools_index_ref.out.versions)
@@ -124,13 +136,14 @@ workflow CALL_BACTERIAL_BASE {
 
     emit:
         assembly        = ch_assembly                       // channel: [ val(meta), path(fasta)]
-        bam             = bwa_mem_ref.out.bam               // channel: [ val(meta), path(bam)]
+        bam             = ch_ref_bam                        // channel: [ val(meta), path(bam)]
         bai             = samtools_index_ref.out.bai        // channel: [ val(meta), path(bai)]
         fastqc          = fastqc.out.output                 // channel: [ val(meta), path(txt)]
         seqplat_meta    = ch_meta                           // channel: [ val(meta), val(str)]
         metadata        = save_analysis_metadata.out.meta   // channel: [ val(meta), path(json)]
         qc              = post_align_qc.out.qc              // channel: [ val(meta), path(fasta)]
-        qc_nano         = nanoplot.out.html                 // channel: [ val(meta), path(html)]
+        qc_nano_raw     = nanoplot.out.html                 // channel: [ val(meta), path(html)]
+        qc_nano_cov     = samtools_coverage_ref.out.txt     // channel: [ val(meta), path(txt)]
         quast           = quast.out.qc                      // channel: [ val(meta), path(qc)]
         reads           = ch_reads                          // channel: [ val(meta), path(json)]
         reads_w_meta    = ch_reads_w_meta                   // channel: [ val(meta), path(meta)]
diff --git a/workflows/escherichia_coli.nf b/workflows/escherichia_coli.nf
index 3b36289c..c4983a71 100644
--- a/workflows/escherichia_coli.nf
+++ b/workflows/escherichia_coli.nf
@@ -5,7 +5,7 @@ nextflow.enable.dsl=2
 include { amrfinderplus                             } from '../nextflow-modules/modules/amrfinderplus/main.nf'
 include { bracken                                   } from '../nextflow-modules/modules/bracken/main.nf'
 include { bwa_index                                 } from '../nextflow-modules/modules/bwa/main.nf'
-include { bwa_mem as bwa_mem_dedup                  } from '../nextflow-modules/modules/bwa/main.nf'
+include { bwa_mem as bwa_mem_assembly               } from '../nextflow-modules/modules/bwa/main.nf'
 include { chewbbaca_allelecall                      } from '../nextflow-modules/modules/chewbbaca/main.nf'
 include { chewbbaca_create_batch_list               } from '../nextflow-modules/modules/chewbbaca/main.nf'
 include { chewbbaca_split_results                   } from '../nextflow-modules/modules/chewbbaca/main.nf'
@@ -16,9 +16,12 @@ include { export_to_cdm                             } from '../nextflow-modules/
 include { freebayes                                 } from '../nextflow-modules/modules/freebayes/main.nf'
 include { kraken                                    } from '../nextflow-modules/modules/kraken/main.nf'
 include { mask_polymorph_assembly                   } from '../nextflow-modules/modules/mask/main.nf'
+include { minimap2_align as minimap2_align_assembly } from '../nextflow-modules/modules/minimap2/main.nf'       
+include { minimap2_index                            } from '../nextflow-modules/modules/minimap2/main.nf'       
 include { mlst                                      } from '../nextflow-modules/modules/mlst/main.nf'
 include { resfinder                                 } from '../nextflow-modules/modules/resfinder/main.nf'
 include { samtools_index as samtools_index_assembly } from '../nextflow-modules/modules/samtools/main.nf'
+include { samtools_sort as samtools_sort_assembly   } from '../nextflow-modules/modules/samtools/main.nf'
 include { serotypefinder                            } from '../nextflow-modules/modules/serotypefinder/main.nf'
 include { shigapass                                 } from '../nextflow-modules/modules/shigapass/main.nf'
 include { virulencefinder                           } from '../nextflow-modules/modules/virulencefinder/main.nf'
@@ -31,8 +34,9 @@ workflow CALL_ESCHERICHIA_COLI {
     // load references 
     referenceGenome = file(params.referenceGenome, checkIfExists: true)
     referenceGenomeDir = file(referenceGenome.getParent(), checkIfExists: true)
-    referenceGenomeIdx = file(params.referenceGenomeIdx, checkIfExists: true)
+    referenceGenomeFai = file(params.referenceGenomeFai, checkIfExists: true)
     referenceGenomeGff = file(params.referenceGenomeGff, checkIfExists: true)
+    referenceGenomeMmi = file(params.referenceGenomeMmi, checkIfExists: true)
     // databases
     amrfinderDb = file(params.amrfinderDb, checkIfExists: true)
     mlstBlastDb = file(params.mlstBlastDb, checkIfExists: true)
@@ -51,7 +55,7 @@ workflow CALL_ESCHERICHIA_COLI {
     main:
         ch_versions = Channel.empty()
 
-        CALL_BACTERIAL_BASE( coreLociBed, referenceGenome, referenceGenomeDir, inputSamples, targetSampleSize )
+        CALL_BACTERIAL_BASE( coreLociBed, referenceGenome, referenceGenomeDir, referenceGenomeMmi, inputSamples, targetSampleSize )
         
         CALL_BACTERIAL_BASE.out.assembly.set{ch_assembly}
         CALL_BACTERIAL_BASE.out.reads.set{ch_reads}
@@ -66,30 +70,41 @@ workflow CALL_ESCHERICHIA_COLI {
         CALL_BACTERIAL_BASE.out.sourmash.set{ch_sourmash}
         CALL_BACTERIAL_BASE.out.ska_build.set{ch_ska}
 
-        bwa_index(ch_assembly)
+        bwa_index(ch_assembly.join(ch_seqplat_meta))
+        minimap2_index(ch_assembly.join(ch_seqplat_meta))
 
-        ch_reads
-            .join(bwa_index.out.idx)
-            .multiMap { id, reads, bai -> 
-                reads: tuple(id, reads)
-                bai: bai
+        // create input map channels for bwa on assembly
+        ch_input_meta
+            .join(bwa_index.out.index)
+            .multiMap { id, reads, platform, index -> 
+                reads_w_meta: tuple(id, reads, platform)
+                index: index
             }
-            .set { bwa_mem_dedup_ch }
-        bwa_mem_dedup(bwa_mem_dedup_ch.reads, bwa_mem_dedup_ch.bai)
-        samtools_index_assembly(bwa_mem_dedup.out.bam)
+            .set{ ch_bwa_mem_assembly_map }
+        bwa_mem_assembly(ch_bwa_mem_assembly_map.reads_w_meta, ch_bwa_mem_assembly_map.index)
+
+        // create input map channels for minimap2 on assembly
+        ch_input_meta
+            .join(minimap2_index.out.index)
+            .multiMap { id, reads, platform, index -> 
+                reads_w_meta: tuple(id, reads, platform)
+                index: index
+            }
+            .set{ ch_minimap2_align_assembly_map }
+        minimap2_align_assembly(ch_minimap2_align_assembly_map.reads_w_meta, ch_minimap2_align_assembly_map.index)
+        samtools_sort_assembly(minimap2_align_assembly.out.sam)
+
+        bwa_mem_assembly.out.bam.mix(samtools_sort_assembly.out.bam).set{ ch_bam }
+
+        samtools_index_assembly(ch_bam)
 
         // construct freebayes input channels
-        ch_assembly
-            .join(bwa_mem_dedup.out.bam)
+        ch_bam
             .join(samtools_index_assembly.out.bai)
-            .multiMap { id, fasta, bam, bai -> 
-                assembly: tuple(id, fasta)
-                mapping: tuple(bam, bai)
-            }
-            .set { freebayes_ch }
+            .set{ ch_bam_bai }
 
         // VARIANT CALLING
-        freebayes(freebayes_ch.assembly, freebayes_ch.mapping)
+        freebayes(ch_assembly, ch_bam_bai)
 
         mask_polymorph_assembly(ch_assembly.join(freebayes.out.vcf))
 
@@ -145,12 +160,12 @@ workflow CALL_ESCHERICHIA_COLI {
             kraken(ch_reads, krakenDb)
             bracken(kraken.out.report, krakenDb).output
             combinedOutput.join(bracken.out.output).set{ combinedOutput }
-            create_analysis_result(combinedOutput, referenceGenome, referenceGenomeIdx, referenceGenomeGff)
+            create_analysis_result(combinedOutput, referenceGenome, referenceGenomeFai, referenceGenomeMmi, referenceGenomeGff)
             ch_versions = ch_versions.mix(kraken.out.versions)
             ch_versions = ch_versions.mix(bracken.out.versions)
         } else {
             combinedOutput.join(ch_empty).set{ combinedOutput }
-            create_analysis_result(combinedOutput, referenceGenome, referenceGenomeIdx, referenceGenomeGff)
+            create_analysis_result(combinedOutput, referenceGenome, referenceGenomeFai, referenceGenomeMmi, referenceGenomeGff)
         }
 
         create_yaml(create_analysis_result.out.json.join(ch_sourmash).join(ch_ska), params.speciesDir)
@@ -167,7 +182,7 @@ workflow CALL_ESCHERICHIA_COLI {
         ch_versions = ch_versions.mix(CALL_BACTERIAL_BASE.out.versions)
         ch_versions = ch_versions.mix(amrfinderplus.out.versions)
         ch_versions = ch_versions.mix(bwa_index.out.versions)
-        ch_versions = ch_versions.mix(bwa_mem_dedup.out.versions)
+        ch_versions = ch_versions.mix(bwa_mem_assembly.out.versions)
         ch_versions = ch_versions.mix(chewbbaca_allelecall.out.versions)
         ch_versions = ch_versions.mix(create_analysis_result.out.versions)
         ch_versions = ch_versions.mix(freebayes.out.versions)
diff --git a/workflows/klebsiella_pneumoniae.nf b/workflows/klebsiella_pneumoniae.nf
index 5d1579a7..1f55b7a8 100644
--- a/workflows/klebsiella_pneumoniae.nf
+++ b/workflows/klebsiella_pneumoniae.nf
@@ -5,7 +5,7 @@ nextflow.enable.dsl=2
 include { amrfinderplus                             } from '../nextflow-modules/modules/amrfinderplus/main.nf'
 include { bracken                                   } from '../nextflow-modules/modules/bracken/main.nf'
 include { bwa_index                                 } from '../nextflow-modules/modules/bwa/main.nf'
-include { bwa_mem as bwa_mem_dedup                  } from '../nextflow-modules/modules/bwa/main.nf'
+include { bwa_mem as bwa_mem_assembly               } from '../nextflow-modules/modules/bwa/main.nf'
 include { chewbbaca_allelecall                      } from '../nextflow-modules/modules/chewbbaca/main.nf'
 include { chewbbaca_create_batch_list               } from '../nextflow-modules/modules/chewbbaca/main.nf'
 include { chewbbaca_split_results                   } from '../nextflow-modules/modules/chewbbaca/main.nf'
@@ -16,9 +16,12 @@ include { export_to_cdm                             } from '../nextflow-modules/
 include { freebayes                                 } from '../nextflow-modules/modules/freebayes/main.nf'
 include { kraken                                    } from '../nextflow-modules/modules/kraken/main.nf'
 include { mask_polymorph_assembly                   } from '../nextflow-modules/modules/mask/main.nf'
+include { minimap2_align as minimap2_align_assembly } from '../nextflow-modules/modules/minimap2/main.nf'       
+include { minimap2_index                            } from '../nextflow-modules/modules/minimap2/main.nf'     
 include { mlst                                      } from '../nextflow-modules/modules/mlst/main.nf'
 include { resfinder                                 } from '../nextflow-modules/modules/resfinder/main.nf'
 include { samtools_index as samtools_index_assembly } from '../nextflow-modules/modules/samtools/main.nf'
+include { samtools_sort as samtools_sort_assembly   } from '../nextflow-modules/modules/samtools/main.nf'
 include { serotypefinder                            } from '../nextflow-modules/modules/serotypefinder/main.nf'
 include { virulencefinder                           } from '../nextflow-modules/modules/virulencefinder/main.nf'
 include { CALL_BACTERIAL_BASE                       } from '../workflows/bacterial_base.nf'
@@ -30,8 +33,9 @@ workflow CALL_KLEBSIELLA_PNEUMONIAE {
     // load references 
     referenceGenome = file(params.referenceGenome, checkIfExists: true)
     referenceGenomeDir = file(referenceGenome.getParent(), checkIfExists: true)
-    referenceGenomeIdx = file(params.referenceGenomeIdx, checkIfExists: true)
+    referenceGenomeFai = file(params.referenceGenomeFai, checkIfExists: true)
     referenceGenomeGff = file(params.referenceGenomeGff, checkIfExists: true)
+    referenceGenomeMmi = file(params.referenceGenomeMmi, checkIfExists: true)
     // databases
     amrfinderDb = file(params.amrfinderDb, checkIfExists: true)
     mlstBlastDb = file(params.mlstBlastDb, checkIfExists: true)
@@ -49,7 +53,7 @@ workflow CALL_KLEBSIELLA_PNEUMONIAE {
     main:
         ch_versions = Channel.empty()
 
-        CALL_BACTERIAL_BASE( coreLociBed, referenceGenome, referenceGenomeDir, inputSamples, targetSampleSize )
+        CALL_BACTERIAL_BASE( coreLociBed, referenceGenome, referenceGenomeDir, referenceGenomeMmi, inputSamples, targetSampleSize )
         
         CALL_BACTERIAL_BASE.out.assembly.set{ch_assembly}
         CALL_BACTERIAL_BASE.out.reads.set{ch_reads}
@@ -64,30 +68,41 @@ workflow CALL_KLEBSIELLA_PNEUMONIAE {
         CALL_BACTERIAL_BASE.out.sourmash.set{ch_sourmash}
         CALL_BACTERIAL_BASE.out.ska_build.set{ch_ska}
 
-        bwa_index(ch_assembly)
+        bwa_index(ch_assembly.join(ch_seqplat_meta))
+        minimap2_index(ch_assembly.join(ch_seqplat_meta))
 
-        ch_reads
-            .join(bwa_index.out.idx)
-            .multiMap { id, reads, bai -> 
-                reads: tuple(id, reads)
-                bai: bai
+        // create input map channels for bwa on assembly
+        ch_input_meta
+            .join(bwa_index.out.index)
+            .multiMap { id, reads, platform, index -> 
+                reads_w_meta: tuple(id, reads, platform)
+                index: index
             }
-            .set { bwa_mem_dedup_ch }
-        bwa_mem_dedup(bwa_mem_dedup_ch.reads, bwa_mem_dedup_ch.bai)
-        samtools_index_assembly(bwa_mem_dedup.out.bam)
+            .set{ ch_bwa_mem_assembly_map }
+        bwa_mem_assembly(ch_bwa_mem_assembly_map.reads_w_meta, ch_bwa_mem_assembly_map.index)
+
+        // create input map channels for minimap2 on assembly
+        ch_input_meta
+            .join(minimap2_index.out.index)
+            .multiMap { id, reads, platform, index -> 
+                reads_w_meta: tuple(id, reads, platform)
+                index: index
+            }
+            .set{ ch_minimap2_align_assembly_map }
+        minimap2_align_assembly(ch_minimap2_align_assembly_map.reads_w_meta, ch_minimap2_align_assembly_map.index)
+        samtools_sort_assembly(minimap2_align_assembly.out.sam)
+
+        bwa_mem_assembly.out.bam.mix(samtools_sort_assembly.out.bam).set{ ch_bam }
+
+        samtools_index_assembly(ch_bam)
 
         // construct freebayes input channels
-        ch_assembly
-            .join(bwa_mem_dedup.out.bam)
+        ch_bam
             .join(samtools_index_assembly.out.bai)
-            .multiMap { id, fasta, bam, bai -> 
-                assembly: tuple(id, fasta)
-                mapping: tuple(bam, bai)
-            }
-            .set { freebayes_ch }
+            .set{ ch_bam_bai }
 
         // VARIANT CALLING
-        freebayes(freebayes_ch.assembly, freebayes_ch.mapping)
+        freebayes(ch_assembly, ch_bam_bai)
 
         mask_polymorph_assembly(ch_assembly.join(freebayes.out.vcf))
 
@@ -142,12 +157,12 @@ workflow CALL_KLEBSIELLA_PNEUMONIAE {
             kraken(ch_reads, krakenDb)
             bracken(kraken.out.report, krakenDb).output
             combinedOutput.join(bracken.out.output).set{ combinedOutput }
-            create_analysis_result(combinedOutput, referenceGenome, referenceGenomeIdx, referenceGenomeGff)
+            create_analysis_result(combinedOutput, referenceGenome, referenceGenomeFai, referenceGenomeMmi, referenceGenomeGff)
             ch_versions = ch_versions.mix(kraken.out.versions)
             ch_versions = ch_versions.mix(bracken.out.versions)
         } else {
             combinedOutput.join(ch_empty).set{ combinedOutput }
-            create_analysis_result(combinedOutput, referenceGenome, referenceGenomeIdx, referenceGenomeGff)
+            create_analysis_result(combinedOutput, referenceGenome, referenceGenomeFai, referenceGenomeMmi, referenceGenomeGff)
         }
 
         create_yaml(create_analysis_result.out.json.join(ch_sourmash).join(ch_ska), params.speciesDir)
@@ -164,7 +179,7 @@ workflow CALL_KLEBSIELLA_PNEUMONIAE {
         ch_versions = ch_versions.mix(CALL_BACTERIAL_BASE.out.versions)
         ch_versions = ch_versions.mix(amrfinderplus.out.versions)
         ch_versions = ch_versions.mix(bwa_index.out.versions)
-        ch_versions = ch_versions.mix(bwa_mem_dedup.out.versions)
+        ch_versions = ch_versions.mix(bwa_mem_assembly.out.versions)
         ch_versions = ch_versions.mix(chewbbaca_allelecall.out.versions)
         ch_versions = ch_versions.mix(create_analysis_result.out.versions)
         ch_versions = ch_versions.mix(freebayes.out.versions)
diff --git a/workflows/mycobacterium_tuberculosis.nf b/workflows/mycobacterium_tuberculosis.nf
index 33f8da04..31b00963 100644
--- a/workflows/mycobacterium_tuberculosis.nf
+++ b/workflows/mycobacterium_tuberculosis.nf
@@ -26,8 +26,9 @@ workflow CALL_MYCOBACTERIUM_TUBERCULOSIS {
     // load references 
     referenceGenome = file(params.referenceGenome, checkIfExists: true)
     referenceGenomeDir = file(referenceGenome.getParent(), checkIfExists: true)
-    referenceGenomeIdx = file(params.referenceGenomeIdx, checkIfExists: true)
+    referenceGenomeFai = file(params.referenceGenomeFai, checkIfExists: true)
     referenceGenomeGff = file(params.referenceGenomeGff, checkIfExists: true)
+    referenceGenomeMmi = file(params.referenceGenomeMmi, checkIfExists: true)
     // databases
     coreLociBed = file(params.coreLociBed, checkIfExists: true)
     tbdbBed = file(params.tbdbBed, checkIfExists: true)
@@ -39,7 +40,7 @@ workflow CALL_MYCOBACTERIUM_TUBERCULOSIS {
     main:
         ch_versions = Channel.empty()
 
-        CALL_BACTERIAL_BASE( coreLociBed, referenceGenome, referenceGenomeDir, inputSamples, targetSampleSize )
+        CALL_BACTERIAL_BASE( coreLociBed, referenceGenome, referenceGenomeDir, referenceGenomeMmi, inputSamples, targetSampleSize )
 
         CALL_BACTERIAL_BASE.out.assembly.set{ch_assembly}
         CALL_BACTERIAL_BASE.out.reads.set{ch_reads}
@@ -90,12 +91,12 @@ workflow CALL_MYCOBACTERIUM_TUBERCULOSIS {
             kraken(ch_reads, krakenDb)
             bracken(kraken.out.report, krakenDb).output
             combinedOutput.join(bracken.out.output).set{ combinedOutput }
-            create_analysis_result(combinedOutput, referenceGenome, referenceGenomeIdx, referenceGenomeGff)
+            create_analysis_result(combinedOutput, referenceGenome, referenceGenomeFai, referenceGenomeMmi, referenceGenomeGff)
             ch_versions = ch_versions.mix(kraken.out.versions)
             ch_versions = ch_versions.mix(bracken.out.versions)
         } else {
             combinedOutput.join(ch_empty).set{ combinedOutput }
-            create_analysis_result(combinedOutput, referenceGenome, referenceGenomeIdx, referenceGenomeGff)
+            create_analysis_result(combinedOutput, referenceGenome, referenceGenomeFai, referenceGenomeMmi, referenceGenomeGff)
         }
 
         // Add IGV annotation tracks
diff --git a/workflows/staphylococcus_aureus.nf b/workflows/staphylococcus_aureus.nf
index c77b5891..26461c92 100644
--- a/workflows/staphylococcus_aureus.nf
+++ b/workflows/staphylococcus_aureus.nf
@@ -2,27 +2,31 @@
 
 nextflow.enable.dsl=2
 
-include { amrfinderplus                             } from '../nextflow-modules/modules/amrfinderplus/main.nf'
-include { bracken                                   } from '../nextflow-modules/modules/bracken/main.nf'
-include { bwa_index                                 } from '../nextflow-modules/modules/bwa/main.nf'
-include { bwa_mem as bwa_mem_dedup                  } from '../nextflow-modules/modules/bwa/main.nf'
-include { chewbbaca_allelecall                      } from '../nextflow-modules/modules/chewbbaca/main.nf'
-include { chewbbaca_create_batch_list               } from '../nextflow-modules/modules/chewbbaca/main.nf'
-include { chewbbaca_split_results                   } from '../nextflow-modules/modules/chewbbaca/main.nf'
-include { create_analysis_result                    } from '../nextflow-modules/modules/prp/main.nf'
-include { create_cdm_input                          } from '../nextflow-modules/modules/prp/main.nf'
-include { create_yaml                               } from '../nextflow-modules/modules/yaml/main.nf'
-include { export_to_cdm                             } from '../nextflow-modules/modules/cmd/main.nf'
-include { freebayes                                 } from '../nextflow-modules/modules/freebayes/main.nf'
-include { kraken                                    } from '../nextflow-modules/modules/kraken/main.nf'
-include { mask_polymorph_assembly                   } from '../nextflow-modules/modules/mask/main.nf'
-include { mlst                                      } from '../nextflow-modules/modules/mlst/main.nf'
-include { resfinder                                 } from '../nextflow-modules/modules/resfinder/main.nf'
-include { samtools_index as samtools_index_assembly } from '../nextflow-modules/modules/samtools/main.nf'
-include { sccmec                                    } from '../nextflow-modules/modules/sccmec/main.nf'
-include { spatyper                                  } from '../nextflow-modules/modules/spatyper/main.nf'
-include { virulencefinder                           } from '../nextflow-modules/modules/virulencefinder/main.nf'
-include { CALL_BACTERIAL_BASE                       } from '../workflows/bacterial_base.nf'
+include { amrfinderplus                                     } from '../nextflow-modules/modules/amrfinderplus/main.nf'
+include { bracken                                           } from '../nextflow-modules/modules/bracken/main.nf'
+include { bwa_index                                         } from '../nextflow-modules/modules/bwa/main.nf'
+include { bwa_mem as bwa_mem_assembly                       } from '../nextflow-modules/modules/bwa/main.nf'
+include { chewbbaca_allelecall                              } from '../nextflow-modules/modules/chewbbaca/main.nf'
+include { chewbbaca_create_batch_list                       } from '../nextflow-modules/modules/chewbbaca/main.nf'
+include { chewbbaca_split_results                           } from '../nextflow-modules/modules/chewbbaca/main.nf'
+include { create_analysis_result                            } from '../nextflow-modules/modules/prp/main.nf'
+include { create_cdm_input                                  } from '../nextflow-modules/modules/prp/main.nf'
+include { create_yaml                                       } from '../nextflow-modules/modules/yaml/main.nf'
+include { export_to_cdm                                     } from '../nextflow-modules/modules/cmd/main.nf'
+include { freebayes                                         } from '../nextflow-modules/modules/freebayes/main.nf'
+include { kraken                                            } from '../nextflow-modules/modules/kraken/main.nf'
+include { mask_polymorph_assembly                           } from '../nextflow-modules/modules/mask/main.nf'
+include { minimap2_align as minimap2_align_assembly         } from '../nextflow-modules/modules/minimap2/main.nf'
+include { minimap2_index                                    } from '../nextflow-modules/modules/minimap2/main.nf'
+include { mlst                                              } from '../nextflow-modules/modules/mlst/main.nf'
+include { resfinder                                         } from '../nextflow-modules/modules/resfinder/main.nf'
+include { samtools_index as samtools_index_assembly         } from '../nextflow-modules/modules/samtools/main.nf'
+include { samtools_sort as samtools_sort_assembly           } from '../nextflow-modules/modules/samtools/main.nf'
+include { samtools_coverage as samtools_coverage_assembly   } from '../nextflow-modules/modules/samtools/main.nf'
+include { sccmec                                            } from '../nextflow-modules/modules/sccmec/main.nf'
+include { spatyper                                          } from '../nextflow-modules/modules/spatyper/main.nf'
+include { virulencefinder                                   } from '../nextflow-modules/modules/virulencefinder/main.nf'
+include { CALL_BACTERIAL_BASE                               } from '../workflows/bacterial_base.nf'
 
 workflow CALL_STAPHYLOCOCCUS_AUREUS {
     // set input data
@@ -31,7 +35,8 @@ workflow CALL_STAPHYLOCOCCUS_AUREUS {
     // load references 
     referenceGenome = file(params.referenceGenome, checkIfExists: true)
     referenceGenomeDir = file(referenceGenome.getParent(), checkIfExists: true)
-    referenceGenomeIdx = file(params.referenceGenomeIdx, checkIfExists: true)
+    referenceGenomeFai = file(params.referenceGenomeFai, checkIfExists: true)
+    referenceGenomeMmi = file(params.referenceGenomeMmi, checkIfExists: true)
     referenceGenomeGff = file(params.referenceGenomeGff, checkIfExists: true)
     // databases
     amrfinderDb = file(params.amrfinderDb, checkIfExists: true)
@@ -49,7 +54,7 @@ workflow CALL_STAPHYLOCOCCUS_AUREUS {
     main:
         ch_versions = Channel.empty()
 
-        CALL_BACTERIAL_BASE( coreLociBed, referenceGenome, referenceGenomeDir, inputSamples, targetSampleSize )
+        CALL_BACTERIAL_BASE( coreLociBed, referenceGenome, referenceGenomeDir, referenceGenomeMmi, inputSamples, targetSampleSize )
         
         CALL_BACTERIAL_BASE.out.assembly.set{ch_assembly}
         CALL_BACTERIAL_BASE.out.reads.set{ch_reads}
@@ -64,30 +69,42 @@ workflow CALL_STAPHYLOCOCCUS_AUREUS {
         CALL_BACTERIAL_BASE.out.sourmash.set{ch_sourmash}
         CALL_BACTERIAL_BASE.out.ska_build.set{ch_ska}
 
-        bwa_index(ch_assembly)
+        bwa_index(ch_assembly.join(ch_seqplat_meta))
+        minimap2_index(ch_assembly.join(ch_seqplat_meta))
 
-        ch_reads
-            .join(bwa_index.out.idx)
-            .multiMap { id, reads, bai -> 
-                reads: tuple(id, reads)
-                bai: bai
+        // create input map channels for bwa on assembly
+        ch_input_meta
+            .join(bwa_index.out.index)
+            .multiMap { id, reads, platform, index -> 
+                reads_w_meta: tuple(id, reads, platform)
+                index: index
             }
-            .set { bwa_mem_dedup_ch }
-        bwa_mem_dedup(bwa_mem_dedup_ch.reads, bwa_mem_dedup_ch.bai)
-        samtools_index_assembly(bwa_mem_dedup.out.bam)
+            .set{ ch_bwa_mem_assembly_map }
+        bwa_mem_assembly(ch_bwa_mem_assembly_map.reads_w_meta, ch_bwa_mem_assembly_map.index)
+
+        // create input map channels for minimap2 on assembly
+        ch_input_meta
+            .join(minimap2_index.out.index)
+            .multiMap { id, reads, platform, index -> 
+                reads_w_meta: tuple(id, reads, platform)
+                index: index
+            }
+            .set{ ch_minimap2_align_assembly_map }
+        minimap2_align_assembly(ch_minimap2_align_assembly_map.reads_w_meta, ch_minimap2_align_assembly_map.index)
+        samtools_sort_assembly(minimap2_align_assembly.out.sam)
+        samtools_coverage_assembly(samtools_sort_assembly.out.bam)
+
+        bwa_mem_assembly.out.bam.mix(samtools_sort_assembly.out.bam).set{ ch_bam }
+
+        samtools_index_assembly(ch_bam)
 
         // construct freebayes input channels
-        ch_assembly
-            .join(bwa_mem_dedup.out.bam)
+        ch_bam
             .join(samtools_index_assembly.out.bai)
-            .multiMap { id, fasta, bam, bai -> 
-                assembly: tuple(id, fasta)
-                mapping: tuple(bam, bai)
-            }
-            .set { freebayes_ch }
+            .set{ ch_bam_bai }
 
         // VARIANT CALLING
-        freebayes(freebayes_ch.assembly, freebayes_ch.mapping)
+        freebayes(ch_assembly, ch_bam_bai)
 
         mask_polymorph_assembly(ch_assembly.join(freebayes.out.vcf))
 
@@ -143,12 +160,12 @@ workflow CALL_STAPHYLOCOCCUS_AUREUS {
             kraken(ch_reads, krakenDb)
             bracken(kraken.out.report, krakenDb).output
             combinedOutput.join(bracken.out.output).set{ combinedOutput }
-            create_analysis_result(combinedOutput, referenceGenome, referenceGenomeIdx, referenceGenomeGff)
+            create_analysis_result(combinedOutput, referenceGenome, referenceGenomeFai, referenceGenomeMmi, referenceGenomeGff)
             ch_versions = ch_versions.mix(kraken.out.versions)
             ch_versions = ch_versions.mix(bracken.out.versions)
         } else {
             combinedOutput.join(ch_empty).set{ combinedOutput }
-            create_analysis_result(combinedOutput, referenceGenome, referenceGenomeIdx, referenceGenomeGff)
+            create_analysis_result(combinedOutput, referenceGenome, referenceGenomeFai, referenceGenomeMmi, referenceGenomeGff)
         }
 
         create_yaml(create_analysis_result.out.json.join(ch_sourmash).join(ch_ska), params.speciesDir)
@@ -165,7 +182,9 @@ workflow CALL_STAPHYLOCOCCUS_AUREUS {
         ch_versions = ch_versions.mix(CALL_BACTERIAL_BASE.out.versions)
         ch_versions = ch_versions.mix(amrfinderplus.out.versions)
         ch_versions = ch_versions.mix(bwa_index.out.versions)
-        ch_versions = ch_versions.mix(bwa_mem_dedup.out.versions)
+        ch_versions = ch_versions.mix(bwa_mem_assembly.out.versions)
+        ch_versions = ch_versions.mix(minimap2_index.out.versions)
+        ch_versions = ch_versions.mix(minimap2_align_assembly.out.versions)
         ch_versions = ch_versions.mix(chewbbaca_allelecall.out.versions)
         ch_versions = ch_versions.mix(create_analysis_result.out.versions)
         ch_versions = ch_versions.mix(freebayes.out.versions)
@@ -175,6 +194,7 @@ workflow CALL_STAPHYLOCOCCUS_AUREUS {
         ch_versions = ch_versions.mix(sccmec.out.versions)
         ch_versions = ch_versions.mix(spatyper.out.versions)
         ch_versions = ch_versions.mix(virulencefinder.out.versions)
+        ch_versions = ch_versions.mix(samtools_coverage_assembly.out.versions)
 
     emit: 
         pipeline_result = create_analysis_result.out.json
diff --git a/workflows/streptococcus.nf b/workflows/streptococcus.nf
index bbf2458a..353679a8 100644
--- a/workflows/streptococcus.nf
+++ b/workflows/streptococcus.nf
@@ -7,7 +7,7 @@ include { get_reads                                 } from '../methods/get_sampl
 include { amrfinderplus                             } from '../nextflow-modules/modules/amrfinderplus/main.nf'
 include { bracken                                   } from '../nextflow-modules/modules/bracken/main.nf'
 include { bwa_index                                 } from '../nextflow-modules/modules/bwa/main.nf'
-include { bwa_mem as bwa_mem_dedup                  } from '../nextflow-modules/modules/bwa/main.nf'
+include { bwa_mem as bwa_mem_assembly               } from '../nextflow-modules/modules/bwa/main.nf'
 include { chewbbaca_allelecall                      } from '../nextflow-modules/modules/chewbbaca/main.nf'
 include { chewbbaca_create_batch_list               } from '../nextflow-modules/modules/chewbbaca/main.nf'
 include { chewbbaca_split_results                   } from '../nextflow-modules/modules/chewbbaca/main.nf'
@@ -19,9 +19,12 @@ include { export_to_cdm                             } from '../nextflow-modules/
 include { freebayes                                 } from '../nextflow-modules/modules/freebayes/main.nf'
 include { kraken                                    } from '../nextflow-modules/modules/kraken/main.nf'
 include { mask_polymorph_assembly                   } from '../nextflow-modules/modules/mask/main.nf'
+include { minimap2_align as minimap2_align_assembly } from '../nextflow-modules/modules/minimap2/main.nf'       
+include { minimap2_index                            } from '../nextflow-modules/modules/minimap2/main.nf'       
 include { mlst                                      } from '../nextflow-modules/modules/mlst/main.nf'
 include { resfinder                                 } from '../nextflow-modules/modules/resfinder/main.nf'
 include { samtools_index as samtools_index_assembly } from '../nextflow-modules/modules/samtools/main.nf'
+include { samtools_sort as samtools_sort_assembly   } from '../nextflow-modules/modules/samtools/main.nf'
 include { serotypefinder                            } from '../nextflow-modules/modules/serotypefinder/main.nf'
 include { shigapass                                 } from '../nextflow-modules/modules/shigapass/main.nf'
 include { virulencefinder                           } from '../nextflow-modules/modules/virulencefinder/main.nf'
@@ -35,7 +38,8 @@ workflow CALL_STREPTOCOCCUS {
     referenceGenome = params.referenceGenome ? file(params.referenceGenome, checkIfExists: true) : Channel.value([])
     referenceGenomeDir = params.referenceGenome ? file(referenceGenome.getParent(), checkIfExists: true) : Channel.value([])
     referenceGenomeGff = params.referenceGenomeGff ? file(params.referenceGenomeGff, checkIfExists: true) : Channel.value([])
-    referenceGenomeIdx = params.referenceGenomeIdx ? file(params.referenceGenomeIdx, checkIfExists: true) : Channel.value([])
+    referenceGenomeFai = params.referenceGenomeFai ? file(params.referenceGenomeFai, checkIfExists: true) : Channel.value([])
+    referenceGenomeMmi = params.referenceGenomeMmi ? file(params.referenceGenomeMmi, checkIfExists: true) : Channel.value([])
     // databases
     amrfinderDb = file(params.amrfinderDb, checkIfExists: true)
     chewbbacaDb = file(params.chewbbacaDb, checkIfExists: true)
@@ -58,7 +62,7 @@ workflow CALL_STREPTOCOCCUS {
     main:
         ch_versions = Channel.empty()
 
-        CALL_BACTERIAL_BASE( coreLociBed, referenceGenome, referenceGenomeDir, inputSamples, targetSampleSize )
+        CALL_BACTERIAL_BASE( coreLociBed, referenceGenome, referenceGenomeDir, referenceGenomeMmi, inputSamples, targetSampleSize )
         
         CALL_BACTERIAL_BASE.out.assembly.set{ch_assembly}
         CALL_BACTERIAL_BASE.out.reads.set{ch_reads}
@@ -73,30 +77,41 @@ workflow CALL_STREPTOCOCCUS {
         CALL_BACTERIAL_BASE.out.sourmash.set{ch_sourmash}
         CALL_BACTERIAL_BASE.out.ska_build.set{ch_ska}
 
-        bwa_index(ch_assembly)
+        bwa_index(ch_assembly.join(ch_seqplat_meta))
+        minimap2_index(ch_assembly.join(ch_seqplat_meta))
 
-        ch_reads
-            .join(bwa_index.out.idx)
-            .multiMap { id, reads, bai -> 
-                reads: tuple(id, reads)
-                bai: bai
+        // create input map channels for bwa on assembly
+        ch_input_meta
+            .join(bwa_index.out.index)
+            .multiMap { id, reads, platform, index -> 
+                reads_w_meta: tuple(id, reads, platform)
+                index: index
             }
-            .set{ bwa_mem_dedup_ch }
-        bwa_mem_dedup(bwa_mem_dedup_ch.reads, bwa_mem_dedup_ch.bai)
-        samtools_index_assembly(bwa_mem_dedup.out.bam)
+            .set{ ch_bwa_mem_assembly_map }
+        bwa_mem_assembly(ch_bwa_mem_assembly_map.reads_w_meta, ch_bwa_mem_assembly_map.index)
+
+        // create input map channels for minimap2 on assembly
+        ch_input_meta
+            .join(minimap2_index.out.index)
+            .multiMap { id, reads, platform, index -> 
+                reads_w_meta: tuple(id, reads, platform)
+                index: index
+            }
+            .set{ ch_minimap2_align_assembly_map }
+        minimap2_align_assembly(ch_minimap2_align_assembly_map.reads_w_meta, ch_minimap2_align_assembly_map.index)
+        samtools_sort_assembly(minimap2_align_assembly.out.sam)
+
+        bwa_mem_assembly.out.bam.mix(samtools_sort_assembly.out.bam).set{ ch_bam }
+
+        samtools_index_assembly(ch_bam)
 
         // construct freebayes input channels
-        ch_assembly
-            .join(bwa_mem_dedup.out.bam)
+        ch_bam
             .join(samtools_index_assembly.out.bai)
-            .multiMap { id, fasta, bam, bai -> 
-                assembly: tuple(id, fasta)
-                mapping: tuple(bam, bai)
-            }
-            .set{ freebayes_ch }
+            .set{ ch_bam_bai }
 
         // VARIANT CALLING
-        freebayes(freebayes_ch.assembly, freebayes_ch.mapping)
+        freebayes(ch_assembly, ch_bam_bai)
 
         mask_polymorph_assembly(ch_assembly.join(freebayes.out.vcf))
 
@@ -153,12 +168,12 @@ workflow CALL_STREPTOCOCCUS {
             kraken(ch_reads, krakenDb)
             bracken(kraken.out.report, krakenDb).output
             combinedOutput.join(bracken.out.output).set{ combinedOutput }
-            create_analysis_result(combinedOutput, referenceGenome, referenceGenomeIdx, referenceGenomeGff)
+            create_analysis_result(combinedOutput, referenceGenome, referenceGenomeFai, referenceGenomeMmi, referenceGenomeGff)
             ch_versions = ch_versions.mix(kraken.out.versions)
             ch_versions = ch_versions.mix(bracken.out.versions)
         } else {
             combinedOutput.join(ch_empty).set{ combinedOutput }
-            create_analysis_result(combinedOutput, referenceGenome, referenceGenomeIdx, referenceGenomeGff)
+            create_analysis_result(combinedOutput, referenceGenome, referenceGenomeFai, referenceGenomeMmi, referenceGenomeGff)
         }
 
         create_yaml(create_analysis_result.out.json.join(ch_sourmash).join(ch_ska), speciesDir)
@@ -176,7 +191,7 @@ workflow CALL_STREPTOCOCCUS {
         ch_versions = ch_versions.mix(amrfinderplus.out.versions)
         ch_versions = ch_versions.mix(bracken.out.versions)
         ch_versions = ch_versions.mix(bwa_index.out.versions)
-        ch_versions = ch_versions.mix(bwa_mem_dedup.out.versions)
+        ch_versions = ch_versions.mix(bwa_mem_assembly.out.versions)
         ch_versions = ch_versions.mix(chewbbaca_allelecall.out.versions)
         ch_versions = ch_versions.mix(create_analysis_result.out.versions)
         ch_versions = ch_versions.mix(emmtyper.out.versions)
diff --git a/workflows/streptococcus_pyogenes.nf b/workflows/streptococcus_pyogenes.nf
index 187d35ce..44a82d20 100644
--- a/workflows/streptococcus_pyogenes.nf
+++ b/workflows/streptococcus_pyogenes.nf
@@ -5,7 +5,7 @@ nextflow.enable.dsl=2
 include { amrfinderplus                             } from '../nextflow-modules/modules/amrfinderplus/main.nf'
 include { bracken                                   } from '../nextflow-modules/modules/bracken/main.nf'
 include { bwa_index                                 } from '../nextflow-modules/modules/bwa/main.nf'
-include { bwa_mem as bwa_mem_dedup                  } from '../nextflow-modules/modules/bwa/main.nf'
+include { bwa_mem as bwa_mem_assembly               } from '../nextflow-modules/modules/bwa/main.nf'
 include { chewbbaca_allelecall                      } from '../nextflow-modules/modules/chewbbaca/main.nf'
 include { chewbbaca_create_batch_list               } from '../nextflow-modules/modules/chewbbaca/main.nf'
 include { chewbbaca_split_results                   } from '../nextflow-modules/modules/chewbbaca/main.nf'
@@ -17,9 +17,12 @@ include { export_to_cdm                             } from '../nextflow-modules/
 include { freebayes                                 } from '../nextflow-modules/modules/freebayes/main.nf'
 include { kraken                                    } from '../nextflow-modules/modules/kraken/main.nf'
 include { mask_polymorph_assembly                   } from '../nextflow-modules/modules/mask/main.nf'
+include { minimap2_align as minimap2_align_assembly } from '../nextflow-modules/modules/minimap2/main.nf'       
+include { minimap2_index                            } from '../nextflow-modules/modules/minimap2/main.nf'      
 include { mlst                                      } from '../nextflow-modules/modules/mlst/main.nf'
 include { resfinder                                 } from '../nextflow-modules/modules/resfinder/main.nf'
 include { samtools_index as samtools_index_assembly } from '../nextflow-modules/modules/samtools/main.nf'
+include { samtools_sort as samtools_sort_assembly   } from '../nextflow-modules/modules/samtools/main.nf'
 include { virulencefinder                           } from '../nextflow-modules/modules/virulencefinder/main.nf'
 include { CALL_BACTERIAL_BASE                       } from '../workflows/bacterial_base.nf'
 
@@ -31,7 +34,8 @@ workflow CALL_STREPTOCOCCUS_PYOGENES {
     referenceGenome = params.referenceGenome ? file(params.referenceGenome, checkIfExists: true) : Channel.value([])
     referenceGenomeDir = params.referenceGenome ? file(referenceGenome.getParent(), checkIfExists: true) : Channel.value([])
     referenceGenomeGff = params.referenceGenomeGff ? file(params.referenceGenomeGff, checkIfExists: true) : Channel.value([])
-    referenceGenomeIdx = params.referenceGenomeIdx ? file(params.referenceGenomeIdx, checkIfExists: true) : Channel.value([])
+    referenceGenomeFai = params.referenceGenomeFai ? file(params.referenceGenomeFai, checkIfExists: true) : Channel.value([])
+    referenceGenomeMmi = params.referenceGenomeMmi ? file(params.referenceGenomeMmi, checkIfExists: true) : Channel.value([])
     // databases
     amrfinderDb = file(params.amrfinderDb, checkIfExists: true)
     chewbbacaDb = file(params.chewbbacaDb, checkIfExists: true)
@@ -52,7 +56,7 @@ workflow CALL_STREPTOCOCCUS_PYOGENES {
     main:
         ch_versions = Channel.empty()
 
-        CALL_BACTERIAL_BASE( coreLociBed, referenceGenome, referenceGenomeDir, inputSamples, targetSampleSize )
+        CALL_BACTERIAL_BASE( coreLociBed, referenceGenome, referenceGenomeDir, referenceGenomeMmi, inputSamples, targetSampleSize )
         
         CALL_BACTERIAL_BASE.out.assembly.set{ch_assembly}
         CALL_BACTERIAL_BASE.out.reads.set{ch_reads}
@@ -67,30 +71,41 @@ workflow CALL_STREPTOCOCCUS_PYOGENES {
         CALL_BACTERIAL_BASE.out.sourmash.set{ch_sourmash}
         CALL_BACTERIAL_BASE.out.ska_build.set{ch_ska}
 
-        bwa_index(ch_assembly)
+        bwa_index(ch_assembly.join(ch_seqplat_meta))
+        minimap2_index(ch_assembly.join(ch_seqplat_meta))
 
-        ch_reads
-            .join(bwa_index.out.idx)
-            .multiMap { id, reads, bai -> 
-                reads: tuple(id, reads)
-                bai: bai
+        // create input map channels for bwa on assembly
+        ch_input_meta
+            .join(bwa_index.out.index)
+            .multiMap { id, reads, platform, index -> 
+                reads_w_meta: tuple(id, reads, platform)
+                index: index
             }
-            .set { bwa_mem_dedup_ch }
-        bwa_mem_dedup(bwa_mem_dedup_ch.reads, bwa_mem_dedup_ch.bai)
-        samtools_index_assembly(bwa_mem_dedup.out.bam)
+            .set{ ch_bwa_mem_assembly_map }
+        bwa_mem_assembly(ch_bwa_mem_assembly_map.reads_w_meta, ch_bwa_mem_assembly_map.index)
+
+        // create input map channels for minimap2 on assembly
+        ch_input_meta
+            .join(minimap2_index.out.index)
+            .multiMap { id, reads, platform, index -> 
+                reads_w_meta: tuple(id, reads, platform)
+                index: index
+            }
+            .set{ ch_minimap2_align_assembly_map }
+        minimap2_align_assembly(ch_minimap2_align_assembly_map.reads_w_meta, ch_minimap2_align_assembly_map.index)
+        samtools_sort_assembly(minimap2_align_assembly.out.sam)
+
+        bwa_mem_assembly.out.bam.mix(samtools_sort_assembly.out.bam).set{ ch_bam }
+
+        samtools_index_assembly(ch_bam)
 
         // construct freebayes input channels
-        ch_assembly
-            .join(bwa_mem_dedup.out.bam)
+        ch_bam
             .join(samtools_index_assembly.out.bai)
-            .multiMap { id, fasta, bam, bai -> 
-                assembly: tuple(id, fasta)
-                mapping: tuple(bam, bai)
-            }
-            .set { freebayes_ch }
+            .set{ ch_bam_bai }
 
         // VARIANT CALLING
-        freebayes(freebayes_ch.assembly, freebayes_ch.mapping)
+        freebayes(ch_assembly, ch_bam_bai)
 
         mask_polymorph_assembly(ch_assembly.join(freebayes.out.vcf))
 
@@ -145,12 +160,12 @@ workflow CALL_STREPTOCOCCUS_PYOGENES {
             kraken(ch_reads, krakenDb)
             bracken(kraken.out.report, krakenDb).output
             combinedOutput.join(bracken.out.output).set{ combinedOutput }
-            create_analysis_result(combinedOutput, referenceGenome, referenceGenomeIdx, referenceGenomeGff)
+            create_analysis_result(combinedOutput, referenceGenome, referenceGenomeFai, referenceGenomeMmi, referenceGenomeGff)
             ch_versions = ch_versions.mix(kraken.out.versions)
             ch_versions = ch_versions.mix(bracken.out.versions)
         } else {
             combinedOutput.join(ch_empty).set{ combinedOutput }
-            create_analysis_result(combinedOutput, referenceGenome, referenceGenomeIdx, referenceGenomeGff)
+            create_analysis_result(combinedOutput, referenceGenome, referenceGenomeFai, referenceGenomeMmi, referenceGenomeGff)
         }
 
         create_yaml(create_analysis_result.out.json.join(ch_sourmash).join(ch_ska), speciesDir)
@@ -167,7 +182,7 @@ workflow CALL_STREPTOCOCCUS_PYOGENES {
         ch_versions = ch_versions.mix(CALL_BACTERIAL_BASE.out.versions)
         ch_versions = ch_versions.mix(amrfinderplus.out.versions)
         ch_versions = ch_versions.mix(bwa_index.out.versions)
-        ch_versions = ch_versions.mix(bwa_mem_dedup.out.versions)
+        ch_versions = ch_versions.mix(bwa_mem_assembly.out.versions)
         ch_versions = ch_versions.mix(chewbbaca_allelecall.out.versions)
         ch_versions = ch_versions.mix(create_analysis_result.out.versions)
         ch_versions = ch_versions.mix(freebayes.out.versions)


Reviews:
user: login: ryanjameskennedy
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-03-19T15:58:24Z
user: login: ryanjameskennedy
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-03-19T15:59:47Z
user: login: ryanjameskennedy
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-03-19T16:03:20Z
user: login: ryanjameskennedy
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-03-19T16:03:43Z
user: login: ryanjameskennedy
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-03-19T16:12:33Z
user: login: ryanjameskennedy
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-03-19T16:16:09Z
user: login: ryanjameskennedy
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-03-19T16:17:05Z
user: login: ryanjameskennedy
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-03-19T16:18:11Z
user: login: ryanjameskennedy
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-03-19T16:21:28Z
user: login: ryanjameskennedy
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-03-19T16:23:05Z
user: login: ryanjameskennedy
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-03-19T16:39:04Z
user: login: ryanjameskennedy
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-03-19T16:44:15Z
user: login: ryanjameskennedy
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-03-19T16:47:29Z
user: login: ryanjameskennedy
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-03-19T16:49:21Z
user: login: ryanjameskennedy
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-03-19T16:58:14Z
user: login: ryanjameskennedy
body: Please could you test a stub-run for all of the profiles to ensure they still work. Make sure the  `create_yaml` stub runs please.
state: CHANGES_REQUESTED
author_association: COLLABORATOR
submitted_at: 2025-03-19T17:05:55Z
user: login: Emkago
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-20T06:51:51Z
user: login: Emkago
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-20T06:55:08Z
user: login: Emkago
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-20T07:21:13Z
user: login: Emkago
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-20T09:41:06Z
user: login: Emkago
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-21T10:24:39Z
user: login: ryanjameskennedy
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-03-21T13:55:50Z
user: login: ryanjameskennedy
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-03-21T14:01:30Z
user: login: ryanjameskennedy
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-03-21T14:02:17Z
user: login: ryanjameskennedy
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-03-21T14:05:54Z
user: login: ryanjameskennedy
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-03-21T14:06:55Z
user: login: Emkago
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-21T14:17:12Z
user: login: Emkago
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-24T09:15:50Z
user: login: Emkago
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-24T10:30:59Z
user: login: Emkago
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-24T12:52:33Z
user: login: ryanjameskennedy
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-03-25T08:28:31Z
user: login: ryanjameskennedy
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-03-25T08:39:50Z
user: login: Emkago
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-25T09:05:02Z
user: login: ryanjameskennedy
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-03-25T10:30:59Z
user: login: ryanjameskennedy
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-03-25T10:41:29Z
user: login: ryanjameskennedy
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-03-25T10:56:19Z
user: login: ryanjameskennedy
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-03-25T12:07:00Z
user: login: Emkago
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-25T12:21:52Z
user: login: ryanjameskennedy
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-03-25T13:13:22Z
user: login: Emkago
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-25T13:51:37Z
user: login: ryanjameskennedy
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-03-25T14:05:02Z
user: login: Emkago
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-26T12:23:50Z
user: login: ryanjameskennedy
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-03-27T12:58:51Z
user: login: ryanjameskennedy
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-03-27T12:59:18Z
user: login: ryanjameskennedy
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-03-27T13:00:04Z
user: login: ryanjameskennedy
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-03-27T13:00:23Z
user: login: ryanjameskennedy
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-03-27T13:00:40Z
user: login: ryanjameskennedy
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-03-27T13:03:57Z
user: login: Emkago
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-27T13:04:41Z
user: login: ryanjameskennedy
body: LGTM!
state: APPROVED
author_association: COLLABORATOR
submitted_at: 2025-03-28T13:33:58Z

Review comments:
diff_hunk: @@ -429,6 +437,8 @@ $(SAUR_CGMLST_DIR)/alleles_rereffed: | $(SAUR_CGMLST_DIR)/alleles/unpacking.done
 ecoli_all: ecoli_download_reference \
 	ecoli_faidx_reference \
 	ecoli_bwaidx_reference \
+	ecoli_minimap2idx_reference \
+	ecoli_download_prodigal_training_file \
path: Makefile
user: login: ryanjameskennedy
body: This was removed in the previous PR
created_at: 2025-03-19T15:58:24Z
author_association: COLLABORATOR
diff_hunk: @@ -469,6 +479,16 @@ $(ECOLI_GENOMES_DIR)/$(ECOLI_REFSEQ_ACC).fasta.bwt: $(ECOLI_GENOMES_DIR)/$(ECOLI
 		bwa index $$(basename $<) |& tee -a $(INSTALL_LOG)
 
 
+ecoli_minimap2idx_reference: $(ECOLI_GENOMES_DIR)/$(ECOLI_REFSEQ_ACC).mmi
+
+$(ECOLI_GENOMES_DIR)/$(ECOLI_REFSEQ_ACC).mmi: $(ECOLI_GENOMES_DIR)/$(ECOLI_REFSEQ_ACC).fasta
+	$(call log_message,"Indexing E. coli genome using minimap2...")
+	cd $(ECOLI_GENOMES_DIR) \
+	&& apptainer exec --bind $(MNT_ROOT) $(CONTAINER_DIR)/minimap2.sif \
+		minimap2 -d $@ $< |& tee -a $(INSTALL_LOG)
+
+
+ecoli_download_prodigal_training_file: $(PRODIGAL_TRAINING_DIR)/Escherichia_coli.trn
path: Makefile
user: login: ryanjameskennedy
body: Related to comment above, was removed in latest PR... 
created_at: 2025-03-19T15:59:47Z
author_association: COLLABORATOR
diff_hunk: @@ -639,6 +668,8 @@ $(KPNEU_CGMLST_DIR)/alleles_rereffed: | $(KPNEU_CGMLST_DIR)/alleles/unpacking.do
 spyogenes_all: spyogenes_download_reference \
 	spyogenes_faidx_reference \
 	spyogenes_bwaidx_reference \
+	spyogenes_minimap2idx_reference \
+	spyogenes_download_prodigal_training_file \
path: Makefile
user: login: ryanjameskennedy
body: Removed in previous PR
created_at: 2025-03-19T16:03:20Z
author_association: COLLABORATOR
diff_hunk: @@ -680,6 +711,16 @@ $(SPYO_GENOMES_DIR)/$(SPYO_REFSEQ_ACC).fasta.bwt: $(SPYO_GENOMES_DIR)/$(SPYO_REF
 		bwa index $$(basename $<) |& tee -a $(INSTALL_LOG)
 
 
+spyogenes_minimap2idx_reference: $(SPYO_GENOMES_DIR)/$(SPYO_REFSEQ_ACC).mmi
+
+$(SPYO_GENOMES_DIR)/$(SPYO_REFSEQ_ACC).mmi: $(SPYO_GENOMES_DIR)/$(SPYO_REFSEQ_ACC).fasta
+	$(call log_message,"Indexing S. pyogenes genome using minimap2...")
+	cd $(SPYO_GENOMES_DIR) \
+	&& apptainer exec --bind $(MNT_ROOT) $(CONTAINER_DIR)/minimap2.sif \
+		minimap2 -d $@ $< |& tee -a $(INSTALL_LOG)
+
+
+spyogenes_download_prodigal_training_file: $(PRODIGAL_TRAINING_DIR)/Streptococcus_pyogenes.trn
path: Makefile
user: login: ryanjameskennedy
body: Removed in previous PR...
created_at: 2025-03-19T16:03:42Z
author_association: COLLABORATOR
diff_hunk: @@ -284,6 +290,10 @@ process {
 		publishDir = [ path: "${params.outdir}/${params.speciesDir}/medaka", mode: 'copy', overwrite: true ]
 		ext.args = "-t 40 --bacteria"
 	}
+	withName: minimap2_to_ref {
+		container = "${params.containerDir}/minimap2.sif"
path: configs/nextflow.base.config
user: login: ryanjameskennedy
body: No `publishDir`? TB a bam file is important. Check `bwa_mem_ref`. I also think `minimap_to_ref` doesn't follow how we've named modules. Would you be okay with `minimap_ref`?
created_at: 2025-03-19T16:12:32Z
author_association: COLLABORATOR
diff_hunk: @@ -317,6 +327,11 @@ process {
 		ext.nanopore_args = "--nanopore --ignore_indels --ignore_stop_codons"
 		ext.when = { params.species != "mycobacterium tuberculosis" }
 	}
+	withName: samtools_coverage {
+		container = "${params.containerDir}/samtools.sif"
+		publishDir = [ path: "${params.outdir}/${params.speciesDir}/postmapqc", mode: 'copy', overwrite: true ]
+		ext.args = ""
path: configs/nextflow.base.config
user: login: ryanjameskennedy
body: Unnecessary to mention `ext.args = ""`
created_at: 2025-03-19T16:16:09Z
author_association: COLLABORATOR
diff_hunk: @@ -330,6 +345,13 @@ process {
 		publishDir = [ path: "${params.outdir}/${params.speciesDir}/${params.bamDir}", mode: 'copy', overwrite: true ]
 		ext.when = { params.referenceGenome && params.species != "mycobacterium tuberculosis" }
 	}
+	withName: samtools_sort {
+		cpus = 16
+		memory = '20.GB'
+		container = "${params.containerDir}/samtools.sif"
+		//publishDir = [ path: "${params.outdir}/${params.speciesDir}/${params.bamDir}", mode: 'copy', overwrite: true ] // temporaray solution bellow
path: configs/nextflow.base.config
user: login: ryanjameskennedy
body: Why not this?
created_at: 2025-03-19T16:17:05Z
author_association: COLLABORATOR
diff_hunk: @@ -266,6 +272,10 @@ process {
 		time=2.h
 		publishDir = [ path: "${params.outdir}/${params.speciesDir}/medaka", mode: 'copy', overwrite: true ]
 		ext.args = "-t 40 --bacteria"
+	}
+		withName: minimap2_to_ref {
path: configs/nextflow.ci.config
user: login: ryanjameskennedy
body: Indentation off here
created_at: 2025-03-19T16:18:11Z
author_association: COLLABORATOR
diff_hunk: @@ -360,6 +375,13 @@ process {
 		publishDir = [ path: "${params.outdir}/${params.speciesDir}/${params.bamDir}", mode: 'copy', overwrite: true ]
 		ext.when = { params.referenceGenome && params.species != "mycobacterium tuberculosis" }
 	}
+	withName: samtools_sort {
+		cpus = 16
+		memory = '20.GB'
+		container = "https://depot.galaxyproject.org/singularity/samtools:1.17--h00cdaf9_0"
+		//publishDir = [ path: "${params.outdir}/${params.speciesDir}/${params.bamDir}", mode: 'copy', overwrite: true ] // temporaray solution bellow
path: configs/nextflow.cmd.config
user: login: ryanjameskennedy
body: See earlier comment...
created_at: 2025-03-19T16:21:28Z
author_association: COLLABORATOR
diff_hunk: @@ -342,6 +357,13 @@ process {
 		publishDir = [ path: "${params.outdir}/${params.speciesDir}/${params.bamDir}", mode: 'copy', overwrite: true ]
 		ext.when = { params.referenceGenome && params.species != "mycobacterium tuberculosis" }
 	}
+	withName: samtools_sort {
+		cpus = 16
+		memory = '20.GB'
+		container = "${params.containerDir}/samtools.sif"
+		//publishDir = [ path: "${params.outdir}/${params.speciesDir}/${params.bamDir}", mode: 'copy', overwrite: true ] // temporaray solution bellow
path: configs/nextflow.ngp.config
user: login: ryanjameskennedy
body: Why not? See above...
created_at: 2025-03-19T16:23:05Z
author_association: COLLABORATOR
diff_hunk: @@ -0,0 +1,41 @@
+process minimap2_to_ref {
path: nextflow-modules/modules/minimap2/main.nf
user: login: ryanjameskennedy
body: ```suggestion
process minimap_ref {
```
created_at: 2025-03-19T16:39:04Z
author_association: COLLABORATOR
diff_hunk: @@ -0,0 +1,41 @@
+process minimap2_to_ref {
+  tag "${sample_id}"
+  scratch params.scratch
+
+  input:
+    tuple val(sample_id), path(reads), val(platform)
+    path referenceGenomeMmi
+  output:
+    tuple val(sample_id), path(output), emit: sam
path: nextflow-modules/modules/minimap2/main.nf
user: login: ryanjameskennedy
body: I think we should produce a bam if it's possible
created_at: 2025-03-19T16:44:15Z
author_association: COLLABORATOR
diff_hunk: @@ -12,9 +12,12 @@ include { flye                                  } from '../nextflow-modules/modu
 include { hostile                               } from '../nextflow-modules/modules/hostile/main.nf'
 include { medaka                                } from '../nextflow-modules/modules/medaka/main.nf'
 include { nanoplot                              } from '../nextflow-modules/modules/nanoplot/main.nf'
+include { minimap2_to_ref                       } from '../nextflow-modules/modules/minimap2/main.nf'       
path: workflows/bacterial_base.nf
user: login: ryanjameskennedy
body: Remember to change to `minimap_ref`
created_at: 2025-03-19T16:47:29Z
author_association: COLLABORATOR
diff_hunk: @@ -96,14 +100,21 @@ workflow CALL_BACTERIAL_BASE {
         // evaluate assembly quality 
         quast(ch_assembly, referenceGenome)
 
-        // qc processing
-        fastqc(ch_reads_w_meta)
path: workflows/bacterial_base.nf
user: login: ryanjameskennedy
body: Does this work as expected?
created_at: 2025-03-19T16:49:21Z
author_association: COLLABORATOR
diff_hunk: @@ -49,7 +50,7 @@ workflow CALL_STAPHYLOCOCCUS_AUREUS {
     main:
         ch_versions = Channel.empty()
 
-        CALL_BACTERIAL_BASE( coreLociBed, referenceGenome, referenceGenomeDir, inputSamples, targetSampleSize )
path: workflows/staphylococcus_aureus.nf
user: login: ryanjameskennedy
body: You didn't do this for all the other workflows? They're all going to fail because `CALL_BACTERIAL_BASE` expects a certain number of channels.
created_at: 2025-03-19T16:58:14Z
author_association: COLLABORATOR
diff_hunk: @@ -284,6 +290,10 @@ process {
 		publishDir = [ path: "${params.outdir}/${params.speciesDir}/medaka", mode: 'copy', overwrite: true ]
 		ext.args = "-t 40 --bacteria"
 	}
+	withName: minimap2_to_ref {
+		container = "${params.containerDir}/minimap2.sif"
path: configs/nextflow.base.config
user: login: Emkago
body: There is no published output, as Minimap2 outputs sam file, which is later sorted and converted to bam with samtools. It gets published after those steps.
created_at: 2025-03-20T06:51:51Z
author_association: CONTRIBUTOR
diff_hunk: @@ -330,6 +345,13 @@ process {
 		publishDir = [ path: "${params.outdir}/${params.speciesDir}/${params.bamDir}", mode: 'copy', overwrite: true ]
 		ext.when = { params.referenceGenome && params.species != "mycobacterium tuberculosis" }
 	}
+	withName: samtools_sort {
+		cpus = 16
+		memory = '20.GB'
+		container = "${params.containerDir}/samtools.sif"
+		//publishDir = [ path: "${params.outdir}/${params.speciesDir}/${params.bamDir}", mode: 'copy', overwrite: true ] // temporaray solution bellow
path: configs/nextflow.base.config
user: login: Emkago
body: Because bwa processes are not yet deactivated for LR and it would interfere. 
created_at: 2025-03-20T06:55:08Z
author_association: CONTRIBUTOR
diff_hunk: @@ -429,6 +437,8 @@ $(SAUR_CGMLST_DIR)/alleles_rereffed: | $(SAUR_CGMLST_DIR)/alleles/unpacking.done
 ecoli_all: ecoli_download_reference \
 	ecoli_faidx_reference \
 	ecoli_bwaidx_reference \
+	ecoli_minimap2idx_reference \
+	ecoli_download_prodigal_training_file \
path: Makefile
user: login: Emkago
body: Mixed it up when resolving conflicts... I'll remove it.
created_at: 2025-03-20T07:21:13Z
author_association: CONTRIBUTOR
diff_hunk: @@ -49,7 +50,7 @@ workflow CALL_STAPHYLOCOCCUS_AUREUS {
     main:
         ch_versions = Channel.empty()
 
-        CALL_BACTERIAL_BASE( coreLociBed, referenceGenome, referenceGenomeDir, inputSamples, targetSampleSize )
path: workflows/staphylococcus_aureus.nf
user: login: Emkago
body: This is something I would like to discuss: what is the best way to provide only one index?

created_at: 2025-03-20T09:41:05Z
author_association: CONTRIBUTOR
diff_hunk: @@ -96,14 +100,21 @@ workflow CALL_BACTERIAL_BASE {
         // evaluate assembly quality 
         quast(ch_assembly, referenceGenome)
 
-        // qc processing
-        fastqc(ch_reads_w_meta)
path: workflows/bacterial_base.nf
user: login: Emkago
body: has been reverted
created_at: 2025-03-21T10:24:38Z
author_association: CONTRIBUTOR
diff_hunk: @@ -284,6 +290,10 @@ process {
 		publishDir = [ path: "${params.outdir}/${params.speciesDir}/medaka", mode: 'copy', overwrite: true ]
 		ext.args = "-t 40 --bacteria"
 	}
+	withName: minimap2_to_ref {
+		container = "${params.containerDir}/minimap2.sif"
path: configs/nextflow.base.config
user: login: ryanjameskennedy
body: Does the minimap2 image have samtool included? If so, you could run the samtools conversion to bam within the same process.
created_at: 2025-03-21T13:55:50Z
author_association: COLLABORATOR
diff_hunk: @@ -330,6 +345,13 @@ process {
 		publishDir = [ path: "${params.outdir}/${params.speciesDir}/${params.bamDir}", mode: 'copy', overwrite: true ]
 		ext.when = { params.referenceGenome && params.species != "mycobacterium tuberculosis" }
 	}
+	withName: samtools_sort {
+		cpus = 16
+		memory = '20.GB'
+		container = "${params.containerDir}/samtools.sif"
+		//publishDir = [ path: "${params.outdir}/${params.speciesDir}/${params.bamDir}", mode: 'copy', overwrite: true ] // temporaray solution bellow
path: configs/nextflow.base.config
user: login: ryanjameskennedy
body: Could be good to save the output filename as `${sample_id}_samtools.bam`. Not sure about the extension but I mean to include the process name in the basename? So nothing will be overwritten regardless.
created_at: 2025-03-21T14:01:29Z
author_association: COLLABORATOR
diff_hunk: @@ -266,6 +272,10 @@ process {
 		time=2.h
 		publishDir = [ path: "${params.outdir}/${params.speciesDir}/medaka", mode: 'copy', overwrite: true ]
 		ext.args = "-t 40 --bacteria"
+	}
+		withName: minimap2_to_ref {
path: configs/nextflow.ci.config
user: login: ryanjameskennedy
body: I don't think you fixed it?
created_at: 2025-03-21T14:02:16Z
author_association: COLLABORATOR
diff_hunk: @@ -49,7 +50,7 @@ workflow CALL_STAPHYLOCOCCUS_AUREUS {
     main:
         ch_versions = Channel.empty()
 
-        CALL_BACTERIAL_BASE( coreLociBed, referenceGenome, referenceGenomeDir, inputSamples, targetSampleSize )
path: workflows/staphylococcus_aureus.nf
user: login: ryanjameskennedy
body: This way is fine, because it's required as an input for a process in `CALL_BACTERIAL_BASE`. No problem with what you have done! Just add to the other workflows please:)
created_at: 2025-03-21T14:05:54Z
author_association: COLLABORATOR
diff_hunk: @@ -266,6 +272,10 @@ process {
 		time=2.h
 		publishDir = [ path: "${params.outdir}/${params.speciesDir}/medaka", mode: 'copy', overwrite: true ]
 		ext.args = "-t 40 --bacteria"
+	}
+		withName: minimap2_to_ref {
path: configs/nextflow.ci.config
user: login: ryanjameskennedy
body: I see you haven't push the commits yet!
created_at: 2025-03-21T14:06:55Z
author_association: COLLABORATOR
diff_hunk: @@ -284,6 +290,10 @@ process {
 		publishDir = [ path: "${params.outdir}/${params.speciesDir}/medaka", mode: 'copy', overwrite: true ]
 		ext.args = "-t 40 --bacteria"
 	}
+	withName: minimap2_to_ref {
+		container = "${params.containerDir}/minimap2.sif"
path: configs/nextflow.base.config
user: login: Emkago
body: Unfortunately not, that is why I convert sam to bam later with samtools. 
created_at: 2025-03-21T14:17:12Z
author_association: CONTRIBUTOR
diff_hunk: @@ -330,6 +345,13 @@ process {
 		publishDir = [ path: "${params.outdir}/${params.speciesDir}/${params.bamDir}", mode: 'copy', overwrite: true ]
 		ext.when = { params.referenceGenome && params.species != "mycobacterium tuberculosis" }
 	}
+	withName: samtools_sort {
+		cpus = 16
+		memory = '20.GB'
+		container = "${params.containerDir}/samtools.sif"
+		//publishDir = [ path: "${params.outdir}/${params.speciesDir}/${params.bamDir}", mode: 'copy', overwrite: true ] // temporaray solution bellow
path: configs/nextflow.base.config
user: login: Emkago
body: Implemented solution: output from mappers are named by the tools used to map the reads and samtools then just take base name of the input to name the output (sorted bam or indexed bam).
created_at: 2025-03-24T09:15:50Z
author_association: CONTRIBUTOR
diff_hunk: @@ -49,7 +50,7 @@ workflow CALL_STAPHYLOCOCCUS_AUREUS {
     main:
         ch_versions = Channel.empty()
 
-        CALL_BACTERIAL_BASE( coreLociBed, referenceGenome, referenceGenomeDir, inputSamples, targetSampleSize )
path: workflows/staphylococcus_aureus.nf
user: login: Emkago
body: Does it change anything downstream in Bonsai, if referenceGenomeMmi is added in creating analysis result?

in the workflow/species.nf:
`create_analysis_result(combinedOutput, referenceGenome, referenceGenomeFai, referenceGenomeMmi, referenceGenomeGff)`

 
in the modules/prp/main.nf:
```
input:
    tuple val(sample_id), path(quast), path(postalignqc), path(mlst), path(cgmlst), path(amr), path(resistance), path(resfinderMeta), path(serotype), path(serotypefinderMeta), path(virulence), path(virulencefinderMeta), path(shigapass), path(emmtyper), path(bam), path(bai), path(runInfo), path(vcf), path(mykrobe), path(tbprofiler), path(bracken)
    path reference_genome
    path reference_genome_fai
    path reference_genome_mmi
    path reference_genome_gff
```
    
    
created_at: 2025-03-24T10:30:59Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,41 @@
+process minimap2_to_ref {
+  tag "${sample_id}"
+  scratch params.scratch
+
+  input:
+    tuple val(sample_id), path(reads), val(platform)
+    path referenceGenomeMmi
+  output:
+    tuple val(sample_id), path(output), emit: sam
path: nextflow-modules/modules/minimap2/main.nf
user: login: Emkago
body: Only sam and paf format are available
created_at: 2025-03-24T12:52:33Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,41 @@
+process minimap2_to_ref {
+  tag "${sample_id}"
+  scratch params.scratch
+
+  input:
+    tuple val(sample_id), path(reads), val(platform)
+    path referenceGenomeMmi
+  output:
+    tuple val(sample_id), path(output), emit: sam
path: nextflow-modules/modules/minimap2/main.nf
user: login: ryanjameskennedy
body: Then I wouldn't publish the sam file then in the config. Huge waste of space to store both `.sam` & `.bam` files
created_at: 2025-03-25T08:28:30Z
author_association: COLLABORATOR
diff_hunk: @@ -49,7 +50,7 @@ workflow CALL_STAPHYLOCOCCUS_AUREUS {
     main:
         ch_versions = Channel.empty()
 
-        CALL_BACTERIAL_BASE( coreLociBed, referenceGenome, referenceGenomeDir, inputSamples, targetSampleSize )
path: workflows/staphylococcus_aureus.nf
user: login: ryanjameskennedy
body: I'm thinking of adding profiles for `illumina` and `nanopore` where we specify one index file (`reference_genome_idx`) which changes based on which profile we specify. There will never be a case where we use two. Then we avoid this problem.
created_at: 2025-03-25T08:39:50Z
author_association: COLLABORATOR
diff_hunk: @@ -0,0 +1,41 @@
+process minimap2_to_ref {
+  tag "${sample_id}"
+  scratch params.scratch
+
+  input:
+    tuple val(sample_id), path(reads), val(platform)
+    path referenceGenomeMmi
+  output:
+    tuple val(sample_id), path(output), emit: sam
path: nextflow-modules/modules/minimap2/main.nf
user: login: Emkago
body: Agree, that is why only sorted bam is published in bam folder, but not sam.
created_at: 2025-03-25T09:05:02Z
author_association: CONTRIBUTOR
diff_hunk: @@ -47,7 +47,7 @@ process bwa_mem {
 
   input:
     tuple val(sample_id), path(reads)
-    path referenceIdx
+    path referenceGenomeDir
path: nextflow-modules/modules/bwa/main.nf
user: login: ryanjameskennedy
body: ```suggestion
    path referenceIdx
```
created_at: 2025-03-25T10:30:59Z
author_association: COLLABORATOR
diff_hunk: @@ -96,23 +100,34 @@ workflow CALL_BACTERIAL_BASE {
         // evaluate assembly quality 
         quast(ch_assembly, referenceGenome)
 
-        // qc processing
+        // qc processing - short read
         fastqc(ch_reads_w_meta)
         bwa_mem_ref(ch_reads, referenceGenomeDir)
-        samtools_index_ref(bwa_mem_ref.out.bam)
 
         post_align_qc(bwa_mem_ref.out.bam, referenceGenome, coreLociBed)
 
+        // qc processing - long read
         nanoplot(ch_reads_w_meta)
+        minimap2_ref(ch_reads_w_meta, referenceGenomeMmi)
+        samtools_sort(minimap2_ref.out.sam)
+        samtools_coverage(samtools_sort.out.bam)
 
-        sourmash(ch_assembly)
+        Channel.empty()
+            .mix(
+                samtools_sort.out.bam, bwa_mem_ref.out.bam
path: workflows/bacterial_base.nf
user: login: ryanjameskennedy
body: I reckon we should change everything from 115-118:
```
samtools_sort.out.bam.mix(bwa_mem_ref.out.bam).set{ ch_ref_bam }
```
created_at: 2025-03-25T10:41:29Z
author_association: COLLABORATOR
diff_hunk: @@ -96,23 +100,34 @@ workflow CALL_BACTERIAL_BASE {
         // evaluate assembly quality 
         quast(ch_assembly, referenceGenome)
 
-        // qc processing
+        // qc processing - short read
         fastqc(ch_reads_w_meta)
         bwa_mem_ref(ch_reads, referenceGenomeDir)
-        samtools_index_ref(bwa_mem_ref.out.bam)
 
         post_align_qc(bwa_mem_ref.out.bam, referenceGenome, coreLociBed)
 
+        // qc processing - long read
         nanoplot(ch_reads_w_meta)
+        minimap2_ref(ch_reads_w_meta, referenceGenomeMmi)
+        samtools_sort(minimap2_ref.out.sam)
+        samtools_coverage(samtools_sort.out.bam)
 
-        sourmash(ch_assembly)
+        Channel.empty()
+            .mix(
+                samtools_sort.out.bam, bwa_mem_ref.out.bam
+            ).set{ ch_sorted_bam }
path: workflows/bacterial_base.nf
user: login: ryanjameskennedy
body: I think we should call this channel `ch_ref_bam`
created_at: 2025-03-25T10:56:19Z
author_association: COLLABORATOR
diff_hunk: @@ -55,9 +55,9 @@ process samtools_sort {
     path "*versions.yml"              , emit: versions
 
   script:
-    output = "${sample_id}.bam"
+    output = "${input.baseName}.bam"
     """
-    samtools sort -@ ${task.cpus} -o ${output} ${input}
+    samtools sort -@ ${task.cpus} -O bam -o ${output} ${input}
path: nextflow-modules/modules/samtools/main.nf
user: login: ryanjameskennedy
body: Surely this should go in the config args?
created_at: 2025-03-25T12:07:00Z
author_association: COLLABORATOR
diff_hunk: @@ -47,7 +47,7 @@ process bwa_mem {
 
   input:
     tuple val(sample_id), path(reads)
-    path referenceIdx
+    path referenceGenomeDir
path: nextflow-modules/modules/bwa/main.nf
user: login: Emkago
body: In bacterial_base.nf , the input to bwa_mem_ref is `bwa_mem_ref(ch_reads, referenceGenomeDir)` . Should it be changed to referenceGenomeFai then in both places??
created_at: 2025-03-25T12:21:51Z
author_association: CONTRIBUTOR
diff_hunk: @@ -47,7 +47,7 @@ process bwa_mem {
 
   input:
     tuple val(sample_id), path(reads)
-    path referenceIdx
+    path referenceGenomeDir
path: nextflow-modules/modules/bwa/main.nf
user: login: ryanjameskennedy
body: No because `referenceGenomeDir` contains bwa index files. However, `referenceGenomeIdx` is a fai file created by samtools
created_at: 2025-03-25T13:13:22Z
author_association: COLLABORATOR
diff_hunk: @@ -47,7 +47,7 @@ process bwa_mem {
 
   input:
     tuple val(sample_id), path(reads)
-    path referenceIdx
+    path referenceGenomeDir
path: nextflow-modules/modules/bwa/main.nf
user: login: Emkago
body: referenceGenomeIdx was earlier name of what is now referenceGenomeFai and is in the same folder as bwa indices (refereceGenomeDir). I thought the second argument that comes in is a directory name/path (bwa_mem_ref(ch_reads, referenceGenomeDir)?

created_at: 2025-03-25T13:51:37Z
author_association: CONTRIBUTOR
diff_hunk: @@ -47,7 +47,7 @@ process bwa_mem {
 
   input:
     tuple val(sample_id), path(reads)
-    path referenceIdx
+    path referenceGenomeDir
path: nextflow-modules/modules/bwa/main.nf
user: login: ryanjameskennedy
body: So in `bwa_mem_ref` has the `refereceGenomeDir` which contains bwa index files. However, `bwa_mem_assembly` has the bwa index files from the previous step. The `bwa_mem` process looks for the bwa index files (and not the `.fai` file) using the following:
```
INDEX=`find -L ./ -name "*.amb" | sed 's/.amb//'`
```
So as long as they're staged in, the correct files will be found!
created_at: 2025-03-25T14:05:02Z
author_association: COLLABORATOR
diff_hunk: @@ -55,9 +55,9 @@ process samtools_sort {
     path "*versions.yml"              , emit: versions
 
   script:
-    output = "${sample_id}.bam"
+    output = "${input.baseName}.bam"
     """
-    samtools sort -@ ${task.cpus} -o ${output} ${input}
+    samtools sort -@ ${task.cpus} -O bam -o ${output} ${input}
path: nextflow-modules/modules/samtools/main.nf
user: login: Emkago
body: It is just explicitly saying that it should be bam file instead of guessing it from `-o`. As we define output name as *.bam it would be misleading to put this as available argument in config file, and getting back a file that is named *.bam even if you choose a different output format.
created_at: 2025-03-26T12:23:50Z
author_association: CONTRIBUTOR
diff_hunk: @@ -66,30 +70,41 @@ workflow CALL_ESCHERICHIA_COLI {
         CALL_BACTERIAL_BASE.out.sourmash.set{ch_sourmash}
         CALL_BACTERIAL_BASE.out.ska_build.set{ch_ska}
 
-        bwa_index(ch_assembly)
+        bwa_index(ch_assembly.join(ch_seqplat_meta))
+        minimap2_index(ch_assembly.join(ch_seqplat_meta))
 
-        ch_reads
-            .join(bwa_index.out.idx)
-            .multiMap { id, reads, bai -> 
-                reads: tuple(id, reads)
-                bai: bai
+        // create input map channels for bwa on assembly
+        ch_input_meta
+            .join(bwa_index.out.index)
path: workflows/escherichia_coli.nf
user: login: ryanjameskennedy
body: ```suggestion
            .join(bwa_index.out.idx)
```
created_at: 2025-03-27T12:58:50Z
author_association: COLLABORATOR
diff_hunk: @@ -64,30 +68,41 @@ workflow CALL_KLEBSIELLA_PNEUMONIAE {
         CALL_BACTERIAL_BASE.out.sourmash.set{ch_sourmash}
         CALL_BACTERIAL_BASE.out.ska_build.set{ch_ska}
 
-        bwa_index(ch_assembly)
+        bwa_index(ch_assembly.join(ch_seqplat_meta))
+        minimap2_index(ch_assembly.join(ch_seqplat_meta))
 
-        ch_reads
-            .join(bwa_index.out.idx)
-            .multiMap { id, reads, bai -> 
-                reads: tuple(id, reads)
-                bai: bai
+        // create input map channels for bwa on assembly
+        ch_input_meta
+            .join(bwa_index.out.index)
path: workflows/klebsiella_pneumoniae.nf
user: login: ryanjameskennedy
body: ```suggestion
            .join(bwa_index.out.idx)
```
created_at: 2025-03-27T12:59:18Z
author_association: COLLABORATOR
diff_hunk: @@ -64,30 +69,42 @@ workflow CALL_STAPHYLOCOCCUS_AUREUS {
         CALL_BACTERIAL_BASE.out.sourmash.set{ch_sourmash}
         CALL_BACTERIAL_BASE.out.ska_build.set{ch_ska}
 
-        bwa_index(ch_assembly)
+        bwa_index(ch_assembly.join(ch_seqplat_meta))
+        minimap2_index(ch_assembly.join(ch_seqplat_meta))
 
-        ch_reads
-            .join(bwa_index.out.idx)
-            .multiMap { id, reads, bai -> 
-                reads: tuple(id, reads)
-                bai: bai
+        // create input map channels for bwa on assembly
+        ch_input_meta
+            .join(bwa_index.out.index)
path: workflows/staphylococcus_aureus.nf
user: login: ryanjameskennedy
body: ```suggestion
            .join(bwa_index.out.idx)
```
created_at: 2025-03-27T13:00:04Z
author_association: COLLABORATOR
diff_hunk: @@ -73,30 +77,41 @@ workflow CALL_STREPTOCOCCUS {
         CALL_BACTERIAL_BASE.out.sourmash.set{ch_sourmash}
         CALL_BACTERIAL_BASE.out.ska_build.set{ch_ska}
 
-        bwa_index(ch_assembly)
+        bwa_index(ch_assembly.join(ch_seqplat_meta))
+        minimap2_index(ch_assembly.join(ch_seqplat_meta))
 
-        ch_reads
-            .join(bwa_index.out.idx)
-            .multiMap { id, reads, bai -> 
-                reads: tuple(id, reads)
-                bai: bai
+        // create input map channels for bwa on assembly
+        ch_input_meta
+            .join(bwa_index.out.index)
path: workflows/streptococcus.nf
user: login: ryanjameskennedy
body: ```suggestion
            .join(bwa_index.out.idx)
```
created_at: 2025-03-27T13:00:22Z
author_association: COLLABORATOR
diff_hunk: @@ -67,30 +71,41 @@ workflow CALL_STREPTOCOCCUS_PYOGENES {
         CALL_BACTERIAL_BASE.out.sourmash.set{ch_sourmash}
         CALL_BACTERIAL_BASE.out.ska_build.set{ch_ska}
 
-        bwa_index(ch_assembly)
+        bwa_index(ch_assembly.join(ch_seqplat_meta))
+        minimap2_index(ch_assembly.join(ch_seqplat_meta))
 
-        ch_reads
-            .join(bwa_index.out.idx)
-            .multiMap { id, reads, bai -> 
-                reads: tuple(id, reads)
-                bai: bai
+        // create input map channels for bwa on assembly
+        ch_input_meta
+            .join(bwa_index.out.index)
path: workflows/streptococcus_pyogenes.nf
user: login: ryanjameskennedy
body: ```suggestion
            .join(bwa_index.out.idx)
```
created_at: 2025-03-27T13:00:40Z
author_association: COLLABORATOR
diff_hunk: @@ -66,30 +70,41 @@ workflow CALL_ESCHERICHIA_COLI {
         CALL_BACTERIAL_BASE.out.sourmash.set{ch_sourmash}
         CALL_BACTERIAL_BASE.out.ska_build.set{ch_ska}
 
-        bwa_index(ch_assembly)
+        bwa_index(ch_assembly.join(ch_seqplat_meta))
+        minimap2_index(ch_assembly.join(ch_seqplat_meta))
 
-        ch_reads
-            .join(bwa_index.out.idx)
-            .multiMap { id, reads, bai -> 
-                reads: tuple(id, reads)
-                bai: bai
+        // create input map channels for bwa on assembly
+        ch_input_meta
+            .join(bwa_index.out.index)
path: workflows/escherichia_coli.nf
user: login: ryanjameskennedy
body: I see you fixed it in the module
created_at: 2025-03-27T13:03:57Z
author_association: COLLABORATOR
diff_hunk: @@ -66,30 +70,41 @@ workflow CALL_ESCHERICHIA_COLI {
         CALL_BACTERIAL_BASE.out.sourmash.set{ch_sourmash}
         CALL_BACTERIAL_BASE.out.ska_build.set{ch_ska}
 
-        bwa_index(ch_assembly)
+        bwa_index(ch_assembly.join(ch_seqplat_meta))
+        minimap2_index(ch_assembly.join(ch_seqplat_meta))
 
-        ch_reads
-            .join(bwa_index.out.idx)
-            .multiMap { id, reads, bai -> 
-                reads: tuple(id, reads)
-                bai: bai
+        // create input map channels for bwa on assembly
+        ch_input_meta
+            .join(bwa_index.out.index)
path: workflows/escherichia_coli.nf
user: login: Emkago
body: I think it's fine to use the `index`, as you suggested earlier, so it's the same for all the platforms. I have changed name of the value that emits from bwa module to account for this.
created_at: 2025-03-27T13:04:41Z
author_association: CONTRIBUTOR

PR comments:
user: login: Emkago
created_at: 2025-03-25T08:58:08Z
body: Tested stub-run for E.coli and S. aureus (Illumina), works fine.
author_association: CONTRIBUTOR
user: login: Emkago
created_at: 2025-03-28T06:57:43Z
body: Workflow S. aureus ONT tested with provided test data, S. aureus and E. coli successful stub runs. Ready for final review.
author_association: CONTRIBUTOR