| from __future__ import annotations | |
| from pathlib import Path | |
| import pandas as pd | |
| REQUIRED_COLUMNS = {"ligand_id", "smiles"} | |
| def read_smiles_table(path: str | Path) -> pd.DataFrame: | |
| """Read ligand table with required columns ligand_id and smiles.""" | |
| source = Path(path) | |
| if source.suffix.lower() in {".tsv", ".txt"}: | |
| df = pd.read_csv(source, sep="\t") | |
| else: | |
| df = pd.read_csv(source) | |
| missing = REQUIRED_COLUMNS - set(df.columns) | |
| if missing: | |
| raise ValueError(f"Missing required columns in {source}: {sorted(missing)}") | |
| return df | |
| def write_smiles_table(df: pd.DataFrame, path: str | Path) -> Path: | |
| target = Path(path) | |
| target.parent.mkdir(parents=True, exist_ok=True) | |
| df.to_csv(target, index=False) | |
| return target | |