Skip to content

Improved microbial enzyme secretion model#801

Merged
jacobcook1995 merged 9 commits intodevelopfrom
760-microbial-enzyme-secretion-model-needs-to-be-improved
Mar 27, 2025
Merged

Improved microbial enzyme secretion model#801
jacobcook1995 merged 9 commits intodevelopfrom
760-microbial-enzyme-secretion-model-needs-to-be-improved

Conversation

@jacobcook1995
Copy link
Copy Markdown
Collaborator

Description

This PR changes how the calculation of enzyme secretion by microbes so that microbes have an allocate a certain fraction of new biomass to extracellular enzymes (previously it was a fraction of cellular maintenance). The reason behind this change is that it allows enzymes to have different stochiometries to the microbes producing them. This is something that needs to be added before fungi can be split between mycorrhizal and saprotrophic.

The main structural change arises because the microbial groups now need information about the enzyme classes (so that the average stoichiometry of the synthesised biomass can be found). So now a set of EnzymeConstants has to be provided for the creation of a MicrobialGroupConstants data class. Feedback on this would be appreciated!

I also fixed a bug I noticed with the calculation of microbial pH suitability.

Fixes #760 #779

Type of change

  • New feature (non-breaking change which adds functionality)
  • Optimization (back-end change that speeds up the code)
  • Bug fix (non-breaking change which fixes an issue)

Key checklist

  • Make sure you've run the pre-commit checks: $ pre-commit run -a
  • All tests pass: $ poetry run pytest

Further checks

  • Code is commented, particularly in hard-to-understand areas
  • Tests added that prove fix is effective or that feature works
  • Relevant documentation reviewed and updated

@jacobcook1995 jacobcook1995 linked an issue Mar 25, 2025 that may be closed by this pull request
@jacobcook1995 jacobcook1995 requested review from dalonsoa, davidorme and sallymatson and removed request for dalonsoa March 25, 2025 12:49
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Mar 25, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.64%. Comparing base (4c03507) to head (9a5c71a).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #801      +/-   ##
===========================================
+ Coverage    94.62%   94.64%   +0.01%     
===========================================
  Files           74       74              
  Lines         5102     5120      +18     
===========================================
+ Hits          4828     4846      +18     
  Misses         274      274              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Collaborator

@dalonsoa dalonsoa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just made a small, maths-related comment, but all looks good otherwise. Quite an interesting business!

Comment on lines +185 to +204
enzyme_c_n_weighted = sum(
enzyme_classes[f"{name}_{substrate}"].c_n_ratio
* allocation
/ total_enzyme_allocation
for substrate, allocation in enzyme_production.items()
)

enzyme_c_p_weighted = sum(
enzyme_classes[f"{name}_{substrate}"].c_p_ratio
* allocation
/ total_enzyme_allocation
for substrate, allocation in enzyme_production.items()
)

return {
"nitrogen": (c_n_ratio + enzyme_c_n_weighted * total_enzyme_allocation)
/ (1.0 + total_enzyme_allocation),
"phosphorus": (c_p_ratio + enzyme_c_p_weighted * total_enzyme_allocation)
/ (1.0 + total_enzyme_allocation),
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, let someone check my maths, but I think that you can take the dividing total_enzyme_allocation out of the sums, in which case it will cancel with the multiplying one below:

Suggested change
enzyme_c_n_weighted = sum(
enzyme_classes[f"{name}_{substrate}"].c_n_ratio
* allocation
/ total_enzyme_allocation
for substrate, allocation in enzyme_production.items()
)
enzyme_c_p_weighted = sum(
enzyme_classes[f"{name}_{substrate}"].c_p_ratio
* allocation
/ total_enzyme_allocation
for substrate, allocation in enzyme_production.items()
)
return {
"nitrogen": (c_n_ratio + enzyme_c_n_weighted * total_enzyme_allocation)
/ (1.0 + total_enzyme_allocation),
"phosphorus": (c_p_ratio + enzyme_c_p_weighted * total_enzyme_allocation)
/ (1.0 + total_enzyme_allocation),
}
enzyme_c_n_weighted = sum(
enzyme_classes[f"{name}_{substrate}"].c_n_ratio
* allocation
for substrate, allocation in enzyme_production.items()
)
enzyme_c_p_weighted = sum(
enzyme_classes[f"{name}_{substrate}"].c_p_ratio
* allocation
for substrate, allocation in enzyme_production.items()
)
return {
"nitrogen": (c_n_ratio + enzyme_c_n_weighted)
/ (1.0 + total_enzyme_allocation),
"phosphorus": (c_p_ratio + enzyme_c_p_weighted)
/ (1.0 + total_enzyme_allocation),
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are right! I think I was overly focused on the line-by-line logic so I lost the big picture

@jacobcook1995 jacobcook1995 merged commit 606cff7 into develop Mar 27, 2025
16 checks passed
@jacobcook1995 jacobcook1995 deleted the 760-microbial-enzyme-secretion-model-needs-to-be-improved branch March 27, 2025 09:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Microbial enzyme secretion model needs to be improved

3 participants