Skip to main content
logo

Hestia-GOOD

Computational tool for generating generalisation-evaluating evaluation sets.

Tutorials GitHub Open In Colab

Contents

Table of Contents

Installation

Installing in a conda environment is recommended. For creating the environment, please run:

conda create -n hestia python
conda activate hestia

1. Python Package

1.1. From PyPI

pip install hestia-good

1.2. Directly from source

pip install git+https://github.com/IBM/Hestia-GOOD

2. Optional dependencies

2.1. Molecular similarity

RDKit is a dependency necessary for calculating molecular similarities:

pip install rdkit

2.2. Sequence alignment

# static build with AVX2 (fastest) (check using: cat /proc/cpuinfo | grep avx2)
wget https://mmseqs.com/latest/mmseqs-linux-avx2.tar.gz; tar xvfz mmseqs-linux-avx2.tar.gz; export PATH=$(pwd)/mmseqs/bin/:$PATH

# static build with SSE4.1  (check using: cat /proc/cpuinfo | grep sse4)
wget https://mmseqs.com/latest/mmseqs-linux-sse41.tar.gz; tar xvfz mmseqs-linux-sse41.tar.gz; export PATH=$(pwd)/mmseqs/bin/:$PATH

# static build with SSE2 (slowest, for very old systems)  (check using: cat /proc/cpuinfo | grep sse2)
wget https://mmseqs.com/latest/mmseqs-linux-sse2.tar.gz; tar xvfz mmseqs-linux-sse2.tar.gz; export PATH=$(pwd)/mmseqs/bin/:$PATH

# MacOS
brew install mmseqs2  

To use Needleman-Wunch, either:

conda install -c bioconda emboss

or

sudo apt install emboss

2.3. Structure alignment

# Linux AVX2 build (check using: cat /proc/cpuinfo | grep avx2)
wget https://mmseqs.com/foldseek/foldseek-linux-avx2.tar.gz; tar xvzf foldseek-linux-avx2.tar.gz; export PATH=$(pwd)/foldseek/bin/:$PATH

# Linux SSE2 build (check using: cat /proc/cpuinfo | grep sse2)
wget https://mmseqs.com/foldseek/foldseek-linux-sse2.tar.gz; tar xvzf foldseek-linux-sse2.tar.gz; export PATH=$(pwd)/foldseek/bin/:$PATH

# Linux ARM64 build
wget https://mmseqs.com/foldseek/foldseek-linux-arm64.tar.gz; tar xvzf foldseek-linux-arm64.tar.gz; export PATH=$(pwd)/foldseek/bin/:$PATH

# MacOS
wget https://mmseqs.com/foldseek/foldseek-osx-universal.tar.gz; tar xvzf foldseek-osx-universal.tar.gz; export PATH=$(pwd)/foldseek/bin/:$PATH

Documentation

1. DatasetGenerator

The HestiaGenerator allows for the easy generation of training/validation/evaluation partitions with different similarity thresholds. Enabling the estimation of model generalisation capabilities. It also allows for the calculation of the AU-GOOD (Area Under the Generalization Out-Of-Distribution curve). More information in Dataset Generator docs.

from hestia.dataset_generator import HestiaGenerator, SimArguments

# Initialise the generator for a DataFrame
generator = HestiaGenerator(df)

# Define the similarity arguments (for more info see the documentation page https://ibm.github.io/Hestia-OOD/datasetgenerator)

# Similarity arguments for protein similarity
prot_args = SimArguments(
    data_type='sequence', field_name='sequence',
    alignment_algorithm='mmseqs2+prefilter', verbose=3
)

# Similarity arguments for molecular similarity
mol_args = SimArguments(
    data_type='small molecule', field_name='SMILES',
    fingeprint='mapc', radius=2, bits=2048
)

# Calculate the similarity
generator.calculate_similarity(prot_args)

# Calculate partitions
generator.calculate_partitions(min_threshold=0.3,
                               threshold_step=0.05,
                               test_size=0.2, valid_size=0.1)

# Save partitions
generator.save_precalculated('precalculated_partitions.gz')

# Load pre-calculated partitions
generator.from_precalculated('precalculated_partitions.gz')

# Training code (filter partitions with test sets less than 18.5% of total data)

for threshold, partition in generator.get_partitions(filter=0.185):
    train = df.iloc[partition['train']]
    valid = df.iloc[partition['valid']]
    test = df.iloc[partition['test']]

# ...

# Calculate AU-GOOD
generator.calculate_augood(results, 'test_mcc')

# Plot GOOD
generator.plot_good(results, 'test_mcc')

# Compare two models
results = {'model A': [values_A], 'model B': [values_B]}
generator.compare_models(results, statistical_test='wilcoxon')

2. Similarity calculation

