# 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):


import logging
import csv
import sys
from collections import defaultdict
from fastalite import fastalite
from taxtastic import refpkg
    with open(pkg.file_abspath('taxonomy'), 'rU') as taxtab, open(pkg.file_abspath('seq_info'), 'rU') as seq_info:
        taxdict = {row['tax_id']: row for row in csv.DictReader(taxtab)}

        tax_ids = [d['tax_id'] for d in csv.DictReader(seq_info)]

    for tax_id in tax_ids:
        tally[tax_id] += 1

    rows = [(taxdict[tax_id]['tax_name'], tax_id, count)
            for tax_id, count in list(tally.items())]

    writer = csv.writer(sys.stdout, quoting=csv.QUOTE_NONNUMERIC)
    writer.writerows(sorted(rows))


def print_lengths(pkg):
    with pkg.open_resource('aln_fasta') as f:
        seqs = fastalite(f)
    writer = csv.writer(sys.stdout)
    writer.writerow(["seqname", "length"])
    for seq in seqs:
        writer.writerow([seq.id, len(str(seq.seq).replace('-', ''))])


def action(args):
    """
    Show information about reference packages.
    """
    log.info('loading reference package')


# 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/subcommands/info.py
import logging
import csv
import sys
from collections import defaultdict
from fastalite import fastalite
from taxtastic import refpkg

    with open(pkg.file_abspath('taxonomy'), 'rU') as taxtab, open(pkg.file_abspath('seq_info'), 'rU') as seq_info:
        taxdict = {row['tax_id']: row for row in csv.DictReader(taxtab)}

        tax_ids = [d['tax_id'] for d in csv.DictReader(seq_info)]

    for tax_id in tax_ids:
        tally[tax_id] += 1

    rows = [(taxdict[tax_id]['tax_name'], tax_id, count)
            for tax_id, count in list(tally.items())]

    writer = csv.writer(sys.stdout, quoting=csv.QUOTE_NONNUMERIC)
    writer.writerows(sorted(rows))


def print_lengths(pkg):
    with pkg.open_resource('aln_fasta') as f:
        seqs = fastalite(f)
    writer = csv.writer(sys.stdout)
    writer.writerow(["seqname", "length"])
    for seq in seqs:
        writer.writerow([seq.id, len(str(seq.seq).replace('-', ''))])


def action(args):
    """
    Show information about reference packages.
    """
    log.info('loading reference package')


    pkg = refpkg.Refpkg(args.refpkg, create=False)