def handle_program_options():
    """
    Uses the built-in argparse module to handle command-line options for the
    program.

    :return: The gathered command-line options specified by the user
    :rtype: argparse.ArgumentParser
    """
    parser = argparse.ArgumentParser(description="Convert Sanger-sequencing \
                                     derived data files for use with the \
                                     metagenomics analysis program QIIME, by \
                                     extracting Sample ID information, adding\
                                     barcodes and primers to the sequence \
                                     data, and outputting a mapping file and\
                                     single FASTA-formatted sequence file \
                                     formed by concatenating all input data.")
    parser.add_argument('-i', '--input_dir', required=True,
                        help="The directory containing sequence data files. \
                              Assumes all data files are placed in this \
                              directory. For files organized within folders by\
                              sample, use -s in addition.")
    parser.add_argument('-m', '--map_file', default='map.txt',
                        help="QIIME-formatted mapping file linking Sample IDs \
                              with barcodes and primers.")
    parser.add_argument('-o', '--output', default='output.fasta',
                        metavar='OUTPUT_FILE',
                        help="Single file containing all sequence data found \
                              in input_dir, FASTA-formatted with barcode and \
                              primer preprended to sequence. If the -q option \
                              is passed, any quality data will also be output \
                              to a single file of the same name with a .qual \
                              extension.")
    parser.add_argument('-b', '--barcode_length', type=int, default=12,
                        help="Length of the generated barcode sequences. \
                              Default is 12 (QIIME default), minimum is 8.")

    parser.add_argument('-q', '--qual', action='store_true', default=False,
                        help="Instruct the program to look for quality \
                              input files")
    parser.add_argument('-u', '--utf16', action='store_true', default=False,
                        help="UTF-16 encoded input files")

    parser.add_argument('-t', '--treatment',
                        help="Inserts an additional column into the mapping \
                              file specifying some treatment or other variable\
                              that separates the current set of sequences \
                              from any other set of seqeunces. For example:\
                              -t DiseaseState=healthy")

    # data input options
    sidGroup = parser.add_mutually_exclusive_group(required=True)
    sidGroup.add_argument('-d', '--identifier_pattern',
                          action=ValidateIDPattern,
                          nargs=2, metavar=('SEPARATOR', 'FIELD_NUMBER'),
                          help="Indicates how to extract the Sample ID from \
                               the description line. Specify two things: \
                               1. Field separator, 2. Field number of Sample \
                               ID (1 or greater). If the separator is a space \
                               or tab, use \s or \\t respectively. \
                               Example: >ka-SampleID-2091, use -i - 2, \
                               indicating - is the separator and the Sample ID\
                               is field #2.")
    sidGroup.add_argument('-f', '--filename_sample_id', action='store_true',
                          default=False, help='Specify that the program should\
                          the name of each fasta file as the Sample ID for use\
                          in the mapping file. This is meant to be used when \
                          all sequence data for a sample is stored in a single\
                          file.')

    return parser.parse_args()
def handle_program_options ( ) : parser = argparse . ArgumentParser ( description = "Convert Sanger-sequencing \
                                     derived data files for use with the \
                                     metagenomics analysis program QIIME, by \
                                     extracting Sample ID information, adding\
                                     barcodes and primers to the sequence \
                                     data, and outputting a mapping file and\
                                     single FASTA-formatted sequence file \
                                     formed by concatenating all input data." ) parser . add_argument ( '-i' , '--input_dir' , required = True , help = "The directory containing sequence data files. \
                              Assumes all data files are placed in this \
                              directory. For files organized within folders by\
                              sample, use -s in addition." ) parser . add_argument ( '-m' , '--map_file' , default = 'map.txt' , help = "QIIME-formatted mapping file linking Sample IDs \
                              with barcodes and primers." ) parser . add_argument ( '-o' , '--output' , default = 'output.fasta' , metavar = 'OUTPUT_FILE' , help = "Single file containing all sequence data found \
                              in input_dir, FASTA-formatted with barcode and \
                              primer preprended to sequence. If the -q option \
                              is passed, any quality data will also be output \
                              to a single file of the same name with a .qual \
                              extension." ) parser . add_argument ( '-b' , '--barcode_length' , type = int , default = 12 , help = "Length of the generated barcode sequences. \
                              Default is 12 (QIIME default), minimum is 8." ) parser . add_argument ( '-q' , '--qual' , action = 'store_true' , default = False , help = "Instruct the program to look for quality \
                              input files" ) parser . add_argument ( '-u' , '--utf16' , action = 'store_true' , default = False , help = "UTF-16 encoded input files" ) parser . add_argument ( '-t' , '--treatment' , help = "Inserts an additional column into the mapping \
                              file specifying some treatment or other variable\
                              that separates the current set of sequences \
                              from any other set of seqeunces. For example:\
                              -t DiseaseState=healthy" ) sidGroup = parser . add_mutually_exclusive_group ( required = True ) sidGroup . add_argument ( '-d' , '--identifier_pattern' , action = ValidateIDPattern , nargs = 2 , metavar = ( 'SEPARATOR' , 'FIELD_NUMBER' ) , help = "Indicates how to extract the Sample ID from \
                               the description line. Specify two things: \
                               1. Field separator, 2. Field number of Sample \
                               ID (1 or greater). If the separator is a space \
                               or tab, use \s or \\t respectively. \
                               Example: >ka-SampleID-2091, use -i - 2, \
                               indicating - is the separator and the Sample ID\
                               is field #2." ) sidGroup . add_argument ( '-f' , '--filename_sample_id' , action = 'store_true' , default = False , help = 'Specify that the program should\
                          the name of each fasta file as the Sample ID for use\
                          in the mapping file. This is meant to be used when \
                          all sequence data for a sample is stored in a single\
                          file.' ) return parser . parse_args ( )
Uses the built-in argparse module to handle command-line options for the
    program.

    :return: The gathered command-line options specified by the user
    :rtype: argparse.ArgumentParser