Skip to content

Commit

Permalink
fix modules db brite table to hierarchy dict method
Browse files Browse the repository at this point in the history
  • Loading branch information
semiller10 committed Dec 15, 2024
1 parent af3e65c commit 61132aa
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions anvio/kegg.py
Original file line number Diff line number Diff line change
Expand Up @@ -9075,8 +9075,15 @@ def get_brite_table_as_ortholog_dict(self, ortholog_accessions_of_interest=None,
return ortholog_dict


def get_brite_table_as_hierarchy_dict(self, hierarchy_accessions_of_interest=None, level_cutoff=None, collapse_keys=False, collapse_mixed_branches=True):
"""Load the BRITE hierarchies table as a dictionary keyed by hierarchy.
def get_brite_table_as_hierarchy_dict(
self,
hierarchy_accessions_of_interest=None,
level_cutoff=None,
collapse_keys=False,
collapse_mixed_branches=True
):
"""
Load the BRITE hierarchies table as a dictionary keyed by hierarchy.

The returned dictionary contains the category structure of the hierarchy and a set of
orthologs in each categorization.
Expand Down Expand Up @@ -9302,22 +9309,25 @@ def get_brite_table_as_hierarchy_dict(self, hierarchy_accessions_of_interest=Non
# find the maximum depth of each hierarchy
max_depth_dict = self.get_brite_max_depth_dict(dict_from_brite_table)

if level_cutoff == 0 or type(level_cutoff) != int:
if level_cutoff is not None and (level_cutoff == 0 or type(level_cutoff) != int):
raise ConfigError("`level_cutoff` must be a nonzero integer.")

# set the level cutoff for each hierarchy
if level_cutoff > 0:
if level_cutoff is None:
topdown_level_cutoff_dict = max_depth_dict
elif level_cutoff > 0:
topdown_level_cutoff_dict = {hierarchy_accession: min(level_cutoff, max_depth) for hierarchy_accession, max_depth in max_depth_dict.items()}
elif level_cutoff < 0:
else:
# find the positive level corresponding to the negative level cutoff for each
# hierarchy, ensuring that at least one category remains per hierarchy
topdown_level_cutoff_dict = {hierarchy_accession: max(max_depth + level_cutoff, 1) for hierarchy_accession, max_depth in max_depth_dict.items()}
else:
topdown_level_cutoff_dict = max_depth_dict

# hierarchy level cutoffs can be affected by collapsing subcategories of mixed categories
if collapse_mixed_branches:
topdown_level_cutoff_dict = self.get_brite_topdown_level_cutoff_dict_ignoring_subcategories_of_mixed_categories(topdown_level_cutoff_dict, dict_from_brite_table)
topdown_level_cutoff_dict = self.get_brite_depth_dict_ignoring_subcategories_of_mixed_categories(
dict_from_brite_table=dict_from_brite_table,
input_depth_dict=topdown_level_cutoff_dict
)

# create the per-hierarchy dict
hierarchy_dict = {}
Expand Down

0 comments on commit 61132aa

Please sign in to comment.