Fast, efficient and scalable SNP distance calculation from disk.
Project description
FN6
Fast, efficient and scalable SNP distance calculation from disk.
FN5 reworked into Rust. Approximately 10x faster, easier to use and maintain, and adds checking for matching reference and mask in FN6 saves, all while retaining interoperability with FN5 saves.
Usage
All FASTA inputs can be optionally gzipped.
Usage: fn6 <COMMAND>
Commands:
reference-compress Reference compress a sample genome. This will create a .fn6 file that can be used for fast comparisons with other samples. The .fn6 file is a binary file that contains the compressed representation of the sample genome, as well as metadata about the reference and mask used for compression
compute Compute distances
add-samples Add some samples to existing samples. Only computes the extra distances required rather than all pairwise distances
bulk-compress Reference compress a set of genomes. Dumber than `ReferenceCompress` as it doesn't allow for setting specific IDs or output paths, but much faster as it can be parallelized across samples
help Print this message or the help of the given subcommand(s)
Options:
-h, --help Print help
-V, --version Print version
Reference compress
Reference compress a sample genome. This will create a .fn6 file that can be used for fast comparisons with other samples. The .fn6 file is a binary file that contains the compressed representation of the sample genome, as well as metadata about the reference and mask used for compression
Usage: fn6 reference-compress [OPTIONS] <REFERENCE> <MASK> <SAMPLE>
Arguments:
<REFERENCE> Path to the reference genome FASTA file
<MASK> Path to the mask file. The mask file is a text file containing the positions of the reference genome that should be masked (i.e., ignored) during the analysis. The positions are 0-based and should be separated by newlines
<SAMPLE> Path to the sample genome FASTA file
Options:
--id <ID> ID for this sample
--output <OUTPUT> Output path for the .fn6 file. If not provided, the .fn6 file will be saved in the same directory as the sample FASTA file with the same name but with a .fn6 extension
--debug Whether to print debug information to stderr
-h, --help Print help
Compute
Compute SNP distances
Usage: fn6 compute [OPTIONS]
Options:
-r, --reference <REFERENCE>
Path to the reference genome FASTA file. Only required if >=1 of the samples specified are fasta files
-m, --mask <MASK>
Path to the mask file. The mask file is a text file containing the positions of the reference genome that should be masked (i.e., ignored) during the analysis. The positions are 0-based and should be separated by newlines. Only required if >=1 of the samples specified are fasta files
-s, --samples <SAMPLES>...
Paths to sample files. Either .fn6, .fn5 or FASTA files. If FASTA files are provided, the `allow-fasta` flag must also be used. They will then be reference compressed on the fly (using the provided reference and mask) before distance computation
-d, --directory <DIRECTORY>
Directory to load from. Either .fn6, .fn5 or FASTA files. If FASTA files are provided, the `allow-fasta` flag must also be used. They will then be reference compressed on the fly (using the provided reference and mask) before distance computation
--cutoff <CUTOFF>
SNP threshold [default: 20]
--fasta-extension <FASTA_EXTENSION>
FASTA file extension to look for when loading from a directory. Only used if loading from a directory and if reference and mask are provided (i.e., if FASTA files need to be reference compressed on the fly). Default is "fasta" [default: fasta]
--allow-fasta
Whether to enable computation from FASTAs. It is recommended to pre-cache the reference compressed versions of the new samples to speed up computation
--debug
Whether to print debug information to stderr
-h, --help
Print help
Add samples
Add some samples to existing samples. Only computes the extra distances required rather than all pairwise distances
Usage: fn6 add-samples [OPTIONS]
Options:
-r, --reference <REFERENCE>
Path to the reference genome FASTA file. Only required if >=1 of the samples specified are fasta files
-m, --mask <MASK>
Path to the mask file. The mask file is a text file containing the positions of the reference genome that should be masked (i.e., ignored) during the analysis. The positions are 0-based and should be separated by newlines. Only required if >=1 of the samples specified are fasta files
-s, --existing-samples <EXISTING_SAMPLES>...
Paths to existing sample files. Either .fn6, .fn5 or FASTA files. If FASTA files are provided, the `allow-fasta` flag must also be used. They will then be reference compressed on the fly (using the provided reference and mask) before distance computation
-d, --existing-directory <EXISTING_DIRECTORY>
Directory to load existing saves from. Either .fn6, .fn5 or FASTA files. If FASTA files are provided, the `allow-fasta` flag must also be used. They will then be reference compressed on the fly (using the provided reference and mask) before distance computation
-S, --new-samples <NEW_SAMPLES>...
Paths to sample files to add. Either .fn6, .fn5 or FASTA files. If FASTA files are provided, the `allow-fasta` flag must also be used. They will then be reference compressed on the fly (using the provided reference and mask) before distance computation
-D, --new-directory <NEW_DIRECTORY>
Directory to load new saves from. Either .fn6, .fn5 or FASTA files. If FASTA files are provided, the `allow-fasta` flag must also be used. They will then be reference compressed on the fly (using the provided reference and mask) before distance computation
--cutoff <CUTOFF>
SNP threshold [default: 20]
-f, --fasta-extension <FASTA_EXTENSION>
FASTA file extension to look for when loading from a directory. Only used if loading from a directory and if reference and mask are provided (i.e., if FASTA files need to be reference compressed on the fly). Default is "fasta" [default: fasta]
--allow-fasta
Whether to enable computation from FASTAs. It is recommended to pre-cache the reference compressed versions of the new samples to speed up computation
--debug
Whether to print debug information to stderr
-h, --help
Print help
Bulk Compress
Reference compress a set of genomes. Dumber than `ReferenceCompress` as it doesn't allow for setting specific IDs or output paths, but much faster as it can be parallelized across samples
Usage: fn6 bulk-compress [OPTIONS] <REFERENCE> <MASK>
Arguments:
<REFERENCE> Path to the reference genome FASTA file
<MASK> Path to the mask file. The mask file is a text file containing the positions of the reference genome that should be masked (i.e., ignored) during the analysis. The positions are 0-based and should be separated by newlines
Options:
-s, --samples <SAMPLES>...
Paths to sample files. Either FASTA files or .fn6 files
-d, --directory <DIRECTORY>
Directory to load from
-l, --list <LIST>
Line separated file to read paths from
-o, --output <OUTPUT>
Output directory to write saves to. Useful when using `list` as it consolidates saves in a single directory. If not provided, the .fn6 files will be saved in the same directory as their corresponding FASTA files with the same name but with a .fn6 extension
--fasta-extension <FASTA_EXTENSION>
FASTA file extension to look for when loading from a directory [default: fasta]
--debug
Whether to print debug information to stderr
-h, --help
Print help
Performance
Both FN5 and FN6 produce the same results, but with condsiderable time differences. Below is a table of comparison between FN5 and FN6 performance on varying sets of Mycobacterium tuberculosis samples, randomly selected from the CRyPTIC dataset https://doi.org/10.5281/zenodo.16041005 All of the benchmarks were run on the same laptop with an Intel i9-13900H and 32GB RAM, directly from SSD.
| N Samples (passing QC) | Comparisons | FN5 Reference compression | FN5 Compute pairwise matrix (per comparison) | FN5 Compute pairwise matrix (per comparison) no cutoff | FN6 Reference compression | FN6 Compute pairwise matrix (per comparison) | FN6 Compute pairwise matrix (per comparison) no cutoff | FN6 Compute pairwise matrix from FN5 saves (per comparison) | FN6 Compute pairwise matrix from FN5 saves (per comparison) no cutoff |
|---|---|---|---|---|---|---|---|---|---|
| 100 | 4,950 | 1.394s | 44ms (8.9µs) | 175ms (35.6µs) | 0.17s | 7.93ms (1.60µs) | 81.28ms (16.42µs) | 9.29ms (1.88µs) | 53.49ms (10.81µs) |
| 250 | 31,125 | 1.698s | 208ms (6.7µs) | 1087ms (34.9µs) | 0.33s | 32.29ms (1.04µs) | 280.36ms (9.01µs) | 24.75ms (795.00ns) | 270.21ms (8.68µs) |
| 500 | 124,750 | 3.506s | 628ms (5.0µs) | 3905ms (31.3µs) | 0.67s | 84.04ms (673.00ns) | 921.34ms (7.39µs) | 48.75ms (390.00ns) | 1010ms (8.13µs) |
| 750 | 280,875 | 5.091s | 1298ms (4.6µs) | 8179ms (29.1µs) | 0.92s | 114.78ms (408.00ns) | 2000ms (7.14µs) | 91.94ms (327.00ns) | 5580ms (19.85µs) |
| 1000 | 499,500 | 6.735s | 2287ms (4.6µs) | 14299ms (28.6µs) | 0.90s | 152.88ms (306.00ns) | 3480ms (6.98µs) | 143.89ms (288.00ns) | 8910ms (17.85µs) |
| 1500 (1493) | 1,113,785 | 11.363s | 7481ms (6.7µs) | 100481ms (90.2µs) | 2.03s | 300.10ms (269.00ns) | 9130ms (8.20µs) | 296.32ms (266.00ns) | 22720ms (20.40µs) |
| 2000 (1992) | 1,983,044 | 16.377s | 30805ms (15.5µs) | 205160ms (103.5µs) | 2.69s | 487.53ms (245.00ns) | 18390ms (9.27µs) | 613.04ms (309.00ns) | 42150ms (21.25µs) |
All of the times to compute a pairwise matrix include the time taken to read the saves from disk. The time taken to load the saves from disk varies by tool, but is an important component of the real world runtime.
Mean time to load a save from disk across all above runs:
| FN5 | FN6 | FN6 (from FN5 saves) |
|---|---|---|
| 64.6µs | 25.0µs | 41.3µs |
This also demonstrates the importance of utilising a SNP cutoff within the computation. Otherwise, per sample comparison times scale according to how disparate samples are.
Testing
For simplicity, testing is based on a dummy genome with 80 bases. This allows for known SNPs to be introduced and manually calculated
cargo test
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fn6-0.2.0-cp310-abi3-win_amd64.whl.
File metadata
- Download URL: fn6-0.2.0-cp310-abi3-win_amd64.whl
- Upload date:
- Size: 265.3 kB
- Tags: CPython 3.10+, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.14.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a48317bcb0e2b773c1e3ed3cf8e0f058fe262a8f671dae88700cc6ccab665980
|
|
| MD5 |
8e4dc19a20469bfdbcd2c89202ca09a9
|
|
| BLAKE2b-256 |
dcbdf0e6340064812c3dd962e0e436c285f4df978c5b5a6b086458b20ee35686
|
File details
Details for the file fn6-0.2.0-cp310-abi3-musllinux_1_2_x86_64.whl.
File metadata
- Download URL: fn6-0.2.0-cp310-abi3-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 988.5 kB
- Tags: CPython 3.10+, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.14.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
26ee4a8966115d366b70a5b2625e1ce53a7f3546f7cbcbb3007b1bacbf84f931
|
|
| MD5 |
244bf68aebb0f075c85dce5d3e475687
|
|
| BLAKE2b-256 |
3a5cf0ab46ea7111da583f5ecb5350902e7d65ce3d2150174ad57f279760ef27
|
File details
Details for the file fn6-0.2.0-cp310-abi3-musllinux_1_2_i686.whl.
File metadata
- Download URL: fn6-0.2.0-cp310-abi3-musllinux_1_2_i686.whl
- Upload date:
- Size: 1.0 MB
- Tags: CPython 3.10+, musllinux: musl 1.2+ i686
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.14.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1ba01cfa8af33f1068c69b4357ec76acb49a20158be1112be6b2bfba64f1576a
|
|
| MD5 |
39ca61553ff5ba5f4105aebfb66a5be8
|
|
| BLAKE2b-256 |
0161b3a557c3289efae91275c4c86d7d32b25bf4e3ab3bc88a3ef3e90c81a04e
|
File details
Details for the file fn6-0.2.0-cp310-abi3-musllinux_1_2_armv7l.whl.
File metadata
- Download URL: fn6-0.2.0-cp310-abi3-musllinux_1_2_armv7l.whl
- Upload date:
- Size: 1.1 MB
- Tags: CPython 3.10+, musllinux: musl 1.2+ ARMv7l
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.14.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d65fe16b6825adeb60e660bfa6312ee4f098861ecd5333765a0fb71768a1427c
|
|
| MD5 |
48e9dd32cc90126312e35b7efa342730
|
|
| BLAKE2b-256 |
e76f8c8320db2b92e8981024f220d296e4ad5104ea496004cd00430ac99bf173
|
File details
Details for the file fn6-0.2.0-cp310-abi3-musllinux_1_2_aarch64.whl.
File metadata
- Download URL: fn6-0.2.0-cp310-abi3-musllinux_1_2_aarch64.whl
- Upload date:
- Size: 943.2 kB
- Tags: CPython 3.10+, musllinux: musl 1.2+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.14.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f68f69ddce77e6c176282c1f8053c64dcb6ee99b7df6153aeff7cbeb79468883
|
|
| MD5 |
cde944df14f49400b0572cf881163582
|
|
| BLAKE2b-256 |
73d4513602fac53018ae47e0156243534a30b3decf50ad28d31fbbba2fea3820
|
File details
Details for the file fn6-0.2.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: fn6-0.2.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 827.3 kB
- Tags: CPython 3.10+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.14.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eac6f3b74a521189c9900fa19c5b120d7256992619277204b731ea8f9487ce48
|
|
| MD5 |
0705a4072232b06e7bba209c44657e85
|
|
| BLAKE2b-256 |
8a4347676d6c81d7259cb17159fd7a6a759e9314c49702f467bba919d11da894
|
File details
Details for the file fn6-0.2.0-cp310-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl.
File metadata
- Download URL: fn6-0.2.0-cp310-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
- Upload date:
- Size: 841.9 kB
- Tags: CPython 3.10+, manylinux: glibc 2.17+ s390x
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.14.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c08990a30bad5733bcafecb99e9301eae85bb42fb180af7c81aeb1b815bc5178
|
|
| MD5 |
11511cfb091533537adeb6d2f529da1f
|
|
| BLAKE2b-256 |
a4d482d9ab0faba35c5767134c6dd604e1f25b2dfa5be249c67307219142f284
|
File details
Details for the file fn6-0.2.0-cp310-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl.
File metadata
- Download URL: fn6-0.2.0-cp310-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
- Upload date:
- Size: 804.0 kB
- Tags: CPython 3.10+, manylinux: glibc 2.17+ ppc64le
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.14.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b4c21b1f3963850ac36d8a0caa13e062806bb098ad045be35513a4c67eb486b7
|
|
| MD5 |
308fc3ac89d53fbe1b18e46712982807
|
|
| BLAKE2b-256 |
38f7a73e989db7bac60226fbeae07da631600776d042c471728d6b3efffd41e1
|
File details
Details for the file fn6-0.2.0-cp310-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl.
File metadata
- Download URL: fn6-0.2.0-cp310-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
- Upload date:
- Size: 804.6 kB
- Tags: CPython 3.10+, manylinux: glibc 2.17+ ARMv7l
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.14.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d5027a92aa00623e05bfff207eed1ea2e45d90190d6933f7806a6597133cb869
|
|
| MD5 |
56cba8160ced7f3476a9718fe40fac6f
|
|
| BLAKE2b-256 |
317906f7ab371d4208a989343403ff8a45a855ec9f049d8d38dbea971cd1e244
|
File details
Details for the file fn6-0.2.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: fn6-0.2.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 770.8 kB
- Tags: CPython 3.10+, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.14.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a9ba0184bbf70ea7b4ac1ce62a5f4620cbd544b8d50d479ba40a8067ba525071
|
|
| MD5 |
6e1b6198a20e9792ccf15c3467c4e666
|
|
| BLAKE2b-256 |
6f29f3f8e44f00b1b459fb3212530a0e71129acf119717b58e5123135df41887
|
File details
Details for the file fn6-0.2.0-cp310-abi3-manylinux_2_12_i686.manylinux2010_i686.whl.
File metadata
- Download URL: fn6-0.2.0-cp310-abi3-manylinux_2_12_i686.manylinux2010_i686.whl
- Upload date:
- Size: 815.8 kB
- Tags: CPython 3.10+, manylinux: glibc 2.12+ i686
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.14.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9db8ddc37206d5500bd61dee8d191b70280c52726523453410e686552bcc7c2c
|
|
| MD5 |
6d7ae673707b2d49757c22c6929f5182
|
|
| BLAKE2b-256 |
e32749f5023ba26a0f624d523d80233d40d93fd87d9fcd2b5021bfb07d80cece
|
File details
Details for the file fn6-0.2.0-cp310-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: fn6-0.2.0-cp310-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 371.4 kB
- Tags: CPython 3.10+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.14.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1e4aae4df62ef8848d9ecacf498f507a23b9413c19c56285d579bcb1edbbb83b
|
|
| MD5 |
ad1f330872d870472185feedcff01e60
|
|
| BLAKE2b-256 |
53d5c02f6bd952a80ed55a0fe589dbf7cceb7561ed3fc61812e72ac1184c9bb9
|