# Path: taxtastic/refpkg.py
# FORMAT_VERSION = '1.1'
# class DerivedFileNotUpdatedWarning(UserWarning):
# class NoAncestor(Exception):
# class Refpkg(object):
# def is_string(val):
# def md5file(fobj):
# def scratch_file(unlink=True, **kwargs):
# def manifest_template():
# def transaction(f, self, *args, **kwargs):
#     def __init__(self, path, create=None):
#     def _install_zipfile_handlers(self):
#         def zipopen(name, *mode):
#         def file_path(name):
#     def file_path(self, name):
#     def open(self, name, *mode):
#     def open_manifest(self, *mode):
#     def open_resource(self, resource, *mode):
#     def resource_name(self, resource):
#     def resource_md5(self, resource):
#     def calculate_resource_md5(self, resource):
#     def resource_path(self, resource):
#     def _set_defaults(self):
#     def _sync_to_disk(self):
#     def _sync_from_disk(self):
#     def _add_file(self, key, path):
#     def _delete_file(self, path):
#     def metadata(self, key):
#     def file_keys(self):
#     def metadata_keys(self):
#     def _log(self, msg):
#     def log(self):
#     def is_invalid(self):
#     def _check_refpkg(self):
#     def update_metadata(self, key, value):
#     def update_file(self, key, new_path):
#     def reroot(self, rppr=None, pretend=False):
#     def update_phylo_model(self, stats_type, stats_file, frequency_type=None):
#     def rollback(self):
#     def rollforward(self):
#     def strip(self):
#     def start_transaction(self):
#     def commit_transaction(self, log=None):
#     def is_ill_formed(self):
#     def load_db(self):
#     def most_recent_common_ancestor(self, *ts):
#     def _large_mrca(self, ts):
#     def _small_mrca(self, ts):
#     def file_abspath(self, resource):
#     def file_name(self, resource):
#     def file_md5(self, resource):
# 
# Path: taxtastic/utils.py
# def get_new_nodes(fname):
# def getlines(fname):
# def try_set_fields(d, regex, text, hook=lambda x: x):
# def parse_raxmlng(handle):
# def parse_raxmlng(handle):
# def parse_raxml(handle):
# def parse_fasttree(fobj):
# def parse_phyml(fobj, frequency_type=None):
# def parse_stockholm(fobj):
# def has_rppr(rppr_name='rppr'):
# def add_database_args(parser):
# def sqlite_default():
#     def parse_url(url):
# def random_name(length):
# class InvalidLogError(ValueError):
# DNA = ['JC', 'K80', 'F81', 'HKY', 'TN93ef', 'TN93', 'K81', 'K81uf', 'TPM2',
#        'TPM2uf', 'TPM3', 'TPM3uf', 'TIM1', 'TIM1uf', 'TIM2', 'TIM2uf',
#        'TIM3', 'TIM3uf', 'TVMef', 'TVM', 'SYM', 'GTR']
# PROT = ['Blosum62', 'cpREV', 'Dayhoff', 'DCMut', 'DEN', 'FLU', 'HIVb',
#         'HIVw', 'JTT', 'JTT-DCMut', 'LG', 'mtART', 'mtMAM', 'mtREV',
#         'mtZOA', 'PMB', 'rtREV', 'stmtREV', 'VT', 'WAG', 'LG4M', 'LG4X',
#         'PROTGTR']
# JTT_MODEL = ('ML Model: Jones-Taylor-Thorton, CAT '
#              'approximation with 20 rate categories')
# WAG_MODEL = ('ML Model: Whelan-And-Goldman, CAT '
#              'approximation with 20 rate categories')
# LG_MODEL = 'ML Model: Le-Gascuel 2008, CAT approximation with 20 rate categories'


import unittest
import tempfile
import shutil
import json
import copy
import os
import os.path
from taxtastic import refpkg, utils
from . import config


HAS_RPPR = utils.has_rppr()


class TestReadStockholm(unittest.TestCase):
    def setUp(self):
        self.fname = os.path.join(config.data_path('lactobacillus2-0.2.refpkg'),
                                  'lactobacillus2.sto')

    def test01(self):
        with open(self.fname, 'r') as fobj:
            names = utils.parse_stockholm(fobj)
        self.assertEqual(len(names), 46)
        self.assertEqual(names[0], '123f3-34')
        self.assertEqual(names[-1], 'S000727873')

    def test02(self):
        with open(self.fname, 'r') as fobj:
            lines = [line for line in fobj][:-1]

