Skip to main content

beave

Table of contents generated with markdown-toc

Introduction

Python CLI

A very Canadian utility for genomic clustering and distance querying.

This program is under active development and is used for creating distance matrices from allelic profiles, or for comparing groups of isolates against multiple reference sequences. This program is similar to cgmlst-dists from Torsten Seeman and gas from the Public Health Agency of Canada.

Contact

[Matthew Wells] : matthew.wells@phac-aspc.gc.ca [Eric Marinier] : eric.marinier@phac-aspc.gc.ca

Compatibility

beave has only been tested on Linux, any system that supports G++ can compile the program. As only the C++ 23 standard library is used, the program may be able to be compiled on Windows system.

This program relies heavily on the compiler to optimize the program and add SIMD instructions, it is recommended to compile the program on your local computer to get the full benefit of the potential instruction sets your CPU may offer. Compilation using AVX-512 instruction sets has been tested, however in our testing the programs performance degrades likely due to throttling by the CPU.

To build the beave Python package, you will first need to install dependencies listed in the pyproject.toml file. Python version 3.13 or greater is required, along with scikit-build-core and the nanobind Python package.

Python runtime dependencies include numpy >= 2.4.0 and polars >= 1.40.1 and scipy >= 1.17.0.

Install

Get Started

Start by pulling the repository.

git clone https://github.com/phac-nml/beave

Python

Without Conda

To build and install the Python package you must have the following python packages, scikit-build-core and nanobind which can be installed with pip install nanobind scikit-build-core[pyproject].

Users can run simply run pip install . to install the package.

Developers can run pip install -ve .[dev] or pip install -Ceditable.rebuild=true -ve .[dev]. Further examples can be found in the nanobind documentation here: nanobind packaging. The --no-build-isolation is not included as running uv pip install with the --no-build-isolation flag tells uv to ignore the build-system.requires section from the pyproject.toml.

To build a wheel that can be distributed instead of installed, simply run pip wheel .

With Conda

  1. Pull the GitHub repository as described above.

  2. Create the Conda environment by running conda env create -f environment-linux.yml for linux and conda env create -f ./environment-osx.yml for mac.

  3. Activate the environment with: conda activate beave

  4. Run pip install ., if you wish to install development dependencies or run tests please run pip install -ve .[dev]

Getting Started

Usage

The main help message for the program is shown below:

>>> beave -h
usage: beave [-h] [--cores CORES] [--delimiter DELIMITER] [--columns-subset COLUMNS_SUBSET] [--count-missing] [--normalize-distance]
             [--filter-threshold FILTER_THRESHOLD] [--verbose] [--version]
             {cluster,match} ...

A very Canadian utility for genomic clustering and distance querying.

positional arguments:
  {cluster,match}       Select a program to run.
    cluster             Run denovo clustering.
    match               Run fast matching.

options:
  -h, --help            show this help message and exit
  --cores, -c CORES     Specify the number of threads to be used. [default 12]
  --delimiter DELIMITER
                        Input alleles delimiter. [default \t] (default: )
  --columns-subset, -s COLUMNS_SUBSET
                        A file containing a single column of the column names to subset from the passed allele profiles. (default: None)
  --count-missing, -m   Count missing values as differences. (default: False)
  --normalize-distance, -n
                        Compute the normalized distance. Distance is presented as a percentage, or a value between [0.0-1.0] (default:
                        False)
  --filter-threshold, -f FILTER_THRESHOLD
                        Exclude samples from analysis if they are missing more than the specified percentage of data. Must be between
                        [0.0-100.0]. [default 100.0] (default: 1.0)
  --verbose             Display logger debug messages. (default: False)
  --version, -v         show program's version number and exit

To run de-novo clustering use the cluster option. The long form options for cluster are shown below:

>>> beave cluster --help

usage: beave cluster [-h] [--cores CORES] [--delimiter DELIMITER] [--columns-subset COLUMNS_SUBSET] [--count-missing] [--normalize-distance] [--filter-threshold FILTER_THRESHOLD] [--verbose] --input INPUT [--output OUTPUT] --thresholds THRESHOLDS [THRESHOLDS ...]
                     [--linkage-method {single,average,complete}] [--branch-type {patristic,cophenetic}] [--matrix]

