diff --git a/PanACoTA/subcommands/annotate.py b/PanACoTA/subcommands/annotate.py index 7ea3801283b7ac9d4e125c0b3172ead4e3c38b7a..616c2a1c19edd4e6ef20ae70321003019a27c25c 100755 --- a/PanACoTA/subcommands/annotate.py +++ b/PanACoTA/subcommands/annotate.py @@ -479,7 +479,7 @@ def build_parser(parser): optional.add_argument("--nbcont", dest="nbcont", type=utils_argparse.cont_num, default=999, help=("Maximum number of contigs allowed to keep a genome. " "Default is 999.")) - optional.add_argument("--cutn", dest="cutn", type=int, default=5, + optional.add_argument("--cutn", dest="cutn", type=utils_argparse.positive_int, default=5, help=("By default, each genome will be cut into new contigs when " "at least 5 'N' in a row are found in its sequence. " "If you don't want to " diff --git a/PanACoTA/subcommands/prepare.py b/PanACoTA/subcommands/prepare.py index 6a9c76591ebd2fa028b85199682e083035531498..ebb00dae3ca7168c3eb1082eb03778e466e9eccc 100644 --- a/PanACoTA/subcommands/prepare.py +++ b/PanACoTA/subcommands/prepare.py @@ -312,7 +312,7 @@ def build_parser(parser): "By default, it will be saved in your " "out_dir/tmp_files.") ) - general.add_argument("--cutn", dest="cutn", type=int, default=5, + general.add_argument("--cutn", dest="cutn", type=utils_argparse.positive_int, default=5, help=("By default, each genome will be cut into new contigs when " "at least 5 'N' in a row are found in its sequence. " "If you don't want to " diff --git a/PanACoTA/utils_argparse.py b/PanACoTA/utils_argparse.py index f5bb49bb4b75dd0228f0b80ae4da7166dafd6cf8..5651d00a731bb7cca96348427e0af222f178606a 100644 --- a/PanACoTA/utils_argparse.py +++ b/PanACoTA/utils_argparse.py @@ -99,3 +99,15 @@ def thread_num(param): elif param == 0: return nb_cpu return param + + +def positive_int(param): + try: + param = int(param) + except ValueError: + msg = f"error: argument --cutn: invalid int value: '{param}'" + raise argparse.ArgumentTypeError(msg) + if param < 0: + msg = f"error: argument --cutn must be a positive integer: invalid int value: '{param}'" + raise argparse.ArgumentTypeError(msg) + return param