OSCR

Physics-constrained neural ordinary differential equation models to discover and predict microbial community dynamics.

Code ↔ Paper

The paper beside its authors' code: matches between them have not been computed for this paper yet.

Paper

Loaded from Europe PMC by your browser; OSCR does not store it: doi.org · Europe PMC

The paper is loaded when this pane is shown.

The authors' code

Jupyter notebook · 290 lines · 7.9 KB · no license

  1. # %%
  2. import numpy as np
  3. import itertools
  4. import pandas as pd
  5. import matplotlib.pyplot as plt
  6. import seaborn as sns
  7. import scipy as sp
  8. from scipy.stats import linregress
  9. import pickle
  10. import time
  11. from nsm.nsm import *
  12. # set plot parameters
  13. params = {'legend.fontsize': 18,
  14. 'figure.figsize': (8, 7),
  15. 'axes.labelsize': 24,
  16. 'axes.titlesize':24,
  17. 'axes.linewidth':3,
  18. 'xtick.labelsize':20,
  19. 'ytick.labelsize':20,
  20. 'xtick.labelsize':20,
  21. 'ytick.labelsize':20}
  22. plt.rcParams.update(params)
  23. # plt.style.use('seaborn-colorblind')
  24. plt.rcParams['pdf.fonttype'] = 42
  25. np.random.seed(123456)
  26. # %% [markdown]
  27. # # Import data
  28. # %%
  29. # import Ryan's 25 mem community data
  30. df = pd.read_csv("data/clark.csv")
  31. # %%
  32. # df_4t = []
  33. # for t, df_t in df.groupby('Treatments'):
  34. # if df_t.shape[0]>2:
  35. # df_4t.append(df_t)
  36. # df = pd.concat(df_4t)
  37. # %%
  38. # define species and metabolites
  39. species = ['ER_OD','FP_OD','AC_OD','CC_OD','RI_OD','DP_OD','BH_OD','CA_OD','PC_OD','DL_OD','CG_OD','BF_OD','EL_OD','CH_OD','BO_OD','BT_OD','BU_OD','BV_OD','BC_OD','BY_OD','PJ_OD','DF_OD','BL_OD','BP_OD','BA_OD']
  40. mediators = ['Acetate', 'Butyrate', 'Lactate', 'Succinate']
  41. inputs = []
  42. # %%
  43. # normalize metabolites to [0, 1]
  44. df[mediators] /= df[mediators].max()
  45. df[mediators]
  46. # %%
  47. # init model
  48. model = NSM(dataframe=df,
  49. species=species,
  50. mediators=mediators,
  51. inputs=inputs,
  52. n_hidden=32, n_layers=1,
  53. nu2=.001, sigma2=.01)
  54. # init params
  55. model.init_params(sample=False)
  56. print(f"Number of parameters: {model.n_params}")
  57. # %%
  58. print(f"Total parameters: {model.n_params}")
  59. t0 = time.time()
  60. model.fit_posterior_EM(lr=.001,
  61. n_sample=1,
  62. n_sample_hypers=100,
  63. max_epochs=10000,
  64. patience=1, max_iterations=10)
  65. print("Elapsed time: {:.3f}s".format(time.time()-t0))
  66. # %%
  67. model.nu2
  68. # %%
  69. model.sigma2
  70. # %%
  71. # Define function to make predictions on test data
  72. def plot_sample(model, df_test):
  73. # save true values and predictions
  74. true = []
  75. pred = []
  76. spcs = []
  77. # pull a random community trajectory
  78. for treatment, comm_data in df_test.groupby("Treatments"):
  79. # make sure comm_data is sorted in chronological order
  80. comm_data.sort_values(by='Time', ascending=True, inplace=True)
  81. tspan = comm_data.Time.values
  82. # pull just the community data
  83. species_true = comm_data[species].values
  84. mediators_true = comm_data[mediators].values
  85. input_vals = comm_data[inputs].values[0]
  86. output_true = np.concatenate((species_true, mediators_true), -1)
  87. # determine initial condition
  88. s0 = species_true[0]
  89. r0 = mediators_true[0]
  90. x0 = np.concatenate((s0, r0))
  91. # increase teval
  92. t_eval = np.linspace(0, tspan[-1] + 5., 100)
  93. steps = len(t_eval)
  94. # generate posterior samples
  95. species_pred, mediators_pred = model.predict_sample(x0,
  96. t_eval,
  97. n_sample=50,
  98. inputs=input_vals)
  99. # compute summary statistics (mean and variance) of posterior predictive distribution
  100. E_species_pred, V_species_pred, E_mediators_pred, V_mediators_pred = model.predict(x0,
  101. t_eval,
  102. n_sample=100,
  103. inputs=input_vals)
  104. # concatenate species and mediator predictions
  105. output_pred = np.concatenate((species_pred, mediators_pred), -1)
  106. E_output_pred = np.concatenate((E_species_pred, E_mediators_pred), -1)
  107. V_output_pred = np.concatenate((V_species_pred, V_mediators_pred), -1)
  108. # predict end-point measured values
  109. true.append(output_true[-1])
  110. pred.append(E_output_pred[-1])
  111. spcs.append(species+mediators)
  112. # plot the results
  113. '''plt.figure(figsize=(8, 6))
  114. k = 0
  115. for i, sp in enumerate(species+mediators):
  116. if sp in mediators:
  117. out_true = output_true[:,i]
  118. plt.scatter(tspan, out_true, color='C{}'.format(k), edgecolor='k', s=100, zorder=2, label=sp)
  119. # plot posterior samples
  120. for out in output_pred:
  121. plt.plot(t_eval, out[:, i], color='C{}'.format(k), alpha=.15, zorder=0)
  122. # plot posterior predictive as a Gaussian
  123. plt.fill_between(t_eval,
  124. E_output_pred[:,i] - V_output_pred[:, i] ** .5,
  125. E_output_pred[:,i] + V_output_pred[:, i] ** .5,
  126. color='C{}'.format(k), alpha=0.2)
  127. # plot mean of posterior
  128. plt.plot(t_eval, E_output_pred[:,i], color='C{}'.format(k), linewidth=3, zorder=1)
  129. k += 1
  130. plt.axhline(y=0, linestyle='-', color='k', alpha=.5)
  131. plt.xlabel("Time (hr)")
  132. plt.ylabel("Species abundance")
  133. plt.legend(fontsize=14, loc='upper left')
  134. # plt.title(input_vals)
  135. # plt.ylim([0, .5])
  136. plt.tight_layout()
  137. plt.savefig("figures/trajectories/nsm.pdf")
  138. plt.title("NSM")
  139. plt.show()
  140. # break'''
  141. return true, pred, spcs
  142. # %%
  143. true, pred, spcs = plot_sample(model, df)
  144. # %%
  145. true = np.array(true).ravel()
  146. pred = np.array(pred).ravel()
  147. # %%
  148. mediator = 'AC_OD'
  149. inds = np.array(spcs).ravel() == mediator
  150. plt.scatter(true[inds], pred[inds])
  151. print(linregress(true[inds], pred[inds]))
  152. plt.title(mediator)
  153. plt.show()
  154. # %%
  155. for mediator in mediators:
  156. inds = np.array(spcs).ravel() == mediator
  157. plt.scatter(true[inds], pred[inds])
  158. print(linregress(true[inds], pred[inds]))
  159. plt.title(mediator)
  160. plt.show()
  161. # %%
  162. def get_params(self, n_sample=100):
  163. # parameter names
  164. param_names = []
  165. # consumption rates
  166. for md in self.mediators:
  167. for sp in self.species:
  168. param_names += [md+"->"+sp]
  169. # production rates
  170. for md in self.mediators:
  171. for sp in self.species:
  172. param_names += [sp+"->"+md]
  173. # sample parameters
  174. y = np.random.randn(n_sample, self.d)
  175. z = batch_T(self.shapes, y, self.lmbda)
  176. # init vector to store parameter samples
  177. params = np.zeros([n_sample, 2 * self.n_m * self.n_s])
  178. # transform and reshape parameters
  179. for i, z_i in enumerate(z):
  180. # transform / reshape parameters
  181. C_i, P_i, *rest = transform(reshape(self.shapes, z_i))
  182. params[i] = np.append(C_i.ravel(), P_i.ravel())
  183. # compute mean / stdv
  184. # C_mean = np.mean(C, 0).ravel()
  185. # C_stdv = np.std(C, 0).ravel()
  186. # P_mean = np.mean(P, 0).ravel()
  187. # P_stdv = np.std(P, 0).ravel()
  188. # save to dataframe
  189. param_df = pd.DataFrame()
  190. # param_df['Parameter'] = param_names
  191. # param_df['$\mu$'] = np.append(C_mean, P_mean)
  192. # param_df['$\sigma$'] = np.append(C_stdv, P_stdv)
  193. param_df[param_names] = np.array(params, float)
  194. return param_df
  195. # %%
  196. param_df = get_params(model)
  197. # %%
  198. plt.hist(param_df['Butyrate->AC_OD'].values)
  199. plt.show()
  200. # %%
  201. plt.hist(param_df['AC_OD->Butyrate'].values)
  202. plt.show()
  203. # %%
  204. C, P, d_m = params[0], params[1], params[2]
  205. # %%
  206. mediators
  207. # %%
  208. np.round(P[1][np.argsort(P[1])[::-1]], 3)
  209. # %%
  210. np.array(species)[np.argsort(P[1])[::-1]]
  211. # %%
  212. np.round(C[1][np.argsort(C[1])[::-1]], 3)
  213. # %%
  214. np.array(species)[np.argsort(C[1])[::-1]]
  215. # %%
  216. np.round(P[0][np.argsort(P[0])[::-1]], 2)
  217. # %%
  218. np.array(species)[np.argsort(P[0])[::-1]]
  219. # %%
  220. np.array(species)[np.argsort(P2[1])]
  221. # %%
  222. np.array(species)[np.argmax(C2[1])]
  223. # %%
  224. d_m

