# Path: abstar/assigners/registry.py
# ASSIGNERS = {'blastn': Blastn}
# 
# Path: abstar/utils/output.py
# def get_abstar_results(antibodies, pretty=False, padding=True, raw=False, keys=None):
#     return [AbstarResult(ab, pretty, padding, raw, keys) for ab in antibodies]
# 
# def write_output(output_dict, output_dir, output_prefix):
#     output_file_dict = {}
#     for fmt in output_dict.keys():
#         subdir = os.path.join(output_dir, fmt)
#         output_name = output_prefix + get_output_suffix(fmt)
#         output_file = os.path.join(subdir, output_name)
#         with open(output_file, 'w') as f:
#             f.write('\n'.join(output_dict[fmt]))
#         output_file_dict[fmt] = output_file
#     return output_file_dict
# 
# Path: abstar/utils/queue/celery.py



from multiprocessing import Pool
from ..assigners.registry import ASSIGNERS
from ..utils.output import get_abstar_results, write_output
from ..utils.queue.celery import celery
from abutils.utils import log

    Input is a a FASTA-formatted file of antibody sequences and the output directory.
    Optional input items include the species (supported species: 'human'); length of
    the unique antibody identifier (UAID); and debug mode (which forces single-threading
    and prints more verbose errors.)

    Output is the number of functional antibody sequences identified in the input file.
    '''
    try:
        # setup logging
        global logger
        logger = log.get_logger(__name__)
        assigned_log = ''
        unassigned_log = ''
        # identify output file
        output_filename = os.path.basename(seq_file)
        if args.output_type == 'json':
            output_file = os.path.join(output_dir, output_filename + '.json')
        elif args.output_type in ['imgt', 'hadoop']:
            output_file = os.path.join(output_dir, output_filename + '.txt')
        # start assignment
        assigner = ASSIGNERS[args.assigner]
        assigner(sequence_file, args.species)
        # process all of the successfully assigned sequences
        assigned = [Antibody(vdj, args.species) for vdj in assigner.assigned]
        for ab in assigned:
            ab.annotate()
            if args.debug:
                assigned_log += ab.format_log()
        results = get_abstar_results(assigned, pretty=args.pretty, padding=args.padding, raw=args.raw)

# Path: abstar/assigners/registry.py
# ASSIGNERS = {'blastn': Blastn}
# 
# Path: abstar/utils/output.py
# def get_abstar_results(antibodies, pretty=False, padding=True, raw=False, keys=None):
#     return [AbstarResult(ab, pretty, padding, raw, keys) for ab in antibodies]
# 
# def write_output(output_dict, output_dir, output_prefix):
#     output_file_dict = {}
#     for fmt in output_dict.keys():
#         subdir = os.path.join(output_dir, fmt)
#         output_name = output_prefix + get_output_suffix(fmt)
#         output_file = os.path.join(subdir, output_name)
#         with open(output_file, 'w') as f:
#             f.write('\n'.join(output_dict[fmt]))
#         output_file_dict[fmt] = output_file
#     return output_file_dict
# 
# Path: abstar/utils/queue/celery.py



# Path: abstar/core/jobs.py
from multiprocessing import Pool
from ..assigners.registry import ASSIGNERS
from ..utils.output import get_abstar_results, write_output
from ..utils.queue.celery import celery
from abutils.utils import log


    Input is a a FASTA-formatted file of antibody sequences and the output directory.
    Optional input items include the species (supported species: 'human'); length of
    the unique antibody identifier (UAID); and debug mode (which forces single-threading
    and prints more verbose errors.)

    Output is the number of functional antibody sequences identified in the input file.
    '''
    try:
        # setup logging
        global logger
        logger = log.get_logger(__name__)
        assigned_log = ''
        unassigned_log = ''
        # identify output file
        output_filename = os.path.basename(seq_file)
        if args.output_type == 'json':
            output_file = os.path.join(output_dir, output_filename + '.json')
        elif args.output_type in ['imgt', 'hadoop']:
            output_file = os.path.join(output_dir, output_filename + '.txt')
        # start assignment
        assigner = ASSIGNERS[args.assigner]
        assigner(sequence_file, args.species)
        # process all of the successfully assigned sequences
        assigned = [Antibody(vdj, args.species) for vdj in assigner.assigned]
        for ab in assigned:
            ab.annotate()
            if args.debug:
                assigned_log += ab.format_log()
        results = get_abstar_results(assigned, pretty=args.pretty, padding=args.padding, raw=args.raw)

        write_output(results, output_file, args.output_type)