|
| 1 | +# scaffoldsplitlab |
| 2 | + |
| 3 | +**Scaffold-based train/val/test splitting for molecular machine learning.** |
| 4 | + |
| 5 | +[](https://github.com/your-org/scaffoldsplitlab/actions/workflows/tests.yml) |
| 6 | +[](https://www.python.org/) |
| 7 | + |
| 8 | +## Overview |
| 9 | + |
| 10 | +`scaffoldsplitlab` splits molecular datasets into training, validation, and test sets using either: |
| 11 | + |
| 12 | +- **Scaffold-based splitting** — groups molecules by their Murcko scaffold and assigns whole scaffolds to the same split. This provides a more realistic estimate of generalization to novel chemical scaffolds. _(Requires optional RDKit.)_ |
| 13 | +- **Random splitting** — standard stratified random split, optionally using a label column for stratification. |
| 14 | +- **Hash-based fallback** — when RDKit is not available, the scaffold method falls back to a deterministic hash-based split using molecule SMILES. |
| 15 | + |
| 16 | +## Installation |
| 17 | + |
| 18 | +```bash |
| 19 | +# Basic install (random splitting only) |
| 20 | +pip install scaffoldsplitlab |
| 21 | + |
| 22 | +# With RDKit support (scaffold splitting) |
| 23 | +pip install scaffoldsplitlab[rdkit] |
| 24 | + |
| 25 | +# Development install |
| 26 | +pip install -e ".[dev,rdkit]" |
| 27 | +``` |
| 28 | + |
| 29 | +## Quick Start |
| 30 | + |
| 31 | +```bash |
| 32 | +# Random split |
| 33 | +scaffold-split --input molecules.csv --method random |
| 34 | + |
| 35 | +# Scaffold split (requires RDKit) |
| 36 | +scaffold-split --input molecules.csv --method scaffold |
| 37 | + |
| 38 | +# Stratified random split |
| 39 | +scaffold-split --input molecules.csv --method random --label-col label |
| 40 | + |
| 41 | +# Custom fractions |
| 42 | +scaffold-split --input molecules.csv --train 0.7 --val 0.15 --test 0.15 --seed 123 |
| 43 | +``` |
| 44 | + |
| 45 | +Run the demo: |
| 46 | + |
| 47 | +```bash |
| 48 | +bash examples/run_demo.sh |
| 49 | +``` |
| 50 | + |
| 51 | +## CLI Reference |
| 52 | + |
| 53 | +``` |
| 54 | +scaffold-split [OPTIONS] |
| 55 | +
|
| 56 | +Options: |
| 57 | + -i, --input PATH Input CSV file (required) |
| 58 | + -s, --smiles-col TEXT SMILES column name [default: smiles] |
| 59 | + -l, --label-col TEXT Label column (for stratification) |
| 60 | + -m, --method TEXT Split method: 'random' or 'scaffold' [default: scaffold] |
| 61 | + --train FLOAT Training fraction [default: 0.8] |
| 62 | + --val FLOAT Validation fraction [default: 0.1] |
| 63 | + --test FLOAT Test fraction [default: 0.1] |
| 64 | + --seed INTEGER Random seed [default: 42] |
| 65 | + -o, --out PATH Output CSV path [default: split_output.csv] |
| 66 | +``` |
| 67 | + |
| 68 | +## Python API |
| 69 | + |
| 70 | +```python |
| 71 | +from scaffoldsplitlab.core import scaffold_split, random_split, check_split_leakage |
| 72 | +from scaffoldsplitlab.io import read_csv, write_csv |
| 73 | + |
| 74 | +df = read_csv("molecules.csv") |
| 75 | +result = scaffold_split(df, smiles_col="smiles", train_frac=0.8, val_frac=0.1, test_frac=0.1) |
| 76 | +write_csv(result, "split_output.csv") |
| 77 | + |
| 78 | +# Check for duplicate SMILES across splits |
| 79 | +leaks = check_split_leakage(result, smiles_col="smiles") |
| 80 | +print(leaks) # {} if no leakage |
| 81 | +``` |
| 82 | + |
| 83 | +## Non-Sensitive Data Statement |
| 84 | + |
| 85 | +This tool processes molecular structure data (SMILES strings) provided by the user. **It does not collect, transmit, or store any user data externally.** All computation is performed locally on the user's machine. No telemetry, analytics, or network calls are made. The tool does not ship with any pre-loaded chemical datasets. The example dataset (`examples/demo_input.csv`) contains 15 small molecules commonly used in cheminformatics tutorials and does not include any personally identifiable, proprietary, or sensitive information. |
| 86 | + |
| 87 | +## Non-Sensitive Data Statement |
| 88 | + |
| 89 | +This repository contains generic utility code and toy/public-data examples only. It does not include unpublished datasets, internal lab data, trained models, manuscript-specific results, or confidential project assets. |
| 90 | + |
| 91 | +## License |
| 92 | + |
| 93 | +MIT |
| 94 | + |
| 95 | +## Development |
| 96 | + |
| 97 | +```bash |
| 98 | +git clone https://github.com/your-org/scaffoldsplitlab.git |
| 99 | +cd scaffoldsplitlab |
| 100 | +pip install -e ".[dev,rdkit]" |
| 101 | +pytest |
| 102 | +ruff check src/ tests/ |
| 103 | +``` |
0 commit comments