From 3597c451fb49d56f9522dc612fb492aab0cdb4f0 Mon Sep 17 00:00:00 2001
From: Julien Guglielmini <julien.guglielmini@pasteur.fr>
Date: Sun, 2 Apr 2023 22:12:45 +0200
Subject: [PATCH] Bold font for colored messages.

---
 wGRR | 72 ++++++++++++++++++++++++++++++------------------------------
 1 file changed, 36 insertions(+), 36 deletions(-)

diff --git a/wGRR b/wGRR
index b4b12fe..b0d91cb 100755
--- a/wGRR
+++ b/wGRR
@@ -128,19 +128,19 @@ JACCARD=0                 ## -j
 ## catch option values
 while getopts :fTsji:p:o:t:a:m:l: option ; do
    case $option in
-   i) PRT="$OPTARG";       if [[ ! -s $PRT ]]; then printf "${red}%-17s  --  %s\n${normal}"  "[ERROR]" "Fasta file '$PRT' not found or empty (option -i)." ; exit 1 ; fi ;;
+   i) PRT="$OPTARG";       if [[ ! -s $PRT ]]; then printf "${bold}${red}%-17s  --  %s\n${normal}"  "[ERROR]" "Fasta file '$PRT' not found or empty (option -i)." ; exit 1 ; fi ;;
    p) MMPATH="$OPTARG"          ;;
-   o) OUT="$OPTARG";       if [[ -f "$OUT".wgrr.final.txt ]]; then printf "${red}%-17s  --  %s\n${normal}"  "[ERROR]" "File $OUT.wgrr.final.txt already exists. Change option -o or remove this file and relaunch." ; exit 1 ; fi ;;
-	t) THREADS="$OPTARG";   if [[ ! $THREADS =~ ^[0-9]+$ ]]; then printf "${red}%-17s  --  %s\n${normal}"  "[ERROR]" "Number of threads $THREADS must be an integer (option -t)." ; exit 1 ; fi ;;
-	a) ARRAYSIZE="$OPTARG"; if [[ ! $ARRAYSIZE =~ ^[0-9]+$ ]]; then if [[ $ARRAYSIZE != "AUTO" ]] ; then printf "${red}%-17s  --  %s\n${normal}" "[ERROR]" "Number of genomes comparisons $ARRAYSIZE must be an integer (option -a)." ; exit 1 ; fi ; fi ;;
-	l) IDLIST="$OPTARG";    if [[ ! -s ${IDLIST} ]] ; then printf "${red}%-17s  --  %s\n${normal}" "[ERROR]" "File ${IDLIST} not found or empty (option -l)." ; exit 1 ; fi ;;
-	m) MAXJOBS="$OPTARG";   if [[ ! $MAXJOBS =~ ^[0-9]+$ ]]; then printf "${red}%-17s  --  %s\n${normal}"  "[ERROR]" "Max number of simulteaneous jobs $MAXJOBS must be an integer (option -m)." ; exit 1 ; fi ;;
+   o) OUT="$OPTARG";       if [[ -f "$OUT".wgrr.final.txt ]]; then printf "${bold}${red}%-17s  --  %s\n${normal}"  "[ERROR]" "File $OUT.wgrr.final.txt already exists. Change option -o or remove this file and relaunch." ; exit 1 ; fi ;;
+	t) THREADS="$OPTARG";   if [[ ! $THREADS =~ ^[0-9]+$ ]]; then printf "${bold}${red}%-17s  --  %s\n${normal}"  "[ERROR]" "Number of threads $THREADS must be an integer (option -t)." ; exit 1 ; fi ;;
+	a) ARRAYSIZE="$OPTARG"; if [[ ! $ARRAYSIZE =~ ^[0-9]+$ ]]; then if [[ $ARRAYSIZE != "AUTO" ]] ; then printf "${bold}${red}%-17s  --  %s\n${normal}" "[ERROR]" "Number of genomes comparisons $ARRAYSIZE must be an integer (option -a)." ; exit 1 ; fi ; fi ;;
+	l) IDLIST="$OPTARG";    if [[ ! -s ${IDLIST} ]] ; then printf "${bold}${red}%-17s  --  %s\n${normal}" "[ERROR]" "File ${IDLIST} not found or empty (option -l)." ; exit 1 ; fi ;;
+	m) MAXJOBS="$OPTARG";   if [[ ! $MAXJOBS =~ ^[0-9]+$ ]]; then printf "${bold}${red}%-17s  --  %s\n${normal}"  "[ERROR]" "Max number of simulteaneous jobs $MAXJOBS must be an integer (option -m)." ; exit 1 ; fi ;;
 	T) TESTRUN=1 ;;
 	f) FAST=1 ;;
 	s) SKIP=1 ;;
 	j) JACCARD=1 ;;