CR_clark_fit (P ds_dt + C s)-checkpoint.ipynb at commit 28caf3b, no license · at the source

Overview

Authors: Jaron Thompson1,2, Bryce M Connors1,2, Victor M Zavala1, Ophelia S Venturelli1,2,3,4
  1. Department of Chemical and Biological Engineering, University of Wisconsin-Madison, Madison, WI 53706
  2. Department of Biochemistry, University of Wisconsin-Madison, Madison, WI 53706
  3. Department of Biological Engineering, Duke University, Durham, NC 27708
  4. Department of Molecular Genetics and Microbiology, Duke University, Durham, NC 27708
Institutions: University of Wisconsin–Madison (United States); Duke University (United States)
Dates: received 9 July 2025; accepted 19 February 2026; published online 27 March 2026; in print 31 March 2026
Type: Research article · Language: English
License: CC BY-NC-ND
Identifiers: DOI 10.1073/pnas.2517661123 · PMID 41894324 · PMCID PMC13037942 · OpenAlex W7141338503
Open access: hybrid, a free copy (OpenAlex)
Status: code verified (how the code is found and verified)
Categories: computational modeling (no new data) (modality), none (in silico) (organism)
Keywords: microbial communities, microbial interaction networks, physics-informed machine learning, neural ordinary differential equations, nonlinear dynamical systems
MeSH: Microbiota*, Models, Biological*, Neural Networks, Computer*, Machine Learning, Predictive Learning Models (* major topic)
Topic: Microbial Metabolic Engineering and Bioproduction (Molecular Biology, Biochemistry, Genetics and Molecular Biology), according to OpenAlex
Funding: National Science Foundation (NSF) (CBET-2315963); DOD | ARPA | Defense Sciences Office, DARPA (DSO) (HR00112320001, HR00112530072); HHS | National Institutes of Health (R01EB030340); NIBIB NIH HHS (R01 EB030340)
Citations: cited by 5 papers (Europe PMC); 59 references in the paper

