Python tools for protein sequence clustering and embedding
Project description
protclust
A Python library for working with protein sequence data, providing:
- Clustering capabilities via MMseqs2
- Machine learning dataset creation with cluster-aware splits
- Protein sequence embeddings and feature extraction
Requirements
This library requires MMseqs2, which must be installed and accessible via the command line. MMseqs2 can be installed using one of the following methods:
Installation Options for MMseqs2
-
Homebrew:
brew install mmseqs2
-
Conda:
conda install -c conda-forge -c bioconda mmseqs2
-
Docker:
docker pull ghcr.io/soedinglab/mmseqs2
-
Static Build (AVX2, SSE4.1, or SSE2):
wget https://mmseqs.com/latest/mmseqs-linux-avx2.tar.gz tar xvfz mmseqs-linux-avx2.tar.gz export PATH=$(pwd)/mmseqs/bin/:$PATH
MMseqs2 must be accessible via the mmseqs command in your system's PATH. If the library cannot detect MMseqs2, it will raise an error.
Installation
Installation
You can install protclust using pip:
pip install protclust
Or if installing from source, clone the repository and run:
pip install -e .
For development purposes, also install the testing dependencies:
pip install pytest pytest-cov pre-commit ruff
Features
Sequence Clustering and Dataset Creation
import pandas as pd
from protclust import clean, cluster, split, set_verbosity
# Enable detailed logging (optional)
set_verbosity(verbose=True)
# Example data
df = pd.DataFrame({
"id": ["seq1", "seq2", "seq3", "seq4"],
"sequence": ["ACDEFGHIKL", "ACDEFGHIKL", "MNPQRSTVWY", "MNPQRSTVWY"]
})
# Clean data
clean_df = clean(df, sequence_col="sequence")
# Cluster sequences
clustered_df = cluster(clean_df, sequence_col="sequence", id_col="id")
# Split data into train and test sets
train_df, test_df = split(clustered_df, group_col="representative_sequence", test_size=0.3)
print("Train set:\n", train_df)
print("Test set:\n", test_df)
# Or use the combined function
from protclust import train_test_cluster_split
train_df, test_df = train_test_cluster_split(df, sequence_col="sequence", id_col="id", test_size=0.3)
Advanced Splitting Options
# Three-way split
from protclust import train_test_val_cluster_split
train_df, val_df, test_df = train_test_val_cluster_split(
df, sequence_col="sequence", test_size=0.2, val_size=0.1
)
# K-fold cross-validation with cluster awareness
from protclust import cluster_kfold
folds = cluster_kfold(df, sequence_col="sequence", n_splits=5)
# MILP-based splitting with property balancing
from protclust import milp_split
train_df, test_df = milp_split(
clustered_df,
group_col="representative_sequence",
test_size=0.3,
balance_cols=["molecular_weight", "hydrophobicity"]
)
Protein Embeddings
# Basic embeddings
from protclust.embeddings import blosum62, aac, property_embedding, onehot
# Add BLOSUM62 embeddings
df_with_blosum = blosum62(df, sequence_col="sequence")
# Generate embeddings with ESM models (requires extra dependencies)
from protclust.embeddings import embed_sequences
# ESM embedding
df_with_esm = embed_sequences(df, "esm", sequence_col="sequence")
# Saving embeddings to HDF5
df_with_refs = embed_sequences(
df,
"esm",
sequence_col="sequence",
use_hdf=True,
hdf_path="embeddings.h5"
)
# Retrieve embeddings
from protclust.embeddings import get_embeddings
embeddings = get_embeddings(df_with_refs, "esm", hdf_path="embeddings.h5")
Parameters
Common parameters for clustering functions:
df: Pandas DataFrame containing sequence datasequence_col: Column name containing sequencesid_col: Column name containing unique identifiersmin_seq_id: Minimum sequence identity threshold (0.0-1.0, default 0.3)coverage: Minimum alignment coverage (0.0-1.0, default 0.5)cov_mode: Coverage mode (0-3, default 0)test_size: Desired fraction of data in test set (default 0.2)random_state: Random seed for reproducibilitytolerance: Acceptable deviation from desired split sizes (default 0.05)
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Run tests (
pytest tests/) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Citation
If you use protclust in your research, please cite:
@software{protclust,
author = {Michael Scutari},
title = {protclust: Protein Sequence Clustering and ML Dataset Creation},
url = {https://github.com/michaelscutari/protclust},
version = {0.1.0},
year = {2025},
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file protclust-0.1.4.tar.gz.
File metadata
- Download URL: protclust-0.1.4.tar.gz
- Upload date:
- Size: 69.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bd781281312f1168c18dfaa700a16b19d1422a6860e09bb436b950b5049d7867
|
|
| MD5 |
fa6b6d0f620ccba361d3e2dfe808cd87
|
|
| BLAKE2b-256 |
47218f29287ba938d076b17cd91e2e2937b962eb433ce81efde47b711943366f
|
File details
Details for the file protclust-0.1.4-py3-none-any.whl.
File metadata
- Download URL: protclust-0.1.4-py3-none-any.whl
- Upload date:
- Size: 36.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0c1e9f5f6ad1a3f2102266476518b9dbd3ab4245ff396a87698373a52486e266
|
|
| MD5 |
4330d30e81a6508b190efe286bc1d7a1
|
|
| BLAKE2b-256 |
3799d52066d0247ab5892107adb2d2089b6f7403d2b05f6df29d88aa841e66dc
|