ProtEnc: generate protein embeddings the easy way
ProtEnc aims to simplify extraction of protein embeddings from various pre-trained models by providing simple APIs and bulk generation scripts for the ever-growing landscape of protein language models (pLMs). Currently, supported models are:
Usage
Installation
pip install protenc
Python API
import protenc
# List available models
print(protenc.list_models())
# Load encoder model
encoder = protenc.get_encoder('esm2_t30_150M_UR50D', device='cuda')
proteins = [
'MKTVRQERLKSIVRILERSKEPVSGAQLAEELSVSRQVIVQDIAYLRSLGYNIVATPRGYVLAGG',
'KALTARQQEVFDLIRDHISQTGMPPTRAEIAQRLGFRSPNAAEEHLKALARKGVIEIVSGASRGIRLLQEE'
]
for embed in encoder(proteins, return_format='numpy'):
# Embeddings have shape [L, D] where L is the sequence length and D the embedding dimensionality.
print(embed.shape)
# Derive a single per-protein embedding vector by averaging along the sequence dimension
embed.mean(0)
Command-line interface
After installation, use the protenc shell command for bulk generation and export of protein embeddings.
protenc sequences.fasta embeddings.lmdb --model_name=<name-of-model>
By default, input and output formats are inferred from the file extensions.
Run
protenc --help
for a detailed usage description.
Example
Generate protein embeddings using the ESM2 650M model for sequences provided in a FASTA file and write embeddings to an LMDB:
protenc proteins.fasta embeddings.lmdb --model_name=esm2_t33_650M_UR50D
The generated embeddings will be stored in a lmdb key-value store and can be easily accessed using the read_from_lmdb utility function:
from protenc.utils import read_from_lmdb
for label, embed in read_from_lmdb('embeddings.lmdb'):
print(label, embed)
Features
Input formats:
- CSV
- JSON
- FASTA
Output format:
General:
- Multi-GPU inference with (
--data_parallel) - FP16 inference (
--amp)
Development
Clone the repository:
git clone git+https://github.com/kklemon/protenc.git
Install dependencies via Poetry:
poetry install
Contribution
Have feature ideas or found a bug? Love to see support for a new model? Feel free to create an issue.
Todo
- Support for more input formats
- CSV
- Parquet
- FASTA
- JSON
- Support for more output formats
- LMDB
- HDF5
- DataFrame
- Pickle
- Support for large models
- Model offloading
- Sharding
- FlashAttention (via Kernl?)
- Support for more protein language models
- Whole ProtTrans family
- Whole ESM family
- AlphaFold (?)
- Implement all remaining TODOs in code
- Evaluation
- Demos
- Distributed inference
- Maybe support some sort of optimized inference such as quantization
- This may be up to the model providers
- Improve documentation
- Support translation of gene sequences
- Add tests. We need tests!!!
Metadata
Release files for protenc 0.1.6
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 | Actions |
|---|---|---|---|---|
| protenc-0.1.6.tar.gz | 12.7 kB | Without provenance | Details for protenc-0.1.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| protenc-0.1.6-py3-none-any.whl | Python 3 | none | any | Details for protenc-0.1.6-py3-none-any.whl |
Total release size: 26.2 kB
Release files / protenc-0.1.6.tar.gz
| Download URL | protenc-0.1.6.tar.gz |
|---|---|
| Size | 12.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b5c9304c9a664abcff9c6540166e83a7ce32d6eb9b3539c8f6ade9fbda080a1f
|
|
BLAKE2b-256 checksum How to use checksums |
d334d73edcf3a7965023b85919fda6230c74d5d608e0ea65bf4ff703d46295f1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.6.1 CPython/3.10.9 Linux/5.15.0-86-generic
|
Release files / protenc-0.1.6-py3-none-any.whl
| Download URL | protenc-0.1.6-py3-none-any.whl |
|---|---|
| Size | 13.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f3271b4c279bef15d315cf7ae00cf950ace17f662ecbb5dbffa6a5a8817d3097
|
|
BLAKE2b-256 checksum How to use checksums |
d5f8b9601dd9d40fa7c0cfe1648abd4bf18f16d42a0ea9daf7e908c81b610dd5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.6.1 CPython/3.10.9 Linux/5.15.0-86-generic
|
Security for protenc 0.1.6
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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.