Skip to main content
Bioinformatics Advances logoLink to Bioinformatics Advances
. 2026 Sep 28;6(1):vbag201. doi: 10.1093/bioadv/vbag201

NeighborFinder: an R package inferring local microbial network around a species of interest

Mathilde Sola 1,2, Adrien Paravel 3, Sandrine Auger 4, Jean-Marc Chatel 5, Florian Plaza Oñate 6, Emmanuelle Le Chatelier 7, Marion Leclerc 8,9, Patrick Veiga 10,11, Clémence Frioux 12,13, Mahendra Mariadassou 14,✉, Magali Berland 15,✉
Editor: Marion Adebiyi
PMCID: PMC13626711  PMID: 42820214

Abstract

Motivation

Understanding interactions from microbiome data is a central aspect in microbial ecology, as it provides insights into ecosystem stability, disease mechanisms, and can be used to design synthetic communities. Current network inference tools reconstruct global networks from co-abundance data, which means they capture the overall correlation structure for the entire set of taxa considered. These approaches are computationally intensive and suboptimal when the focus is on the local neighborhood of one or a few taxa of interest.

Results

We introduce NeighborFinder, a local network inference method that enables the targeted discovery of direct neighbors around a species of interest. Using cross-validated multiple linear regression with ℓ1 penalty and microbiome-specific filters, our approach infers interpretable species-centered interactions, with F1 score ≥ 0.95 on simulated cohorts ranging from 250 to 1000 samples. This method is well-suited for large metagenomic datasets and is particularly valuable for exploratory studies where the targeted hypotheses outweigh the need for global community structure. The approach complements existing methods by being biologically intuitive and computationally efficient.

Availability and Implementation

The R package is available on CRAN https://CRAN.R-project.org/package=NeighborFinder. The data and source code used to calculate performances and produce the use case example can be found respectively at: https://doi.org/10.57745/UPITJ0 and https://doi.org/10.57745/HJLWW4.

Supplementary information

Supplementary data are available at Bioinformatics Advances online.

1 Introduction

In recent years, metagenomic sequencing has revolutionized our understanding of microbial communities and enabled researchers to identify species, estimate their abundances, and infer functional potential. As metagenomic datasets grow in scale and resolution, so does the interest in moving towards a more mechanistic understanding of microbial communities. Microbial networks, where nodes are taxa and edges represent total or partial correlations between taxa, offer a powerful framework to explore community structure (Layeghifard et al. 2017). While total correlations capture overall co-abundance patterns, partial correlations condition on all other taxa to infer only direct associations which can provide insights into potential ecological interactions.

Existing network inference methods, mostly based on Graphical Gaussian Models (GGM) (Champion et al. 2024), rely on global modeling approaches and infer the full network, at great cost in terms of computational burden and statistical power. However, researchers may be primarily interested not in the whole network but only in the neighbors of a specific species of interest (e.g. a pathogen, a probiotic) (Meinshausen and Bühlmann 2006) as a proxy for direct interactions. Those neighbors can for instance support the design of consortia promoting or inhibiting the growth of a species (Poudel et al. 2023).

Here, we introduce NeighborFinder, a local inference method integrated into an R package that enables fast (running time < 1 minute up to 1100 samples), efficient and scalable identification of direct neighbors around a species of interest (i.e. the nodes directly linked to the node of interest by an edge).

2 Overview of the method

NeighborFinder is tailored to microbiome data. It was specifically developed for shotgun metagenomic data and includes a default normalization step for such datasets, but can accommodate metabarcoding data (and other count-based inputs) by skipping this step.

The primary function for inferring the local neighborhood of a species is apply_neighborfinder(). The R package provides helper functions to visualize results, either as a network or a table, and to construct consensus based on the intersection of multiple inferences. A technical report and a vignette illustrate typical use cases and provide methodological details.

Here, we show how NeighborFinder infers local networks from bacterial abundances in shotgun metagenomic data, focusing on the neighborhoods of three well-known species.

2.1 NeighborFinder description

NeighborFinder performs a three-step procedure illustrated in Fig. 1a and detailed below.

Figure 1.

For image description, please refer to the figure legend and surrounding text.