Abstract

The abstract is not reproduced here: the paper's license (CC BY-NC-ND) does not allow it. Read it in the paper, at the publisher or on Europe PMC.

Repository

Its files are read in the Code ↔ Paper reader above.

VenturelliLab/Thompson_et_al_2025

License: none: the authors keep all their rights
State: the link answers, verified on 30 September 2026
Evidence: files inventoried
Commit: 28caf3ba3ead37b2a796896cde9e960ba4c06ee6, 9 March 2026
Languages: Jupyter (172), Python (72), Shell (31)
Size: 11,758 files, 275 scripts
Software Heritage: not archived
Found in: “Data, Materials, and Software Availability”
Holds: 12 notebooks
Not found: README, license file, CITATION.cff, environment file, tests, continuous integration, documentation
Tools: Matplotlib (14 files), NumPy (14 files), pandas (14 files), SciPy (13 files), seaborn (10 files), SHAP (2 files)
Availability: 1 check, the latest on 30 September 2026: the link answers
  • 30 September 2026: the link answers
14 files

The paper's code and data availability statement is in the Data section.

Tracing map

Proposed by the machine: these links were found in the paper and verified at the source, without human review. The map will receive a Zenodo DOI once one of the paper's authors has validated it with their ORCID.

What the map holds:

  • 1 repository of the authors' code, each at its verified commit, with its license and how the link was found in the paper;
  • 14 scripts, each with its path and the digest of its content;
  • no match between paragraphs and code yet;
  • neither the text of the paper nor the code itself.

Its JSON (tracing-map.json) is deposited on Zenodo with its DOI once the map is validated.

Data

Datasets cited

Code and data availability statement

The paper has a code and data availability statement. Its license (CC BY-NC-ND) does not allow reproducing it here; in short, from what the harvester recognized in it:

Read it in the paper: doi.org/10.1073/pnas.2517661123.

Versions

The history of this record: each version stored by the harvester or made by a correction of its authors or of the maintainers of its code, and what changed in its facts. The texts of the paper (its abstract, its availability statements) are not part of it; versions that changed only those are not listed.

Version 1, 30 September 2026: the first record

Recorded: type, language, journal, volume, issue, pages, dates, 4 authors, 5 keywords, 5 MeSH terms, 4 funders, 35 references.

Cite

This paper

Thompson, J., Connors, B. M., Zavala, V. M., & Venturelli, O. S. (2026). Physics-constrained neural ordinary differential equation models to discover and predict microbial community dynamics. Proceedings of the National Academy of Sciences of the United States of America, 123(13), e2517661123. https://doi.org/10.1073/pnas.2517661123

BibTeX

@article{thompson2026physics,
author = {Thompson, Jaron and Connors, Bryce M and Zavala, Victor M and Venturelli, Ophelia S},
title = {{Physics-constrained neural ordinary differential equation models to discover and predict microbial community dynamics}},
journal = {Proceedings of the National Academy of Sciences of the United States of America},
year = {2026},
month = mar,
volume = {123},
number = {13},
pages = {e2517661123},
publisher = {National Academy of Sciences},
issn = {0027-8424},
doi = {10.1073/pnas.2517661123},
url = {https://doi.org/10.1073/pnas.2517661123},
pmid = {41894324},
pmcid = {PMC13037942}
}

RIS

TY - JOUR
AU - Thompson, Jaron
AU - Connors, Bryce M
AU - Zavala, Victor M
AU - Venturelli, Ophelia S
TI - Physics-constrained neural ordinary differential equation models to discover and predict microbial community dynamics
T2 - Proceedings of the National Academy of Sciences of the United States of America
J2 - Proc Natl Acad Sci U S A
PY - 2026
DA - 2026/03/27
VL - 123
IS - 13
SP - e2517661123
SN - 0027-8424
PB - National Academy of Sciences
DO - 10.1073/pnas.2517661123
UR - https://doi.org/10.1073/pnas.2517661123
LA - en
ER -

CSL-JSON

{
"id": "10.1073/pnas.2517661123",
"type": "article-journal",
"title": "Physics-constrained neural ordinary differential equation models to discover and predict microbial community dynamics",
"container-title": "Proceedings of the National Academy of Sciences of the United States of America",
"author": [
{
"family": "Thompson",
"given": "Jaron"
},
{
"family": "Connors",
"given": "Bryce M"
},
{
"family": "Zavala",
"given": "Victor M"
},
{
"family": "Venturelli",
"given": "Ophelia S"
}
],
"container-title-short": "Proc Natl Acad Sci U S A",
"volume": "123",
"issue": "13",
"page": "e2517661123",
"DOI": "10.1073/pnas.2517661123",
"PMID": "41894324",
"PMCID": "PMC13037942",
"ISSN": "0027-8424",
"publisher": "National Academy of Sciences",
"URL": "https://doi.org/10.1073/pnas.2517661123",
"language": "en",
"issued": {
"date-parts": [
[
2026,
3,
27
]
]
}
}

The tracing map gets a citation of its own once an author has validated it and it has a DOI.

Similar papers

The papers with a page that share the most with this one: the tools found in their code, their categories, datasets, cited references and authors, the rarest counting most.

[1] doi:10.1126/sciadv.adj0400 [code]
A digital twin of the infant microbiome to predict neurodevelopmental deficits.
Journal: Science advances
In common: SHAP, seaborn, pandas, 3 other tools, 1 reference
[2] doi:10.1016/j.celrep.2026.117793 [code]
Clustered inputs engage dendritic nonlinearities and calcium signaling to support efficient place-field formation in CA1 pyramidal neurons.
Journal: Cell reports
In common: SHAP, seaborn, pandas, 3 other tools, none (in silico), computational modeling (no new data)
[3] doi:10.1038/s44387-025-00053-3 [code]
Uncertainty-aware genomic deep learning with knowledge distillation.
Journal: NPJ artificial intelligence
In common: SHAP, seaborn, pandas, 3 other tools, none (in silico), computational modeling (no new data)
[4] doi:10.1117/1.jbo.31.2.026004 [code]
Learning to simulate realistic human diffuse reflectance spectra.
Journal: Journal of biomedical optics
In common: SHAP, seaborn, pandas, 3 other tools, computational modeling (no new data)
[5] doi:10.1038/s41746-025-01484-7 [code]
Predicting clinical pathways of traumatic brain injuries (TBIs) through process mining.
Journal: NPJ digital medicine
In common: SHAP, seaborn, pandas, 3 other tools, computational modeling (no new data)
[6] doi:10.1371/journal.pcbi.1012356 [code]
Regression convolutional neural network models implicate peripheral immune regulatory variants in the predisposition to Alzheimer's disease.
Journal: PLoS computational biology
In common: SHAP, seaborn, pandas, 3 other tools, computational modeling (no new data)
[7] doi:10.1038/s41467-026-77651-5 [code]
Single-cell machine learning uncovers genetically anchored, cell-type specific programs of Alzheimer's disease.
Journal: Nature communications
In common: SHAP, seaborn, pandas, 3 other tools
[8] doi:10.1111/acel.70656 [code]
Deep Learning Predicts Hematopoietic Stem Cell Aging From 3D Chromatin Images.
Journal: Aging cell
In common: SHAP, seaborn, pandas, 3 other tools
[9] doi:10.1126/sciadv.aef9864 [code]
Speech clocks decode dementia phenotypes, social exposome, and biological aging.
Journal: Science advances
In common: SHAP, seaborn, pandas, 3 other tools
[10] doi:10.1038/s42003-026-10957-8 [code]
Brain defence by the extracellular matrix protein Cochlin.
Journal: Communications biology
In common: SHAP, seaborn, pandas, 3 other tools

Contribute

The authors of this paper can claim it, correct its record and validate its tracing map, and the maintainers of its code (its owner, or a public member of its organization) correct what it says of their repository; anyone signed in can ask for its removal. Every request goes to OSCR's own machine, which answers it; your account page follows them.

Sign in with ORCID to claim this paper as one of its authors, correct its record or validate its tracing map: when the paper's metadata lists your ORCID iD, you are recognized at once. Maintainers of its code: sign in with GitHub, then claim the repository on your account page.

Add the badge to the code's README

OSCR: the badge of this paper

If you are an author or a maintainer of this paper's code, you can add this badge. It says what OSCR knows of the paper (its code, its validated tracing map) and links the code to this page. Paste one of these snippets under the README's title. Keep the two marks around it, so that the badge can be replaced in place and is never added twice. OSCR changes nothing in your repository.

Markdown
<!-- oscr-badge:start -->
[![OSCR](https://openscicode.org/badge/doi/10.1073/pnas.2517661123.svg)](https://openscicode.org/badge/doi/10.1073/pnas.2517661123)
<!-- oscr-badge:end -->
reStructuredText
.. oscr-badge:start

.. image:: https://openscicode.org/badge/doi/10.1073/pnas.2517661123.svg
   :target: https://openscicode.org/badge/doi/10.1073/pnas.2517661123
   :alt: OSCR

.. oscr-badge:end
HTML
<!-- oscr-badge:start -->
<a href="https://openscicode.org/badge/doi/10.1073/pnas.2517661123"><img src="https://openscicode.org/badge/doi/10.1073/pnas.2517661123.svg" alt="OSCR"></a>
<!-- oscr-badge:end -->

On GitHub, open the README, choose Edit (the pencil), paste the snippet under the title, then "Commit changes".

If you choose to, you can have the badge kept up to date for you, with oscr badge --write from the command line or with the GitHub Action in your repository's workflows. Every other form and option (a card, AsciiDoc, LaTeX, shields.io) is on the badge page.

Request its removal

To ask OSCR to remove this record, the copies of its authors' scripts or its tracing map, use the removal request page: signed in, you say who you are, what to remove and why, then review and confirm the request. Published rules decide every request (how).

Discussion, reproductions, activity

Discussion: code errors and mismatches between the code and the paper about this paper and its code, from readers and its authors, beside the paper and its tracing map.

Report a mismatch between the code and the paper · Report a code error (signed in)

Reproductions: reports from readers who ran the authors' code and did not get the paper's result, what they ran, with which environment, commit and data.

Report a reproduction failure (signed in)

Versions of its code: the releases of its code tied to a version of this paper (the preprint, the accepted manuscript, the version of record…), each with the tracing map versioned with it.

Activity: what happens around this paper: new versions of its record, its map's validation, discussions and reproductions. It opens with sign-in.