Calculating pairwise similarity between the entities within a DataFrame df_query or between two DataFrames df_query and df_target can be achieved through the calculate_similarity function. More details about similarity calculation can be found in the Similarity calculation documentation.

from hestia.similarity import sequence_similarity_mmseqs
import pandas as pd

df_query = pd.read_csv('example.csv')

# The CSV file needs to have a column describing the entities, i.e., their sequence, their SMILES, or a path to their PDB structure.
# This column corresponds to `field_name` in the function.

sim_df = sequence_similarity_mmseqs(df_query, field_name='sequence', prefilter=True)

3. Clustering

Clustering the entities within a DataFrame df can be achieved through the generate_clusters function. There are three clustering algorithms currently supported: CDHIT, greedy_cover_set, or connected_components. More details about clustering can be found in the Clustering documentation.

from hestia.similarity import sequence_similarity_mmseqs
from hestia.clustering import generate_clusters
import pandas as pd

df = pd.read_csv('example.csv')
sim_df = sequence_similarity_mmseqs(df, field_name='sequence')
clusters_df = generate_clusters(df, field_name='sequence', sim_df=sim_df,
                                cluster_algorithm='CDHIT')

4. Partitioning

Partitioning the entities within a DataFrame df into a training and an evaluation subsets can be achieved through 4 different functions: ccpart, graph_part, reduction_partition, and random_partition. More details about partitioning algorithms can be found in the Partitioning documentation. An example of how ccpart would be used is:

from hestia.similarity import sequence_similarity_mmseqs
from hestia.partition import ccpart
import pandas as pd

df = pd.read_csv('example.csv')
sim_df = sequence_similarity_mmseqs(df, field_name='sequence')
train, test, partition_labs = ccpart(df, threshold=0.3, test_size=0.2, sim_df=sim_df)

train_df = df.iloc[train, :]
test_df = df.iloc[test, :]

5. AutoHestia

AutoHestia automatically benchmarks all combinations of partitioning algorithms and similarity metrics on your dataset, then selects the best-performing splits using guardrails (minimum test size and dynamic range). More information in the AutoHestia docs.

from hestia.autohestia import AutoHestia
import pandas as pd
import numpy as np

df = pd.read_csv('example.csv')

# Pre-computed feature matrix and labels
x = np.load('features.npy')
y = np.load('labels.npy')

# Pre-computed similarity DataFrames keyed by metric name
sim_dfs = {
    'mmseqs2': sim_df_mmseqs,
    'tanimoto': sim_df_tanimoto,
}

auto = AutoHestia(
    df=df,
    field_name='sequence',
    x=x,
    y=y,
    sim_dfs=sim_dfs,
    verbose_level='info'
)

# Run guardrailed experiment sweep
output = auto.best_guardrailed_splits(
    top_k_parts=3,
    top_l_sims=3,
    min_test_size=0.185,
    min_dynamic_range=0.4,
    save_dir='results'
)

# Retrieve the best partitions
best_parts = output['best-parts']
top_combination = output['top-combination']   # (part_alg, sim_metric)

# Plot GOOD curves for all evaluated combinations
auto.plot_good_curves(save_dir='results')

License

Hestia is an open-source software licensed under the MIT Clause License. Check the details in the LICENSE file.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hestia_good-1.2.2.tar.gz (51.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hestia_good-1.2.2-py3-none-any.whl (50.8 kB view details)

Uploaded Python 3

File details

Details for the file hestia_good-1.2.2.tar.gz.

File metadata

  • Download URL: hestia_good-1.2.2.tar.gz
  • Upload date:
  • Size: 51.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for hestia_good-1.2.2.tar.gz
Algorithm Hash digest
SHA256 3e139fa7b99a87900a9bbe57e806517f0ac3f61afebbc8f3675f144281702b81
MD5 8eb042252e6869cb5318bd86f92771d7
BLAKE2b-256 abd68559079a656c72c9ec188ae2ca50b9934989a3428359838afdf722b0d999

See more details on using hashes here.

File details

Details for the file hestia_good-1.2.2-py3-none-any.whl.

File metadata

  • Download URL: hestia_good-1.2.2-py3-none-any.whl
  • Upload date:
  • Size: 50.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for hestia_good-1.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 31b2c8e3697ec845af779b711734ea9ea6d17378f1afd0f4f7d2c249160bc255
MD5 c38e0f525727dd818421530148cb6c5b
BLAKE2b-256 0e6193202313bf75146655a9acedda189101d983bc132f7da9fe8a4d6e6b4de2

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.2.2 This release

2 files

1.2.1

2 files

1.2.0

2 files

1.1.2

2 files

1.1.1

2 files

1.1.0

2 files

1.0.4

2 files

1.0.2

2 files

1.0.1

2 files

1.0.0

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

0.0.37

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page