Overview of NeighborFinder, its use cases and an example. (a) Presentation of the key function apply_neighborfinder() with metagenomic data as input (microbial abundances for each sample), highlighting the two parameters that can be adjusted by the user: prev_level and filtering_top. (b) Description of two main NeighborFinder use cases: on a single dataset, or on multiple datasets for aggregation purposes. (c) Aggregated network of an application example focused on three species of interest (yellow nodes): Bifidobacterium longum, Bifidobacterium dentium, and Bacteroides thetaiotaomicron in eight datasets. The edge label is the number of datasets in which the edge was detected; the width is proportional to the mean coefficient value.

  1. Data preparation. Input data is a species-by-sample abundance table. The first step filters out low-prevalence (≤ prev_level) species, for which network interaction detection is notoriously difficult, especially with limited sample sizes (Röttjers and Faust 2018). Next, shotgun metagenomic abundances are transformed into count-like values (with get_count_table()), by scaling and rounding all values such that the minimum non-zero count is 1. Finally, mclr normalization is applied to the previously transformed abundance data. While other normalization strategies are viable (clr, VST, TSS, etc.), mclr was selected based on its demonstrated performance in previous microbiome network analyses (Yoon et al. 2019) as this adapted version of the clr normalization preserves the zeros in the dataset and doesn’t require the addition of pseudo counts.

  2. Network inference. The local species abundance is regressed against all other using ℓ1 penalized linear regression and neighbors are species with non-null regression coefficients, following (Meinshausen and Bühlmann 2006). The regression is performed using glmnet::cv.glmnet() (Friedman et al. 2010), with cross-validation used to select the ℓ1 penalty parameter λ. The regression is applied 10 times, with 10 different Random Number Generator (RNG) seeds and the results are filtered in each run to keep only the topmost coefficients in absolute value (top_filtering = 30% by default) and limit spurious detection of neighbors.

  3. Network stabilization. To further improve robustness and reproducibility, only neighbors consistently detected in at least half of the runs are kept. For the conserved edges, the final coefficient is computed as the median over all runs.

2.2 Performance of the method

2.2.1 Simulation strategy

The function apply_neighborfinder() has two key parameters (prev_level and top_filtering shown in Fig. 1a) that shape the output. It is also well documented that the dataset size has an impact on the inferred network as more samples lead to more edges (Champion et al. 2024).

Our performance assessment strategy therefore consisted in covering a range of values for both parameters for sizes observed in the literature, with the aim of providing users with guidelines to pick the most suitable combination depending on their dataset size.

We then tested the performance of NeighborFinder on eight independent shotgun metagenomic cohorts (sample sizes from n = 347 to n = 1084). For each cohort, similar microbiome data was simulated with known interaction networks (see Supplementary Material). NeighborFinder’s performance was evaluated using precision and recall, aggregated into the F1 score (harmonic mean of recall and precision).

2.2.2 Evaluation procedure

For each bacterial species, local networks were inferred using prev_level values between 15% and 35% (in 5% increments). Each setting was repeated 10 times with different RNG seeds, for all simulated datasets. The glmnet::cv.glmnet() function was applied, using cvglm_to_coeffs_by_object() from the NeighborFinder package. The resulting inferences were then filtered following the procedure implemented in apply_NeighborFinder() keeping only the top filtering_top% coefficients, ranging from 5% to 30% (in 5% increments), and including 100% to assess unfiltered results (see Fig. 1a, steps 1 and 2).

Finally, for each species, a network was obtained through the stabilization step implemented in NeighborFinder (see Fig. 1a, step 3), where edges were retained if detected in at least 5 of the 10 runs across different seeds. F1-scores were calculated for each species, then averaged across species and cohorts.

2.3 Determining the best combination of parameters

Figure S1 summarizes performance scores calculated on simulated dataset with sizes ranging from n = 100 to n = 1000, and Figure S2 focuses on n = 50 using a wider range of prevalence filters. They show that parameters prev_level and filtering_top should be adjusted according to the size of the dataset. When n is large, many parameter combinations lead to similar performance (dark green area, F1 score ≥0.9 in Figure S1). The best strategy is to select a low value of prev_level, to include as many species as possible, before adjusting filtering_top value to ensure good performance (e.g. with n = 1000, prev_level = 0.15 and filtering_top = 30). As n decreases, increasing prev_level while keeping a high filtering_top value is required to maintain high F1-scores. In particular, for small datasets (n = 50), Figure S2 highlights that stringent prevalence filtering (prev_level  ≥ 0.4) is mandatory to achieve a F1 score above 0.7.