options:
  -h, --help            show this help message and exit
  --cores, -c CORES     Specify the number of threads to be used. (default 12)
  --delimiter DELIMITER
                        Input alleles delimiter. (default \t)
  --columns-subset, -s COLUMNS_SUBSET
                        A file containing a single column of the column names to subset from the passed allele profiles.
  --count-missing, -m   Count missing values as differences.
  --normalize-distance, -n
                        Compute the normalized distance. Distance is presented as a percentage, or a value between [0.0-1.0]
  --filter-threshold, -f FILTER_THRESHOLD
                        Exclude samples from analysis if they are missing more than the specified percentage of data. Must be between [0.0-100.0]. (default 100.0)
  --verbose             Display logger debug messages.
  --input, -i INPUT     Input alleles. (required)
  --output, -o OUTPUT   Output directory for generated tree and clusters, directory will be created if does not exist. (default: beave)
  --thresholds, -t THRESHOLDS [THRESHOLDS ...]
                        List of threshold values to use. (required)
  --linkage-method, -l {single,average,complete}
                        Hierarchical clustering linkage to use. (default: average)
  --branch-type, -b {patristic,cophenetic}
                        Determine how to display tree lenghts in the Newick file. (default cophenetic)
  --matrix              Write the computed distance matrix to a file in the output directory called 'matrix.tsv'.

>>> # Example programs
>>> beave cluster --input src/beave/tests/data/R1KC1K.2-zeroes.does-not-exist.csv -o out -l average -nm -b cophenetic -c 2 -t 0.9 0.5 --delimiter , --matrix
>>> beave cluster --input src/beave/tests/data/R1KC1K.tsv -l average -b cophenetic -c 1 --thresholds 10 9 8

The match argument may be used to compute pairwise distances between a group of query samples against a group of reference samples. The parameters for running match are described below:

>>> beave match --help

usage: beave match [-h] [--cores CORES] [--delimiter DELIMITER] [--columns-subset COLUMNS_SUBSET] [--count-missing] [--normalize-distance] [--filter-threshold FILTER_THRESHOLD] [--verbose] --reference REFERENCE --query QUERY [--threshold THRESHOLD] [--output OUTPUT]

options:
  -h, --help            show this help message and exit
  --cores, -c CORES     Specify the number of threads to be used. (default 12)
  --delimiter DELIMITER
                        Input alleles delimiter. (default \t)
  --columns-subset, -s COLUMNS_SUBSET
                        A file containing a single column of the column names to subset from the passed allele profiles.
  --count-missing, -m   Count missing values as differences.
  --normalize-distance, -n
                        Compute the normalized distance. Distance is presented as a percentage, or a value between [0.0-1.0]
  --filter-threshold, -f FILTER_THRESHOLD
                        Exclude samples from analysis if they are missing more than the specified percentage of data. Must be between [0.0-100.0]. (default 100.0)
  --verbose             Display logger debug messages.
  --reference, -r REFERENCE
                        Profiles to compare against. Query samples will be included in comparisons. (required)
  --query, -q QUERY     Profiles containing new-samples for comparisons. (required)
  --threshold, -t THRESHOLD
                        Only report distances below specified threshold. (default: infinity)
  --output, -o OUTPUT   Output directory for calculated distances, directory will be created if does not exist. (default: beave)

>>> # Example programs
>>> beave match -q src/beave/tests/data/R1KC1K.head.tsv -r src/beave/tests/data/R1KC1K.tail.tsv -nm --verbose
>>> beave match -q src/beave/tests/data/R1KC1K.head.tsv -r src/beave/tests/data/R1KC1K.tail.tsv -t 101 -l average -c 8

Data Input

The inputs for this program must be tabular, any delimiter is supported as long is it is a single character. The first column of the file must contain no duplicates or missing values. The columns are not inspected to verify unique values only, so duplicate column names will be name mangled and treated as another unique column. The characters "?", " ", "", "-", "_", and "0" are treated as missing values by the program unless the -c option is added to the program. All other values are treated as a valid alleles. Example inputs can be found in the tests folder. Thresholds are always converted to float values, however you can specify either integers not just decimals.

When running match, the query and reference profiles will be merged by the program. If duplicate ID's are detected an error will be raised by the program.

Data Output

