From 37282ca8cdd10c82a4d84b3fb9a70777d0166914 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Tue, 29 Oct 2024 14:01:27 -0500 Subject: Use argparse.ArgumentParser to collect CLI args from user Collect arguments from the CLI using argparse rather than sys.argv directly. --- scripts/maintenance/QTL_Reaper_v6.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'scripts/maintenance/QTL_Reaper_v6.py') diff --git a/scripts/maintenance/QTL_Reaper_v6.py b/scripts/maintenance/QTL_Reaper_v6.py index cfbf31bb..3f202285 100755 --- a/scripts/maintenance/QTL_Reaper_v6.py +++ b/scripts/maintenance/QTL_Reaper_v6.py @@ -1,14 +1,12 @@ ####### To run this program do: python QTL_Reaper_v2.py 235 #Where 163 is the ProbeSetFreeze Id of the database that we want to calculate #the LRS #!/usr/bin/python -import sys -import os import reaper import MySQLdb -import time +from argparse import ArgumentParser -def run_qtl_reaper(cursor, genotypeDir): +def run_qtl_reaper(cursor, genotypeDir, ProbeSetFreezeIds): genotype_1 = reaper.Dataset() #####get all of the genotypes cursor.execute('select Id, Name from InbredSet') @@ -17,7 +15,6 @@ def run_qtl_reaper(cursor, genotypeDir): for item in results: InbredSets[item[0]] = genotypeDir+str(item[1])+'.geno' - ProbeSetFreezeIds=sys.argv[1:] if ProbeSetFreezeIds: #####convert the Ids to integer ProbeSetFreezeIds=list(map(int, ProbeSetFreezeIds)) @@ -106,9 +103,19 @@ def run_qtl_reaper(cursor, genotypeDir): cursor.close() def main(): - con = MySQLdb.Connect(db='db_webqtl', user='username', passwd='', host="localhost") - run_qtl_reaper(con.cursor(), "/gnshare/gn/web/genotypes/") - con.close() + parser = ArgumentParser(prog="QTLReaper", description="Python-2 QTLReaper.") + parser.add_argument("db_config_file", + type=str, + default="dbconfig", + help="File with database connection configuration") + parser.add_argument("genotype_dir", + type=str, + default="/gnshare/gn/web/genotypes/", + help="Directory with the genotype CSV files.") + parser.add_argument("ProbeSetFreezeIds", + nargs="*", + help="The ProbeSetFreezeIds to act on.") + args = parser.parse_args() if __name__ == "__main__": main() -- cgit v1.2.3