3 Usage scenario

3.1 Use cases

The method can be applied to one dataset or to several independent datasets (Fig. 1b). In the latter case, NeighborFinder is applied to each dataset and a consensus is built from edges detected across several datasets (e.g. at least 3 out of 5 datasets) to enhance the overall robustness of the inferred neighborhood. This strategy is illustrated in Fig. 1c, with details in Table 1.

Table 1.

Application example listing detected neighbors (Node 2) of 3 species of interest (Node 1), with an aggregation strategy. For each edge, the occurrence in the 8 datasets, the mean coefficient (Mean coef) and standard deviation (SD) are indicated along with a potential biological interpretation, supported by references.

Node 1 Node 2 Occurrence Mean coef SD Biological interpretation
Bacteroides thetaiotaomicron Bacteroides ovatus 4/8 0.054 0.016 Functional complementarity (Martens et al. 2011)
Bacteroides thetaiotaomicron Parabacteroides distasonis 4/8 0.21 0.092 Taxonomic proximity, niche preference (Röttjers and Faust 2018)
Bacteroides thetaiotaomicron Bacteroides uniformis 4/8 0.13 0.084 Taxonomic proximity, niche preference (Röttjers and Faust 2018)
Bacteroides thetaiotaomicron Odoribacter splanchnicus 4/8 0.090 0.054 Potential cross-feeding
Bacteroides thetaiotaomicron Phocaeicola vulgatus 6/8 0.18 0.082 Functional complementarity (Nilsen et al. 2023)
Bifidobacterium longum Anaerostipes hadrus 6/8 0.11 0.053 Potential cross-feeding (Rivière et al. 2016)
Bifidobacterium longum Bifidobacterium pseudocatenulatum 6/8 0.15 0.040 Taxonomic proximity, niche preference (Röttjers and Faust 2018)
Bifidobacterium longum Bifidobacterium adolescentis 7/8 0.15 0.058 Taxonomic proximity, niche preference (Röttjers and Faust 2018)
Bifidobacterium dentium Streptococcus anginosus 4/8 0.20 0.060 Niche preference (Kianoush et al. 2014)

3.2 Application example

NeighborFinder was applied to eight independent human gut microbiome datasets (details of each dataset in Supplementary Material) to identify the neighbors of three species: Bifidobacterium longum (probiotic), Bifidobacterium dentium (opportunistic pathogen), and Bacteroides thetaiotaomicron (gut symbiont). The eight datasets are used to find robust and ubiquitous neighbors (detected in at least 4 out of the 8 datasets). Figure 1c shows the resulting network and Table 1 lists the following descriptors for each edge: occurrence (number of datasets where detected), mean coefficient and standard deviation, and biological interpretation of the edge based on literature review.

In particular, the interaction between B. thetaiotaomicron and Bacteroides ovatus may reflect functional complementarity: B. ovatus harbors different glycoside hydrolases and polysaccharide utilization loci (PULs) able to degrade complex plant polysaccharides such as hemicelluloses (galactomannans and xylans) that B. thetaiotaomicron lacks (Martens et al. 2011). Such complementarity characterizes B. ovatus as a companion species to B. thetaiotaomicron. Similarly, B. vulgatus complements the enzymatic activity of B. thetaiotaomicron (Nilsen et al. 2023). The interaction between B. longum and Anaerostipes hadrus may plausibly involve cross-feeding, as previously demonstrated between Bifidobacterium species and butyrate-producing bacteria such as Anaerostipes species (Rivière et al. 2016). Other detected neighbors may be explained by taxonomic proximity or niche similarity, as often happening with edges detected by network inference methods when the environment is not explicitly accounted for (Röttjers and Faust 2018). For example, B. dentium and Streptococcus anginosus both inhabit the human oral cavity (Kianoush et al. 2014).

