Parse a single kraken-report entry and return a dictionary of taxa for its
    named ranks.

    :type entry: dict
    :param entry: attributes of a single kraken-report row.
    :type tax_lvl_depth: list
    :param tax_lvl_depth: running record of taxon levels encountered in
    previous calls.

def parse_tax_lvl(entry, tax_lvl_depth=[]):
    """
    Parse a single kraken-report entry and return a dictionary of taxa for its
    named ranks.

    :type entry: dict
    :param entry: attributes of a single kraken-report row.
    :type tax_lvl_depth: list
    :param tax_lvl_depth: running record of taxon levels encountered in
    previous calls.
    """
    # How deep in the hierarchy are we currently?  Each two spaces of
    # indentation is one level deeper.  Also parse the scientific name at this
    # level.
    depth_and_name = re.match('^( *)(.*)', entry['sci_name'])
    depth = len(depth_and_name.group(1))//2
    name = depth_and_name.group(2)
    # Remove the previous levels so we're one higher than the level of the new
    # taxon.  (This also works if we're just starting out or are going deeper.)
    del tax_lvl_depth[depth:]
    # Append the new taxon.
    tax_lvl_depth.append((entry['rank'], name))
    # Create a tax_lvl dict for the named ranks.
    tax_lvl = {x[0]: x[1] for x in tax_lvl_depth if x[0] in ranks}
    return(tax_lvl)