From 57d8b892408ae81b1a01e3440bf0a671ae14c7d8 Mon Sep 17 00:00:00 2001 From: sfluegel Date: Wed, 22 Jul 2026 16:43:38 +0200 Subject: [PATCH 1/2] add empty molecule filter --- chebi_utils/sdf_extractor.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/chebi_utils/sdf_extractor.py b/chebi_utils/sdf_extractor.py index 5d961d7..cf3c207 100644 --- a/chebi_utils/sdf_extractor.py +++ b/chebi_utils/sdf_extractor.py @@ -160,12 +160,14 @@ def extract_molecules(filepath: str | Path) -> pd.DataFrame: df["mol"] = [_parse_molblock(mb, cid) for mb, cid in zip(molblocks, chebi_ids, strict=False)] df["chebi_id"] = df["chebi_id"].apply(_chebi_id_to_str) - # exclude records without a valid mol, but keep the same columns for consistency + # exclude records without a valid molecule df = df[df["mol"].notna()] + # some molecule records are valid, but have no atoms (e.g. ) + df[[mol.GetNumAtoms() > 0 for mol in df["mol"]]] return df if __name__ == "__main__": - df = extract_molecules("data/chebi.sdf.gz") + df = extract_molecules("chebi.sdf.gz") print(df.head()) From dc08b71e9fc38ca799fd5f23b9416c6fb5974c9e Mon Sep 17 00:00:00 2001 From: sfluegel Date: Wed, 22 Jul 2026 16:45:09 +0200 Subject: [PATCH 2/2] add description --- chebi_utils/sdf_extractor.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chebi_utils/sdf_extractor.py b/chebi_utils/sdf_extractor.py index cf3c207..98607e5 100644 --- a/chebi_utils/sdf_extractor.py +++ b/chebi_utils/sdf_extractor.py @@ -162,8 +162,8 @@ def extract_molecules(filepath: str | Path) -> pd.DataFrame: # exclude records without a valid molecule df = df[df["mol"].notna()] - # some molecule records are valid, but have no atoms (e.g. ) - df[[mol.GetNumAtoms() > 0 for mol in df["mol"]]] + # some molecule records are valid, but have no atoms (e.g. CHEBI:192499 in v251, cf. https://github.com/ebi-chebi/ChEBI/issues/4915) + df = df[[mol.GetNumAtoms() > 0 for mol in df["mol"]]] return df