# Path: augur/translate.py
# class MissingNodeError(Exception):
# class MismatchNodeError(Exception):
# def safe_translate(sequence, report_exceptions=False):
# def translate_feature(aln, feature):
# def translate_vcf_feature(sequences, ref, feature):
#     def str_reverse_comp(str_seq):
# def construct_mut(start, pos, end):
# def assign_aa_vcf(tree, translations):
# def assign_aa_fasta(tree, translations):
# def get_genes_from_file(fname):
# def register_arguments(parser):
# def run(args):


import json
import numpy as np
import pytest
import sys
import os
import treetime
from pathlib import Path
from Bio.Seq import Seq
from Bio.SeqFeature import SeqFeature, FeatureLocation
from augur import translate
                           (('ATG---',), 'M-'),
                           (('ATGTAG',), 'M*'),
                           (('',), ''),
                           (('ATGT',), 'MX'),
                           (('ATG', True), ('M', False)),
                           (('ATGA-G', True), ('MX', True))]

        # input each pair into the function and check
        for pair in params_and_outs:
            params, out = pair
            assert translate.safe_translate(*params) == out

    def test_translate_feature(self):
        '''
        Test translate_feature from a dictionary of given nucleotides to dictionary of translated amino acids
        '''
        # Seq -> Amino https://en.wikipedia.org/wiki/DNA_codon_table
        seq1 = Seq("TTTCTTATGGTCGTA") 
        seq2 = Seq("TCTTCAACTGCTACA")
        seq3 = Seq("CATAATGAATATAAT")
        aln = {'seq1': seq1,
               'seq2': seq2,
               'seq3': seq3}
        feature = SeqFeature(FeatureLocation(0, 15), type="domain")

        # expected results
        expected_translations = {'seq1': 'FLMVV',
                                 'seq2': 'SSTAT',
                                 'seq3': 'HNEYN'}


# Path: augur/translate.py
# class MissingNodeError(Exception):
# class MismatchNodeError(Exception):
# def safe_translate(sequence, report_exceptions=False):
# def translate_feature(aln, feature):
# def translate_vcf_feature(sequences, ref, feature):
#     def str_reverse_comp(str_seq):
# def construct_mut(start, pos, end):
# def assign_aa_vcf(tree, translations):
# def assign_aa_fasta(tree, translations):
# def get_genes_from_file(fname):
# def register_arguments(parser):
# def run(args):


# Path: tests/test_translate.py
import json
import numpy as np
import pytest
import sys
import os
import treetime
from pathlib import Path
from Bio.Seq import Seq
from Bio.SeqFeature import SeqFeature, FeatureLocation
from augur import translate

                           (('ATG---',), 'M-'),
                           (('ATGTAG',), 'M*'),
                           (('',), ''),
                           (('ATGT',), 'MX'),
                           (('ATG', True), ('M', False)),
                           (('ATGA-G', True), ('MX', True))]

        # input each pair into the function and check
        for pair in params_and_outs:
            params, out = pair
            assert translate.safe_translate(*params) == out

    def test_translate_feature(self):
        '''
        Test translate_feature from a dictionary of given nucleotides to dictionary of translated amino acids
        '''
        # Seq -> Amino https://en.wikipedia.org/wiki/DNA_codon_table
        seq1 = Seq("TTTCTTATGGTCGTA") 
        seq2 = Seq("TCTTCAACTGCTACA")
        seq3 = Seq("CATAATGAATATAAT")
        aln = {'seq1': seq1,
               'seq2': seq2,
               'seq3': seq3}
        feature = SeqFeature(FeatureLocation(0, 15), type="domain")

        # expected results
        expected_translations = {'seq1': 'FLMVV',
                                 'seq2': 'SSTAT',
                                 'seq3': 'HNEYN'}


        assert translate.translate_feature(aln, feature) == expected_translations