Skip to main content

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

Tree building

Optionally included in the Python package is code to produce a neighbour joining phylogenetic tree in newick format. This has a few requirements:

  • A minimum of 4 samples within the comparison
  • Distances are computed with no SNP cutoff

Example:

# Optional virtual environment
python -m venv env
source env/bin/activate

# Install fn6, both as a rust CLI tool and a python library
cargo install fn6
pip install "fn6[tree]"

# Create a table of distances with an arbitrarily high cutoff
fn6 compute -d path/to/some/samples -r path/to/a/reference -m path/to/a/mask --cutoff 9999999 > your-distances.txt

# Build a tree
find-neighbour-to-tree --input your-distances.txt --output your-tree.nwk

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

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

fn6-0.1.3-cp312-cp312-win_amd64.whl (263.9 kB view details)

Uploaded CPython 3.12Windows x86-64

fn6-0.1.3-cp312-cp312-musllinux_1_2_x86_64.whl (985.7 kB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

fn6-0.1.3-cp312-cp312-musllinux_1_2_i686.whl (1.0 MB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ i686

fn6-0.1.3-cp312-cp312-musllinux_1_2_armv7l.whl (1.1 MB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ ARMv7l

fn6-0.1.3-cp312-cp312-musllinux_1_2_aarch64.whl (940.7 kB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ ARM64

fn6-0.1.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (823.6 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

fn6-0.1.3-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl (840.3 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ s390x

fn6-0.1.3-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (800.5 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ppc64le

fn6-0.1.3-cp312-cp312-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (801.0 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARMv7l

fn6-0.1.3-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (767.5 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

fn6-0.1.3-cp312-cp312-manylinux_2_12_i686.manylinux2010_i686.whl (811.8 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.12+ i686

fn6-0.1.3-cp312-cp312-macosx_11_0_arm64.whl (366.9 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

File details

Details for the file fn6-0.1.3-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: fn6-0.1.3-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 263.9 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.14.1

File hashes

Hashes for fn6-0.1.3-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 410506a29ae975a33230d06c97cf1ff4d342bdc54718d387d07a5d8d30b65a0e
MD5 b73aba8b7436a7f07b482d1c45e7a0d6
BLAKE2b-256 a2543d08c6667ff48b69094302dc8d73f07c593ebd3c405033a543a4ebca3ebe

See more details on using hashes here.

File details

Details for the file fn6-0.1.3-cp312-cp312-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for fn6-0.1.3-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 f066a5b388b740f1365e452748ae0c7aa8224d6eea37be5bb53c3b1af2422a8a
MD5 9daadd6bab5831173c2d79bffdf41c65
BLAKE2b-256 c9b46d9d4f4781b18e14c9938b2a99baed3e8a5c3b14e3461b1e759b7e473d70

See more details on using hashes here.

File details

Details for the file fn6-0.1.3-cp312-cp312-musllinux_1_2_i686.whl.

File metadata

File hashes

Hashes for fn6-0.1.3-cp312-cp312-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 f90165e67adb1190e6abc5d010fdbe61b8601cdbb6afec8ace0f2c55e3d7f2a6
MD5 e260e84fcffafd90e7de7272c7046e72
BLAKE2b-256 b96819a9187a1b7c3016c9426a63c3adf37908cd3a0715a2fe363886684ff624

See more details on using hashes here.

File details

Details for the file fn6-0.1.3-cp312-cp312-musllinux_1_2_armv7l.whl.

File metadata

File hashes

Hashes for fn6-0.1.3-cp312-cp312-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 f1194da9f1e110e0e41b481b9bd68bb697d605ec79528bc382222b13d1d8e50b
MD5 a11c43b892b5ffd88aee140ba885a0f9
BLAKE2b-256 d5662583ff41826b3195c656ba2207126c21c2c36aca563b7d96b4461f8fe880

See more details on using hashes here.

File details

Details for the file fn6-0.1.3-cp312-cp312-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for fn6-0.1.3-cp312-cp312-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 86c0806032cbfa2ac1f13122d23ab0071beba38a24fc7dd14019e46d8707af08
MD5 ab02226748825c342c4a05161813b92d
BLAKE2b-256 c55e249c0cc0e9d6060a221ed8fc43fccb1a920cb8e261153386aca8179c86c4

See more details on using hashes here.

File details

Details for the file fn6-0.1.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for fn6-0.1.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c86a6b7d426cea18f3f1feff7cb4fc712536557c149802b4e8403dc35d570936
MD5 d39492c5d5064295cb2bd55cf7f39f0b
BLAKE2b-256 f01a44eb53f284447297a341c2b8527f61e1b1a6ab52cceee6d4fdbd10ac4561

See more details on using hashes here.

File details

Details for the file fn6-0.1.3-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl.

File metadata

File hashes

Hashes for fn6-0.1.3-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 be622513c1f0b58fc89c96f9f698639aad6cdf4d9381d1ffeb098e551d692eb3
MD5 cbb4d6349c1d7a9e7760c1e9a56bde61
BLAKE2b-256 244fe7cdadf218c3d9e93ec39b7443a6b1aef178f08b422eaefe2c5944d25e10

See more details on using hashes here.

File details

Details for the file fn6-0.1.3-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl.

File metadata

File hashes

Hashes for fn6-0.1.3-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 5b949b417cfe105f3f6c77dc58edca70382df372a5c1429be0213be935a992b3
MD5 0275e20824afaa7358ba7e4f73ba7afe
BLAKE2b-256 8ac811d78d77cd162cc8158d501b692f6a3e848388f1f99c61669380b78f3014

See more details on using hashes here.

File details

Details for the file fn6-0.1.3-cp312-cp312-manylinux_2_17_armv7l.manylinux2014_armv7l.whl.

File metadata

File hashes

Hashes for fn6-0.1.3-cp312-cp312-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 3972223ad67931cafacc5b4732d2fd30a065ebc8f702fb4c87c7e17bbc509c7a
MD5 5d171c3338f628ae67104ab33298cb2f
BLAKE2b-256 e3fcd15f0c1f47e67765f494c990521292ee8bf7ec111c7f2719d85d5ef91c72

See more details on using hashes here.

File details

Details for the file fn6-0.1.3-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for fn6-0.1.3-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 bee2a1169b3e98195dce42684129f65bc8b70ba1277ddf32b9b8a93efbf29879
MD5 a91442005d32167836622f0c22c8b20e
BLAKE2b-256 2162853a6f7e2a6ec9c1fea459071435168c54d56e7186328f2956e36b634570

See more details on using hashes here.

File details

Details for the file fn6-0.1.3-cp312-cp312-manylinux_2_12_i686.manylinux2010_i686.whl.

File metadata

File hashes

Hashes for fn6-0.1.3-cp312-cp312-manylinux_2_12_i686.manylinux2010_i686.whl
Algorithm Hash digest
SHA256 04e54ebd4c7a5f7bda291118b8e6dd50bf684d051752c40d08356aa3ba5d46cb
MD5 0bbe2f43cef138c58c25b86c3ecff75b
BLAKE2b-256 840d4ef67dfda711a2e067d7ec8d5445cdd7ba208217261c9f564d7c835010f1

See more details on using hashes here.

File details

Details for the file fn6-0.1.3-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for fn6-0.1.3-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c6e8d3b014d5d73be7c60d6b0c956129e9430c01be0aad10bc697c04d2044afc
MD5 74d1d04d769ab32ad4ea70118df58c60
BLAKE2b-256 b0be51259acbf834b3eeb6ec810c6f8400cbf0cfdfaed57f902ce6bd511ffda1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page