# Path: taxtastic/refpkg.py
# FORMAT_VERSION = '1.1'
# class DerivedFileNotUpdatedWarning(UserWarning):
# class NoAncestor(Exception):
# class Refpkg(object):
# def is_string(val):
# def md5file(fobj):
# def scratch_file(unlink=True, **kwargs):
# def manifest_template():
# def transaction(f, self, *args, **kwargs):
#     def __init__(self, path, create=None):
#     def _install_zipfile_handlers(self):
#         def zipopen(name, *mode):
#         def file_path(name):
#     def file_path(self, name):
#     def open(self, name, *mode):
#     def open_manifest(self, *mode):
#     def open_resource(self, resource, *mode):
#     def resource_name(self, resource):
#     def resource_md5(self, resource):
#     def calculate_resource_md5(self, resource):
#     def resource_path(self, resource):
#     def _set_defaults(self):
#     def _sync_to_disk(self):
#     def _sync_from_disk(self):
#     def _add_file(self, key, path):
#     def _delete_file(self, path):
#     def metadata(self, key):
#     def file_keys(self):
#     def metadata_keys(self):
#     def _log(self, msg):
#     def log(self):
#     def is_invalid(self):
#     def _check_refpkg(self):
#     def update_metadata(self, key, value):
#     def update_file(self, key, new_path):
#     def reroot(self, rppr=None, pretend=False):
#     def update_phylo_model(self, stats_type, stats_file, frequency_type=None):
#     def rollback(self):
#     def rollforward(self):
#     def strip(self):
#     def start_transaction(self):
#     def commit_transaction(self, log=None):
#     def is_ill_formed(self):
#     def load_db(self):
#     def most_recent_common_ancestor(self, *ts):
#     def _large_mrca(self, ts):
#     def _small_mrca(self, ts):
#     def file_abspath(self, resource):
#     def file_name(self, resource):
#     def file_md5(self, resource):
# 
# Path: taxtastic/utils.py
# def get_new_nodes(fname):
# def getlines(fname):
# def try_set_fields(d, regex, text, hook=lambda x: x):
# def parse_raxmlng(handle):
# def parse_raxmlng(handle):
# def parse_raxml(handle):
# def parse_fasttree(fobj):
# def parse_phyml(fobj, frequency_type=None):
# def parse_stockholm(fobj):
# def has_rppr(rppr_name='rppr'):
# def add_database_args(parser):
# def sqlite_default():
#     def parse_url(url):
# def random_name(length):
# class InvalidLogError(ValueError):
# DNA = ['JC', 'K80', 'F81', 'HKY', 'TN93ef', 'TN93', 'K81', 'K81uf', 'TPM2',
#        'TPM2uf', 'TPM3', 'TPM3uf', 'TIM1', 'TIM1uf', 'TIM2', 'TIM2uf',
#        'TIM3', 'TIM3uf', 'TVMef', 'TVM', 'SYM', 'GTR']
# PROT = ['Blosum62', 'cpREV', 'Dayhoff', 'DCMut', 'DEN', 'FLU', 'HIVb',
#         'HIVw', 'JTT', 'JTT-DCMut', 'LG', 'mtART', 'mtMAM', 'mtREV',
#         'mtZOA', 'PMB', 'rtREV', 'stmtREV', 'VT', 'WAG', 'LG4M', 'LG4X',
#         'PROTGTR']
# JTT_MODEL = ('ML Model: Jones-Taylor-Thorton, CAT '
#              'approximation with 20 rate categories')
# WAG_MODEL = ('ML Model: Whelan-And-Goldman, CAT '
#              'approximation with 20 rate categories')
# LG_MODEL = 'ML Model: Le-Gascuel 2008, CAT approximation with 20 rate categories'


# Path: tests/test_refpkg.py
import unittest
import tempfile
import shutil
import json
import copy
import os
import os.path
from taxtastic import refpkg, utils
from . import config



HAS_RPPR = utils.has_rppr()


class TestReadStockholm(unittest.TestCase):
    def setUp(self):
        self.fname = os.path.join(config.data_path('lactobacillus2-0.2.refpkg'),
                                  'lactobacillus2.sto')

    def test01(self):
        with open(self.fname, 'r') as fobj:
            names = utils.parse_stockholm(fobj)
        self.assertEqual(len(names), 46)
        self.assertEqual(names[0], '123f3-34')
        self.assertEqual(names[-1], 'S000727873')

    def test02(self):
        with open(self.fname, 'r') as fobj:
            lines = [line for line in fobj][:-1]

            self.assertRaises(ValueError, utils.parse_stockholm, lines)