From 9d07bca28cf02c991bcbad24d071698fe4cf93de Mon Sep 17 00:00:00 2001 From: Auden Cote-L'Heureux <52716489+AudenCote@users.noreply.github.com> Date: Tue, 24 Oct 2023 11:15:37 -0400 Subject: [PATCH] Updating arg parsing in tip counting script --- Utilities/for_trees/count_tips.py | 37 ++++++++++++------------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/Utilities/for_trees/count_tips.py b/Utilities/for_trees/count_tips.py index 16452eb..b9078bb 100644 --- a/Utilities/for_trees/count_tips.py +++ b/Utilities/for_trees/count_tips.py @@ -1,6 +1,6 @@ ''' Author: Auden Cote-L'Heureux -Last updated: 06/14/23 by Elinor +Last updated: 10/24/23 Motivation: Count the number of occurences of each taxa in each OG in a post guidance file Dependencies: Bio python, os, sys Inputs: Directory of postguidance files @@ -15,31 +15,22 @@ from Bio import SeqIO def get_args(): - in_dir = '' - - if('--input' in sys.argv or '-i' in sys.argv): - try: - if('--input' in sys.argv): - in_dir = sys.argv[sys.argv.index('--input') + 1] - else: - in_dir = sys.argv[sys.argv.index('-i') + 1] - except IndexError: - print('\nError: Something went wrong went parsing the arguments... maybe you forgot to input an input directory of trees?\n') - print('\nPlease input a folder of .tre files:\n\n\tpython count_tips.py --input \n') - exit() - else: - print('\nPlease input a folder of .tre files:\n\n\tpython count_tips.py --input \n') - exit() + parser = argparse.ArgumentParser( + prog = 'Tip counting script', + description = "Updated Oct 24th, 2023 by Auden Cote-L'Heureux." + ) + + parser.add_argument('-i', '--input', type = str, required = True, help = 'Path to the folder containing the input trees') + args = parser.parse_args() + if(args.input.endswith('/')): + args.input = args.input[:-1] - if(in_dir.endswith('/')): - in_dir = in_dir[:-1] - - if(not os.path.isdir(in_dir)): - print('\nPlease input a folder of .tre files:\n\n\tpython count_tips.py --input \n') + if(not os.path.isdir(args.input)): + print('\nThe input folder (--input) could not be found. Make sure you have given the correct path.\n') exit() - return in_dir + return args.input def count_tips(in_dir): @@ -79,4 +70,4 @@ def main(): count_tips(in_dir) -main() \ No newline at end of file +main()