# 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 datetime
import pytest
from pathlib import Path
from unittest.mock import patch
from freezegun import freeze_time
from augur import utils
from test_filter import write_metadata
        with open(mask_file, "w") as fh:
            fh.write("\n".join(bad_mask_sites))
        with pytest.raises(ValueError):
            utils.read_mask_file(mask_file)

    def test_read_bed_file_good_input(self, tmpdir):
        """read_bed_file should read site ranges from properly formatted bed files"""
        bed_file = str(tmpdir / "temp.bed")
        bed_lines = ["SEQ\t7\t8", "SEQ\t2\t6", "SEQ\t3\t4"]
        expected_sites = [2,3,4,5,7]
        with open(bed_file, "w") as fh:
            fh.write("\n".join(bed_lines))
        assert utils.read_bed_file(bed_file) == expected_sites

    def test_read_bed_file_with_header(self, tmpdir):
        """read_bed_file should skip header lines if they exist in bed files"""
        bed_file = str(tmpdir / "temp.bed")
        bed_lines = ["CHROM\tSTART\tEND","SEQ\t7\t8", "SEQ\t2\t5"]
        expected_sites = [2,3,4,7]
        with open(bed_file, "w") as fh:
            fh.write("\n".join(bed_lines))
        assert utils.read_bed_file(bed_file) == expected_sites

    def test_read_bed_file_with_bad_lines(self, tmpdir):
        """read_bed_file should error out if any other lines are unreadable"""
        bed_file = str(tmpdir / "temp.bed")
        bed_lines = ["SEQ\t7\t8", "CHROM\tSTART\tEND", "SEQ\t2\t5"]
        with open(bed_file, "w") as fh:
            fh.write("\n".join(bed_lines))
        with pytest.raises(Exception):

# 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: tests/test_utils.py
import datetime
import pytest
from pathlib import Path
from unittest.mock import patch
from freezegun import freeze_time
from augur import utils
from test_filter import write_metadata

        with open(mask_file, "w") as fh:
            fh.write("\n".join(bad_mask_sites))
        with pytest.raises(ValueError):
            utils.read_mask_file(mask_file)

    def test_read_bed_file_good_input(self, tmpdir):
        """read_bed_file should read site ranges from properly formatted bed files"""
        bed_file = str(tmpdir / "temp.bed")
        bed_lines = ["SEQ\t7\t8", "SEQ\t2\t6", "SEQ\t3\t4"]
        expected_sites = [2,3,4,5,7]
        with open(bed_file, "w") as fh:
            fh.write("\n".join(bed_lines))
        assert utils.read_bed_file(bed_file) == expected_sites

    def test_read_bed_file_with_header(self, tmpdir):
        """read_bed_file should skip header lines if they exist in bed files"""
        bed_file = str(tmpdir / "temp.bed")
        bed_lines = ["CHROM\tSTART\tEND","SEQ\t7\t8", "SEQ\t2\t5"]
        expected_sites = [2,3,4,7]
        with open(bed_file, "w") as fh:
            fh.write("\n".join(bed_lines))
        assert utils.read_bed_file(bed_file) == expected_sites

    def test_read_bed_file_with_bad_lines(self, tmpdir):
        """read_bed_file should error out if any other lines are unreadable"""
        bed_file = str(tmpdir / "temp.bed")
        bed_lines = ["SEQ\t7\t8", "CHROM\tSTART\tEND", "SEQ\t2\t5"]
        with open(bed_file, "w") as fh:
            fh.write("\n".join(bed_lines))
        with pytest.raises(Exception):

            utils.read_bed_file(bed_file)