From 384da11fa5e53944941dcc4b2b329ff04a894f24 Mon Sep 17 00:00:00 2001
From: mahajrod <mahajrod@gmail.com>
Date: Sat, 19 Oct 2024 13:17:52 +0200
Subject: [PATCH] Added support for bwa-mem2 to the CPU version to speedup the
 alignment and simplify integration in pipelines already using bwa-mem2 as
 main alignment. Selection between bwa and bwa-mem2 depends on the presense of
 the index files: *.bwt.2bit.64 for bwa-mem2 and *.bwt for bwa. First the
 presence of the bwa-mem2 index is checked. If it is absent test for bwa index
 is done.

---
 CPU/juicer.sh | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/CPU/juicer.sh b/CPU/juicer.sh
index 24b5f7b..841db9a 100755
--- a/CPU/juicer.sh
+++ b/CPU/juicer.sh
@@ -262,10 +262,19 @@ then
     fi
 
     ## Check that index for refSeq exists
-    if [[ ! -e "${refSeq}.bwt" ]] 
+    if [[ ! -e "${refSeq}.bwt.2bit.64" ]]
     then
-	echo "***! Reference sequence $refSeq does not appear to have been indexed. Please run bwa index on this file before running juicer.";
-	exit 1;
+        echo "bwa-mem2 index was not found. Checking if bwa index exists...";
+        if [[ ! -e "${refSeq}.bwt" ]]
+            then
+            echo "***! Reference sequence $refSeq does not appear to have been indexed. Please run 'bwa index' or 'bwa-mem2 index' on this file before running juicer.";
+	        exit 1;
+	    fi
+	    echo "bwa index was found. Using...";
+	    bwa_cmd="bwa";
+	else
+	    echo "bwa-mem2 index was found. Using...";
+	    bwa_cmd="bwa-mem2";
     fi
 fi