This very simple PR fixes issue #2173 and another bug that I found along the way. The fix and its caveats are detailed in #2173, but to summarize:
in most cases, multiple annotations to the same gene are direct alternatives in a given pathway, which means that we can arbitrarily keep one annotation and ignore the rest of them. This is what the new function get_dereplicated_enzyme_hits_for_step_in_module() does before each step's copy number is calculated from the annotation data.
an edge case occurs when the multiple enzyme annotations to that one gene are in a more complex relationship with each other. The simplistic fix might undercount the step copy number in this case, depending on which enzyme annotation was arbitrarily kept for the dereplicated annotation set
I couldn't figure out a better algorithm that handles the edge case properly, so I settled for warning the user about it instead
the other new function are_enzymes_indirect_alternatives_within_step is used to detect the edge cases. It does NOT perfectly detect all indirect relationships between all enzymes in a step and should not be used generally for that purpose, but it works okay for the limited use-case of warning the user about specific overlapping annotations. See #2173 for an example warning.
In short, stepwise copy numbers will no longer be inflated when one gene has multiple annotations. In the worst case, they may be too low rather than too high.
Finally, there was another bug that was also contributing to the inflation of step copy numbers in some cases -- missing annotations for direct alternatives were not counted as 0s if they were the first out of all the alternatives to be considered. This and its fix are also described in #2173, and I will note that it is perhaps the more important of the two fixes because it was not obvious and it affected more modules (15, in my test data, compared to 8 for the multiple annotations bug).
This very simple PR fixes issue #2173 and another bug that I found along the way. The fix and its caveats are detailed in #2173, but to summarize:
get_dereplicated_enzyme_hits_for_step_in_module()
does before each step's copy number is calculated from the annotation data.are_enzymes_indirect_alternatives_within_step
is used to detect the edge cases. It does NOT perfectly detect all indirect relationships between all enzymes in a step and should not be used generally for that purpose, but it works okay for the limited use-case of warning the user about specific overlapping annotations. See #2173 for an example warning.In short, stepwise copy numbers will no longer be inflated when one gene has multiple annotations. In the worst case, they may be too low rather than too high.
Finally, there was another bug that was also contributing to the inflation of step copy numbers in some cases -- missing annotations for direct alternatives were not counted as 0s if they were the first out of all the alternatives to be considered. This and its fix are also described in #2173, and I will note that it is perhaps the more important of the two fixes because it was not obvious and it affected more modules (15, in my test data, compared to 8 for the multiple annotations bug).