-   :) printf "${red}%-17s  --  %s\n${normal}" "[ERROR]" "option $OPTARG : missing argument" ; exit 1  ;;
-   \?) printf "${red}%-17s  --  %s\n${normal}" "[ERROR]" "$OPTARG : invalid option" ; exit 1  ;;
+   :) printf "${bold}${red}%-17s  --  %s\n${normal}" "[ERROR]" "option $OPTARG : missing argument" ; exit 1  ;;
+   \?) printf "${bold}${red}%-17s  --  %s\n${normal}" "[ERROR]" "$OPTARG : invalid option" ; exit 1  ;;
    esac
 done
 shift "$((OPTIND - 1))"
@@ -152,7 +152,7 @@ unalias -a
 STIME=$(date +%s)
 
 if [[ -e ${OUT}.wgrr.log ]] ; then
-	printf "${yellow}%-17s  --  %s\n${normal}" "[WARNING]" "Appending to existing log"
+	printf "${bold}${yellow}%-17s  --  %s\n${normal}" "[WARNING]" "Appending to existing log"
 	printf "\n####################################\n" >> ${OUT}.wgrr.log
 fi
 
@@ -210,10 +210,10 @@ printf "%-17s  --  %s\n" "["$(textifyDuration $SECONDS)"]" "wGRR version ${VERSI
 
 if [[ $BATCHFLAG == 0 ]] ; then
 	if [[ $FAST == 1 ]] ; then
-		printf "${yellow}%-17s  --  %s\n${normal}" "[WARNING]" "The fast flag (-f) is useless when not using sbatch"  | tee -a ${OUT}.wgrr.log
+		printf "${bold}${yellow}%-17s  --  %s\n${normal}" "[WARNING]" "The fast flag (-f) is useless when not using sbatch"  | tee -a ${OUT}.wgrr.log
 	fi
 	if [[ $THREADS -gt $(nproc) ]] ; then
-		printf "${red}%-17s  --  %s\n${normal}" "[ERROR]" "You requested $THREADS threads but your machine has $(nproc) cores."  | tee -a ${OUT}.wgrr.log
+		printf "${bold}${red}%-17s  --  %s\n${normal}" "[ERROR]" "You requested $THREADS threads but your machine has $(nproc) cores."  | tee -a ${OUT}.wgrr.log
 		exit 1
 	fi
 	printf "%-17s  --  %s\n" "["$(textifyDuration $SECONDS)"]" "The command is:"  >> ${OUT}.wgrr.log
@@ -224,25 +224,25 @@ else
 fi
 
 if [[ ! -f wGRR.awk ]] ; then
-	printf "${red}%-17s  --  %s\n${normal}" "[ERROR]" "awk script wGRR.awk not found."  | tee -a ${OUT}.wgrr.log
+	printf "${bold}${red}%-17s  --  %s\n${normal}" "[ERROR]" "awk script wGRR.awk not found."  | tee -a ${OUT}.wgrr.log
 	exit 1
 fi
 
 if [[ ! -f wGRR_worker.zsh ]] ; then
-	printf "${red}%-17s  --  %s\n${normal}" "[ERROR]" "awk script wGRR_worker.zsh not found."  | tee -a ${OUT}.wgrr.log
+	printf "${bold}${red}%-17s  --  %s\n${normal}" "[ERROR]" "awk script wGRR_worker.zsh not found."  | tee -a ${OUT}.wgrr.log
 	exit 1
 fi
 
 ## Check awk
 if ! AWKEXE=$(command -v gawk) ; then
 	if ! AWKEXE=$(command -v awk) ; then
-		printf "${red}%-17s  --  %s\n${normal}" "[ERROR]" "Could not find awk or gawk executable."  | tee -a ${OUT}.wgrr.log
+		printf "${bold}${red}%-17s  --  %s\n${normal}" "[ERROR]" "Could not find awk or gawk executable."  | tee -a ${OUT}.wgrr.log
 		exit 1
 	fi
 fi
 
 if ! echo "" | $AWKEXE '{a[1][2]=3}' &> /dev/null ; then
-	printf "${red}%-17s  --  %s\n${normal}" "[ERROR]" "Your awk version is too old. Please install a more recent version (gawk is recommended)."  | tee -a ${OUT}.wgrr.log
+	printf "${bold}${red}%-17s  --  %s\n${normal}" "[ERROR]" "Your awk version is too old. Please install a more recent version (gawk is recommended)."  | tee -a ${OUT}.wgrr.log
 	exit 1
 fi
 
@@ -251,16 +251,16 @@ alias awk=$AWKEXE
 ## Check MMseqs
 if [[ $MMPATH == "N.O.P.A.T.H" ]] ; then
 	if ! MMSEQS=$(command -v mmseqs)  ; then
-		printf "${red}%-17s  --  %s\n${normal}" "[ERROR]" "MMseqs binary not found."  | tee -a ${OUT}.wgrr.log
+		printf "${bold}${red}%-17s  --  %s\n${normal}" "[ERROR]" "MMseqs binary not found."  | tee -a ${OUT}.wgrr.log
 		exit 1
 	fi
 else
 	if ! MMSEQS=$(command -v $MMPATH/mmseqs) ; then
 		if ! MMSEQS=$(command -v mmseqs) ; then
-			printf "${red}%-17s  --  %s\n${normal}" "[ERROR]" "MMseqs binary not found in your PATH."  | tee -a ${OUT}.wgrr.log
+			printf "${bold}${red}%-17s  --  %s\n${normal}" "[ERROR]" "MMseqs binary not found in your PATH."  | tee -a ${OUT}.wgrr.log
 			exit 1
 		else
-			printf "${red}%-17s  --  %s\n${normal}" "[ERROR]" "MMseqs binary not found in ${MMPATH}."  | tee -a ${OUT}.wgrr.log
+			printf "${bold}${red}%-17s  --  %s\n${normal}" "[ERROR]" "MMseqs binary not found in ${MMPATH}."  | tee -a ${OUT}.wgrr.log
 		fi
 	fi
 fi
@@ -313,22 +313,22 @@ fi
 
 NPAIRS=$(wc -l $OUT.allpairs.txt | awk '{print $1}')
 if [[ ! -f $OUT.allpairs.txt ]] || [[ $NPAIRS < 1 ]] ; then
-	printf "${red}%-17s  --  %s\n${normal}" "[ERROR]" "An error occurred when writing the $OUT.allpairs.txt file." | tee -a ${OUT}.wgrr.log
+	printf "${bold}${red}%-17s  --  %s\n${normal}" "[ERROR]" "An error occurred when writing the $OUT.allpairs.txt file." | tee -a ${OUT}.wgrr.log
 	exit 1
 fi
 
 NJOBS=$(( (NPAIRS+ARRAYSIZE-1)/ARRAYSIZE))
 
 if [[ $BATCHFLAG == 1 && $SKIP == 1 ]] ; then
-	printf "${yellow}%-17s  --  %s\n${normal}" "[WARNING]" "Skipping estimation of required memory (option -s) is not available with sbatch runs" | tee -a ${OUT}.wgrr.log
-	printf "${yellow}%-17s  --  %s\n${normal}" "[WARNING]" "The run will continue ignoring the -s option" | tee -a ${OUT}.wgrr.log
+	printf "${bold}${yellow}%-17s  --  %s\n${normal}" "[WARNING]" "Skipping estimation of required memory (option -s) is not available with sbatch runs" | tee -a ${OUT}.wgrr.log
+	printf "${bold}${yellow}%-17s  --  %s\n${normal}" "[WARNING]" "The run will continue ignoring the -s option" | tee -a ${OUT}.wgrr.log
 elif [[ $SKIP == 1 ]] ; then
-	printf "${yellow}%-17s  --  %s\n${normal}" "[WARNING]" "Skipping estimation of required memory (option -s) can lead to exhaustion of system resources!"${normal} | tee -a ${OUT}.wgrr.log
+	printf "${bold}${yellow}%-17s  --  %s\n${normal}" "[WARNING]" "Skipping estimation of required memory (option -s) can lead to exhaustion of system resources!"${normal} | tee -a ${OUT}.wgrr.log
 fi
 
 if [[ $BATCHFLAG == 1 && $TESTRUN == 1 ]] ; then