Although they have different goals, we compared our findings to SPIEC-EASI (Kurtz et al. 2015). It was applied to each dataset and a consensus network was built from the eight inferred networks before extracting the neighbors of the three previous species (see Supplementary Materials). SPIEC-EASI was 37 times slower (4-core parallelization) than NeighborFinder (single core), as expected for the reconstruction of the full network, and missed 6 of the 9 edges found by NeighborFinder, including all neighbors of B. thetaiotaomicron, due to lower statistical power for the specific neighborhood reconstruction problem. This application illustrates the variety of biological insights that can emerge from co-abundance patterns in NeighborFinder local networks and its advantage over global network methods.

4 Discussion

NeighborFinder provides an efficient and interpretable approach complementary to global network inference. This framework is particularly suited for large-scale datasets and exploratory analyses where speed (see Figure S3 for execution time details), simplicity, and species-centered hypotheses are key.

While it addresses key challenges such as compositionality and sparsity through mclr normalization and prevalence filtering to exclude low-prevalence taxa, NeighborFinder suffers from the linearity assumption inherent to GGM-based approaches, which may limit the description of certain types of biological interactions (amensalism, parasitism, etc.) (Röttjers and Faust 2018). Similarly to global approaches, our method detects relatively few negative edges. These could be interpreted as signals of competition or inhibition between taxa.

To mitigate instability and noise inherent to all network inference methods, we extended the naive cv.glmnet approach with additional features specifically tailored to microbiome data. We used ℓ1 penalized regression combined with data-specific filtering steps, applied post-processing to the results, and introduced the use of multiple repetitions alongside cross-validation to improve robustness.

Although NeighborFinder has been designed for microbiome data, this method could be useful to explore local networks in other context of tabular data ranging from different taxonomic levels to functional modules for example.

Supplementary Material

vbag201_Supplementary_Data

Contributor Information

Mathilde Sola, Université Paris-Saclay, INRAE, MGP, 78350, Jouy-en-Josas, France; Inria, University of Bordeaux, INRAE, 33400, Talence, France.

Adrien Paravel, Université Paris-Saclay, INRAE, MICALIS, 78350, Jouy-en-Josas, France.

Sandrine Auger, Université Paris-Saclay, INRAE, MICALIS, 78350, Jouy-en-Josas, France.

Jean-Marc Chatel, Université Paris-Saclay, INRAE, MICALIS, 78350, Jouy-en-Josas, France.

Florian Plaza Oñate, Université Paris-Saclay, INRAE, MGP, 78350, Jouy-en-Josas, France.

Emmanuelle Le Chatelier, Université Paris-Saclay, INRAE, MGP, 78350, Jouy-en-Josas, France.

Marion Leclerc, Université Paris-Saclay, INRAE, MGP, 78350, Jouy-en-Josas, France; Université Clermont Auvergne, INRAE, UMR454 MEDIS, 63000, Clermont-Ferrand, France.

Patrick Veiga, Université Paris-Saclay, INRAE, MGP, 78350, Jouy-en-Josas, France; Université Paris-Saclay, INRAE, MICALIS, 78350, Jouy-en-Josas, France.

Clémence Frioux, Université Paris-Saclay, INRAE, MGP, 78350, Jouy-en-Josas, France; Inria, University of Bordeaux, INRAE, 33400, Talence, France.

Mahendra Mariadassou, Université Paris-Saclay, INRAE, MaIAGE, 78350, Jouy-en-Josas, France.

Magali Berland, Université Paris-Saclay, INRAE, MGP, 78350, Jouy-en-Josas, France.

Author contributions

M.M. and M.B. conceived the project and M.B. obtained the funding for the project. A.P., S.A., J.M.C., F.P.O., E.L.C., M.L., M.M., M.B., and M.S. designed the methodology. M.M., M.B., and M.S. developed the software. E.L.C. and F.P.O. prepared the datasets used for the application example and performance evaluation. A.P., S.A., J.M.C., and M.L. contributed their biological expertise to the design of the use case to validate the method. M.S. conducted the formal analyses and performed validation of the results. M.M., M.B., C.F., P.V., and M.S. prepared the original draft of the manuscript. All authors contributed to the interpretation of the results, reviewed and edited the manuscript, and approved the final version.

