Abstract
UniFrac measures phylogeny-aware differences between microbiome samples but scales poorly with modern dataset sizes. We introduce an algorithm, DartUniFrac, and a near-optimal implementation with graphics processing unit acceleration that is up to three orders of magnitude faster than UniFrac and scales to millions of samples (pairwise) and billions of taxa. DartUniFrac connects UniFrac with weighted Jaccard similarity and exploits sketching algorithms for fast computation.
Article PDF
Main
UniFrac1,2,3 is a phylogenetic beta-diversity metric that has been widely used in many microbiome and/or microbial ecology studies (>15,000), including large-scale ones such as the Earth Microbiome Project (EMP)4 and American Gut Project (AGP)5, due to its capability to incorporate gene/genome evolutionary histories into community dissimilarity metrics. By leveraging branch-length information on the phylogeny, UniFrac frequently yields stronger between-group separation (for example, higher PERMANOVA R2 values and clearer ordinations) than nonphylogenetic distances such as Bray–Curtis and Jaccard dissimilarity, particularly when community turnover involves distantly related lineages, as shown in comparative evaluations across diverse datasets2. As a fundamental biological community distance metric, UniFrac is not limited to amplicon sequencing-based community profiling techniques, and it is natural to extend it to metagenomic/genomic-based community profiling techniques as long as the unit of interest is clearly defined (for example, amplicon sequence variants/operational taxonomic units (OTUs) or a metagenome-assembled genome-derived species unit based on average nucleotide identity, or ANI)6. The computational complexity of UniFrac (weighted) is proportional to the number of taxa in the phylogenetic tree and is quadratic in the number of samples in a given study (pairwise comparisons)7. Model-based estimates of microbial diversity using the 16S rRNA gene suggest that Earth may harbor more than 1012 microbial species8 or even more with whole-genome-based approaches. However, we are far from capturing these diverse microbial species. As high-throughput sequencing is becoming readily accessible in standard microbiome studies, we can now sequence thousands of samples with millions of species in a single project. This, however, has created a major challenge—computing all-versus-all UniFrac distances becomes a bottleneck for real-world datasets with even more samples and taxa. Many computational optimizations have been developed for faster UniFrac computation for large numbers of samples (for example, a few thousand) over the past 20 years7,9,10, for example, faster tree traversal strategies10, better parallel efficiency (Striped UniFrac)7 and hardware acceleration (for example, single instruction, multiple data (SIMD) and graphics processing unit (GPU))9. However, these improvements were based on the same UniFrac algorithm and cannot scale further.
Here, we introduce a UniFrac algorithm, DartUniFrac, that scales to millions of samples with billions of taxa. First, we revisited the original UniFrac algorithm1 (unweighted; Supplementary Fig. 1a): ({D}_{{{mathrm{UniFrac}}}}(A,B)=frac{sum _{iin E}{ell}_{i}times |{X}_{i}(A)-{X}_{i}(B)|}{sum _{iin E}{ell}_{i}{times} max {{X}_{i}(A),{X}_{i}(B)}}), where ({X}_{i}(S)!:=mathop{rm{max}}limits_{jin text{Desc}(i)}{x}_{!j}(S)in {0,1}) and xj(S) is defined as ({x}_{!j}(S)=left{begin{array}{ll}1, & {text{if taxon}},{j};{text{is present in sample}},{S},\ 0, & text{otherwise}.end{array}right.). Weighted UniFrac is defined as ({D}_{{{textrm{WUniFrac}}}}=frac{{sum }_{iin E}{{ell}}_{i}left|{sum }_{jin {{textrm{Desc}}}(i)}{a}_{j}-{sum }_{jin {{textrm{Desc}}}(i)}{b}_{!j}right|}{{sum }_{iin E}{{ell}}_{i}({sum }_{jin {{textrm{Desc}}}(i)}{a}_{j}+{sum }_{jin {{textrm{Desc}}}(i)}{b}_{!j})}) (see the detailed definition of each individual variable in Supplementary Fig. 1b and Supplementary Methods, a different but equivalent equation to the original weighted UniFrac)2. We prove that unweighted and weighted UniFrac are essentially weighted Jaccard similarity on tree branches (Supplementary Methods and Supplementary Fig. 1a,b). For unweighted UniFrac, ({D}_{{{textrm{UniFrac}}}}=1-{J}_{{textrm{w}}}(mathbf{x},mathbf{y})), where ({J}_{{textrm{w}}}(mathbf{x},mathbf{y})=frac{sum min ({x}_{i},{y}_{i})}{sum max ({x}_{i},{y}_{i})}) (also known as weighted Jaccard similarity), ({x}_{i}={{ell}}_{i}times {X}_{i}(A)) and ({y}_{i}={{ell}}_{i} times {X}_{i}(B)) (Supplementary Fig. 1a). For weighted UniFrac, ({D}_{{{textrm{WUniFrac}}}}=frac{1-{J}_{{textrm{w}}}(mathbf{x},mathbf{y})}{1+{J}_{{textrm{w}}}(mathbf{x},mathbf{y})}), where ({J}_{{textrm{w}}}(mathbf{x},mathbf{y})=frac{sum min {{x}_{i},{y}_{i}}}{sum max {{x}_{i},{y}_{i}}}), ({x}_{i}=)({ell }_{i}times {A}_{i},{y}_{i}=)({ell }_{i} times {B}_{i}) and ({A}_{i}=sum _{jin {{textrm{Desc}}}(i)}{a}_{!j},{B}_{i}=sum _{jin {{textrm{Desc}}}(i)}{b}_{!j}) (Supplementary Fig. 1b). In both unweighted and weighted UniFrac, computing weighted Jaccard similarity ({J}_{{textrm{w}}}(x,y)=frac{sum min {{x}_{i},{y}_{i}}}{sum max {{x}_{i},{y}_{i}}}) is the limiting step because, for real-world datasets, the dimension of x aninid y (equal to the number of branches in the phylogenetic tree) can be millions or even billions. The problem becomes how to compute weighted Jaccard similarity quickly and efficiently. First, we used a succinct balanced-parentheses data structure to represent phylogenetic trees, enabling efficient, pointer-free navigation operations such as parent, child and sibling traversal through auxiliary rank/select and parenthesis-matching indexes (Fig. 1a and Methods). This allows representation and efficient traversal of trees with billions of taxa. Each branch of the tree is now a set element, but the weight of each set element is related to the samples, either the presence or absence of taxa that are descendants of the branch (unweighted) or the sum of the relative abundances of taxa that are descendants of the branch (weighted) (Fig. 1a, Supplementary Fig. 1a,b and Supplementary Methods). After obtaining the weighted sets (Fig. 1a), computing weighted Jaccard similarity is the most expensive step because, for real-world microbiome datasets, there can be billions of taxa/branches and millions of samples. We relied on weighted MinHash (also known as sketching algorithms) to sketch weighted sets for computing weighted Jaccard similarity. MinHash belongs to a category of locality-sensitive hashing algorithms that is widely used in data mining for large-scale web and text comparison. MinHash is also widely used in genomics and metagenomics for computing ANI at large scale11,12,13,14, and it allows for the computation of weighted Jaccard similarity efficiently with controllable estimation error, which converges to 0 as the sketch size increases (Methods). Among several weighted MinHash algorithms, DartMinHash and efficient rejection sampling (ERS) are the most efficient for sparse and dense sets, respectively15,16. In the resulting sketch (a low-dimensional representation with length S of original weighted sets from all branches), computing an integer-based Hamming similarity (normalized) for each pair of sketches estimates weighted Jaccard (Jw) and thus also unweighted UniFrac or weighted UniFrac (Fig. 1a and Methods). Real-world microbiome datasets are sparse, such that most branch sets are empty, making the weighted MinHash sketch step extremely fast, with DartMinHash being the fastest weighted MinHash algorithm both in theory and in practice15, to the best of our knowledge. Overall, the big-O notation for DartUniFrac is O(N × Tactive + N × S × log(S) + N2 × S), where N is the number of samples, Tactive is the number of active branches on average across all samples and S is the weighted MinHash sketch vector length (see detailed big-O analysis in Methods). Big-O notation for the exact UniFrac is O(N2 ×T), where T is the total number of branches or taxa and, in practice, S << T (S is less than or equal to 2,048 in practice). The computational bottleneck for DartUniFrac for millions of samples is dominated by the pairwise integer Hamming similarity step (O(N2× S), which computes equal slots for sketch vectors with the same length, where the slots are 16-bit integers) (Fig. 1a and Methods). We first maximized central processing unit (CPU) performance for this step using multithreading and SIMD. However, Hamming similarity computation is bound by memory bandwidth, such that further speedups on a CPU are limited (for example, more CPU threads), but can benefit from hardware with higher memory bandwidth. We therefore offloaded this step to GPUs to further speed up the computation for large numbers of samples (Fig. 1a). A streaming mode (both CPU and GPU implementation), which allows block-by-block computation of the full distance matrix, is also provided when the distance matrix cannot fit into random access memory (RAM) (Fig. 1a).
a, Schematic overview of the DartUniFrac algorithm and implementation. The phylogenetic tree is represented by optimal balanced parentheses for efficient retrieval of branch lengths relevant for each sample. Then, the input set vectors (each dimension represents a branch of the tree, skipped if not relevant for that sample; there can be millions of branches or more for big trees) are collected and passed to sketching algorithms, DartMinHash (default) or ERS. The output from sketching is a much smaller vector (1,000–2,000, called sketch vectors) storing 64-bit integer hashes (truncated to lower b bits afterward; Supplementary Methods). The number of equal hashes for all slots in the sketching vector out of the total slots equals the weighted Jaccard similarity. CPU multithreading and SIMD or multi-GPU processing can be used to speed up the pairwise computation of equal hashes. DM, distance matrix; Int, integer. b, Scalability of the DartUniFrac-CPU implementation with respect to the number of CPU threads. c, Speedup of DartUniFrac-CPU relative to Striped UniFrac and unifrac-binaries-CPU (hardware-optimized Striped UniFrac, here SIMD for unifrac-binaries-CPU) for weighted UniFrac with respect to the number of samples. d, Speedup of DartUniFrac-GPU relative to unifrac-binaries-GPU for 100,000, 300,000 and 500,000 samples. This benchmark was performed on an Intel Xeon 6972 P 96-thread CPU with NVIDIA A100 (HBM2e) GPUs. e, GPU memory requirements for DartUniFrac-GPU and unifrac-binaries-GPU. f, Procrustes analysis comparing DartUniFrac and Striped UniFrac for the GWMC dataset (unweighted). Procrustes M2 is shown in the plot. P = 0.00038. See Supplementary Fig. 3 for the weighted analysis. g, Mantel correlation coefficients for distance matrices estimated by DartUniFrac and Striped UniFrac (truth) for weighted UniFrac across 5 datasets (all P values < 0.001; Supplementary Table 2). DartMH, DartMinHash. h, RMSE of the DartUniFrac DartMinHash estimator versus the sketch size for the GWMC dataset. Each data point is the mean of n = 10 independent computational replicate runs, each initialized with a different random seed. Error bars represent the s.d. across replicates. i, Mantel correlation coefficients, using Pearson and Spearman correlations, of the DartMinHash estimator versus the sketch size for the GWMC dataset. Each data point is the mean of n = 10 independent computational replicate runs, each initialized with a different random seed. Error bars represent the s.d. across replicates.
DartUniFrac-CPU scales well with increasing number of CPU threads (Fig. 1b) and is more than 200 times faster than the state-of-the-art UniFrac algorithms (Striped UniFrac7 and a hardware-optimized version, called unifrac-binaries9; both are exact UniFrac algorithms) for in-memory mode (Fig. 1c and Table 1). Additionally, DartUniFrac-CPU can compute pairwise UniFrac for a million samples (87,522 taxa) in 1.8 h on a CPU (Supplementary Table 1), provided that enough RAM is available or in approximately 4.5 h in a streaming mode when there is not enough RAM (Supplementary Table 1). Notably, the existing state-of-the-art unifrac-binaries-CPU required more than 20 days to complete the same task on a CPU. In streaming mode, memory requirements can be one order of magnitude smaller for DartUniFrac-CPU (Supplementary Fig. 2). DartUniFrac-GPU is on average ~900 times faster than the unifrac-binaries-GPU implementation (Fig. 1d) while consuming ~24 times less GPU memory for ~87,522 taxa and 500,000 samples (Fig. 1e). Procrustes analysis showed that DartUniFrac aligned almost perfectly with the exact UniFrac for the Global Water Microbiome Consortium (GWMC) dataset (unweighted in Fig. 1f and weighted in Supplementary Fig. 3) (M2 = 0.0042 and 0.0039; P < 0.001) and the EMP dataset (Supplementary Fig. 4). Mantel analysis showed strong correlations between DartUniFrac and exact UniFrac distances across all datasets (Mantel r ≥ 0.98; P < 0.001; Fig. 1g and Supplementary Table 2). To better understand the effects of sketch size (the length of vectors storing hashes from DartMinHash and ERS) on DartUniFrac accuracy and running time, we varied the sketch size and conducted a series of experiments on several accuracy metrics for the GWMC dataset. Root-mean-square error (RMSE) converges to 0 as sketch size increases (Fig. 1h and Supplementary Fig. 5a). Mantel correlation coefficients (both Pearson and Spearman), Procrustes M2, PERMANOVA effect size (pseudo-F) and R2 and nearest-neighbor recall all converge to the ground truth as sketch size increases based on the DartMinHash estimator (Fig. 1i and Supplementary Figs. 5b–e and 6a).
In tests of whether DartUniFrac runtime is sensitive to tree size and number of samples, we showed that, for a fixed number of samples and sparsity, the running time to extract branches via balanced-parentheses representation linearly increases with respect to the number of taxa in the tree and is generally less than a few seconds (Fig. 2a), consistent with the claim above that balanced parentheses can scale to billions of taxa (Supplementary Methods). As sparsity increases without changing the number of samples, running time increases proportionally (Fig. 2a). In practice, increasing the number of samples will increase both the number of taxa and the number of total branches. Therefore, DartMinHash sketching time increases proportionally with the number of samples, but this step is generally fast with multithreaded implementation (Fig. 2b). DartUniFrac-GPU is approximately two times slower in streaming mode than in in-memory mode but requires ~10 times less CPU RAM (Fig. 2c,d). Principal-coordinate analysis (PCoA) on the EMP and GWMC datasets17 showed that DartUniFrac with the default sketch size provides results nearly identical to exact UniFrac distances on the exact same input data, as measured by Mantel and Procrustes analysis (see Fig. 2e,f for DartUniFrac, unweighted and weighted EMP, and Fig. 2g,h for exact UniFrac, unweighted and weighted, for the EMP dataset; in Supplementary Fig. 7a–d, panels a and c show DartUniFrac and b and d show exact UniFrac for the GWMC dataset). PCoA analysis based on Qiita amplicon studies (279,443 samples)18 showed similar results (Supplementary Fig. 8a–d, with panels a and c showing unweighted results and b and d showing weighted results). Similar results were also found for large-scale animal gut microbiome datasets and human gut metagenomic datasets (Supplementary Figs. 9a–d and 10a–d). GPU support provides a speedup of another ~20 fold relative to CPU implementation (Fig. 2i and Supplementary Table 3). Integer Hamming similarity computation in DartUniFrac is bound by memory bandwidth, and we observed significantly faster runtimes on recent GPUs relative to CPUs (Fig. 2i and Supplementary Tables 3–6). Because DartUniFrac-GPU only stores only the sketch vector (16 bits per sketch element) for each sample in GPU memory, it can easily scale to millions of samples with moderate GPU memory (for example, 48 GB is enough for 10 million samples with the default sketch size) (Fig. 2j). DartUniFrac-GPU can be even more GPU memory efficient as the number of samples further increases (Methods). DartUniFrac allows computing of UniFrac distances beyond the limitations of BIOM Format (version 2.1.0)19, a common container for microbiome feature tables, which is capped at 220 nonzero values in the feature table; with feature tables that extend the limit for nonzero values to 264, DartUniFrac-GPU can finish in 13.8 min for 500,000 samples with 20 million taxa using two GPUs (see detailed hardware information in Supplementary Table 4). For 1,000,000 samples or more, DartUniFrac-GPU is >1,000 times faster than unifrac-binaries-GPU in terms of compute time because both require the same input–output time (Supplementary Table 5).
a, Branch set construction time with respect to the number of taxa and sparsity while fixing the number of samples. b, DartMinHash sketching time with respect to the number of samples. c, Running time comparisons between DartUniFrac-GPU in-memory mode and streaming mode. d, Peak RAM comparisons between DartUniFrac-GPU in-memory mode and streaming mode. e–h, PCoA visualization for the EMP dataset for DartUniFrac, unweighted (e) and weighted (f), respectively, and Striped UniFrac, unweighted (g) and weighted (h) (exact UniFrac). The PCoA explanation rate for each principal coordinate is included next to the axis. Data points were grouped by country. A detailed legend for e–h can be found in Supplementary Fig. 11. i, GPU running time for DartUniFrac versus CPU running time for DartUniFrac with respect to the number of samples and the number of GPUs. j, DartUniFrac-GPU memory requirement with respect to the number of samples. VRAM, video RAM. k, Estimation error of our DartMinHash implementation for simulated UniFrac distance between (0, 1), including RMSE, absolute error and theoretical error. A sketch size of 2,048 was used for this analysis. Each data point for RMSE and absolute error is the mean of n = 10 independent computational replicate runs, each initialized with a different random seed. Error bars represent the s.d. across replicates. l, Running time versus sparsity of input weighted sets for DartMinHash and ERS. Sparsity was measured as the fraction of nonzero values considering all the set/branch elements.
At the default sketch size of 2,048 for DartMinHash, the observed DartUniFrac RMSE and absolute error across simulated UniFrac distances closely matched the theoretical error (Fig. 2k). ERS also showed similar PCoA results for the EMP dataset (Supplementary Fig. 11a,b) and similar Mantel results with exact UniFrac (Supplementary Table 7) but was ~60 times slower than DartMinHash for the sparse EMP dataset (Supplementary Table 8 and Supplementary Fig. 12a). However, for a denser dataset, the GWMC dataset with an average sparsity of ~10.3% (Supplementary Fig. 12b), ERS was ~2–3 times faster than DartMinHash (Fig. 2l and Supplementary Table 9). For the ERS estimator, the results were consistent with those of the DartMinHash estimator, although ERS was slightly less accurate and was slower than DartMinHash for the same sketch size (Supplementary Figs. 6b, 13a–f and 14a,b). To evaluate the effect of sketch size on running time (both CPU and GPU implementation), we used the AGP and EMP datasets (~50,000 samples) and showed that running time increased linearly with respect to the sketch size (Supplementary Figs. 5f, 13f and 14a,b), dominated by the pairwise integer Hamming step. Therefore, as sketch size increases, DartUniFrac becomes more accurate but slower. The speed–accuracy trade-off is consistent with theoretical expectations15. Similar results were observed for the AGP dataset (Supplementary Figs. 15a–d, 16a–d, 17a–d and 18a–d). We also studied the effect of sketch size on hierarchical clustering topology to determine how much sketching resolution is needed for DartUniFrac to recover tree structures consistent with the truth. Hierarchical clustering trees from DartUniFrac increasingly matched the truth as sketch size grew: cophenetic correlations rose, and RMSE decreased for both the DartMinHash and ERS estimators, with convergence evident at larger sketch sizes (Supplementary Fig. 19a–d). Because hierarchical clustering is highly sensitive to small distance perturbations, lower accuracy at small sketch sizes such as 2,000–3,000 is expected. Topological agreement also improved with sketch size, as raw Robinson–Foulds distance decreased substantially from ~566 at a sketch size of 1,024 to ~337 at a sketch size of 6,656, indicating more shared internal clades/splits for DartMinHash and ERS (Supplementary Fig. 20a–d). Similar results were observed for cophenetic correlation-based analysis (Supplementary Fig. 21a–d) and Robinson–Foulds distance-based analysis (Supplementary Fig. 22a–d) for the AGP dataset.
To further speed up downstream analysis for a large number of samples (large distance matrix output), we developed a new fast PCoA (fPCoA) algorithm. The key step is to replace the exact but much slower singular value decomposition (SVD) step with a faster approximate SVD—randomized SVD—with controllable error. Among several variants of randomized SVD, we relied on the subspace iteration-type randomized SVD21 as subspace iteration was shown to have fewer vectors to orthogonalize (Methods). fPCoA is >100 times faster than exact PCoA and can be ~25% to ~33% faster than the fast PCoA in scikit-bio (Supplementary Table 10). The ordination results showed that fPCoA was nearly identical to exact PCoA for top coordinates (Supplementary Fig. 23; Procrustes M2 = 0.00001, P < 0.001). Because DartUniFrac is much faster, it can be used to perform statistical resampling tests on UniFrac-based clustering (for example, unweighted pair group method with arithmetic mean (UPGMA) or neighbor joining), allowing us to quantify how robust the resulting trees are to sampling noise in community composition, a well-recognized issue in PCR-based amplicon community profiling22. For the GWMC dataset (n = 1,185), UPGMA trees obtained from jackknife resampling with DartUniFrac were highly consistent with those derived from the same jackknife procedure using exact UniFrac distances, indicating similar clustering structure (Supplementary Fig. 24). For the full EMP and AGP dataset (n = 50,085), 50 rounds of jackknife resampling with DartUniFrac (CPU) were completed in under 45 min, whereas the same procedure with exact UniFrac (Striped UniFrac) required more than 10 h (Supplementary Table 11). With multi-GPU support, the same procedure can be completed in 6.3 min using DartUniFrac, whereas it requires 2.1 h using unifrac-binaries-GPU (Supplementary Table 11). DartUniFrac also enables large-scale phylogeny-aware differential abundance analysis by providing an unbiased approximation of EMDUniFrac23 (see detailed proof in Supplementary Methods). For example, we applied DartUniFrac as a component of all-versus-all EMDUniFrac computation to identify key bacterial species from time-series stool samples collected from a patient with inflammatory bowel disease24 (Supplementary Table 12).
DartUniFrac can greatly accelerate large-scale UniFrac computation for many applications. For example, in the web-enabled microbiome meta-analysis platform Qiita18, users have deposited more than half a million microbiome samples (including metagenomic datasets) and the total number of unique taxon markers is in the tens of millions (including both amplicon sequencing and metagenomic sequencing) (accessed November 2025). It also enables routine cross-study meta-analysis at repository scale and makes sensitivity analyses (for example, jackknifing, bootstrapping, permutation-based significance testing) computationally feasible. When a fixed reference phylogeny is used—as is typical for close-reference community profiling—new samples can be appended by computing only the new rows/columns against the existing sketches, avoiding recomputation of the full DartUniFrac distance matrix. Together, these capabilities lower the computational cost and energy barrier for million-sample phylogenetic beta-diversity analyses. The algorithm can compute only unweighted and weighted UniFrac but not generalized UniFrac25 or variance-adjusted UniFrac26 as the latter two UniFrac algorithms cannot be formulated as weighted Jaccard similarity over tree branches. Because of this, both generalized UniFrac and variance-adjusted UniFrac remain difficult to run beyond a few thousand samples in practice despite their potential advantages in handling abundance-dependent effects, improving power for shifts in rare to moderately abundant taxa and stabilizing noisy abundance differences through variance weighting. EMDUniFrac23,27, which was proposed recently and is essentially the numerator of weighted UniFrac (Supplementary Fig. 1b), however, cannot be efficiently approximated via other unbiased locality-sensitive hashing algorithms28, whereas weighted MinHash (DartMinHash) for the original UniFrac (both unweighted and weighted) is unbiased. We found that DartUniFrac can also provide an unbiased estimation for EMDUniFrac23 because the denominator ((sum _{j}{d}_{!j}times({a}_{!j}+{b}_{!j})=sum _{i}{{ell}}_{i}times(sum _{jin {{textrm{Desc}}}(i)}{a}_{!j}+sum _{jin {{textrm{Desc}}}(i)}{b}_{!j}))) in weighted UniFrac (Supplementary Methods) can be computed per sample using a single traversal over branches followed by constant-time pairwise addition7. This is much cheaper than computing the numerator exactly for each pair. Based on this unbiased EMDUniFrac estimate, large-scale differential abundance analysis that accounts for evolutionary histories is no longer computationally prohibitive. Notably, the DartUniFrac algorithm can be equally applied to absolute abundance UniFrac29, where we take absolute cell counts of a given species or strain instead of relative abundance as inputs to build the sample set vectors.
Computational complexity analysis showed that DartUniFrac computation time is dominated by the number of samples but not the number of taxa, whereas exact UniFrac algorithms are dominated by O(N2 × T)2, which becomes impractical when the taxon count T increases with sample size—often approximately proportional to N as additional samples reveal new taxa/strains—such that the worst runtime can approach O(N3) (or even worse) in practice. In fact, none of the packages providing current exact UniFrac implementations support more than 20 million taxa and 500,000 samples (in part due to input file format limitations), which makes DartUniFrac the only option without additional software engineering effort. Crucially, this scalability is about not only a peak throughput but also about feasibility: without sketching, the memory footprint of O(N2 × T) methods becomes prohibitive long before computation finishes. By decoupling computation from the raw taxon count and operating on fixed-length signatures, DartUniFrac remains tractable as reference phylogenies and feature catalogs continue to expand (for example, strain-resolved and spatially resolved metagenomics). DartUniFrac can handle real-world large-scale datasets with different sparsity; for example, per-sample amplicon denoising30 and pool-sample amplicon denoising31,32 methods can have different sparsity (~0.01% and ~5%, respectively)4,17. The ERS algorithm is especially efficient relative to DartMinHash for datasets with >4% sparsity (Fig. 2l). With the recent advancement in spatial metagenomics technology at fine resolution20, it is not uncommon to obtain even denser datasets with millions or billions of taxa, especially for homogeneous environments such as marine and freshwater environments. The balanced-parentheses data structure for representing trees is theoretically optimal33 and can scale to trees with billions of taxa. Both DartMinHash and ERS match the current theoretical lower bound for unbiased estimation of weighted Jaccard similarity for sparse and dense datasets, achieving better accuracy and running speed than BagMinHash and Improved Consistent Weighted Sampling (ICWS)34,35,36. Because these estimators recover similarity purely from hash collision counts, the problem of large-scale UniFrac computation in DartUniFrac essentially reduces to computing integer Hamming similarities (normalized) between fixed-length hash signatures. However, integer Hamming similarity between fixed-length integer hash signatures is purely memory-bandwidth bound, but not compute bound, indicating that hardware with better memory bandwidth is the most efficient way to speed up DartUniFrac computation. This is consistent with our experiments, where DartUniFrac on commodity GPUs (for example, NVIDIA RTX 6000 Pro or A100) was much faster than on CPUs for the integer Hamming similarity step.
The accuracy of DartUniFrac can be further improved by increasing the sketch size, at additional computational cost—for example, by performing integer Hamming similarity on longer vectors/sketches—which in turn places even greater demands on hardware memory bandwidth (both CPU and GPU) to achieve high speed. We also provide both CPU and GPU streaming modes so that a small portion of the large distance matrix (N2 entries) can be computed to avoid large RAM requirements for millions of samples. In addition, the main computational bottleneck—computing the pairwise integer Hamming similarity between sketch vectors—is embarrassingly parallel and can be distributed across many computing nodes, with or without GPUs. The pairwise sketch-level computations decompose naturally into independent subproblems (blocks of the distance matrix) that can be assigned to different nodes with minimal communication overhead.
In downstream analysis, for example, PCoA, for the accuracy levels relevant to our applications, we find that power iteration-based randomized SVD achieves the desired precision while operating on a smaller working subspace than a randomized block Krylov implementation21. This reduces orthogonalization and memory traffic and yields a modest speedup in practice, consistent with theoretical prediction. Power iteration naturally supports a streaming/out-of-core implementation: each pass over the distance matrix requires only the current sketch, so the matrix can be processed in blocks. In contrast, randomized block Krylov methods must construct and orthogonalize a full block Krylov basis of dimension, which is difficult to maintain in a streaming setting without storing all intermediate blocks or recomputing them37. For an even larger number of samples (for example, more than a million), combined with streaming mode in DartUniFrac, streaming PCoA can reduce memory requirements significantly without sacrificing accuracy.
In summary, DartUniFrac will enable the study of much more diverse environments, such as the soil at fine-grained spatial and temporal resolution and help address microbial ecological and evolutionary questions at unprecedented scales. DartUniFrac paves the way for training deep learning models for microbiomes by providing fast and accurate ground truth at the scale of millions or above.
Methods
Balanced-parentheses representation of phylogenetic trees
For a given Newick format tree, we represent the tree using a succinct, bit-level balanced-parentheses encoding instead of a pointer-based tree. During a preorder traversal, we append an open bit (1) when first visiting a node and a close bit (0) after processing its children while storing node labels (for example, taxon IDs) in a compact array in the same order. The resulting bitstring is stored as 64-bit words with a succinct rank/select index and a two-level ‘pioneer’ index for matching parentheses across word boundaries. This supports succinct-index-based tree navigation, including first-child and next-sibling traversal, using packed 64-bit words, auxiliary rank/select structures and a pioneer index for long-distance parentheses matching. In practice, these operations access a small number of contiguous machine words and auxiliary index entries, with no pointer chasing (Fig. 1a). The raw topology is stored as one bit per parenthesis, requiring 2(N + 1) bits for N tree nodes plus a virtual root, with additional overhead for the rank/select and pioneer indexes. Thus, even trees with billions of taxa remain memory feasible and efficiently traversable on modern multicore CPUs. The balanced-parentheses representations are known to be asymptotically succinct for rooted ordered trees and can approach the information-theoretic space bound while supporting efficient navigation operations33. See Supplementary Methods for a detailed description.
DartMinHash implementation
For any given weighted set (X={(i,{x}_{i})}) with non-negative weights (here i indicates a branch, while xi is ({{ell}}_{i}times sum _{jin {{textrm{Desc}}}(i)}{a}_{!j}) for weighted UniFrac), our bucket-style DartMinHash sketch produces k independent MinHash sketches as follows. First, we performed a parameterization step: choose k and set the expected dart budget (tapprox {k}times{textrm{ln}} {k}+2times k). Define a rank threshold θ (initially 1.0). Let (W=sum _{i}{x}_{i}) and ({r}_{max }=theta /W). Then we performed dyadic tiling of the weight–rank space (Supplementary Fig. 25). For each element (i, xi), we iterated over dyadic scales (nu ,rho ge 0). Each pair (v, p) defines a rectangular ‘tile’ with width (Delta w={2}^{nu }/ttimes {2}^{-rho }) and height (Delta r={2}^{rho }times {2}^{-nu }). We traversed tiles in increasing w and r, stopping early when (wge {x}_{i}) or (rge {r}_{max }) (which is (frac{varphi }{parallel mathbf{x} {parallel }_{1}}); (varphi) controls the upper limit on the rank of darts to return, such that the algorithm returns (varphitimes t) darts in expectation) (Supplementary Fig. 25). Next, we started a hash-driven Poisson dart count. For every tile, we formed a 64-bit key by XORing tabular hashes of i, v, p and the tile’s local integer offsets. From this key, we draw a Poisson(1) count via a cumulative distribution function (CDF) table; this gives the number of darts landing inside the tile. For each dart assigned to a tile, we draw two independent pseudorandom values ({U}_{w},{U}_{r}sim {{textrm{uniform}}}(mathrm{0,1})) from the hash and converted them into continuous offsets (w, r) inside the tile: (w={w}_{0}+Delta wtimes {U}_{w}), (r={r}_{0}+Delta rtimes {U}_{r}). This yields a point uniformly distributed over the tile area. We accept the dart if w < xi and r < rmax. Each accepted dart carries an ID h (another 64-bit tabular hash of the tile key plus a per-dart index) and its rank r. After this, we performed a bucketization step. We maintained k buckets or partitions, each storing the minimum rank seen thus far. A separate 64-bit tabular hasher maps h to a bucket index j = h mod k. If some buckets remain empty after one pass, we increase θ and repeat steps 2 to 5 until all k buckets are filled. For all the hashing-related steps, we used a simple tabulation hashing (32 and 64 bits), which indexes small random tables with byte/word positions and XORs the looked-up entries38. It is fast and stateless and provides strong practical independence when composing multiple keys (IDs, scales and tile offsets) for MinHash-like algorithms. It has been shown that, for simple MinHash, tabulation hashing, especially mixed tabulation hashing, yields concentration essentially as good as truly random hashing for bucket/partition hashing39. DartMinHash produces per-bucket minima via an exponential race; once each bucket has a winner, the collision indicators across buckets behave like independent Bernoulli trials with the mean equal to weighted Jaccard similarity. Under the hashing assumptions (as good as truly random hashing), DartMinHash has variance and concentration that match the unweighted case in practice, although mixed tabulation hashing provides even stronger guarantees39. For any two resulting sketches with length k, the hash collision probability of IDs across positions is an unbiased estimator of weighted Jaccard similarity, and the variance is J(1 – J)/k. Default sketch size k is 2,048 unless specified otherwise. In practice, a sketch size around 2,000 to 3,000 is good enough for drawing biological conclusions from analyses such as PERMANOVA and PCoA based on DartUniFrac. However, users may need to increase the sketch size for analyses such as hierarchical clustering and high-recall (for example, >0.95) nearest-neighbor search, following (kge frac{1}{4{delta }^{2}}) for an expected absolute error ẟ (Supplementary Methods). See the detailed guidelines in Supplementary Table 13.
Big-O notation for DartMinHash and b-bit DartMinHash
The DartMinHash sketch step big-O notation is (Oleft(ktimes{log}(k)+right.)(parallel x{parallel }_{0})({log}left(parallel {mathbf{x}} {parallel }_{1}+right.)(frac{1}{parallel {mathbf{x}} {parallel }_{1}}left.left.right)right))15, where (parallel mathbf{x}{parallel }_{0}) is the number of nonzero elements in a set (one sample), while (parallel mathbf{x} {parallel }_{1}) is the sum of weights of all nonzero elements. This holds as long as (parallel mathbf{x} {parallel }_{1}) is not extremely small or large, which is the case for real-world microbiome datasets, DartMinHash sketching complexity is simply (O({k}times{mathrm{log}}(k)+ctimes parallel mathbf{x} {parallel }_{0})), where c is a small constant. In the case of DartUniFrac, (parallel mathbf{x} {parallel }_{0}) will be the average number of active branches for each sample, and k is the sketch size. We rewrite the sketching complexity for N samples using Tactive as (parallel mathbf{x} {parallel }_{0}) and S as the sketch size: O(N × Tactive + N × S × log(S)). Similar to the b-bit MinHash idea40, the 64-bit integer hashes in sketch vectors can be reduced to b = 32 or 16 bits (default) by extracting the lower 32 or 16 bits of hashes before computing collision probability40. The noise of the new estimator is 2−b. For b > 14, the noise can be ignored as 2−b is rather small.
ERS implementation
We first defined caps and red–green indexes. For a weighted set X = {(i, xi)} (here i indicates a branch, while xi is ({{ell}}_{i}times sum _{jin {{textrm{Desc}}}(i)}{a}_{j}), where aj is the abundance of descendant taxa/leaves under branch i) with xi > 0, choose tight real-valued caps mi ≥ max xi(s) across the dataset and build a cumulative array cum with cum[0] = 0, cum[i + 1] = cum[i] + mi; let (M=sum _{i}{m}_{i}). This defines a line [0, M) partitioned into segments [cum[i], cum[i + 1]]. A draw (rin [0,M)) maps to component i by binary search (‘red–green’ test). Then, for efficiency, we created dense weights for membership tests. Materialize a dense vector w of length D with wi = xi (0 otherwise). This allows an O(1) acceptance check once the component index is found. We then generated k independent sequences. For each hash position (jin {0,ldots ,k-1}), generate a fixed-length sequence ({r}_{!j,1},ldots ,{r}_{!j,L}). Each rj,t is produced by hashing the key (j, t) to a uniform distribution (uin [mathrm{0,1})) and setting r = μ. Next, the red–green acceptance test maps r to component i by upper bounding in cum. The draw is green (accept) if r ≤ cum[i] + xi; otherwise, it is red (reject). Upon the first green for position j, emit the pair (IDj, rankj), where IDj is a 64-bit hash derived from the accepted draw r and ({text{rank}}_{j}:=t) (the first-hit index). After the red–green test, a densification (or rotation) is performed. If a position j has no green after L attempts, mark it empty and densify draw a per-j offset (oin {1,ldots ,k-1}) and scan circularly to copy the nearest nonempty bucket’s (ID, rank). This procedure is data-independent and preserves the collision-probability estimator. We finally return k pairs (IDj, rankj). For any two sketches, the collision probability of IDs across positions is an unbiased estimator of weighted Jaccard similarity, and the variance is J(1 – J)/k. Tight capacities (small M) increase acceptance and allow smaller L. All randomness is via simple tabulation hashing: treat keys as words/bytes, look up in small random tables and XOR results38. Separate 64-/32-bit tabulators drive (1) uniforms u for r; (2) stable IDs from r; and (3) densification offsets—yielding fast, stateless, reproducible pseudorandomness suitable for composing keys (j, t) and r. Let (p=Pr [{{textrm{green}}}]=parallel mathbf{x} {parallel }_{1}/M) under caps mi (with (M=sum _{i}{m}_{i})). A bucket is empty only if all L trials are rejected, so ({p}_{{{textrm{empty}}}}={(1-p)}^{L}approx {e}^{-{pL}}). We choose L to make empties rare across the sketch, for example, (ktimes{p}_{{{textrm{empty}}}}le epsilon), giving (Lgtrsim mathrm{ln}(k/epsilon )/p). Thus, tighter caps (smaller M) and larger sample mass (parallel mathbf{x} {parallel }_{1}) allow smaller L; in practice, we use a conservative fixed L or adapt L using (p=parallel mathbf{x} {parallel }_{1}/M). In microbiome feature tables that are highly sparse (typically 0.1–10% nonzero), the effective ERS acceptance probability (p=parallel mathbf{x} {parallel }_{1}/M) is often on the order of 10−2 or higher under tight dataset-wide caps; in this regime, L = 512 makes empty buckets rare for k = 2048 (because (ktimes{(1-p)}^{L}approx ktimes{e}^{-{pL}}ll 1)). Accordingly, we use L = 512 as a conservative default and increase L for datasets where the observed p is smaller. The same b-bit idea can be applied to ERS.
Sketch cost, size and set dimension
DartUniFrac approximates UniFrac distances by estimating the underlying weighted Jaccard similarity Jw between branch-length-weighted feature vectors using weighted MinHash (DartMinHash or ERS). Theoretical results for (weighted) MinHash show that the estimator Jw is unbiased and that its variance scales approximately as ({{textrm{Var}}}({hat{J}}_{{textrm{w}}})propto 1/k), where k is the sketch size and does not depend on the ambient dimensionality (for example, the number of taxa or branches in the tree). Intuitively, the sketch samples from the distribution of nonzero branch masses in each sample; adding branches with zero mass in both samples does not change this distribution and therefore does not affect the approximation error. Consequently, for a given similarity regime and typical sparsity pattern (that is, when the number of nonempty taxa per sample remains stable), keeping k fixed yields approximately constant RMSE in Jw and thus in the resulting UniFrac distances, even as the tree grows to include many more taxa and branches. This is the advantage over exact methods, where if samples contain the taxa, these taxa/branches must be built into the stripe in the Striped UniFrac algorithm and then compared in a pairwise manner, thus substantially increasing the space and computation. For DartUniFrac, due to early-stop conditions in DartMinHash, more taxa/branches will only add to the hashing cost per sample, which is a constant-time operation.
Implementation, parallelization, SIMD Hamming and GPU integer Hamming
DartUniFrac is implemented in pure Rust. All steps, including tree traversal, sample vector parsing, DartMinHash/ERS sketching and integer Hamming distance computation, are fully parallelized via the Rayon library. To further speed up integer Hamming distance computation on the CPU, we used SIMD on modern CPUs via the Rust standard library portable SIMD API. GPU implementation is based on cudarc (https://crates.io/crates/cudarc), a Rust API around the NVIDIA CUDA library, supporting multiple NVIDIA GPUs. Briefly, each sketch vector (representing each sample) is sent from CPU to GPU, and each GPU maintains a copy of all sketches. Because the sketch vector is very small (a few kilobytes), GPU memory consumption is rather small even for millions of samples (~3 GB with default b bits=16) (Fig. 2j). Each GPU is only responsible for computing a small portion of the integer Hamming similarity computation in a multi-GPU setting. The resulting integer Hamming similarity will be sent to the CPU once the computation is finished and stored in CPU RAM. In the streaming setting, a block of the distance matrix will be computed first and then sent to the CPU for writing, while the GPU starts computation for the next block of the distance matrix. Once the writing of the first block is finished, it will be released from CPU memory (RAM). In practice, writing is faster than GPU computing if the block size is not too large compared with the number of samples.
fPCoA based on randomized SVD
Instead of exact SVD in exact PCoA (the speed-limiting step)41, we use a randomized SVD based on randomized subspace iteration (simultaneous power iteration) for datasets with >5,000 samples rather than the randomized block Krylov method used in scikit-bio (v0.7.0)41. Subspace iteration typically requires orthogonalizing fewer basis vectors and can be more GEMM heavy (and thus more cache friendly for level 3 BLAS), whereas block Krylov methods offer stronger accuracy guarantees per pass37. We perform the required vector orthogonalization using a LAPACK backend via the Rust lax crate. In our regime—dense N × N distance matrices with up to hundreds of thousands of samples and a modest target rank, randomized subspace iteration and randomized block Krylov have essentially the same dominant cost because both are driven primarily by a small number of passes over the distance matrix (matrix-block multiplies)37. Therefore, only modest speedups are expected from switching between these two approaches for in-memory implementations. The output from fPCoA can be imported directly to scikit-bio and QIIME 2 for visualization. To compare with scikit-bio (v0.7.1) fast PCoA, the ‘fsvd’ option was used to perform randomized block Krylov SVD. k = 10 was used for both fast PCoA in scikit-bio and DartUniFrac.
Benchmarking software packages and dataset generation
We use the original Striped UniFrac (v0.9.3)7 and the hardware-optimized Striped UniFrac called unifrac-binaries (v1.6.0)9 as the truth. For GPU-based comparisons, the GPU implementation of unifrac-binaries is used. The latter represents the current fastest exact UniFrac implementation with hardware optimization. DartUniFrac v0.3.0 was used for all the benchmarks. EMP data were downloaded from the EMP project4. The same processing pipeline was used to obtain OTU feature tables and phylogenetic trees. Briefly, sequence data were error filtered and trimmed to the length of the shortest sequencing run (90 bp) using Deblur (v1.1.1)30. Deblur observation tables were filtered to keep only tag sequences with at least 25 total reads across all samples. For comparison to existing OTU tables, traditional closed-reference OTU picking was done against the 16S rRNA databases Greengenes 13.8 (ref. 42) and SILVA 123 (ref. 43) using SortMeRNA (v6.0.2)44 and subsampled open-reference OTU picking was done against Greengenes 13.8. The AGP data were also obtained from the original paper5, and a similar processing approach was used to obtain the OTU feature table and the phylogenetic tree. Then, OTU feature tables from EMP and AGP were merged (the same closed-reference 16S rRNA gene database and phylogeny were used) to build a combined EMP and AGP dataset. The GMTOL dataset, which is a subset of EMP with samples that were taken from animal gut, was generated by mapping the metadata from EMP. We then also retrieved all amplicon studies (278,499 samples, ~1 million taxa) from Qiita18 via Rediom (v0.3.9)45 and applied a similar sequence processing pipeline as above to obtain OTU feature tables and phylogeny but against the most recent Greengenes 2 database46, a comprehensive 16S rRNA-based taxonomy–phylogeny framework anchored in a whole-genome phylogeny. The three-country THDMI (The Healthy Diet and Microbiome Initiative) dataset was downloaded from the original paper47. Briefly, quality-controlled reads from shotgun metagenomic sequencing were mapped to Web of Life version 2 (ref. 48) using Bowtie 2 (v2.5.4)49 with the SHOGUN (v1.0.0)50 parameter set in paired-end mode with a feature table estimated from Woltka (v0.1.7)6. Then, the abundance of each genome was obtained by counting the number of reads mapped to the genome with a minimum coverage breadth filter (0.1%)51. The phylogenetic tree was provided by the abovementioned genome database. For simulated datasets, for example, 100,000, 300,000, 500,000 and 1,000,000 samples, all taxa from EMP and AGP (875,222 taxa) and Greengenes 2 (23,450,268 taxa) were used as input features, and then taxon abundances for each sample were generated from a normal distribution with adjustable sparsity (for example, 0.05–5%). The code repository for simulating feature tables can be found in the Code availability section. All statistical analyses, including PERMANOVA, Procrustes, Mantel and hierarchical clustering topology analyses, were performed using scikit-bio (v0.7.0)41 and SciPy (v1.16.1)52.
Reporting summary
Further information on research design is available in the Nature Portfolio Reporting Summary linked to this article.
Data availability
All the data mentioned above are publicly available.
Code availability
DartUniFrac implementation can be found in the GitHub repository at https://github.com/jianshu93/DartUniFrac or via Zenodo53. Scripts for reproducing the main figures/results can be found in the scripts folder of the GitHub repository. DartUniFrac (including the GPU version) can be easily installed via Bioconda (https://anaconda.org/bioconda/dartunifrac). GitHub repositories of key libraries, including DartMinHash/ERS, succparen, SIMD Hamming and fPCoA, can also be found in the above main DartUniFrac repository. GPU implementation can be found at https://github.com/jianshu93/DartUniFrac/tree/DartUniFrac-GPU. The code for simulating large numbers of microbiome feature tables can be found here: https://github.com/jianshu93/sparse_features.
References
Lozupone, C. & Knight, R. UniFrac: a new phylogenetic method for comparing microbial communities. Appl. Environ. Microbiol. 71, 8228–8235 (2005).
Google Scholar
Lozupone, C. A., Hamady, M., Kelley, S. T. & Knight, R. Quantitative and qualitative β diversity measures lead to different insights into factors that structure microbial communities. Appl. Environ. Microbiol. 73, 1576–1585 (2007).
Google Scholar
Lozupone, C., Lladser, M. E., Knights, D., Stombaugh, J. & Knight, R. UniFrac: an effective distance metric for microbial community comparison. ISME J. 5, 169–172 (2011).
Google Scholar
Thompson, L. R. et al. A communal catalogue reveals Earth’s multiscale microbial diversity. Nature 551, 457–463 (2017).
Google Scholar
McDonald, D. et al. American Gut: an open platform for citizen science microbiome research. mSystems 3, 00031-18 (2018).
Zhu, Q. et al. Phylogeny-aware analysis of metagenome community ecology based on matched reference genomes while bypassing taxonomy. mSystems 7, e00167-22 (2022).
Google Scholar
McDonald, D. et al. Striped UniFrac: enabling microbiome analysis at unprecedented scale. Nat. Methods 15, 847–848 (2018).
Google Scholar
Locey, K. J. & Lennon, J. T. Scaling laws predict global microbial diversity. Proc. Natl Acad. Sci. USA 113, 5970–5975 (2016).
Google Scholar
Sfiligoi, I., Armstrong, G., Gonzalez, A., McDonald, D. & Knight, R. Optimizing UniFrac with OpenACC yields greater than one thousand times speed increase. mSystems 7, e00028–22 (2022).
Google Scholar
Hamady, M., Lozupone, C. & Knight, R. Fast UniFrac: facilitating high-throughput phylogenetic analyses of microbial communities including analysis of pyrosequencing and PhyloChip data. ISME J. 4, 17–27 (2010).
Google Scholar
Jain, C., Rodriguez-R, L. M., Phillippy, A. M., Konstantinidis, K. T. & Aluru, S. High-throughput ANI analysis of 90K prokaryotic genomes reveals clear species boundaries. Nat. Commun. 9, 5114 (2018).
Google Scholar
Zhao, J., Both, J. P., Rodriguez-R, L. M. & Konstantinidis, K. T. GSearch: ultra-fast and scalable genome search by combining K-mer hashing with hierarchical navigable small world graphs. Nucleic Acids Res. 52, e74 (2024).
Google Scholar
Ondov, B. D. et al. Mash: fast genome and metagenome distance estimation using MinHash. Genome Biol. 17, 132 (2016).
Google Scholar
Zhao, X. BinDash, software for fast genome distance estimation on a typical personal laptop. Bioinformatics 35, 671–673 (2019).
Google Scholar
Christiani, T. Dartminhash: fast sketching for weighted sets. Preprint at arXiv https://doi.org/10.48550/arXiv.2005.11547 (2020).
Li, X. & Li, P. Rejection sampling for weighted Jaccard similarity revisited. In Proc. AAAI Conference on Artificial Intelligence Vol. 35 (eds Leyton-Brown, K. & Mausam) 4197–4205 (AAAI Press, 2021).
Wu, L. et al. Global diversity and biogeography of bacterial communities in wastewater treatment plants. Nat. Microbiol. 4, 1183–1195 (2019).
Google Scholar
Gonzalez, A. et al. Qiita: rapid, web-enabled microbiome meta-analysis. Nat. Methods 15, 796–798 (2018).
Google Scholar
McDonald, D. et al. The Biological Observation Matrix (BIOM) format or: how I learned to stop worrying and love the ome-ome. Gigascience 1, 7 (2012).
Google Scholar
Sheth, R. U. et al. Spatial metagenomic characterization of microbial biogeography in the gut. Nat. Biotechnol. 37, 877–883 (2019).
Google Scholar
Halko, N., Martinsson, P.-G. & Tropp, J. A. Finding structure with randomness: probabilistic algorithms for constructing approximate matrix decompositions. SIAM Rev. 53, 217–288 (2011).
Google Scholar
van de Velde, C. et al. Technical versus biological variability in a synthetic human gut community. Gut Microbes 15, 2155019 (2023).
Google Scholar
McClelland, J. & Koslicki, D. EMDUniFrac: exact linear time computation of the UniFrac metric and identification of differentially abundant organisms. J. Math. Biol. 77, 935–949 (2018).
Google Scholar
Smarr, L. Quantifying your body: a how-to guide from a systems biology perspective. Biotechnol. J. 7, 980–991 (2012).
Google Scholar
Chen, J. et al. Associating microbiome composition with environmental covariates using generalized UniFrac distances. Bioinformatics 28, 2106–2113 (2012).
Google Scholar
Chang, Q., Luan, Y. & Sun, F. Variance-adjusted weighted UniFrac: a powerful beta diversity measure for comparing communities based on phylogeny. BMC Bioinform. 12, 118 (2011).
Google Scholar
Evans, S. N. & Matsen, F. A. The phylogenetic Kantorovich–Rubinstein metric for environmental sequence samples. J. R. Stat. Soc. B 74, 569–592 (2012).
Google Scholar
Charikar, M. S. Similarity estimation techniques from rounding algorithms. In Proc. 34th Annual ACM Symposium on Theory of Computing (ed. Reif, J.) 380–388 (ACM, 2002).
Pendleton, A. & Schmidt, M. L. Interpreting UniFrac with absolute abundance: a conceptual and practical guide. ISME Commun. 6, ycaf250 https://doi.org/10.1093/ismeco/ycaf250 (2026).
Amir, A. et al. Deblur rapidly resolves single-nucleotide community sequence patterns. mSystems https://doi.org/10.1128/msystems.00191-00116 (2017).
Callahan, B. J. et al. DADA2: high-resolution sample inference from Illumina amplicon data. Nat. Methods 13, 581–583 (2016).
Google Scholar
Edgar, R. C. UNOISE2: improved error-correction for Illumina 16S and ITS amplicon sequencing. bioRxiv https://doi.org/10.1101/081257 (2016).
Geary, R. F., Rahman, N., Raman, R. & Raman, V. A simple optimal representation for balanced parentheses. Theor. Comput. Sci. 368, 231–246 (2006).
Google Scholar
Ertl, O. Bagminhash-minwise hashing algorithm for weighted sets. In Proc. 24th ACM SIGKDD International Conference on Knowledge Discovery & Data Mining (eds Guo, Y. & Farooq, F.) 1368–1377 (ACM, 2018).
Wu, W., Li, B., Chen, L., Zhang, C. & Yu, P. S. Improved consistent weighted sampling revisited. IEEE Trans. Knowl. Data Eng. 31, 2332–2345 (2018).
Google Scholar
Ioffe, S. Improved consistent sampling, weighted minhash and L1 sketching. In 2010 IEEE International Conference on Data Mining 246–255 (IEEE, 2010).
Musco, C. & Musco, C. Randomized block Krylov methods for stronger and faster approximate singular value decomposition. In Advances in Neural Information Processing Systems 28 (eds Cortes, C. et al.) 1396–1404 (Curran Associates, 2015).
Pǎtraşcu, M. & Thorup, M. The power of simple tabulation hashing. J. ACM 59, 1–50 (2012).
Google Scholar
Dahlgaard, S., Knudsen, M. B. T., Rotenberg, E. & Thorup, M. Hashing for statistics over k-partitions. In 2015 IEEE 56th Annual Symposium on Foundations of Computer Science 1292–1310 (IEEE, 2015).
Li, P. & König, C. b-Bit minwise hashing. In Proc. 19th International Conference on World Wide Web (eds Rappa, M. et al.) 671–680 (ACM, 2010).
Aton, M. et al. Scikit-bio: a fundamental Python library for biological omic data analysis. Nat. Methods 23, 274–276 (2026).
Google Scholar
McDonald, D. et al. An improved Greengenes taxonomy with explicit ranks for ecological and evolutionary analyses of bacteria and archaea. ISME J. 6, 610–618 (2012).
Google Scholar
Quast, C. et al. The SILVA ribosomal RNA gene database project: improved data processing and web-based tools. Nucleic Acids Res. 41, D590–D596 (2012).
Google Scholar
Kopylova, E., Noé, L. & Touzet, H. SortMeRNA: fast and accurate filtering of ribosomal RNAs in metatranscriptomic data. Bioinformatics 28, 3211–3217 (2012).
Google Scholar
McDonald, D. et al. Redbiom: a rapid sample discovery and feature characterization system. mSystems https://doi.org/10.1128/msystems.00215-00219 (2019).
McDonald, D. et al. Greengenes2 unifies microbial data in a single reference tree. Nat. Biotechnol. 42, 715–718 (2024).
Google Scholar
Khatib, L. et al. A three-country analysis of the gut microbiome indicates taxon associations with diet vary by taxon resolution and population. mSystems 10, e0054425 (2025).
Zhu, Q. et al. Phylogenomics of 10,575 genomes reveals evolutionary proximity between domains bacteria and archaea. Nat. Commun. 10, 5477 (2019).
Google Scholar
Langmead, B. & Salzberg, S. L. Fast gapped-read alignment with Bowtie 2. Nat. Methods 9, 357–359 (2012).
Google Scholar
Hillmann, B. et al. SHOGUN: a modular, accurate and scalable framework for microbiome quantification. Bioinformatics 36, 4088–4090 (2020).
Google Scholar
Weng, Y. et al. Calculating fast differential genome coverages among metagenomic sources using micov. Commun. Biol. 8, 1624 (2025).
Google Scholar
Virtanen, P. et al. SciPy 1.0: fundamental algorithms for scientific computing in Python. Nat. Methods 17, 261–272 (2020).
Google Scholar
Zhao, J. DartUniFrac: approximate UniFrac via weighted MinHash. Zenodo https://doi.org/10.5281/zenodo.18486836 (2026).
Acknowledgements
We thank T. Christiani and O. Ertl for discussions on the DartMinHash algorithm and X. Li for discussions on implementation details of the ERS algorithm.
Funding
This work was funded in part by the Department of Energy, USA, to R.K. (DE-SC0024320). This work was also funded by the Minderoo Foundation (project title: eDNAID: Environmental DNA and AI as Tools for Ocean Aid) under award number CLB-3502 and the NIH under U19AG063744 (R.K.). L.P. is supported by NIH/NIGMS T32GM007198 and NIH/NIA F30AG094275.
Author information
Authors and Affiliations
Contributions
J.Z. designed the algorithm, conducted the proof and implemented the code. M.E.L. and C.A.L. helped with the mathematical proof. J.Z. performed the software benchmarking. D.M., I.S., L.P., Y.W., L.K., S.D. and A.G. helped with the software benchmarking. I.S. helped with GPU code compiling. J.Z. wrote the paper with input from all authors. R.K. supervised the work.
Corresponding author
Ethics declarations
Competing interests
R.K. is a scientific advisory board member and consultant for BiomeSense and has equity and receives income. He is a scientific advisory board member for and has equity in GenCirq. He has equity in and acts as a consultant for Cybele. He is a vice president and board member of Microbiota Vault. He is a board member of the N = 1 IBS advisory board and receives compensation. He is a senior visiting fellow of the HKUST Jockey Club Institute for Advanced Study. The terms of these arrangements have been reviewed and approved by the University of California, San Diego, in accordance with its conflict-of-interest policies. D.M. is a consultant for and has equity in BiomeSense. The terms of these arrangements have been reviewed and approved by the University of California, San Diego, in accordance with its conflict-of-interest policies. The other authors declare no competing interests.
Peer review
Peer review information
Nature Biotechnology thanks Brian Ondov and the other, anonymous, reviewer(s) for their contribution to the peer review of this work. Peer reviewer reports are available.
Additional information
Publisher’s note Springer Nature remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.
Supplementary information
Supplementary Information (download PDF )
Supplementary Tables 1–13, Figs. 1–25 and Methods.
Reporting Summary (download PDF )
Peer Review File (download PDF )
Rights and permissions
Open Access This article is licensed under a Creative Commons Attribution 4.0 International License, which permits use, sharing, adaptation, distribution and reproduction in any medium or format, as long as you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons licence, and indicate if changes were made. The images or other third party material in this article are included in the article’s Creative Commons licence, unless indicated otherwise in a credit line to the material. If material is not included in the article’s Creative Commons licence and your intended use is not permitted by statutory regulation or exceeds the permitted use, you will need to obtain permission directly from the copyright holder. To view a copy of this licence, visit http://creativecommons.org/licenses/by/4.0/.
Reprints and permissions
About this article
Cite this article
Zhao, J., McDonald, D., Sfiligoi, I. et al. Megascale microbiome analysis with DartUniFrac.
Nat Biotechnol (2026). https://doi.org/10.1038/s41587-026-03260-8
Received:
Accepted:
Published:
Version of record:
DOI: https://doi.org/10.1038/s41587-026-03260-8
Source: Ecology - nature.com