Cluster Outputs

The program outputs a Newick-Format file containing the tree generated by whichever linkage metric is selected, the sample IDs and their addresses are put out in a separate file specified by the user in TSV format. Addresses are delimited by an '.'.

Example of cluster outputs:

SampleID level_10.0 level_9.0 denovo_address
CoolSample 1 2 1.2
CoolSample2 2 1 2.1
Match Outputs

The output of match is a single file showing the query sample, the reference sample and distance.

The general structure of the match output:

query_id ref_id dist_{hamming,normalized}
1 2 4
1 3 8
1 4 10

Troubleshooting and FAQs

  • There may be issues with the Python build system, please create a GitHub issue for any issues identified.

  • If there are duplicate identifiers with different profiles. The distance between the two values will still be reported as no duplicates detection is performed currently. Future iterations may add this functionality.

  • -ffast-math is enabled during compilation to prevent sub-normals. This leads to some error in floating point operations, the affect of this is being evaluated and this compiler flag may be removed after further testing is performed.

Legal and Compliance Information

Copyright Government of Canada [2026]

Written by: National Microbiology Laboratory, Public Health Agency of Canada

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this work except in compliance with the License. You may obtain a copy of the License at:

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Updates and Release Notes

Please see the CHANGELOG.md.

Metadata

Release files for beave 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for beave 1.0.0
File Size Uploaded
beave-1.0.0.tar.gz 3.8 MB Details

Built distributions (wheels)

Table of built distributions (wheels) for beave 1.0.0
File Interpreter ABI Platform
beave-1.0.0-cp312-abi3-musllinux_1_2_x86_64.whl CPython 3.12 abi3 Linux musl 1.2+ x86-64 Details
beave-1.0.0-cp312-abi3-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl CPython 3.12 abi3 Linux glibc 2.26+ x86-64, Linux glibc 2.28+ x86-64 Details
beave-1.0.0-cp312-abi3-macosx_15_0_x86_64.whl CPython 3.12 abi3 macOS 15.0+ x86-64 Details

Total release size: 17.7 MB

Release files / beave-1.0.0.tar.gz

Download URL beave-1.0.0.tar.gz
Size 3.8 MB
Tags Source
SHA-256 checksum
How to use checksums
63cbed87699d4689df0993c775590575a4d6e9c1af2b8e6c3d572b73a3ecd274
BLAKE2b-256 checksum
How to use checksums
8be9d36e74e1ea10846630b469d88dd2fabacbe40b8c711199090123e7c1cd8d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.1

Release files / beave-1.0.0-cp312-abi3-musllinux_1_2_x86_64.whl

Download URL beave-1.0.0-cp312-abi3-musllinux_1_2_x86_64.whl
Size 4.6 MB
Tags CPython 3.12 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
62ea42536f4930ed0a10bbbe8ddb6b7b7f94768d02b97e42e11a4d0aa3aad2ef
BLAKE2b-256 checksum
How to use checksums
36dffc2a8d55430284480ec3fcdd8b531defaeac1cc2c3ae1ad3c5aaab01f930
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.1

Release files / beave-1.0.0-cp312-abi3-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl

Download URL beave-1.0.0-cp312-abi3-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl
Size 4.1 MB
Tags CPython 3.12 Linux glibc 2.26+ x86-64 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
058fd0da305c69a8697ac1455d93a6341a421065e00e66d8e2e997af6e1083b1
BLAKE2b-256 checksum
How to use checksums
81fa1991f9b2d798990b039f7ffb35d4e5adf1c7221117352358c88eb1a3e20d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.1

Release files / beave-1.0.0-cp312-abi3-macosx_15_0_x86_64.whl

Download URL beave-1.0.0-cp312-abi3-macosx_15_0_x86_64.whl
Size 5.1 MB
Tags CPython 3.12 abi3 macOS 15.0+ x86-64
SHA-256 checksum
How to use checksums
8fea45f8c8d4f27e1eab53b7624ffb178d4d1c7b83e46164a60701a071717e07
BLAKE2b-256 checksum
How to use checksums
464a26b8f5ff1765fa28748bf5cf08e8274884a234fb65eda38348fbc57d8ea4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.1

Release history Release notifications | RSS feed

This release

1.0.0 This release

4 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page