# Path: augur/utils.py
# class AugurException(Exception):
# class InvalidTreeError(Exception):
# def is_vcf(filename):
# def read_vcf(filename):
# def myopen(fname, mode):
# def get_json_name(args, default=None):
# def ambiguous_date_to_date_range(uncertain_date, fmt, min_max_year=None):
# def read_metadata(fname, query=None, as_data_frame=False):
# def is_date_ambiguous(date, ambiguous_by="any"):
# def get_numerical_date_from_value(value, fmt=None, min_max_year=None):
# def get_numerical_dates(meta_dict, name_col = None, date_col='date', fmt=None, min_max_year=None):
# def read_tree(fname, min_terminals=3):
# def read_node_data(fnames, tree=None):
# def write_json(data, file_name, indent=(None if os.environ.get("AUGUR_MINIFY_JSON") else 2), include_version=True):
# def load_features(reference, feature_names=None):
# def read_config(fname):
# def read_lat_longs(overrides=None, use_defaults=True):
#     def add_line_to_coordinates(line):
# def read_colors(overrides=None, use_defaults=True):
# def write_VCF_translation(prot_dict, vcf_file_name, ref_file_name):
# def run_shell_command(cmd, raise_errors=False, extra_env=None):
# def first_line(text):
# def available_cpu_cores(fallback: int = 1) -> int:
# def nthreads_value(value):
# def get_parent_name_by_child_name_for_tree(tree):
# def annotate_parents_for_tree(tree):
# def json_to_tree(json_dict, root=True):
# def get_augur_version():
# def read_bed_file(bed_file):
# def read_mask_file(mask_file):
# def load_mask_sites(mask_file):
# def read_strains(*files, comment_char="#"):
#     T = None
#             T = Bio.Phylo.read(fname, fmt)
#                 T = None
# VALID_NUCLEOTIDES = { # http://reverse-complement.com/ambiguity.html
#     "A", "G", "C", "T", "U", "N", "R", "Y", "S", "W", "K", "M", "B", "V", "D", "H", "-",
#     "a", "g", "c", "t", "u", "n", "r", "y", "s", "w", "k", "m", "b", "v", "d", "h", "-"
# }


import os
import numpy as np
from shutil import copyfile
from Bio import AlignIO, SeqIO, Seq, Align
from .utils import run_shell_command, nthreads_value, shquote
from collections import defaultdict
"""
Align multiple sequences from FASTA.
"""


class AlignmentError(Exception):
    # TODO: this exception should potentially be renamed and made augur-wide
    # thus allowing any module to raise it and have the message printed & augur
    # exit with code 1
    pass

def register_arguments(parser):
    parser.add_argument('--sequences', '-s', required=True, nargs="+", metavar="FASTA", help="sequences to align")
    parser.add_argument('--output', '-o', default="alignment.fasta", help="output file (default: %(default)s)")

# Path: augur/utils.py
# class AugurException(Exception):
# class InvalidTreeError(Exception):
# def is_vcf(filename):
# def read_vcf(filename):
# def myopen(fname, mode):
# def get_json_name(args, default=None):
# def ambiguous_date_to_date_range(uncertain_date, fmt, min_max_year=None):
# def read_metadata(fname, query=None, as_data_frame=False):
# def is_date_ambiguous(date, ambiguous_by="any"):
# def get_numerical_date_from_value(value, fmt=None, min_max_year=None):
# def get_numerical_dates(meta_dict, name_col = None, date_col='date', fmt=None, min_max_year=None):
# def read_tree(fname, min_terminals=3):
# def read_node_data(fnames, tree=None):
# def write_json(data, file_name, indent=(None if os.environ.get("AUGUR_MINIFY_JSON") else 2), include_version=True):
# def load_features(reference, feature_names=None):
# def read_config(fname):
# def read_lat_longs(overrides=None, use_defaults=True):
#     def add_line_to_coordinates(line):
# def read_colors(overrides=None, use_defaults=True):
# def write_VCF_translation(prot_dict, vcf_file_name, ref_file_name):
# def run_shell_command(cmd, raise_errors=False, extra_env=None):
# def first_line(text):
# def available_cpu_cores(fallback: int = 1) -> int:
# def nthreads_value(value):
# def get_parent_name_by_child_name_for_tree(tree):
# def annotate_parents_for_tree(tree):
# def json_to_tree(json_dict, root=True):
# def get_augur_version():
# def read_bed_file(bed_file):
# def read_mask_file(mask_file):
# def load_mask_sites(mask_file):
# def read_strains(*files, comment_char="#"):
#     T = None
#             T = Bio.Phylo.read(fname, fmt)
#                 T = None
# VALID_NUCLEOTIDES = { # http://reverse-complement.com/ambiguity.html
#     "A", "G", "C", "T", "U", "N", "R", "Y", "S", "W", "K", "M", "B", "V", "D", "H", "-",
#     "a", "g", "c", "t", "u", "n", "r", "y", "s", "w", "k", "m", "b", "v", "d", "h", "-"
# }


# Path: augur/align.py
import os
import numpy as np
from shutil import copyfile
from Bio import AlignIO, SeqIO, Seq, Align
from .utils import run_shell_command, nthreads_value, shquote
from collections import defaultdict

"""
Align multiple sequences from FASTA.
"""


class AlignmentError(Exception):
    # TODO: this exception should potentially be renamed and made augur-wide
    # thus allowing any module to raise it and have the message printed & augur
    # exit with code 1
    pass

def register_arguments(parser):
    parser.add_argument('--sequences', '-s', required=True, nargs="+", metavar="FASTA", help="sequences to align")
    parser.add_argument('--output', '-o', default="alignment.fasta", help="output file (default: %(default)s)")

    parser.add_argument('--nthreads', type=nthreads_value, default=1,