ReLaG
In datasets generated using a RGP (Relational Generative Process), such as datasets generated using evolution-like processes, the relational structure is important to consider for multiple tasks such as split without leakage, visualization, hypothesis generation / validation, etc. The relational structure of the dataset consists of knowing which pairs of elements are related (for example, which samples are evolutionary related). However, this structure is rarely known in advance, so we need to infer it.
Given a distance measurement, we can brute-force compute all pair distances to find related samples. Then, we can define a distance threshold under which samples are considered related. Linking those samples with an edge and the distance as weight yields a thresholded-proximity graph.
The problem with the brute force approach is that it has an $O(n^2)$ computational complexity, and does not scale well for large datasets. Fortunately, we defined a variant of the Hierarchical Navigable Small World (HNSW) algorithm to build this thresholded proximity graph in $O(nlog(n))$ instead.
Once the graph is obtained, operations on the dataset become easier, and more theoretically grounded. In fact, the distance in the graph between two samples can correlate with the likelihood of two samples being related if the distance measurement is well chosen. Hence, this helps visualize the data, split datasets without leakage, make discoveries, etc.
Furthermore, we can cluster the graph by finding communities or connected components. From these clusters, we can effectively split the dataset into train and test set without leakage with respect to the proximity threshold by splitting along clusters.
This library contains a toolkit of efficient functions and data structures to work with datasets generated from RGP. The core computations are implemented in Rust and multithreaded for maximum throughput! Everything is wrapped within an easy to use Python API. It currently supports:
- Protein/dna sequences with Local and Global alignments.
- Molecules with Real and Bit based Tanimoto similarities.
- Protein, DNA and RNA structures with USAlign.
- More coming!
To give an idea of what the library contains, we have these functions:
- HNSW approximate proximity graph in $O(nlog(n))$
- Find nearest neighbors using an exact algorithm ($O(n)$) or approximate using HNSW ($O(log(n))$)
- Exact proximity graph in $O(n^2)$
- Leiden clustering to find communities in the graph.
- Find connected components within the graph.
- Partition a dataset along clusters to prevent data leakage.
- And more!
Installation – Python
pip install relag
Build from source (latest version, potentially unstable)
pip install "git+https://github.com/anthol42/relag.git#subdirectory=py"
Example
The following example shows how to split a protein dataset using 1 - global alignment as the distance function using the python API.
from relag import KernelVariant, HNSWState, find_communities, find_components, partition
from relag.utils import read_fasta
# Load the dataset
dataset = read_fasta("datasets/proteins.fasta")
sequences = [seq for header, seq in dataset]
# Initiate the HNSW index
hnsw = HNSWState(KernelVariant.AlignmentGlobal, sequences, proximity_threshold=0.3)
# Build it
hnsw.build()
# Get the proximity edges
edges = hnsw.edges()
# Load the graph
g = edges.graph()
# Get clusters
clusters = find_components(g) # Component based clustering – faster
clusters = find_communities(g) # Community based clustering - smaller clusters
# Partition into train and test
train_ids, test_ids = partition(clusters, g, post_filtering=True)
train = [dataset[i] for i in train_ids]
test = [dataset[i] for i in test_ids]
Documentation
See the documentation references here: https://anthol42.github.io/relag/
Feedback
This project is currently in active development, and your feedback is greatly appreciated. If you find a bug, or would like a new feature, or give your thoughts on the API, please open an issue and we will be happy to help.
Metadata
Release files for relag 0.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| relag-0.0.4.tar.gz | 232.0 kB | Without provenance | Details |
Built distributions (wheels)
Total release size: 69.1 MB
Release files / relag-0.0.4.tar.gz
| Download URL | relag-0.0.4.tar.gz |
|---|---|
| Size | 232.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6b015e3b4568472b0ce1591e5c259d097d1f0aae9b66d8135fe6751e93dc1b22
|
|
BLAKE2b-256 checksum How to use checksums |
03110bb16171679255b9669eae6cf2cd3099a9bd7860f8645c0407a859916db7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / relag-0.0.4-cp314-cp314-win_amd64.whl
| Download URL | relag-0.0.4-cp314-cp314-win_amd64.whl |
|---|---|
| Size | 3.7 MB |
| Tags | CPython 3.14 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
f80dc1c94b8d65b4c84b8b52c08d2bfc9fc7a669b4279b41261b6428271c89ce
|
|
BLAKE2b-256 checksum How to use checksums |
36a3df881a6ba65ef723f8c6dcf33207e9323148f97e4b1bdf473c025ea81430
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / relag-0.0.4-cp314-cp314-manylinux_2_28_x86_64.whl
| Download URL | relag-0.0.4-cp314-cp314-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 4.4 MB |
| Tags | CPython 3.14 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
bd3778c12be32f77e0ded008df398192d5f664aec81edb9c8b966dc5f4ca5b43
|
|
BLAKE2b-256 checksum How to use checksums |
4a617ab6744d461044d52f7e95f0502970efb3e599f3c67e2a0394ba556e9afd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / relag-0.0.4-cp314-cp314-macosx_11_0_arm64.whl
| Download URL | relag-0.0.4-cp314-cp314-macosx_11_0_arm64.whl |
|---|---|
| Size | 2.0 MB |
| Tags | CPython 3.14 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
db547012aaef5592e88fe4f5509da161d778e79901ed4d3e09d593fcb02f6b1f
|
|
BLAKE2b-256 checksum How to use checksums |
2837d3c9fc51d53032efafae828b06aa3068df538a64c8f50f8ffd9e2cc11866
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / relag-0.0.4-cp314-cp314-macosx_10_15_x86_64.whl
| Download URL | relag-0.0.4-cp314-cp314-macosx_10_15_x86_64.whl |
|---|---|
| Size | 3.6 MB |
| Tags | CPython 3.14 macOS 10.15+ x86-64 |
|
SHA-256 checksum How to use checksums |
4fed3b9b538ebc4e6c80c99808c3e113fbfcaa3a18098329b97f231bb61a4b11
|
|
BLAKE2b-256 checksum How to use checksums |
978c231e868056174246d2f8262e78c17f2eff68257e1f8d397ec37f09581a59
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / relag-0.0.4-cp313-cp313-win_amd64.whl
| Download URL | relag-0.0.4-cp313-cp313-win_amd64.whl |
|---|---|
| Size | 3.7 MB |
| Tags | CPython 3.13 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
9ffda67921cfa2ed4ca9fa2d4e2a441e40ec4e0d814ad44bc5b2463f26216b83
|
|
BLAKE2b-256 checksum How to use checksums |
512dda74c717d994e85aebc15d9f8f274de785031a4ea13d7cbdcebb63ad5953
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / relag-0.0.4-cp313-cp313-manylinux_2_28_x86_64.whl
| Download URL | relag-0.0.4-cp313-cp313-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 4.4 MB |
| Tags | CPython 3.13 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
0086bde574a4d8f3bcd1bec6c50d6d565b57ee65647abde3c9f4b4119e9a5652
|
|
BLAKE2b-256 checksum How to use checksums |
6e3257a78d18ae7aa0241c8f5bd1e336ba6ac24e006903f755c6e744d1d64bb1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / relag-0.0.4-cp313-cp313-macosx_11_0_arm64.whl
| Download URL | relag-0.0.4-cp313-cp313-macosx_11_0_arm64.whl |
|---|---|
| Size | 2.0 MB |
| Tags | CPython 3.13 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
ae7d354eb130f80ec83298a19660d14f42869f95d65c3201d9db270070f3d1f5
|
|
BLAKE2b-256 checksum How to use checksums |
0c975e0708a53bace98276a8101c2d413e515466f1f2e111b490d2c50dd4af2e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / relag-0.0.4-cp313-cp313-macosx_10_14_x86_64.whl
| Download URL | relag-0.0.4-cp313-cp313-macosx_10_14_x86_64.whl |
|---|---|
| Size | 3.6 MB |
| Tags | CPython 3.13 macOS 10.14+ x86-64 |
|
SHA-256 checksum How to use checksums |
0919087a840b3c1f5a35a5d174366c2d6d23a2fb58299773dfa38c0981267094
|
|
BLAKE2b-256 checksum How to use checksums |
0d0731092a48fbc9ba8a0b0f9f36b5a400cf943ee3795d225e7a6532e655149f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / relag-0.0.4-cp312-cp312-win_amd64.whl
| Download URL | relag-0.0.4-cp312-cp312-win_amd64.whl |
|---|---|
| Size | 3.7 MB |
| Tags | CPython 3.12 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
beaba7c94500e4ac543eebed45e2b461ed1f9105d7bcec7c8658a86f0f9fec5c
|
|
BLAKE2b-256 checksum How to use checksums |
7cf7f63c29624d650856ea7f5d594d8c7444cecd4312e53c35a8fe6b02124125
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / relag-0.0.4-cp312-cp312-manylinux_2_28_x86_64.whl
| Download URL | relag-0.0.4-cp312-cp312-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 4.4 MB |
| Tags | CPython 3.12 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
da5d040f0439ef0f494d7bdce3adabfd4a2ea741b831f842254dc494e820b698
|
|
BLAKE2b-256 checksum How to use checksums |
9c845a0d2f1fe097775deb5d713ffa1a81c5f6b31fdd9f5ff19c9877e3e277fb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / relag-0.0.4-cp312-cp312-macosx_11_0_arm64.whl
| Download URL | relag-0.0.4-cp312-cp312-macosx_11_0_arm64.whl |
|---|---|
| Size | 2.0 MB |
| Tags | CPython 3.12 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
60d16c36ecd559b45c325e9bdd5412c4adb09cf7edf2bb948fd7e77a72c38557
|
|
BLAKE2b-256 checksum How to use checksums |
8b1d0fca356f214b5bb0a8b0f07d96b7c425aa82ca8995248b482fe2966d6ef8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / relag-0.0.4-cp312-cp312-macosx_10_14_x86_64.whl
| Download URL | relag-0.0.4-cp312-cp312-macosx_10_14_x86_64.whl |
|---|---|
| Size | 3.6 MB |
| Tags | CPython 3.12 macOS 10.14+ x86-64 |
|
SHA-256 checksum How to use checksums |
6057c3df0ea9707daa824840ea059d9bf41ddd40368ef94ad217c05d1f58c1ac
|
|
BLAKE2b-256 checksum How to use checksums |
bc3189867c5684b0f3a7a621728515aa39ea0d9d734bb1fc76e05ed8dc50459d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / relag-0.0.4-cp311-cp311-win_amd64.whl
| Download URL | relag-0.0.4-cp311-cp311-win_amd64.whl |
|---|---|
| Size | 3.7 MB |
| Tags | CPython 3.11 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
0731320858051eaed221c1ac38d6f1e0cff27a77f3bf53627c157ed708a4862e
|
|
BLAKE2b-256 checksum How to use checksums |
7c4e018370e4aa3ade17e2c815211b8253fa6341052f5815aa421d4b394d507e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / relag-0.0.4-cp311-cp311-manylinux_2_28_x86_64.whl
| Download URL | relag-0.0.4-cp311-cp311-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 4.4 MB |
| Tags | CPython 3.11 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
62319d356b2742c9318c57d39b7fa10c5833dd12583bad5e50a0f01a9d17915d
|
|
BLAKE2b-256 checksum How to use checksums |
f526f9bb9e6abb961a3fe6a55bd9f36e5e40cc60b94a1b9bc07d0069ddc9537e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / relag-0.0.4-cp311-cp311-macosx_11_0_arm64.whl
| Download URL | relag-0.0.4-cp311-cp311-macosx_11_0_arm64.whl |
|---|---|
| Size | 2.0 MB |
| Tags | CPython 3.11 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
f0114cc8e2afcf4e1dca418367284a4be4fdccd4f3895be104dbe21a1aa4a2c6
|
|
BLAKE2b-256 checksum How to use checksums |
9a20a0948e86e1061faa9f30b9f5fe59e85214dedb5f3526a2025f1833ffdc49
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / relag-0.0.4-cp311-cp311-macosx_10_14_x86_64.whl
| Download URL | relag-0.0.4-cp311-cp311-macosx_10_14_x86_64.whl |
|---|---|
| Size | 3.6 MB |
| Tags | CPython 3.11 macOS 10.14+ x86-64 |
|
SHA-256 checksum How to use checksums |
2a213360a7f9c89058d8ac4d4cbb11c4d8daf995270a2506706ab74895b18da7
|
|
BLAKE2b-256 checksum How to use checksums |
4f6cf4e9b7d7e7e770cdeefa59a6af560f167d29ff672738032ea4c6b8fd7bc5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / relag-0.0.4-cp310-cp310-win_amd64.whl
| Download URL | relag-0.0.4-cp310-cp310-win_amd64.whl |
|---|---|
| Size | 3.7 MB |
| Tags | CPython 3.10 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
f8cdc038fdb6e39a62c7ff1ae5105a8993f7e2f0b7f3de5ecda6b2539630ef88
|
|
BLAKE2b-256 checksum How to use checksums |
658e914dd2c40e5cf0d9e0a666a49ea3cc8f2effbb6e4d82e02de509508e50fa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / relag-0.0.4-cp310-cp310-manylinux_2_28_x86_64.whl
| Download URL | relag-0.0.4-cp310-cp310-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 4.4 MB |
| Tags | CPython 3.10 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
636a96ee021230e7eb108e3e2060e3f0e29539739dc5fe26f9b639b3e36a0e47
|
|
BLAKE2b-256 checksum How to use checksums |
870f064b65608451aee785bda007c90403cab3fca43bcb0eab2c2141c59bfc6c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / relag-0.0.4-cp310-cp310-macosx_11_0_arm64.whl
| Download URL | relag-0.0.4-cp310-cp310-macosx_11_0_arm64.whl |
|---|---|
| Size | 2.0 MB |
| Tags | CPython 3.10 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
1e0d8d4a7fc40363918399cb4093b341adb627342b23e8a543993416f113d318
|
|
BLAKE2b-256 checksum How to use checksums |
8642396680d586d7380f9d044adc9b0d1036b2f27d025f959660b4c12d2dc374
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / relag-0.0.4-cp310-cp310-macosx_10_14_x86_64.whl
| Download URL | relag-0.0.4-cp310-cp310-macosx_10_14_x86_64.whl |
|---|---|
| Size | 3.6 MB |
| Tags | CPython 3.10 macOS 10.14+ x86-64 |
|
SHA-256 checksum How to use checksums |
a29f319828699870bcd7d64bf5581d0510a90236acbbf3d94cd1a3389e340414
|
|
BLAKE2b-256 checksum How to use checksums |
90e10c6b95c3028ae6c099fc137bb5fa33322df7215979a816351f5b51b155a9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Security for relag 0.0.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.