Skip to content
Snippets Groups Projects
Commit 2dc6b57c authored by Amandine  PERRIN's avatar Amandine PERRIN
Browse files

Move check type of argument (percentage) to utils_argparse.py

parent a9b8567e
No related branches found
No related tags found
No related merge requests found
......@@ -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)."
......
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment