Predicting microbial community structure and temporal dynamics by using graph neural network models

Kasper Skytte Andersen, Kai Zhao, Alexander de Linde Agerskov, Christian Sørensen, Trine Juhl Holmager, Marta Nierychlo, Miriam Peces, Chenjuan Guo, Per Halkjær NielsenNature Communications 2025

Abstract

Understanding species-level abundance dynamics in complex microbial communities is key to managing microbial ecosystems, yet it remains a major challenge. In wastewater treatment plants (WWTPs), the presence and abundance of process-critical bacteria are essential for removing or recycling pollutants. However, individual species can fluctuate without recurring patterns. Accurately forecasting these dynamics is critical for preventing failures and guiding process optimization. We have developed a graph neural network-based model that uses only historical relative abundance data to predict future dynamics. Each model is trained and tested on individual time-series from 24 full-scale Danish WWTPs (4709 samples collected over 3-8 years, 2-5 times per month). It accurately predicts species dynamics up to 10 time points ahead (2-4 months), sometimes up to 20 (8 months). The approach, implemented as the "mc-prediction" workflow, is also tested on other datasets, including a human gut microbiome, showing its suitability for any longitudinal microbial dataset.

Introduction

Microbial communities are the "engine rooms" of our planet, driving essential processes from sewage treatment to human health. However, these communities are notoriously fickle. Species abundances fluctuate due to complex inter-species interactions and environmental shifts, often without obvious recurring patterns. For wastewater treatment plant (WWTP) operators, a sudden bloom of "bulking" bacteria can lead to system failure. Traditionally, predicting these shifts required exhaustive environmental metadata (temperature, pH, nutrient levels) which is expensive and difficult to collect consistently. This research addresses the challenge of building a high-resolution (species-level) predictive model that relies solely on the "memory" of the community itself—its historical relative abundance.

Methodology: The mc-prediction Workflow

The researchers developed mc-prediction, a workflow centered on a Graph Neural Network (GNN) approach. Unlike standard time-series models like LSTMs, GNNs are designed to capture the relational dependencies between entities—in this case, interacting microbes.

Overall architecture and data splitting strategy of the mc-prediction model.

The architecture consists of three primary stages:

  1. Pre-clustering: To manage complexity, Amplicon Sequence Variants (ASVs) are grouped into clusters. The model performs best when clustering is based on graph interaction strengths learned by the model itself, rather than predefined biological functions.
  2. Dual Convolution Layers:
    • A Graph Convolution Layer learns interaction strengths and extracts features based on species relationships.
  3. A Temporal Convolution Layer captures how these features evolve over time.
  4. Output Layer: A fully connected network predicts the relative abundance of each ASV for the next 10 time points based on a moving window of 10 historical samples.

The model was validated using a massive longitudinal dataset from 24 full-scale Danish WWTPs (4,709 samples over 3–8 years), as well as datasets from the human gut microbiome (332 samples) and coastal marine fungal eDNA.

Results and Key Insights

The GNN-based approach demonstrated that microbial interactions are highly informative for forecasting. The model's superior performance suggests that relational dependencies between species are more predictive than individual temporal trends alone.

Observed vs. predicted relative abundances for three key bacterial species in a wastewater treatment plant.

Forecasting Performance

  • Forecasting Horizon: The model accurately predicts dynamics 10 time points ahead (typically 2–4 months) and can extend to 20 points (8 months) in some cases.
  • Quantitative Accuracy: Median Mean Absolute Percentage Error (MAPE) for individual species ranged between 14.2% and 17.7%.
  • Community Similarity: Using the Bray-Curtis metric, the model achieved a median dissimilarity of 0.147, indicating high fidelity to actual community structures.
  • Capturing Extremes: Notably, the model successfully predicted blooms of Candidatus Microthrix, a problematic filamentous bacterium, even when bloom magnitudes in the test set significantly exceeded those in the training data.

One surprising finding was that mathematical interaction-based clustering outperformed biological function-based clustering. This suggests that current functional classifications might overlook subtle but critical ecological dependencies.

Discussion and Future Outlook

While highly effective for dominant taxa in stable systems, the model faced challenges with extremely sparse datasets, such as the fungal eDNA "stress test," where species appeared and disappeared too abruptly for stable pattern learning. Additionally, low-abundance members of the "rare biosphere" remain difficult to forecast accurately.

Despite these limitations, the "mc-prediction" workflow offers a portable tool for ecosystem management. Its success with the human gut microbiome suggests potential applications in personalized health monitoring to predict dysbiosis before symptoms occur. Future integration with real-time DNA sequencing technologies, such as Oxford Nanopore, could enable plant operators to run "what-if" scenarios and optimize system performance dynamically.

Summary updated

BibTeX
@inproceedings{andersen2025predicting,
  author = {Kasper Skytte Andersen and Kai Zhao and Alexander de Linde Agerskov and Christian Sørensen and Trine Juhl Holmager and Marta Nierychlo and Miriam Peces and Chenjuan Guo and Per Halkjær Nielsen},
  title = {{Predicting microbial community structure and temporal dynamics by using graph neural network models}},
  booktitle = {Nature Communications},
  year = {2025},
  doi = {10.1038/s41467-025-64175-7},
}
Figure