def build_lca_map(gen: typing.Iterator, tree: Taxonomy) -> dict:
"""
Build a last common ancestor dictionary
:param sam_inf: path to SAM infile
:param extract_ncbi_tid: function to extract ncbi_tid
:param tree: NCBITree
:return: dict key (query name: string) value (ncbi_tid: int)
"""
lca_map = {}
for qname, rname in gen:
tax = tree(rname)
if qname in lca_map:
current_tax = lca_map[qname]
if current_tax:
if current_tax != tax:
lca_map[qname] = least_common_ancestor((tax, current_tax))
else:
lca_map[qname] = tax
return lca_map
评论列表
文章目录