From e4c4f89b344f656258d96dd59760e4a14ef8fda6 Mon Sep 17 00:00:00 2001
From: Amandine PERRIN <amandine.perrin@pasteur.fr>
Date: Thu, 28 Nov 2019 11:50:32 +0100
Subject: [PATCH] Solve logger issue for plot_distr functions

---
 PanACoTA/annotate_module/genome_seq_functions.py |  5 +++--
 PanACoTA/utils.py                                | 12 +++++++++---
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/PanACoTA/annotate_module/genome_seq_functions.py b/PanACoTA/annotate_module/genome_seq_functions.py
index dacb8c6f..1dc8f794 100755
--- a/PanACoTA/annotate_module/genome_seq_functions.py
+++ b/PanACoTA/annotate_module/genome_seq_functions.py
@@ -21,6 +21,7 @@ import progressbar
 
 from PanACoTA import utils
 
+logger = logging.getLogger("annotate.gseq_functions")
 
 def analyse_all_genomes(genomes, dbpath, tmp_path, nbn, soft, logger, quiet=False):
     """
@@ -454,10 +455,10 @@ def plot_distributions(genomes, res_path, listfile_base, l90, nbconts):
     nbcont_vals = [val for _, (_, _, _, _, val, _) in genomes.items()]
     outnbcont = os.path.join(res_path, "QC_nb-contigs-" + listfile_base + ".png")
     dist1 = utils.plot_distr(l90_vals, l90, "L90 distribution for all genomes",
-                             "max L90 =")
+                             "max L90 =", logger)
     dist2 = utils.plot_distr(nbcont_vals, nbconts,
                              "Distribution of number of contigs among all genomes",
-                             "max #contigs =")
+                             "max #contigs =", logger)
     dist1.savefig(outl90)
     dist2.savefig(outnbcont)
     return l90_vals, nbcont_vals, dist1, dist2
diff --git a/PanACoTA/utils.py b/PanACoTA/utils.py
index 11eee75f..3654e601 100755
--- a/PanACoTA/utils.py
+++ b/PanACoTA/utils.py
@@ -319,7 +319,7 @@ def run_cmd(cmd, error, eof=False, **kwargs):
     return call
 
 
-def plot_distr(values, limit, title, text):
+def plot_distr(values, limit, title, text, logger):
     """
     Plot histogram of given 'values', and add a vertical line corresponding to the chosen
     'limit' and return the mpl figure
@@ -334,6 +334,8 @@ def plot_distr(values, limit, title, text):
         Title to give to plot
     text : str
         text to write near the vertical line representing the limit
+    logger : logging.Logger
+        logger object to write log information
 
     Returns
     -------
@@ -764,7 +766,7 @@ def read_genomes_info(list_file, name, date=None, logger=None):
             # If invalid values, warning message and ignore genome
             except ValueError:
                 logger.warning(f"For genome {gname}, at least one of your columns 'gsize', "
-                                "'nb_conts' or 'L90' contains a non numeric character. "
+                                "'nb_conts' or 'L90' contains a non numeric value. "
                                 "This genome will be ignored.")
                 continue
             # If no value for at least 1 field, warning message and ignore genome
@@ -786,7 +788,11 @@ def read_genomes_info(list_file, name, date=None, logger=None):
                 gfile = os.path.basename(gpath)
                 gname = os.path.splitext(gfile)[0]
                 genomes[gfile] = [gname, gpath, gpath, gsize, gcont, gl90]
-    logger.info(("Found {} genomes in total").format(len(genomes)))
+    if len(genomes) > 0:
+        logger.info(("Found {} genomes in total").format(len(genomes)))
+    else:
+        logger.error(f"no genome listed in {list_file} were found.")
+        sys.exit(1)
     return genomes
 
 
-- 
GitLab