def get_summary_counts(counts, max_counts, min_counts, path):
    """
    Get summary counts from the total counts.

    This works iteratively to return a list of tuples:
    [(count, taxonomic_path), ...]

    The function calls itself for any subcategories whose counts exceed
    'max_counts'. Otherwise it returns counts and current path. Categories
    with counts less than 'min_counts' are not reported.
    """
    summary_counts = []
    total = sum([counts[cat]['count'] for cat in counts if cat != 'count'])
    categories = sorted(counts.keys())
    unclassified = 0
    if 'count' in counts:
        this_count = counts.pop('count')
        categories = sorted(counts.keys())
        unclassified = this_count - total
        if unclassified > 0:
            counts['Unclassified'] = {'count': unclassified}
            categories.append('Unclassified')
    for category in categories:
        if (counts[category]['count'] > max_counts and
                [k for k in counts[category] if k != 'count']):
            summary_counts += get_summary_counts(
                counts[category],
                max_counts=max_counts,
                min_counts=min_counts,
                path=path+[category])
        else:
            if counts[category]['count'] >= min_counts:
                summary_counts += [
                    (path+[category], counts[category]['count'])]

    return summary_counts