# found on https://stackoverflow.com/questions/11540854/file-as-command-line-argument-for-argparse-error-message-if-argument-is-not-va
defextant_file(x):
"""
'Type' for argparse - checks that file exists but does not open.
"""
ifnotos.path.exists(x):
# Argparse uses the ArgumentTypeError to give a rejection message like:
# error: argument input: x does not exist
raiseargparse.ArgumentTypeError("{0} does not exist".format(x))
returnx
# Parse command-line arguments
defparse_arguments():
parser=argparse.ArgumentParser(description="Takes as input FASTA file of cDNA sequences, a CSV with sequence counts, and mean and std. dev. of fragment lengths. Outputs most terminal fragment (within desired length range) for each sequence.")
parser.add_argument('--fasta',required=True,type=extant_file,help="FASTA file with cDNA sequences")
parser.add_argument('--counts',required=True,type=extant_file,help="CSV file with sequence counts")
parser.add_argument('--mean',required=False,default=10,type=int,help="Mean fragment length (default: 10)")
parser.add_argument('--std',required=False,default=1,type=int,help="Standard deviation fragment length (defafult: 1)")