Skip to content

Latest commit

 

History

8 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LeakGuard

Data leakage detection library and CLI for molecular machine learning.

License: MIT Python 3.9+ Rust

LeakGuard is a Python package that checks for structural and fingerprint data leakage between training and testing splits in molecular datasets. It uses a Rust backend (via PyO3 and Rayon) to accelerate pairwise Tanimoto similarity calculations, and RDKit to handle SMILES canonicalization and Bemis-Murcko scaffolds.

Features

Randomly splitting chemical datasets can lead to unintended memorization. LeakGuard scans for three common forms of data leakage:

  1. Exact SMILES Overlap: Checks for identical molecules in both train and test splits.
  2. Bemis-Murcko Scaffold Leakage: Checks if molecules in the test set share a core scaffold with the training set.
  3. Fingerprint Similarity: Calculates a pairwise Tanimoto similarity matrix using Morgan Fingerprints to flag highly similar compounds.

Installation

Standard Installation

Requires Python 3.9+ and Rust (Cargo).

git clone https://github.com/VoidEchoes42/LeakGuard.git
cd LeakGuard

# Create and activate virtual environment
python -m venv .venv
source .venv/bin/activate  # On Windows: .\.venv\Scripts\activate

# Install package (will compile the Rust extension)
pip install -e .

Global Installation (CLI only)

If you prefer not to manage a virtual environment and just want the CLI tool available globally, use pipx or uv:

# Using pipx
pipx install .

# Using uv
uv tool install .

Usage

The package provides a CLI for quick analysis of CSV datasets.

leakguard analyze --train data/train.csv --test data/test.csv --smiles-col smiles

Options

  • --train (Required): Path to the training data CSV.
  • --test (Required): Path to the testing data CSV.
  • --smiles-col: Column name containing the SMILES strings (Default: "smiles").
  • --threshold: Tanimoto similarity threshold for flagging leaked pairs (Default: 0.8).
  • --output: File path to save the report (JSON or TXT).

Architecture

  • Python Frontend (leakguard/): Uses RDKit for cheminformatics tasks and Typer for the CLI. Converts valid SMILES into Morgan fingerprint bit vectors.
  • Rust Backend (src/lib.rs): Takes NumPy bit vectors from Python and computes the Tanimoto similarity matrix in parallel across available CPU threads.

License

MIT License. See the LICENSE file.

About

High-performance data leakage detection library and CLI for molecular machine learning datasets. Built with Python and Rust.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages