Commit 84536fc3 authored by peguerin's avatar peguerin
Browse files

check arguments

parent 18f19220
import argparse
import sys
import os
import pandas
HELPER_TEXT ="""
.___ ___. __ ___ .______ _______ .______
......@@ -24,7 +24,39 @@ For help:
"""
def check_taxdumpdir(ncbiTaxdumpDir):
nodesFile=str(ncbiTaxdumpDir)+'/nodes.dmp'
namesFile=str(ncbiTaxdumpDir)+'/names.dmp'
if not os.path.exists(ncbiTaxdumpDir):
print('ARGUMENTS ERROR: arguments ncbi_taxdump {0}. This path not exists.'.format(ncbiTaxdumpDir))
return False
if not os.path.isfile(nodesFile):
print('ARGUMENTS ERROR: arguments ncbi_taxdump {0}. {1} is missing.'.format(ncbiTaxdumpDir, nodesFile))
return False
elif not os.path.isfile(namesFile):
print('ARGUMENTS ERROR: arguments ncbi_taxdump {0}. {1} is missing.'.format(ncbiTaxdumpDir, namesFile))
return False
else:
return True
def check_curatecsv(curateCsvFile):
curateColons = ['current_name', 'ncbi_name', 'genus', 'family', 'ncbi_rank']
if not os.path.isfile(curateCsvFile):
print('ARGUMENTS ERROR: arguments curate {0}. {0} file not exists.'.format(curateCsvFile))
return False
try:
dfCure = pandas.read_csv(curateCsvFile, sep=";")
except ValueError:
print("ARGUMENTS ERROR: arguments curate {0}. {0} is not a CSV file and must have ';' as delimiter'.".format(curateCsvFile))
return False
colons = list(dfCure.columns.values)
for colon in curateColons:
if colon not in colons:
print("ARGUMENTS ERROR: arguments curate {0}. {1} colon is missing.".format(curateCsvFile, colon))
return False
return True
def parse_args(usage=HELPER_TEXT):
parser = argparse.ArgumentParser(description='mkbdr - to build a custom metabarcoding reference database.')
......@@ -45,11 +77,29 @@ def parse_args(usage=HELPER_TEXT):
curegen.add_argument("-n","--ncbi_taxdump", type=str, help='path of NCBI taxdump.tar.gz file', required=False, default="NA")
curegen.add_argument("-d","--database_globalnames", type=str, help="Name of the selected database from GlobalNames i.e. 'Catalogue of Life' or 'Fishbase Cache'", required=False, default='FishBase Cache')
curegen.add_argument("-o","--output_prefix", type=str, help='prefix of the output curated taxonomy CSV such as [PREFIX].csv')
curegen.add_argument("-l","--ncbi_taxdump_load", action='store_true', help='load NCBI taxonomy folder')
args = parser.parse_args()
if args.command not in ['validate', 'curegen']:
print(usage)
sys.exit(0)
print("Checking arguments...", end='')
## check arguments are not faulty
if args.command == 'validate':
if args.curate != 'NA':
if check_curatecsv(args.curate) is False:
print(usage)
sys.exit(0)
if args.ncbi_taxdump_edition or args.ncbi_taxdump_load:
if args.ncbi_taxdump == 'NA':
print('ARGUMENT ERROR: ncbi_taxdump argument is needed.')
print(usage)
sys.exit(0)
else:
if check_taxdumpdir(args.ncbi_taxdump) is False:
print(usage)
sys.exit(0)
print("done.")
return args
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment