Pytdc

From aipoch/medical-research-skills · View interactive version

Pytdc is an AI agent skill from the GitHub repository aipoch/medical-research-skills. Therapeutics Data Commons (PyTDC) for AI-ready therapeutic ML datasets and benchmarks; use it when you need standardized dataset loading, meaningful splits (e.g., scaffold/cold-start), and consistent evaluation for ADME/Toxicity/DTI/DDI or molecular optimization.

How to use this skill

Skill file

Source: https://github.com/aipoch/medical-research-skills

When to Use

Key Features

Dependencies

Install (recommended):

uv pip install PyTDC

Upgrade:

uv pip install PyTDC --upgrade

Core runtime dependencies (installed automatically; versions depend on the PyTDC release you install):

Optional dependencies may be pulled in automatically depending on which submodules you use (e.g., graph backends or chemistry toolchains).

Example Usage

A complete runnable example that:

1) loads an ADME dataset,

2) performs a scaffold split,

3) trains a simple baseline model,

4) evaluates with a standard metric,

5) queries an Oracle score for a SMILES.

# pip install PyTDC scikit-learn

from tdc.single_pred import ADME
from tdc import Evaluator, Oracle

from sklearn.pipeline import Pipeline
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.linear_model import Ridge

def main():
    # 1) Load a single-instance prediction dataset (ADME)
    data = ADME(name="Caco2_Wang")

    # 2) Create a scaffold split (train/valid/test)
    split = data.get_split(method="scaffold", seed=42, frac=[0.7, 0.1, 0.2])
    train, valid, test = split["train"], split["valid"], split["test"]

    # 3) Train a simple baseline model on SMILES strings
    #    (character n-gram + ridge regression; replace with your own model)
    model = Pipeline(
        steps=[
            ("featurizer", CountVectorizer(analyzer="char", ngram_range=(2, 5))),
            ("regressor", Ridge(alpha=1.0)),
        ]
    )
    model.fit(train["Drug"], train["Y"])

    # 4) Evaluate on the test set using a TDC Evaluator
    y_pred = model.predict(test["Drug"])
    evaluator = Evaluator(name="MAE")
    mae = evaluator(test["Y"], y_pred)
    print(f"Test MAE: {mae:.4f}")

    # 5) Oracle scoring example (property scoring for a SMILES)
    oracle = Oracle(name="DRD2")
    score = oracle("CC(C)Cc1ccc(cc1)C(C)C(O)=O")
    print(f"DRD2 Oracle score: {score}")

if __name__ == "__main__":
    main()

Related references and templates (if present in this skill package):

Implementation Details

1) Dataset Access Pattern

PyTDC datasets follow a consistent interface:

from tdc.<problem> import <Task>

data = <Task>(name="<DatasetName>")
df = data.get_data(format="df")
split = data.get_split(method="scaffold", seed=1, frac=[0.7, 0.1, 0.2])

2) Splitting Strategies (Key Parameters)

Use get_split(...) to obtain {"train": ..., "valid": ..., "test": ...}.

Common parameters:

Typical methods:

Example:

split = data.get_split(method="cold_target", seed=1)

3) Standardized Evaluation

TDC provides a unified evaluator:

from tdc import Evaluator

evaluator = Evaluator(name="ROC-AUC")  # classification
score = evaluator(y_true, y_pred)

Choose metrics appropriate to the task type:

4) Data Schemas (What Columns to Expect)

While schemas vary by task, common conventions include:

5) Oracles for Molecular Optimization

Oracles provide a callable scoring interface:

from tdc import Oracle

oracle = Oracle(name="GSK3B")
score = oracle("CCO...")
scores = oracle(["SMILES1", "SMILES2"])

Use Oracles to:

For the full list of Oracles and their expected inputs/outputs, see references/oracles.md.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.