Abstract
Sequence comparison tools for metagenome-assembled genomes (MAGs) struggle with high-volume or low-quality data. We present skani (https://github.com/bluenote-1577/skani), a method for determining average nucleotide identity (ANI) via sparse approximate alignments. skani outperforms FastANI in accuracy and speed (>20× faster) for fragmented, incomplete MAGs. skani can query genomes against >65,000 prokaryotic genomes in seconds and 6 GB memory. skani unlocks higher-resolution insights for extensive, noisy metagenomic datasets.
Subject terms: Genome informatics, Software, Metagenomics, Metagenomics
skani achieves fast calculation of average nucleotide identity (ANI) between metagenome-assembled genomes (MAGs), with improved robustness against incomplete and fragmented MAGs.
Main
Consider the fundamental problem of computing sequence-to-sequence similarity between metagenome-assembled genomes (MAGs). Modern studies generate hundreds of thousands of MAGs1,2, and searching these MAGs against a database or computing all pairwise similarities takes billions of comparisons; this is infeasible with traditional alignment-based methods. Thus, large-scale sequence comparison for metagenomic data is dominated by sketching methods. Sketching methods summarize datasets into small collections of k-mers; these sketches can be efficiently compared against one another and return an average nucleotide identity (ANI) estimate.
Unfortunately, sketching methods such as Mash3 or sourmash4 may underestimate ANI when genome incompleteness is present5. The decrease has nothing to do with the genetic distance between the genomes; it is simply an artefact of the assembly being incomplete. Even ‘medium-quality’ MAGs typically only require >50% completeness1, so this is an issue in practice. On the other hand, alignment-based methods are able to estimate ANI from only the orthologous regions, so incompleteness is not an issue. Additionally, the fraction of the genomes aligned to one another (the aligned fraction) is a useful statistic that pure sketching methods do not estimate. There is thus a need for algorithms that are fast, like sketching methods, yet robust to noise due to assembly artefacts, like alignment methods.
We developed skani, a fast, robust tool for calculating aligned fraction and ANIs in the >82% range. skani’s ANI method is robust against incomplete and fragmented MAGs, yet it is multiple orders of magnitude faster than alignment-based methods and over an order of magnitude faster than even the state-of-the-art FastANI6. skani uses a very sparse k-mer chaining7–9 procedure to quickly find orthologous regions between two genomes. This allows for sequence identity estimation using k-mers on only the shared regions between two genomes (Fig. 1a), avoiding the pitfalls of alignment-ignorant sketching methods. Like BLAST-based ANI methods, skani breaks genomes into nonoverlapping fragments, estimates the ANI for each fragment and then averages the ANI to output an ANI estimate. We then use a trained regression model to debias our ANI estimates (Methods).
We first verified that existing ANI methods are indeed sensitive to incompleteness and fragmentation in Extended Data Fig. 1. In a synthetic test, fragmented, incomplete yet identical genomes had ANI estimates that were systematically lower than 100% for all methods but ANIm10,11, a slow but accurate method. We subsequently chose ANIm as a baseline when comparing MAGs. Mash was the most affected, with up to a difference of 4% ANI at 50% completeness, which can cause two very similar genomes of up to 99% ANI to be classified as different species when subject to the standard 95% ANI species threshold6. FastANI was sensitive to fragmentation (low N50), which is why a minimum N50 of 10,000 is used in the original study6, but that N50 requirement is not met in many real experiments1,12. We additionally show simulations with mutations and chimeric genomes in Supplementary Figs. 1–3.
Next, we showed on real MAGs that only skani and ANIm are robust to MAG quality for high-resolution ANI calculations. In Fig. 1b, we compared subspecies level MAGs generated by Pasolli et al1, a large collection of medium-quality and high-quality short-read assembled MAGs. As incompleteness and contamination increase, Mash and FastANI trend toward lower ANI, but this is not seen for ANIm (Extended Data Fig. 2) or skani. Extended Data Fig. 3 confirms our simulation results and shows that incompleteness and fragmentation are to blame for the bias.
Because ANI underestimations due to MAG quality are systematically biased, such ANI estimates can strongly impact downstream applications. We show in Fig. 1c that the cluster heatmaps obtained by average-linkage clustering for a species-level bin differ greatly between ANI methods. skani’s heatmap qualitatively resembles ANIm’s heatmap (Extended Data Fig. 2) more closely than the other methods, yet it is >500 times faster than ANIm and >50 times faster than FastANI for computing the distance matrix (Supplementary Fig. 5).
To quantify the concordance of the clustering against ANIm, we used cophenetic correlation13 (Supplementary Note). In Fig. 1c and Extended Data Fig. 4, we see that skani has a better cophenetic correlation with respect to ANIm than all other compared methods. Notably, the ordering of the methods with respect to cophenetic correlation in Extended Data Fig. 4 is skani > sourmash max-contain14 > FastANI > mash; this exactly agrees with the ordering using R2 values from the contamination-incompleteness plots in Fig. 1b and Extended Data Fig. 2, implying that MAG assembly artefacts are indeed to blame for the clustering discordance.
We explore skani on three additional datasets: ocean eukaryotic MAGs15,16, ocean archaea MAGs12 and soil prokaryotic MAGs17, which in addition to the Pasolli et al. dataset gives four datasets in total. Extended Data Fig. 5 shows that skani’s results generalize to a diverse set of genomes, including eukaryotic MAGs with a median size of 17.6 Mbp (and 32 MAGs of size >100 Mbp). When comparing each method’s deviation from ANIm and considering the 1 to 99 percentile deviations, skani has the smallest 1 to 99 percentile interval lengths, indicating robustness. Extended Data Figs. 6 and 7 show that skani has a better linear aligned fraction correlation with ANIm than FastANI. The aligned fraction accuracy can be improved further by controlling subsampling rate of the k-mers (parameter c in Methods).
An important task is classifying MAGs (or isolate genomes) by searching against a database of reference genomes. Such databases represent a diverse collection of genomes where only a fraction of the genomes are similar to the query. Therefore, sensitively searching against each reference is unnecessary. To enable efficient database search, we augmented skani with a quick sketching-based ANI filter against distant genomes before performing a more accurate ANI computation.
Figure 2 shows that skani can query an Escherichia coli genome against the GTDB R207 database18 (>65,000 genomes) in comparable speed and memory to Mash. skani is much faster than FastANI for querying (>20 times on the E. coli dataset) and is >2.5 times faster than Mash for indexing. Furthermore, skani can do all-to-all comparisons on a set of 4,233 bacterial genomes as quickly as Mash due to the fast filtering of unrelated genomes. FastANI takes much longer (Supplementary Fig. 9), but FastANI does more comparisons due to a slightly larger valid ANI range.
In Fig. 2a and Supplementary Fig. 7, we benchmarked skani against OrthoANIu19,20 (which we shorten to ANIu), a faster but almost-identical analogue of the BLAST-based ANIb, as a baseline. We did not use ANIm, because ANIm overestimates ANI for pairs of genomes with <90% ANI20,21. skani outputs an ANI estimate only if one of the genomes has predicted AF ≥15% by default, which ends up giving reasonable ANIs down to the 82% range on the three datasets shown. skani’s accuracy is usually better than Mash but slightly worse than FastANI for reference-quality genomes, skani is better on the E. coli dataset, which includes many fragmented, possibly incomplete genomes that give rise to many Mash and FastANI outliers. The results for FastANI improved (Pearson R from 0.974 to 0.994) on the E. coli dataset if we removed genomes with N50 <10,000, giving the exact same Pearson R value as the originally reported FastANI results6. Thus, skani gives only slightly less accurate values than FastANI on reference-quality genomes with the assurance of robustness for low-quality assemblies.
We have shown that skani improves on the state-of-the-art for metagenomic sequence comparison. skani’s key operating regimes are for medium-to-high ANI (>82%), comparisons against diverse sets of genomes (such as databases), and fast all-to-all comparisons for up to tens of thousands of highly similar genomes. skani is limited in extreme regimes, such as low ANI or comparing hundreds of thousands of similar genomes (for example all-to-all calculation for the >200,000 E. coli genomes currently available in RefSeq). Future work includes exploring parameter choices and methods for accessing more extreme operating regimes, for example, linear-time clustering heuristics or more sensitive amino-acid computations.
In conclusion, skani is almost as fast as sketching-based methods for ANI database search, yet it gives a more robust signal when comparing noisy MAGs. Given the overwhelming amount of data generated by modern metagenomic studies, we believe skani’s ability to analyze an order of magnitude more data while simultaneously giving a stronger signal will allow examination of vast metagenomic sequences at a higher resolution, unlocking new types of analysis not possible before.
Methods
Sequence identity estimation
Formally, let G be a string of nucleotides and be a mutated version of G where every letter is independently changed to a different letter with probability θ. We will define the true ANI to be equal to 1 − θ under our model. Under the usual assumption of no repetitive k-mers24, it is easy to estimate θ from k-mer matching statistics3,24,25 between G and . We proved in a previous work that for random, mutating strings, the expected number of k-mer matches arising spuriously from repetitiveness for a string of length n is (Theorem 4 in Shaw and Yu26), so the usual assumption of no repetitive k-mers is not a bad one in practice for simpler, non-eukaryotic genomes and large enough k.
Sketching methods such as Mash3 or sourmash4 use the above framework to calculate ANI through the aforementioned k-mer statistics, which are built around estimating the normalized overlap between the k-mers in two genomes. More precisely, these indices take the form where A and B are the sets of k-mers in two genomes, and f(A, B) controls the normalization. The Jaccard index used in Mash3 corresponds to f(A, B) = ∣A ∪ B∣, and the containment index is f(A, B) = ∣A∣ (ref. 14). The main index we consider is the max-containment index, which corresponds to ; minimizing the denominator maximizes the containment. These indices can approximate ANI through simple formulas25,27.
However, when dealing with MAGs, we do not have G and but instead fragmented, contaminated and incomplete versions of G and . The models used in these sketching methods give biased estimates for ANI, resulting in underestimated ANIs, because missing k-mer matches may be due to mutations, incompleteness, or contamination instead of only due to mutations. Thus, all of the above k-mer statistics suffer from the following problem: as two MAGs become more incomplete, the overlap ∣A ∩ B∣ may decrease more than f(A, B) because a homologous k-mer is simply not present in the assembly, therefore making the index smaller.
This issue is also present in the context of k-mer based alignment-free genome comparison using reads28–30, where a genome could potentially not be fully covered due to the random sampling of reads. In our case, however, we have access to incomplete, fragmented assemblies instead of reads. Thus, to accurately use k-mer statistics, we first find orthologous regions by approximate alignment and then use k-mer statistics.
Algorithm outline
The main idea behind skani is to find an approximate set of orthologous alignments between two genomes by obtaining a set of minimally overlapping k-mer chains7 (the chains do not overlap much; the k-mers may overlap within the chain). We can then estimate ANI from the statistics of the k-mers in the chains, avoiding costly base-level alignment. The main algorithmic steps are listed below.
We use a very sparse set of marker ℓ-mers to estimate max-containment index and obtain a putative ANI using the FracMinHash method (section Sketching by FracMinHash). We filter out pairs of genomes with putative ANI <80% (section Max-containment putative ANI screening with marker ℓ-mers).
We select the genome with the larger score, defined as total sequence length times mean contig length, to be the reference and the other to be the query. We then fragment the query into 20-kb nonoverlapping chunks. In particular, this implies that the ANI computed by skani does not depend on the order of the inputs (that is, it is symmetric).
We extract fraction of k-mers for both genomes for some c (c = 125 by default) as seeds to be used for chaining using FracMinHash (section Obtaining sparse seeds for chaining).
For each chunk on the query, we chain the seeds using a standard banded, heuristic chaining method against the reference (section Chaining sparse k-mer seeds).
We greedily extract minimally overlapping chains between the query and the reference and output aligned fraction (section Obtaining orthologous chains from homologous chains).
We estimate the ANI for each chunk, output the mean ANI over all chunks, and perform a learned ANI debiasing step (sections Estimating ANI from chains and Nonparametric regression for ANI debiasing).
Sketching by FracMinHash
Instead of using the set of all k-mers in a genome, we use a compressed representation by sketching, by which we mean selecting only a subset of all k-mers. To obtain such a set of k-mers, we use the FracMinHash method31: given a hash function h that maps k-mers to [0, M], we select the k-mer x as a seed if h(x) < M/γ, where γ controls the fraction of selected k-mers. Assuming a uniform hash function, the expected fraction of selected k-mers is .
Although FastANI uses minimizer32 k-mers to estimate Jaccard index and then ANI, recently, it was shown that Jaccard estimates (and thus ANI estimates) from minimizer k-mers are biased27 and depend crucially on the window size w. Although this bias is not too bad when the w is small (FastANI uses relatively small w = 24), it scales as w increases. This means that a minimizer ANI estimator cannot use very sparse seeds, since the fraction of selected seeds is (ref. 33).
Max-containment putative ANI screening with marker ℓ-mers
skani is not optimized for comparing distant genomes, so we can filter out comparisons against distant genomes using a very sparse set of FracMinHash ℓ-mers, which we call markers. We use these markers to estimate the max-containment index14; the same method is implemented in sourmash25, although sourmash does not use max containment by default. Let a set of markers obtained from FracMinHash from the genome G1 (with γ = cm and ℓ-mers) be denoted as A, and denote B as the analogous set from the genome G2. Assuming one of the genomes is contained in the other completely, we then calculate an ANI estimate between two genomes G1, G2 as
The term on the right inside the exponent is the max-containment index. FracMinHash has only negligible bias in calculating the containment index25 and can be used to obtain an estimate of ANI no matter the density (the fraction of selected k-mers). We let ℓ = 21 for our marker ℓ-mers and cm = 1,000 by default. We found skani’s ANI algorithm was most accurate when ANI ≥ ~82%, so we only compare genomes with ANIFMH > 80% as a conservative underestimate.
We can store all markers contained in the reference genomes as keys in a hash table with the associated values being the set of genomes containing the key (that is, an inverted index). Given a query genome, we can then obtain the intersection of all markers for the query against the references by checking all of its markers against the inverted index. This allows computation of the max-containment index in running time dependent on the number of similar genomes in the references34. From this, we can obtain ANIFMH, making our filtering step fast as long as our reference and query genomes are diverse. When performing all-to-all pairwise comparisons, skani uses this strategy by default. However, when querying a small number of genomes against a database, skani iteratively checks all pairs of genomes by default because building the hash table takes a nontrivial amount of time.
Obtaining sparse seeds for chaining
The marker ℓ-mers described above are only used for filtering, but not for actually estimating the ANI. To actually estimate the ANI, we use a hybrid approach via local mapping (without base-level alignment) and containment index estimation. The first step in our approach is to obtain a different set of FracMinHash k-mers, this time taking γ, the sampling rate of k-mers, to be γ = c where c < cm, and k < ℓ. This gives a denser, more sensitive set of k-mers to be used as seeds. These new k-mers are called seeds instead of markers because we actually use them as seeds for k-mer matching and alignment. We note that although we could have used other ‘context-independent’ k-mer seeding methods that are more ‘conserved’ than FracMinHash35, we found that FracMinHash works well enough for relatively sparse seeds when c ≫ k.
By default, k = 15 and c = 125. We note that the small value of k = 15 used by default leads to too many repetitive anchors on larger genomes, so we mask the top seeds that occur more than 2,500/c times by default. See the section Chaining score function and algorithm below for a justification of the choice of 2,500/c.
Choosing the c parameter
The main parameter influencing runtime and accuracy is the c parameter. The default value of c = 125 works well on a variety of tasks such as searching databases and MAG comparison. We found that for very fragmented and distant genomes, lowering c may lead to more accurate ANI and AF estimates (Extended Data Figs. 5–7 and Supplementary Fig. 10). However, the runtime is inversely proportional to c. To guide users for choosing c, we suggest three different pre-set values of c (in addition to the default) in skani v0.1.2’s help messages based on empirical heuristics: a ‘slow’ pre-set with c = 30 for the most accurate AF estimates and pairs of genomes with N50 ≈ 3 kb, a ‘medium’ pre-set with c = 70 for genomes with ANI ≤95 and N50 ≤10 kb, and a ‘fast’ pre-set c = 200 for similar genomes with >95% ANI with N50 >10 kb.
skani’s index file sizes are inversely proportional to c, and a drawback of skani is that the index file sizes are larger than pure sketching methods (Supplementary Table 3), but the full indices can be stored on disk and only read into RAM by skani as needed (see skani implementation details).
Chaining sparse k-mer seeds
After selecting one genome as a reference and the other as the query, we fragment the query into 20-kb nonoverlapping chunks. For each chunk, we find a set anchors, which are exact k-mer matches between g and . Each anchor can be described by a tuple (x, y), indicating the starting position of the matching k-mers on g and respectively. We collect the anchors into a strictly increasing subsequence called a chain7 based on the ordering (x1, y1) ≺ (x2, y2) if x1 < x2 and y1 < y2.
We sort the anchors (x1, y1), …(xN, yN) in lexicographic order and let S(i, j) be the score of chaining the ith anchor to the jth anchor. We wish to find a strictly increasing subsequence (based on our previously defined ordering ≺ ) of anchors (i1, i2, …) maximizing ∑ℓS(iℓ, iℓ−1). The optimal such subsequence can be calculated in O(N2) time where N is the number of anchors by the following dynamic programming: letting f(i) be the optimal score of the chain up to the ith anchor, let
After calculating f(i) for each anchor i, we can obtain a set of optimal chains. We describe this in detail below.
Chaining score function and algorithm
The chaining problem can be solved optimally in sub-quadratic time for a variety of chaining costs8,9, but we opt for a simple heuristic method that is fast and good enough for our purposes instead. Letting (xi, yi) and (xj, yj) be the ith and jth anchors, we define our chaining cost to simply be S(i, j) = 20 − ∣(yj − yi) − (xj − xi)∣. Notably, we allow and do not penalize overlapping k-mers because this would bias the ANI calculation, as we want the chain to include all k-mers that arise from sequence homology. We also do not need to use more sophisticated scoring functions because we do not actually need to worry about base-level alignments or finding the longest chain. We use a banded dynamic programming method where instead of iterating over all j < i, we iterate only up to i − A < j < i or stop if ∣xi − xj∣ > B for some constants A and B. Thus, the worst-case time is O(AN) instead of O(N2). By default, we let A = B/c, where B = 2,500 and c is the seed subsampling rate. This banded procedure is a simpler version of minimap2.23’s chaining procedure, which also employs a heuristic to stop chaining early via the --max-chain-skip parameter.
Obtaining homologous chains by backtracking
For each chunk, after computing all optimal scores f(i) over all anchors using banded dynamic programming, we obtain optimal chains using the standard method of backtracking. That is, we store an array of pointers corresponding to anchors, where the pointer points to the optimal predecessor determined by the dynamic programming. For any anchor, we could then trace through this array to obtain the best chain corresponding to each anchor.
We wish to obtain a set of chains that do not share any anchors for each chunk. To do this, we partition the anchors into disjoint sets using a union-find data structure, taking unions of two anchor representatives whenever one anchor is an optimal predecessor of another. We then find the best f(i) within each disjoint set and backtrack to obtain the optimal chain within each disjoint set. We take the set of all such chains over all chunks and call these chains homologous chains.
Obtaining orthologous chains from homologous chains
It is possible that a single region chains to multiple paralogs, so the homologous chains obtained above may not be orthologous. We will use the term ‘orthologous’ loosely in the same sense as other ANI methods6 – we denote a set of mappings (corresponding to chains) to be orthologous if they do not overlap too much along one of the genomes (that is, no duplicated one-to-all mappings). To obtain orthologous chains, we use a greedy minimally overlapping chain-finding procedure. We first sort every homologous chain (over all chunks) by its score and examine the best chain, only examining chains with three or more anchors. If the overlap between this current best chain and any other already selected chains is less than 50% of the current chain’s length, we select this best homologous chain as an orthologous chain and then examine the next best homologous chain. We repeat this procedure until all remaining homologous chains overlap an orthologous chain by more than 50% and return all orthologous chains.
This procedure is similar in spirit to the reciprocal mapping method used in other ANI methods6,19 to capture orthology, but it avoids performing alignment twice, making running time twice as fast. Other more sophisticated methods36 exist for finding sets of orthologous alignments but we found this heuristic to be good enough for our method.
Estimating ANI from chains
For a given chunk, let α be the number of anchors in the orthologous chains on that chunk, and M be the number of seeds in the chunk. Then we estimate an ANI for each chunk by
This comes from modeling each k-mer as being an exact match and thus an anchor with probability (1 − θ)k under a simple, independent mutation model, so the expected number of anchors is (1 − θ)k times the number of k-mers25.
However, the above formula fails when only part of the chunk is homologous to the reference, which may happen due to incompleteness of MAGs or structural variation. This will underestimate the ANI, since not all seeds in the chunk arise from sequence homology. Let MLR be the number of seeds in the chunk contained only between the leftmost and rightmost anchor over all minimally overlapping chains, and consider
If and the number of bases covered by in between these flanking anchors is >4*c, then we use as the estimate instead. This heuristic comes from the observation that when the ANI is large enough, our sparse chains are relatively accurate, so we can truncate the chunk with good accuracy. However, if ANI is small, it is more possible that this heuristic incorrectly excludes seeds that arise from sequence homology, so we avoid applying the heuristic to distant pairs of genomes.
Estimating final ANI and AF
To obtain our final ANI estimates, we take a weighted mean over all chunks with weights given by M (or MLR if the heuristic is applied instead), the number of seeds in the chunk. We also report the reference and query alignment fraction as the sum of the bases covered by all chains divided by the respective genome size. The number of bases in a chain is the last anchor position minus the first anchor position plus 2*c, where the 2*c term is to account for k-mers near the edge of the chain missed by subsampling. By default, we only output a final ANI value if the alignment fraction is greater than 15%.
Because our final ANI estimate is just a weighted mean over the ANIs of the chunks, once we have these ANIs, we can quickly do bootstrapping by resampling the chunks and calculating the weighted mean over the resamples. We use 100 iterations and only proceed if there are >10 chunks, outputting the 5th and 95th percentile ANIs to be our final 90% confidence interval. We found that the bootstrap gave reasonable ANI confidence intervals over skani’s inherent uncertainty (for example k-mer seeding variance), but we stress that it does not account for any systematic biases of skani’s ANI estimator relative to other methods.
Nonparametric regression for ANI debiasing
The chaining procedure can overestimate ANI, because the chains may exclude homologous but mutated k-mers near the edges of the chain due to the local mapping procedure. To handle this, we introduce an optional post-processing regression step to debias skani.
We trained a gradient boosted regression tree with absolute deviation loss where the target variable is ANIm’s ANI calculation, and the features consist of the following: skani’s ANI, standard deviation of skani’s putative ANI distribution, and the 90th percentile contig lengths in the reference and query, and the average length of the k-mer chains, giving five features in total. We trained skani on a large, diverse set of 52,515 MAGs from Nayfach et al2. We computed all-to-all pairwise ANI values with >90% ANI according to an untrained version skani, and ran ANIm on the resulting 1,004,213 pairs of genomes. To tune hyperparameters such as tree depth, number of trees, and learning rate, we chose a set of human gut MAGs37 that comes from a separate study than the training set and the datasets used in our results and then optimized our parameters over this new dataset.
To show that skani is not simply memorizing the organisms in the dataset, we partitioned this training set into two sets, A and B, where each part is ‘disjoint’ from one another in the sense that skani does not output an ANI estimate between any MAG in A and B due to low aligned fraction (<15%). We show in Supplementary Figs. 6 and 11 that this debiasing procedure still corrects the ANI to be closer to a MUMmer-based ground truth.
We only debias comparisons with putative ANI > 90% and > 150, 000 aligned bases. We enable the debiasing procedure by default when the parameter c is ≥70. We noticed that for smaller c, bias is less of an issue. We trained two models, one for c = 125 (default) and another for c = 200. If the user selects a specific value of c, the model with corresponding c closer to the selected value is used. In particular, our results with c = 125 have debiasing enabled, but our results with c = 30 do not.
skani implementation details
skani is implemented in the rust, a systems-level programming language, for speed. skani implements four primary subcommands: sketch, dist, search and triangle. The sketch command stores genomes in sketched representation (k-mer seeds and markers) for drop-in replacement for the other three commands. We use the same fast invertible k-mer hash function as minimap2 (ref. 38) for sketching. Additionally, skani uses AVX2 SIMD instructions to do vectorized seeding of 64-bit k-mers in 256-bit lanes when AVX2 instructions are detected, which we found to speed up sketching by approximately 30%. Chaining was implemented naively with no hardware accelerations.
The three commands for sequence comparison, dist, triangle, and search, all calculate AF and ANI but have different runtime behavior. dist and triangle keeps all sketches in RAM, whereas the search command only keeps the marker k-mers in memory and allows for on-the-fly loading of the full sketch for each genome into RAM if the marker-based ANI threshold for the comparison is sufficiently high (≥ 80% by default), afterward discarding the index from RAM. This makes search much more memory efficient and possibly more time-efficient than dist when querying a large database, but it is IO-bound and not as efficient as dist when performing all-to-all comparisons. The triangle command is similar to dist but is limited to computing distance matrices, but because skani is symmetric, it performs only n(n − 1)/2 comparisons instead of all n2. The inverted index for marker k-mer filtering is enabled by default in triangle, and otherwise in search and dist when the number of query genomes is ≥100. See Supplementary Fig. 12 for a benchmark on skani’s runtime scaling with thread usage.
Benchmarking details
All runtimes were benchmarked on a Intel Xeon CPU at 3.10 GHz machine with 64 cores and 240 GB RAM as a Google Cloud instance with a persistent SSD disk. Unless otherwise specified, all programs were run using 50 threads. Exact commands are shown in Supplementary Table 1.
Reporting summary
Further information on research design is available in the Nature Portfolio Reporting Summary linked to this article.
Online content
Any methods, additional references, Nature Portfolio reporting summaries, source data, extended data, supplementary information, acknowledgements, peer review information; details of author contributions and competing interests; and statements of data and code availability are available at 10.1038/s41592-023-02018-3.
Supplementary information
Acknowledgements
J.S. was supported by an NSERC CGS-D scholarship. Work supported by Natural Sciences and Engineering Research Council of Canada (NSERC) grant RGPIN-2022-03074 and DND/NSERC Supplement DGDND-2022-03074.
Extended data
Author contributions
J.S. conceived the project, designed the algorithms and implemented skani. Y.W.Y. supervised and contributed to the development of the methods. Both authors wrote and edited the manuscript.
Peer review
Peer review information
Nature Methods thanks Donovan Parks, Rob Patro, and the other, anonymous, reviewer(s) for their contribution to the peer review of this work. Peer reviewer reports are available. Primary Handling Editor: Lin Tang, in collaboration with the Nature Methods team.
Data availability
All datasets are also specified in Supplementary Table 2 with descriptions. The Pasolli et al. 25-50 dataset1 is available at http://segatalab.cibio.unitn.it/data/Pasolli_et_al.html. Ocean archaea MAGs12 are available at 10.6084/m9.figshare.c.5564844.v1. Soil MAGs17 are available at https://figshare.com/collections/Genomes_for_consistent_metagenome-derived_metrics_verify_and_define_bacterial_species_boundaries/4508162/1. Ocean eukaryotic MAGs15,16 are available at https://osf.io/gm564/ and https://www.genoscope.cns.fr/tara/. Nayfach et al. MAGs2 are available at https://genome.jgi.doe.gov/GEMs. E. coli, B. anthracis, and the D5 dataset genomes are available at http://enve-omics.ce.gatech.edu/data/fastani. GTDB-R207 (ref. 18) database is available at https://gtdb.ecogenomic.org. B. fragilis genomes and the refseq-rc database is available at https://zenodo.org/record/8058221 (ref. 39).
Code availability
skani is available at https://github.com/bluenote-1577/skani. Scripts and notebooks for reproducing all figures is available at https://github.com/bluenote-1577/skani-test. skani v0.1.4’s source code is deposited at https://zenodo.org/record/8058221 (ref. 39).
Competing interests
The authors declare no competing interests.
Footnotes
Publisher’s note Springer Nature remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.
Contributor Information
Jim Shaw, Email: jshaw@math.toronto.edu.
Yun William Yu, Email: ywyu@cmu.edu.
Extended data
is available for this paper at 10.1038/s41592-023-02018-3.
Supplementary information
The online version contains supplementary material available at 10.1038/s41592-023-02018-3.
References
- 1.Pasolli E, et al. Extensive unexplored human microbiome diversity revealed by over 150,000 genomes from metagenomes spanning age, geography, and lifestyle. Cell. 2019;176:649–662. doi: 10.1016/j.cell.2019.01.001. [DOI] [PMC free article] [PubMed] [Google Scholar]
- 2.Nayfach S, et al. A genomic catalog of Earth’s microbiomes. Nat. Biotechnol. 2021;39:499–509. doi: 10.1038/s41587-020-0718-6. [DOI] [PMC free article] [PubMed] [Google Scholar]
- 3.Ondov BD, et al. Mash: Fast genome and metagenome distance estimation using MinHash. Genome Biol. 2016;17:132. doi: 10.1186/s13059-016-0997-x. [DOI] [PMC free article] [PubMed] [Google Scholar]
- 4.Pierce NT, Irber L, Reiter T, Brooks P, Brown CT. Large-scale sequence comparisons with sourmash. F1000Research. 2019;8:1006. doi: 10.12688/f1000research.19675.1. [DOI] [PMC free article] [PubMed] [Google Scholar]
- 5.Olm MR, Brown CT, Brooks B, Banfield JF. dRep: A tool for fast and accurate genomic comparisons that enables improved genome recovery from metagenomes through de-replication. The ISME Journal. 2017;11:2864–2868. doi: 10.1038/ismej.2017.126. [DOI] [PMC free article] [PubMed] [Google Scholar]
- 6.Jain C, Rodriguez-R LM, Phillippy AM, Konstantinidis KT, Aluru S. High throughput ANI analysis of 90K prokaryotic genomes reveals clear species boundaries. Nat. Commun. 2018;9:5114. doi: 10.1038/s41467-018-07641-9. [DOI] [PMC free article] [PubMed] [Google Scholar]
- 7.Abouelhoda MI, Ohlebusch E. Chaining algorithms for multiple genome comparison. J. Discrete Algorithms. 2005;3:321–341. doi: 10.1016/j.jda.2004.08.011. [DOI] [Google Scholar]
- 8.Jain, C., Gibney, D. & Thankachan, S. V. Co-linear chaining with overlaps and gap costs. In Pe’er, I. (ed.) Research in Computational Molecular Biology, Lecture Notes in Computer Science, 246–262 (Springer International Publishing, 2022). [DOI] [PubMed]
- 9.Mäkinen, V. & Sahlin, K. Chaining with Overlaps Revisited. In Gørtz, I. L. & Weimann, O. (eds.) 31st Annual Symposium on Combinatorial Pattern Matching (CPM 2020), vol. 161, Leibniz International Proceedings in Informatics (LIPIcs), 25:1–25:12 (Schloss Dagstuhl–Leibniz-Zentrum für Informatik, 2020).
- 10.Richter M, Rosselló-Móra R. Shifting the genomic gold standard for the prokaryotic species definition. Proc. Natl Acad. Sci. USA. 2009;106:19126–19131. doi: 10.1073/pnas.0906412106. [DOI] [PMC free article] [PubMed] [Google Scholar]
- 11.Marçais G, et al. MUMmer4: A fast and versatile genome alignment system. PLoS Comput. Biol. 2018;14:e1005944. doi: 10.1371/journal.pcbi.1005944. [DOI] [PMC free article] [PubMed] [Google Scholar]
- 12.Nishimura Y, Yoshizawa S. The OceanDNA MAG catalog contains over 50,000 prokaryotic genomes originated from various marine environments. Sci. Data. 2022;9:305. doi: 10.1038/s41597-022-01392-5. [DOI] [PMC free article] [PubMed] [Google Scholar]
- 13.Sokal RR, Rohlf FJ. The comparison of dendrograms by objective methods. Taxon. 1962;11:33–40. doi: 10.2307/1217208. [DOI] [Google Scholar]
- 14.Koslicki D, Zabeti H. Improving MinHash via the containment index with applications to metagenomic analysis. Appl. Math. Comput. 2019;354:206–215. doi: 10.1016/j.amc.2019.02.018. [DOI] [Google Scholar]
- 15.Alexander, H. et al. Eukaryotic genomes from a global metagenomic dataset illuminate trophic modes and biogeography of ocean plankton. Preprint at bioRxiv10.1101/2021.07.25.453713 (2022). [DOI] [PMC free article] [PubMed]
- 16.Delmont TO, et al. Functional repertoire convergence of distantly related eukaryotic plankton lineages abundant in the sunlit ocean. Cell Genom. 2022;2:100123. doi: 10.1016/j.xgen.2022.100123. [DOI] [PMC free article] [PubMed] [Google Scholar]
- 17.Olm MR, et al. Consistent metagenome-derived metrics verify and delineate bacterial species boundaries. mSystems. 2020;5:e00731–19. doi: 10.1128/mSystems.00731-19. [DOI] [PMC free article] [PubMed] [Google Scholar]
- 18.Parks DH, et al. A standardized bacterial taxonomy based on genome phylogeny substantially revises the tree of life. Nat. Biotechnol. 2018;36:996–1004. doi: 10.1038/nbt.4229. [DOI] [PubMed] [Google Scholar]
- 19.Lee I, Ouk Kim Y, Park S-C, Chun J. OrthoANI: An improved algorithm and software for calculating average nucleotide identity. Int. J. Syst. Evol. Microbiol. 2016;66:1100–1103. doi: 10.1099/ijsem.0.000760. [DOI] [PubMed] [Google Scholar]
- 20.Yoon S-H, Ha S-m, Lim J, Kwon S, Chun J. A large-scale evaluation of algorithms to calculate average nucleotide identity. Antonie van Leeuwenhoek. 2017;110:1281–1286. doi: 10.1007/s10482-017-0844-4. [DOI] [PubMed] [Google Scholar]
- 21.Palmer M, Steenkamp ET, Blom J, Hedlund BP, Venter SN. All ANIs are not created equal: Implications for prokaryotic species boundaries and integration of ANIs into polyphasic taxonomy. Int. J.Syst. Evol. Microbiol. 2020;70:2937–2948. doi: 10.1099/ijsem.0.004124. [DOI] [PubMed] [Google Scholar]
- 22.Parks DH, Imelfort M, Skennerton CT, Hugenholtz P, Tyson GW. CheckM: Assessing the quality of microbial genomes recovered from isolates, single cells, and metagenomes. Genome Res. 2015;25:1043–1055. doi: 10.1101/gr.186072.114. [DOI] [PMC free article] [PubMed] [Google Scholar]
- 23.Robinson DF, Foulds LR. Comparison of phylogenetic trees. Math. Biosci. 1981;53:131–147. doi: 10.1016/0025-5564(81)90043-2. [DOI] [Google Scholar]
- 24.Blanca A, Harris RS, Koslicki D, Medvedev P. The statistics of k-mers from a sequence undergoing a simple mutation process without spurious matches. J. Comput. Biol. 2022;29:155–168. doi: 10.1089/cmb.2021.0431. [DOI] [PubMed] [Google Scholar]
- 25.Hera MR, et al. Deriving confidence intervals for mutation rates across a wide range of evolutionary distances using fracminhash. Genome Res. 2023;33:1061–1068. doi: 10.1101/gr.277651.123. [DOI] [PMC free article] [PubMed] [Google Scholar]
- 26.Shaw J, Yu YW. Proving sequence aligners can guarantee accuracy in almost O(m log n) time through an average-case analysis of the seed-chain-extend heuristic. Genome Res. 2023;33:1175–1187. doi: 10.1101/gr.277637.122. [DOI] [PMC free article] [PubMed] [Google Scholar]
- 27.Belbasi M, Blanca A, Harris RS, Koslicki D, Medvedev P. The minimizer Jaccard estimator is biased and inconsistent. Bioinformatics. 2022;38:i169–i176. doi: 10.1093/bioinformatics/btac244. [DOI] [PMC free article] [PubMed] [Google Scholar]
- 28.Tang K, Ren J, Sun F. Afann: Bias adjustment for alignment-free sequence comparison based on sequencing data using neural network regression. Genome Biol. 2019;20:266. doi: 10.1186/s13059-019-1872-3. [DOI] [PMC free article] [PubMed] [Google Scholar]
- 29.Fan H, Ives AR, Surget-Groba Y, Cannon CH. An assembly and alignment-free method of phylogeny reconstruction from next-generation sequencing data. BMC Genom. 2015;16:522. doi: 10.1186/s12864-015-1647-5. [DOI] [PMC free article] [PubMed] [Google Scholar]
- 30.Sarmashghi S, Bohmann K, P. Gilbert MT, Bafna V, Mirarab S. Skmer: Assembly-free and alignment-free sample identification using genome skims. Genome Biol. 2019;20:34. doi: 10.1186/s13059-019-1632-4. [DOI] [PMC free article] [PubMed] [Google Scholar]
- 31.Irber, L. et al. Lightweight compositional analysis of metagenomes with FracMinHash and minimum metagenome covers. Preprint at bioRxiv10.1101/2022.01.11.475838 (2022).
- 32.Roberts M, Hayes W, Hunt BR, Mount SM, Yorke JA. Reducing storage requirements for biological sequence comparison. Bioinformatics. 2004;20:3363–3369. doi: 10.1093/bioinformatics/bth408. [DOI] [PubMed] [Google Scholar]
- 33.Schleimer, S., Wilkerson, D. S. & Aiken, A. Winnowing: Local algorithms for document fingerprinting. In Proceedings of the 2003 ACM SIGMOD International Conference on Management of Data, SIGMOD ’03, 76–85 (Association for Computing Machinery, 2003).
- 34.Yu YW, Daniels NM, Danko DC, Berger B. Entropy-scaling search of massive biological data. Cell Syst. 2015;1:130–140. doi: 10.1016/j.cels.2015.08.004. [DOI] [PMC free article] [PubMed] [Google Scholar]
- 35.Shaw J, Yu YW. Theory of local k-mer selection with applications to long-read alignment. Bioinformatics. 2022;38:4659–4669. doi: 10.1093/bioinformatics/btab790. [DOI] [PMC free article] [PubMed] [Google Scholar]
- 36.Frith MC, Kawaguchi R. Split-alignment of genomes finds orthologies more accurately. Genome Biol. 2015;16:106. doi: 10.1186/s13059-015-0670-9. [DOI] [PMC free article] [PubMed] [Google Scholar]
- 37.Zeng S, et al. A compendium of 32,277 metagenome-assembled genomes and over 80 million genes from the early-life human gut microbiome. Nat. Commun. 2022;13:5139. doi: 10.1038/s41467-022-32805-z. [DOI] [PMC free article] [PubMed] [Google Scholar]
- 38.Li H. Minimap2: Pairwise alignment for nucleotide sequences. Bioinformatics. 2018;34:3094–3100. doi: 10.1093/bioinformatics/bty191. [DOI] [PMC free article] [PubMed] [Google Scholar]
- 39.Shaw, J. & Yu, Y.W. skani experiment files and source code. Zenodohttps://zenodo.org/record/8058221 (2023).
Associated Data
This section collects any data citations, data availability statements, or supplementary materials included in this article.
Supplementary Materials
Data Availability Statement
All datasets are also specified in Supplementary Table 2 with descriptions. The Pasolli et al. 25-50 dataset1 is available at http://segatalab.cibio.unitn.it/data/Pasolli_et_al.html. Ocean archaea MAGs12 are available at 10.6084/m9.figshare.c.5564844.v1. Soil MAGs17 are available at https://figshare.com/collections/Genomes_for_consistent_metagenome-derived_metrics_verify_and_define_bacterial_species_boundaries/4508162/1. Ocean eukaryotic MAGs15,16 are available at https://osf.io/gm564/ and https://www.genoscope.cns.fr/tara/. Nayfach et al. MAGs2 are available at https://genome.jgi.doe.gov/GEMs. E. coli, B. anthracis, and the D5 dataset genomes are available at http://enve-omics.ce.gatech.edu/data/fastani. GTDB-R207 (ref. 18) database is available at https://gtdb.ecogenomic.org. B. fragilis genomes and the refseq-rc database is available at https://zenodo.org/record/8058221 (ref. 39).
skani is available at https://github.com/bluenote-1577/skani. Scripts and notebooks for reproducing all figures is available at https://github.com/bluenote-1577/skani-test. skani v0.1.4’s source code is deposited at https://zenodo.org/record/8058221 (ref. 39).