Skip to content

Type confusion with get_lineage - tax_id can be int, or str #8

@jakobnissen

Description

@jakobnissen

In get_lineage, the types are not specified, and tax_id can be of either int or str. Indeed, the function itself seems confused as to what they are, with both the check tax_id == 1 and the check tax_id != '1'.

def get_lineage(tax_id, map_child_parent):
if tax_id == 0 or tax_id == 1:
logger.info(f"No lineage for ID: {tax_id}")
return ''
if tax_id not in map_child_parent:
logger.info(f"ID not found in NCBI lineage: {tax_id}")
return ''
lineage = []
while tax_id in map_child_parent and tax_id != '1':
lineage.append(tax_id)
tax_id = map_child_parent[tax_id]
if tax_id != '1':
logger.info(f"Parent node warning: {tax_id} is the root, but does not stem from 1. Returning empty lineage.")
return ''
return ';'.join(lineage[::-1])

This causes bugs in a trial run of Taxonverter.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions