# 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: taxtastic/taxdb.py
# class OnUpdate(object):
# class _IntermediateTaxon(object):
# class Taxdb(object):
#     def __init__(self, proxied):
#     def __get__(self, inst, cls):
#     def __set__(self, inst, value):
#     def __call__(self, f):
#     def __init__(self, tax_id, parent, rank, tax_name):
#     def parent(self, p):
#     def adjacent_to(self, n):
#     def iterate_children(self, on_pop=None, including_self=True):
#     def __init__(self, sqlite_db=None):
#     def __getattr__(self, attr):
#     def create_tables(self):
#     def insert_from_taxtable(self, fieldnames_cb, table):
#         def on_pop(parent):


import errno
import os
import time
import warnings
import sys
import contextlib
import copy
import csv
import functools
import hashlib
import json
import shutil
import subprocess
import tempfile
import zipfile
import dendropy
from decorator import decorator
from fastalite import fastalite
from taxtastic import utils, taxdb
            if k not in self.contents['files']:
                return "RefPkg has no key " + k

        # aln_fasta, seq_info, tree, and aln_sto must be valid FASTA,
        # CSV, Newick, and Stockholm files, respectively, and describe
        # the same sequences.

        with self.open_resource('aln_fasta') as f:
            firstline = f.readline()
            if firstline.startswith('>'):
                f.seek(0)
            else:
                return 'aln_fasta file is not valid FASTA.'
            fasta_names = {seq.id for seq in fastalite(f)}

        with self.open_resource('seq_info') as f:
            lines = list(csv.reader(f))
            headers = set(lines[0])

            # Check required headers
            for req_header in 'seqname', 'tax_id':
                if req_header not in headers:
                    return "seq_info is missing {0}".format(req_header)
            lengths = {len(line) for line in lines}
            if len(lengths) > 1:
                return "some lines in seq_info differ in field cout"
            csv_names = {line[0] for line in lines[1:]}

        with self.open_resource('aln_sto') as f:
            try:

# 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: taxtastic/taxdb.py
# class OnUpdate(object):
# class _IntermediateTaxon(object):
# class Taxdb(object):
#     def __init__(self, proxied):
#     def __get__(self, inst, cls):
#     def __set__(self, inst, value):
#     def __call__(self, f):
#     def __init__(self, tax_id, parent, rank, tax_name):
#     def parent(self, p):
#     def adjacent_to(self, n):
#     def iterate_children(self, on_pop=None, including_self=True):
#     def __init__(self, sqlite_db=None):
#     def __getattr__(self, attr):
#     def create_tables(self):
#     def insert_from_taxtable(self, fieldnames_cb, table):
#         def on_pop(parent):


# Path: taxtastic/refpkg.py
import errno
import os
import time
import warnings
import sys
import contextlib
import copy
import csv
import functools
import hashlib
import json
import shutil
import subprocess
import tempfile
import zipfile
import dendropy
from decorator import decorator
from fastalite import fastalite
from taxtastic import utils, taxdb

            if k not in self.contents['files']:
                return "RefPkg has no key " + k

        # aln_fasta, seq_info, tree, and aln_sto must be valid FASTA,
        # CSV, Newick, and Stockholm files, respectively, and describe
        # the same sequences.

        with self.open_resource('aln_fasta') as f:
            firstline = f.readline()
            if firstline.startswith('>'):
                f.seek(0)
            else:
                return 'aln_fasta file is not valid FASTA.'
            fasta_names = {seq.id for seq in fastalite(f)}

        with self.open_resource('seq_info') as f:
            lines = list(csv.reader(f))
            headers = set(lines[0])

            # Check required headers
            for req_header in 'seqname', 'tax_id':
                if req_header not in headers:
                    return "seq_info is missing {0}".format(req_header)
            lengths = {len(line) for line in lines}
            if len(lengths) > 1:
                return "some lines in seq_info differ in field cout"
            csv_names = {line[0] for line in lines[1:]}

        with self.open_resource('aln_sto') as f:
            try:

                sto_names = set(utils.parse_stockholm(f))