diff --git a/PanACoTA/subcommands/corepers.py b/PanACoTA/subcommands/corepers.py index d9e97bde1b6f200e4cd567bc019e5d472275ed60..62756a8c677191fde6ca40deb986f175a6aaaebc 100755 --- a/PanACoTA/subcommands/corepers.py +++ b/PanACoTA/subcommands/corepers.py @@ -200,18 +200,7 @@ def build_parser(parser): parser to configure in order to extract command-line arguments """ import argparse - - def percentage(param): - try: - param = float(param) - except Exception: - msg = "argument -t tol: invalid float value: {}".format(param) - raise argparse.ArgumentTypeError(msg) - if param < 0 or param > 1: - msg = ("The minimum %% of genomes required in a family to be persistent must " - "be in [0, 1]. Invalid value: {}".format(param)) - raise argparse.ArgumentTypeError(msg) - return param + from PanACoTA import utils_argparse # Create command-line parser for all options and arguments to give required = parser.add_argument_group('Required arguments') @@ -221,7 +210,7 @@ def build_parser(parser): help=("Specify the output directory for your core/persistent genome."), default=".") optional = parser.add_argument_group('Optional arguments') - optional.add_argument("-t", "--tol", dest="tol", default=1, type=percentage, + optional.add_argument("-t", "--tol", dest="tol", default=1, type=utils_argparse.percentage, help=("min %% of genomes having at least 1 member in a family to " "consider the family as persistent (between 0 and 1, " "default is 1 = 100%% of genomes = Core genome)." diff --git a/PanACoTA/utils_argparse.py b/PanACoTA/utils_argparse.py index f553a571f80c99d7e5ed42793dd165306558f03b..8f07f93986393b4d92e0e8491c4cd70422e5063d 100644 --- a/PanACoTA/utils_argparse.py +++ b/PanACoTA/utils_argparse.py @@ -123,3 +123,16 @@ def mash_dist(param): msg = f"error: mash distance must be between 0 and 1: invalid value: '{param}'" raise argparse.ArgumentTypeError(msg) return param + + +def percentage(param): + try: + param = float(param) + except Exception: + msg = "argument -t tol: invalid float value: {}".format(param) + raise argparse.ArgumentTypeError(msg) + if param < 0 or param > 1: + msg = ("The minimum %% of genomes required in a family to be persistent must " + "be in [0, 1]. Invalid value: {}".format(param)) + raise argparse.ArgumentTypeError(msg) + return param