From 5d9c929eec00c82e8771ca51afc66b0f5c3c09d2 Mon Sep 17 00:00:00 2001 From: Benjamin Coltman Date: Mon, 9 Sep 2024 11:08:20 +0200 Subject: [PATCH 1/3] Revert to seperating the ko_stray_dict as a seperate entity. Fixes issues when calling: anvi-estimate-metabolism --include-stray-KOs Which would lead to the following errors: Traceback (most recent call last): File github/anvio/bin/anvi-estimate-metabolism, line 148, in main(args) File github/anvio/anvio/terminal.py, line 915, in wrapper program_method(*args, **kwargs) File github/anvio/bin/anvi-estimate-metabolism, line 39, in main m.estimate_metabolism() File github/anvio/anvio/kegg.py, line 6014, in estimate_metabolism kegg_metabolism_superdict, kofam_hits_superdict = self.estimate_for_genome(kofam_hits_info) File github/anvio/anvio/kegg.py, line 5516, in estimate_for_genome self.append_kegg_metabolism_superdicts(genome_metabolism_superdict, genome_ko_superdict) File github/anvio/anvio/kegg.py, line 6557, in append_kegg_metabolism_superdicts output_dict = self.generate_output_dict_for_kofams(ko_superdict_for_list_of_splits, headers_to_include=header_list) File github/anvio/anvio/kegg.py, line 6416, in generate_output_dict_for_kofams metadata_dict = self.get_ko_metadata_dictionary(ko, dont_fail_if_not_found=True) File github/anvio/anvio/kegg.py, line 3456, in get_ko_metadata_dictionary elif self.include_stray_kos and self.stray_ko_dict and knum in self.stray_ko_dict: AttributeError: 'KeggMetabolismEstimator' object has no attribute 'stray_ko_dict'. Did you mean: 'setup_ko_dict'? --- anvio/kegg.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/anvio/kegg.py b/anvio/kegg.py index 1811a9ae3..2495777a5 100644 --- a/anvio/kegg.py +++ b/anvio/kegg.py @@ -4211,7 +4211,7 @@ def __init__(self, args, run=run, progress=progress): # (henceforth referred to as the KO dict, even though it doesn't only contain KOs for user data) self.setup_ko_dict(exclude_threshold=self.exclude_kos_no_threshold) if self.include_stray_kos: - self.setup_stray_ko_dict(add_entries_to_regular_ko_dict=True) + self.setup_stray_ko_dict(add_entries_to_regular_ko_dict=False) annotation_source_set = set(['KOfam']) # check for kegg modules db From 62632848f739ea45c56c8ea8c897905c041a6e85 Mon Sep 17 00:00:00 2001 From: Iva Veseli Date: Wed, 11 Sep 2024 12:09:27 +0200 Subject: [PATCH 2/3] initialize stray ko dict attribute to None even if we are putting those kos in the regular dict --- anvio/kegg.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/anvio/kegg.py b/anvio/kegg.py index 085b76a3e..6aeef61f4 100644 --- a/anvio/kegg.py +++ b/anvio/kegg.py @@ -459,6 +459,8 @@ def setup_stray_ko_dict(self, add_entries_to_regular_ko_dict=False): if add_entries_to_regular_ko_dict: stray_kos = utils.get_TAB_delimited_file_as_dictionary(self.stray_ko_thresholds_file) self.ko_dict.update(stray_kos) + # initialize it to None so that things don't break if we try to access this downstream + self.stray_ko_dict = None else: self.stray_ko_dict = utils.get_TAB_delimited_file_as_dictionary(self.stray_ko_thresholds_file) else: From bff78bcda9bf5f6af8b32237feedd648782fcccd Mon Sep 17 00:00:00 2001 From: Iva Veseli Date: Wed, 11 Sep 2024 12:24:35 +0200 Subject: [PATCH 3/3] another place where we should not depend on stray KOs being in the regular ko dict --- anvio/kegg.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/anvio/kegg.py b/anvio/kegg.py index 6aeef61f4..433e483b4 100644 --- a/anvio/kegg.py +++ b/anvio/kegg.py @@ -3702,7 +3702,7 @@ def init_data_from_modules_db(self): # if we have our own versions of any stray KOs, then we include them here to enable lookups downstream k_anvio = f"{k}{STRAY_KO_ANVIO_SUFFIX}" - if self.include_stray_kos and k_anvio in self.ko_dict: + if self.include_stray_kos and (k_anvio in self.ko_dict or (self.stray_ko_dict and k_anvio in self.stray_ko_dict)): if k_anvio not in self.all_kos_in_db: src = 'KOfam' func = self.all_modules_in_db[mod]['ORTHOLOGY'][k] if 'ORTHOLOGY' in self.all_modules_in_db[mod] else self.ko_dict[k_anvio]['definition']