# Path: lib/core_preprocessor.py
# def preprocess(args):
#     """Build the databases required by atram."""
#     log = Logger(args['log_file'], args['log_level'])
#     log.header()
# 
#     with util.make_temp_dir(
#             where=args['temp_dir'],
#             prefix='atram_preprocessor_',
#             keep=args['keep_temp_dir']) as temp_dir:
#         util.update_temp_dir(temp_dir, args)
# 
#         with db.connect(args['blast_db'], clean=True) as cxn:
#             db_preprocessor.create_metadata_table(cxn, args)
# 
#             db_preprocessor.create_sequences_table(cxn)
#             load_seqs(args, cxn, log)
# 
#             log.info('Creating an index for the sequence table')
#             db_preprocessor.create_sequences_index(cxn)
# 
#             if not args['shuffle']:
#                 shard_list = assign_seqs_to_shards(
#                     cxn, log, args['shard_count'])
# 
#         if args['shuffle']:
#             create_all_shuffled_shards(args, cxn, log, args['shard_count'])
#         else:
#             create_all_shards(args, log, shard_list)


import argparse
import os
import textwrap
import lib.blast as blast
import lib.db as db
import lib.util as util
from datetime import date
from glob import glob
from itertools import chain
from os.path import join
from lib.core_preprocessor import preprocess
        '--shuffle', action='store_true',
        help="""Shuffle sequences before putting them into blast files?""")

    args = vars(parser.parse_args())

    # Prepend to PATH environment variable if requested
    if args['path']:
        os.environ['PATH'] = '{}:{}'.format(args['path'], os.environ['PATH'])

    all_files = []
    for ends in ['mixed_ends', 'end_1', 'end_2', 'single_ends']:
        if args.get(ends):
            end_files = [glob(p) for p in args[ends]]
            end_files = sorted(list(chain.from_iterable(end_files)))
            args[ends] = end_files
            all_files.extend(end_files)

    args['shard_count'] = blast.default_shard_count(args, all_files)

    blast.make_blast_output_dir(args['blast_db'])

    blast.find_program('makeblastdb')

    util.temp_dir_exists(args['temp_dir'])

    return args


if __name__ == '__main__':
    ARGS = parse_command_line()

# Path: lib/core_preprocessor.py
# def preprocess(args):
#     """Build the databases required by atram."""
#     log = Logger(args['log_file'], args['log_level'])
#     log.header()
# 
#     with util.make_temp_dir(
#             where=args['temp_dir'],
#             prefix='atram_preprocessor_',
#             keep=args['keep_temp_dir']) as temp_dir:
#         util.update_temp_dir(temp_dir, args)
# 
#         with db.connect(args['blast_db'], clean=True) as cxn:
#             db_preprocessor.create_metadata_table(cxn, args)
# 
#             db_preprocessor.create_sequences_table(cxn)
#             load_seqs(args, cxn, log)
# 
#             log.info('Creating an index for the sequence table')
#             db_preprocessor.create_sequences_index(cxn)
# 
#             if not args['shuffle']:
#                 shard_list = assign_seqs_to_shards(
#                     cxn, log, args['shard_count'])
# 
#         if args['shuffle']:
#             create_all_shuffled_shards(args, cxn, log, args['shard_count'])
#         else:
#             create_all_shards(args, log, shard_list)


# Path: atram_preprocessor.py
import argparse
import os
import textwrap
import lib.blast as blast
import lib.db as db
import lib.util as util
from datetime import date
from glob import glob
from itertools import chain
from os.path import join
from lib.core_preprocessor import preprocess

        '--shuffle', action='store_true',
        help="""Shuffle sequences before putting them into blast files?""")

    args = vars(parser.parse_args())

    # Prepend to PATH environment variable if requested
    if args['path']:
        os.environ['PATH'] = '{}:{}'.format(args['path'], os.environ['PATH'])

    all_files = []
    for ends in ['mixed_ends', 'end_1', 'end_2', 'single_ends']:
        if args.get(ends):
            end_files = [glob(p) for p in args[ends]]
            end_files = sorted(list(chain.from_iterable(end_files)))
            args[ends] = end_files
            all_files.extend(end_files)

    args['shard_count'] = blast.default_shard_count(args, all_files)

    blast.make_blast_output_dir(args['blast_db'])

    blast.find_program('makeblastdb')

    util.temp_dir_exists(args['temp_dir'])

    return args


if __name__ == '__main__':
    ARGS = parse_command_line()

    preprocess(ARGS)