-	printf "${yellow}%-17s  --  %s\n${normal}" "[WARNING]" "Test run (option -T) is not available with sbatch runs" | tee -a ${OUT}.wgrr.log
-	printf "${yellow}%-17s  --  %s\n${normal}" "[WARNING]" "The run will continue ignoring the -T option" | tee -a ${OUT}.wgrr.log
+	printf "${bold}${yellow}%-17s  --  %s\n${normal}" "[WARNING]" "Test run (option -T) is not available with sbatch runs" | tee -a ${OUT}.wgrr.log
+	printf "${bold}${yellow}%-17s  --  %s\n${normal}" "[WARNING]" "The run will continue ignoring the -T option" | tee -a ${OUT}.wgrr.log
 	printf "%-17s  --  %s\n" "["$(textifyDuration $SECONDS)"]" "Estimating required memory" | tee -a ${OUT}.wgrr.log
 elif [[ $TESTRUN == 1 ]] ; then
 	printf "%-17s  --  %s\n" "["$(textifyDuration $SECONDS)"]" "This is a test run (option -T)" | tee -a ${OUT}.wgrr.log
@@ -358,7 +358,7 @@ if [[ $SKIP == 0 || $BATCHFLAG == 1 ]] ; then
 		printf "%-17s  --  %s\n" "["$(textifyDuration $SECONDS)"]" "Each worker will require approximately $REQMEM" | tee -a ${OUT}.wgrr.log
 		printf "%-17s  --  %s\n" "["$(textifyDuration $SECONDS)"]" "With the number of threads you specified (-t $THREADS) you will need a total of $REQMEMT" | tee -a ${OUT}.wgrr.log
 		if [[ $TOTALMEM == 0 ]] ; then
-			printf "${yellow}%-17s  --  %s\n${normal}" "[WARNING]" "Total memory of your system could not be determined" | tee -a ${OUT}.wgrr.log
+			printf "${bold}${yellow}%-17s  --  %s\n${normal}" "[WARNING]" "Total memory of your system could not be determined" | tee -a ${OUT}.wgrr.log
 		else
 			printf "%-17s  --  %s\n" "["$(textifyDuration $SECONDS)"]" "Total memory of your system: $(numfmt --to=iec $TOTALMEM)" | tee -a ${OUT}.wgrr.log
 		fi
@@ -371,14 +371,14 @@ if [[ $SKIP == 0 || $BATCHFLAG == 1 ]] ; then
 
 	if [[ $TESTRUN == 0 && $BATCHFLAG == 0 ]] ; then
 		if [[ $TOTALMEM -lt $(bc -l <<< $(numfmt --from=iec $REQMEM)*$THREADS) ]] ; then
-			printf "${red}%-17s  --  %s\n${normal}" "[ERROR]" "Your system does not have enough memory (${REQMEMT} required). Try decreasing the -a parameter and/or the number of threads." | tee -a ${OUT}.wgrr.log
+			printf "${bold}${red}%-17s  --  %s\n${normal}" "[ERROR]" "Your system does not have enough memory (${REQMEMT} required). Try decreasing the -a parameter and/or the number of threads." | tee -a ${OUT}.wgrr.log
 			exit 1
 		fi
 	fi
 fi
 
 if [[ $TESTRUN == 1 && $BATCHFLAG == 0 ]] ; then
-	printf "${green}%-17s  --  %s\n${normal}" "["$(textifyDuration $SECONDS)"]" "Done." | tee -a ${OUT}.wgrr.log
+	printf "${bold}${green}%-17s  --  %s\n${normal}" "["$(textifyDuration $SECONDS)"]" "Done." | tee -a ${OUT}.wgrr.log
 	exit 0
 fi
 
@@ -426,7 +426,7 @@ else
 fi
 
 if [[ ! -f $OUT.m8 ]] ; then
-	printf "${red}%-17s  --  %s\n${normal}" "Something went wrong during the MMseqs step." | tee -a ${OUT}.wgrr.log
+	printf "${bold}${red}%-17s  --  %s\n${normal}" "Something went wrong during the MMseqs step." | tee -a ${OUT}.wgrr.log
 	exit 1
 fi
 
@@ -473,8 +473,8 @@ else
 	fi
 	JID=$(sbatch --parsable --wait -p ${PARTITION} --array="$JOBARRAY" -c 1 -J "wGRR_worker" --mem=$REQMEM --wrap="./wGRR_worker.zsh $AWKEXE $ARRAYSIZE $OUT $NJOBS 1 $PRT $tmp")
 	if [[ `sacct -j $JID | grep "TIMEOUT"` ]] ; then