Supplementary material

Supplementary material is available at Bioinformatics Advances online.

Conflicts of interest

None declared.

Funding

This work was supported by grants Carnot Qualiment® (#20 CARN 0026 01) and MetaGenoPolis (ANR-11-DPBS-0001).

References

  1. Champion C, Momal R, Chatelier EL  et al.  OneNet—one network to rule them all: consensus network inference from microbiome data. PLoS Comput Biol  2024;20:e1012627. 10.1371/journal.pcbi.1012627 [DOI] [PMC free article] [PubMed] [Google Scholar]
  2. Friedman J, Hastie T, Tibshirani R.  Regularization paths for generalized linear models via coordinate descent. J Stat Softw  2010;33:1–22. 10.18637/jss.v033.i01 [DOI] [PMC free article] [PubMed] [Google Scholar]
  3. Kianoush N, Adler CJ, Nguyen K-AT  et al.  Bacterial profile of dentine caries and the impact of pH on bacterial population diversity. PLoS One  2014;9:e92940. 10.1371/journal.pone.0092940 [DOI] [PMC free article] [PubMed] [Google Scholar]
  4. Kurtz ZD, Müller CL, Miraldi ER  et al.  Sparse and compositionally robust inference of microbial ecological networks. PLoS Comput Biol  2015;11:e1004226. 10.1371/journal.pcbi.1004226 [DOI] [PMC free article] [PubMed] [Google Scholar]
  5. Layeghifard M, Hwang DM, Guttman DS.  Disentangling interactions in the microbiome: a network perspective. Trends Microbiol  2017;25:217–28. 10.1016/j.tim.2016.11.008 [DOI] [PMC free article] [PubMed] [Google Scholar]
  6. Martens EC, Lowe EC, Chiang H  et al.  Recognition and degradation of plant cell wall polysaccharides by two human gut symbionts. PLoS Biol  2011;9:e1001221. 10.1371/journal.pbio.1001221 [DOI] [PMC free article] [PubMed] [Google Scholar]
  7. Meinshausen N, Bühlmann P.  High-dimensional graphs and variable selection with the Lasso. Ann Statist  2006;34:1436–62. 10.1214/009053606000000281 [DOI] [Google Scholar]
  8. Nilsen M, Rehbinder EM, Lødrup Carlsen KC  et al.  A globally distributed Bacteroides caccae strain is the most prevalent mother-child shared bacteroidaceae strain in a large Scandinavian cohort. Appl Environ Microbiol  2023;89:e00789–23. 10.1128/aem.00789-23 [DOI] [PMC free article] [PubMed] [Google Scholar]
  9. Poudel R, Jumpponen A, Kennelly MM  et al.  Integration of phenotypes in microbiome networks for designing synthetic communities: a study of mycobiomes in the grafted tomato system. Appl Environ Microbiol  2023;89:e01843–22. 10.1128/aem.01843-22 [DOI] [PMC free article] [PubMed] [Google Scholar]
  10. Rivière A, Selak M, Lantin D  et al.  Bifidobacteria and butyrate-producing colon bacteria: importance and strategies for their stimulation in the human gut. Front Microbiol  2016;7:979. 10.3389/fmicb.2016.00979 [DOI] [PMC free article] [PubMed] [Google Scholar]
  11. Röttjers L, Faust K.  From hairballs to hypotheses–biological insights from microbial networks. FEMS Microbiol Rev  2018;42:761–80. 10.1093/femsre/fuy030 [DOI] [PMC free article] [PubMed] [Google Scholar]
  12. Yoon G, Gaynanova I, Müller CL.  Microbial networks in SPRING - Semi-parametric rank-based correlation and partial correlation estimation for quantitative microbiome data. Front Genet  2019;10:516. 10.3389/fgene.2019.00516 [DOI] [PMC free article] [PubMed] [Google Scholar]

Associated Data

This section collects any data citations, data availability statements, or supplementary materials included in this article.

Supplementary Materials

vbag201_Supplementary_Data

Articles from Bioinformatics Advances are provided here courtesy of Oxford University Press

RESOURCES