NeighborFinder: an R package inferring local microbial network around a species of interest Mathilde Sola, Adrien Paravel, Sandrine Auger, Jean-Marc Chatel, Florian Plaza Oñate, Emmanuelle Le Chatelier, Marion Leclerc, Patrick Veiga, Clémence Frioux, Mahendra Mariadassou, Magali Berland, Marion Adebiyi Abstract AbstractMotivationUnderstanding 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.ResultsWe 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 l1 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 ImplementationThe 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 informationSupplementary 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 (). 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) (), 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) () as a proxy for direct interactions. Those neighbors can for instance support the design of consortia promoting or inhibiting the growth of a species (). 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 and detailed below. - 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 (). 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 () as this adapted version of the clr normalization preserves the zeros in the dataset and doesn’t require the addition of pseudo counts. - Network inference. The local species abundance is regressed against all other using l1 penalized linear regression and neighbors are species with non-null regression coefficients, following (). The regression is performed using glmnet::cv.glmnet() (), with cross-validation used to select the l1 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. - 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 ) 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 (). 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 ). 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 , steps 1 and 2). Finally, for each species, a network was obtained through the stabilization step implemented in NeighborFinder (see , 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 summarizes performance scores calculated on simulated dataset with sizes ranging from n = 100 to n = 1000, and 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 ). 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), 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 (). 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 , with details in . 3.2 Application example NeighborFinder was applied to eight independent human gut microbiome datasets (details of each dataset in ) 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). shows the resulting network and 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 (). Such complementarity characterizes B. ovatus as a companion species to B. thetaiotaomicron. Similarly, B. vulgatus complements the enzymatic activity of B. thetaiotaomicron (). 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 (). 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 (). For example, B. dentium and Streptococcus anginosus both inhabit the human oral cavity (). Although they have different goals, we compared our findings to SPIEC-EASI (). 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 ). 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 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.) (). 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 l1 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. 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.