# Path: augur/import_beast.py
# def run_beast(args):
#     '''
#     BEAST MCC tree to newick and node-data JSON for further augur processing / export
#     '''
#     verbose = args.verbose
#     print("importing from BEAST MCC tree", args.mcc)
# 
#     if args.recursion_limit:
#         print("Setting recursion limit to %d"%(args.recursion_limit))
#         sys.setrecursionlimit(args.recursion_limit)
# 
#     # node data is the dict that will be exported as json
#     node_data = {
#         'comment': "Imported from a BEAST MCC tree using `augur import beast`",
#         'mcc_file': args.mcc
#     }
# 
#     tree = parse_nexus(tree_path=args.mcc, verbose=args.verbose)
#     summarise_parsed_traits(tree)
#     # Phylo.draw_ascii(tree)
#     # instantiate treetime for the sole reason to name internal nodes (!)
#     # note that tt.tree = tree, and this is modified in-place by this function
#     tt = TreeAnc(tree=tree, aln=fake_alignment(tree), ref=None, gtr='JC69', verbose=1)
# 
# 
#     # extract date information from the tree
#     root_date_offset, most_recent_tip = calc_tree_dates(tree, args.most_recent_tip_date, args.tip_date_regex, args.tip_date_format, args.tip_date_delimeter)
#     compute_entropies_for_discrete_traits(tree)
# 
#     node_data['nodes'] = collect_node_data(tree, root_date_offset, most_recent_tip)
# 
#     tree_success = Phylo.write(tree, args.output_tree, 'newick', format_branch_length='%1.8f')
#     json_success = write_json(node_data, args.output_node_data)
# 
#     print_what_to_do_next(nodes=node_data['nodes'], mcc_path=args.mcc, tree_path=args.output_tree, node_data_path=args.output_node_data)
# 
# def register_arguments_beast(subparsers):
#     """
#     Arguments available to `augur import beast`
#     """
#     beast_parser = subparsers.add_parser('beast', help="Import beast analysis")
#     beast_parser.add_argument("--beast", help=SUPPRESS, default=True) # used to disambiguate subcommands
#     beast_parser.add_argument('--mcc', required=True, help="BEAST MCC tree")
#     beast_parser.add_argument('--most-recent-tip-date', default=0, type=float, help='Numeric date of most recent tip in tree (--tip-date-regex, --tip-date-format and --tip-date-delimeter are ignored if this is set)')
#     beast_parser.add_argument('--tip-date-regex', default=r'[0-9]{4}(\-[0-9]{2})*(\-[0-9]{2})*$', type=str, help='regex to extract dates from tip names')
#     beast_parser.add_argument('--tip-date-format', default="%Y-%m-%d", type=str, help='Format of date (if extracted by regex)')
#     beast_parser.add_argument('--tip-date-delimeter', default="-", type=str, help='delimeter used in tip-date-format. Used to match partial dates.')
#     beast_parser.add_argument('--verbose', action="store_true", help="Display verbose output. Only useful for debugging.")
#     beast_parser.add_argument('--recursion-limit', default=False, type=int, help="Set a custom recursion limit (dangerous!)")
#     beast_parser.add_argument('--output-tree', required=True, type=str, help='file name to write tree to')
#     beast_parser.add_argument('--output-node-data', required=True, type=str, help='file name to write (temporal) branch lengths & BEAST traits as node data')


from .import_beast import run_beast, register_arguments_beast
"""
Import analyses into augur pipeline from other systems
"""

def register_arguments(parser):
    metavar_msg = "Import analyses into augur pipeline from other systems"
    subparsers = parser.add_subparsers(title="TYPE",
                                       metavar=metavar_msg)
    subparsers.required = True
    register_arguments_beast(subparsers)

def run(args):
    if "beast" in args:

# Path: augur/import_beast.py
# def run_beast(args):
#     '''
#     BEAST MCC tree to newick and node-data JSON for further augur processing / export
#     '''
#     verbose = args.verbose
#     print("importing from BEAST MCC tree", args.mcc)
# 
#     if args.recursion_limit:
#         print("Setting recursion limit to %d"%(args.recursion_limit))
#         sys.setrecursionlimit(args.recursion_limit)
# 
#     # node data is the dict that will be exported as json
#     node_data = {
#         'comment': "Imported from a BEAST MCC tree using `augur import beast`",
#         'mcc_file': args.mcc
#     }
# 
#     tree = parse_nexus(tree_path=args.mcc, verbose=args.verbose)
#     summarise_parsed_traits(tree)
#     # Phylo.draw_ascii(tree)
#     # instantiate treetime for the sole reason to name internal nodes (!)
#     # note that tt.tree = tree, and this is modified in-place by this function
#     tt = TreeAnc(tree=tree, aln=fake_alignment(tree), ref=None, gtr='JC69', verbose=1)
# 
# 
#     # extract date information from the tree
#     root_date_offset, most_recent_tip = calc_tree_dates(tree, args.most_recent_tip_date, args.tip_date_regex, args.tip_date_format, args.tip_date_delimeter)
#     compute_entropies_for_discrete_traits(tree)
# 
#     node_data['nodes'] = collect_node_data(tree, root_date_offset, most_recent_tip)
# 
#     tree_success = Phylo.write(tree, args.output_tree, 'newick', format_branch_length='%1.8f')
#     json_success = write_json(node_data, args.output_node_data)
# 
#     print_what_to_do_next(nodes=node_data['nodes'], mcc_path=args.mcc, tree_path=args.output_tree, node_data_path=args.output_node_data)
# 
# def register_arguments_beast(subparsers):
#     """
#     Arguments available to `augur import beast`
#     """
#     beast_parser = subparsers.add_parser('beast', help="Import beast analysis")
#     beast_parser.add_argument("--beast", help=SUPPRESS, default=True) # used to disambiguate subcommands
#     beast_parser.add_argument('--mcc', required=True, help="BEAST MCC tree")
#     beast_parser.add_argument('--most-recent-tip-date', default=0, type=float, help='Numeric date of most recent tip in tree (--tip-date-regex, --tip-date-format and --tip-date-delimeter are ignored if this is set)')
#     beast_parser.add_argument('--tip-date-regex', default=r'[0-9]{4}(\-[0-9]{2})*(\-[0-9]{2})*$', type=str, help='regex to extract dates from tip names')
#     beast_parser.add_argument('--tip-date-format', default="%Y-%m-%d", type=str, help='Format of date (if extracted by regex)')
#     beast_parser.add_argument('--tip-date-delimeter', default="-", type=str, help='delimeter used in tip-date-format. Used to match partial dates.')
#     beast_parser.add_argument('--verbose', action="store_true", help="Display verbose output. Only useful for debugging.")
#     beast_parser.add_argument('--recursion-limit', default=False, type=int, help="Set a custom recursion limit (dangerous!)")
#     beast_parser.add_argument('--output-tree', required=True, type=str, help='file name to write tree to')
#     beast_parser.add_argument('--output-node-data', required=True, type=str, help='file name to write (temporal) branch lengths & BEAST traits as node data')


# Path: augur/import.py
from .import_beast import run_beast, register_arguments_beast

"""
Import analyses into augur pipeline from other systems
"""

def register_arguments(parser):
    metavar_msg = "Import analyses into augur pipeline from other systems"
    subparsers = parser.add_subparsers(title="TYPE",
                                       metavar=metavar_msg)
    subparsers.required = True
    register_arguments_beast(subparsers)

def run(args):
    if "beast" in args:

        return run_beast(args)