From 7338b5c9f96d935773a5677260db6d2cf917d6c5 Mon Sep 17 00:00:00 2001
From: Amandine PERRIN <amandine.perrin@pasteur.fr>
Date: Thu, 22 Oct 2020 16:12:43 +0200
Subject: [PATCH] Check parser type from utils_argparse

---
 PanACoTA/subcommands/pangenome.py | 22 +---------------------
 1 file changed, 1 insertion(+), 21 deletions(-)

diff --git a/PanACoTA/subcommands/pangenome.py b/PanACoTA/subcommands/pangenome.py
index cff2ec2d..e74e0400 100755
--- a/PanACoTA/subcommands/pangenome.py
+++ b/PanACoTA/subcommands/pangenome.py
@@ -156,28 +156,8 @@ def build_parser(parser):
         parser to configure in order to extract command-line arguments
     """
     import argparse
-    import multiprocessing
     from PanACoTA import utils_argparse
 
-    def thread_num(param):
-        try:
-            param = int(param)
-        except Exception:
-            msg = "argument --threads threads: invalid int value: {}".format(param)
-            raise argparse.ArgumentTypeError(msg)
-        nb_cpu = multiprocessing.cpu_count()
-        if param > nb_cpu:
-            msg = ("You have {} threads on your computer, you cannot ask for more: "
-                   "invalid value: {}").format(nb_cpu, param)
-            raise argparse.ArgumentTypeError(msg)
-        elif param < 0:
-            msg = ("Please provide a positive number of threads (or 0 for all threads): "
-                   "Invalid value: {}").format(param)
-            raise argparse.ArgumentTypeError(msg)
-        elif param == 0:
-            return multiprocessing.cpu_count()
-        return param
-
     # Create command-line parser for all options and arguments to give
     required = parser.add_argument_group('Required arguments')
     required.add_argument("-l", dest="lstinfo_file", required=True,
@@ -218,7 +198,7 @@ def build_parser(parser):
                           help=("use this option if you want to save the concatenated protein "
                                 "databank in another directory than the one containing all "
                                 "individual protein files ('Proteins' folder)."))
-    optional.add_argument("--threads", dest="threads", default=1, type=thread_num,
+    optional.add_argument("--threads", dest="threads", default=1, type=utils_argparse.thread_num,
                           help=("add this option if you want to parallelize on several threads. "
                                 "Indicate on how many threads you want to parallelize. "
                                 "By default, it uses 1 thread. Put 0 if you want to use "
-- 
GitLab