-		printf "${red}%-17s  --  %s\n${normal}" "[ERROR]" "Some workers encountered a TIMEOUT." | tee -a ${OUT}.wgrr.log
-		printf "${red}%-17s  --  %s\n${normal}" "[ERROR]" "Saving the partial files in ${OUT}.wgrr_part directory." | tee -a ${OUT}.wgrr.log
+		printf "${bold}${red}%-17s  --  %s\n${normal}" "[ERROR]" "Some workers encountered a TIMEOUT." | tee -a ${OUT}.wgrr.log
+		printf "${bold}${red}%-17s  --  %s\n${normal}" "[ERROR]" "Saving the partial files in ${OUT}.wgrr_part directory." | tee -a ${OUT}.wgrr.log
 		rm -rf "$OUT".wgrr_part
 		mkdir "$OUT".wgrr_part
 		mv $tmp/"$OUT".wgrr_part.* "$OUT".wgrr_part/
@@ -491,8 +491,8 @@ printf "%-17s  --  %s\n" "["$(textifyDuration $SECONDS)"]" "Sorting results" | t
 sort -m "$tmp"/$OUT.wgrr_part.* | sort -u -k1,1V -k2,2V | awk 'BEGIN{print "GenomeA\tGenomeB\twGRR\tSørensen-Dice\tCommon\tNprotA\tNprotB"}1' > $OUT.wgrr.txt
 
 if [[ ! -f "$OUT".wgrr.txt ]] ; then
-	printf "${red}%-17s  --  %s\n${normal}" "[ERROR]" "Failed to sort the wGRR table." | tee -a ${OUT}.wgrr.log
-	printf "${red}%-17s  --  %s\n${normal}" "[ERROR]" "Saving the partial files in ${OUT}.wgrr_part directory." | tee -a ${OUT}.wgrr.log
+	printf "${bold}${red}%-17s  --  %s\n${normal}" "[ERROR]" "Failed to sort the wGRR table." | tee -a ${OUT}.wgrr.log
+	printf "${bold}${red}%-17s  --  %s\n${normal}" "[ERROR]" "Saving the partial files in ${OUT}.wgrr_part directory." | tee -a ${OUT}.wgrr.log
 	rm -rf "$OUT".wgrr_part
 	mkdir "$OUT".wgrr_part
 	mv $tmp/"$OUT".wgrr_part.* "$OUT".wgrr_part/
@@ -508,9 +508,9 @@ fi
 NLINES=$(wc -l "$OUT".wgrr.txt | awk '{print $1}')
 NWGRR=$((STATS[1]*STATS[1]+1))
 if [[ $NLINES -lt $NWGRR ]] ; then
-	printf "${red}%-17s  --  %s\n${normal}" "[ERROR]" "An error occurred during wGRR calculation:" | tee -a ${OUT}.wgrr.log
-	printf "${red}%-17s  --  %s\n${normal}" "[ERROR]" "less lines than expected in the final file." | tee -a ${OUT}.wgrr.log
-	printf "${red}%-17s  --  %s\n${normal}" "[ERROR]" "Saving the partial files in ${OUT}.wgrr_part directory." | tee -a ${OUT}.wgrr.log
+	printf "${bold}${red}%-17s  --  %s\n${normal}" "[ERROR]" "An error occurred during wGRR calculation:" | tee -a ${OUT}.wgrr.log
+	printf "${bold}${red}%-17s  --  %s\n${normal}" "[ERROR]" "less lines than expected in the final file." | tee -a ${OUT}.wgrr.log
+	printf "${bold}${red}%-17s  --  %s\n${normal}" "[ERROR]" "Saving the partial files in ${OUT}.wgrr_part directory." | tee -a ${OUT}.wgrr.log
 	rm -rf "$OUT".wgrr_part
 	mkdir "$OUT".wgrr_part
 	mv $tmp/"$OUT".wgrr_part.* "$OUT".wgrr_part/
@@ -526,7 +526,7 @@ fi
 
 rm -rf "$OUT".logs
 
-printf "${green}%-17s  --  %s\n${normal}" "["$(textifyDuration $SECONDS)"]" "Done." | tee -a ${OUT}.wgrr.log
+printf "${bold}${green}%-17s  --  %s\n${normal}" "["$(textifyDuration $SECONDS)"]" "Done." | tee -a ${OUT}.wgrr.log
 if [[ $QT != 0 ]] ; then
 	printf "%-17s  --  %s\n" "["$(textifyDuration $SECONDS)"]" "Total time in queue: $(textifyDuration $QT)" | tee -a ${OUT}.wgrr.log
 fi
-- 
GitLab