pino-source-code / tests /test_build_goodscents_odor_source_v11.py
Matthew Ford
Complete catalog recovery and enrichment
83db774
Raw
History Blame Contribute Delete
2.47 kB
from __future__ import annotations
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "scripts"))
import build_goodscents_odor_source_v11 as source # noqa: E402
def test_build_rows_requires_valid_unique_exact_cas():
opl = [
{"TGSC ID": "one", "CAS Number": "100-52-7"},
{"TGSC ID": "ambiguous", "CAS Number": "100-52-7"},
{"TGSC ID": "ambiguous", "CAS Number": "100-51-6"},
{"TGSC ID": "bad", "CAS Number": "100-52-8"},
{"TGSC ID": "structure", "CAS Number": "71-43-2", "CID": "241"},
]
odor = [
{"TGSC ID": "one", "Description": "sweet almond", "Source": "TGSC"},
{"TGSC ID": "ambiguous", "Description": "woody"},
{"TGSC ID": "bad", "Description": "fruity"},
{"TGSC ID": "structure", "Description": "aromatic"},
]
molecules = [{"CID": "241", "IsomericSMILES": "c1ccccc1"}]
profiles = [
{"cas": "100-52-7", "smiles": "O=Cc1ccccc1"},
{"cas": "100-51-6", "smiles": "OCc1ccccc1"},
{"cas": "100-52-8", "smiles": ""},
{"cas": "SMILES:c1ccccc1", "smiles": "c1ccccc1"},
]
rows, report = source.build_rows(opl, odor, molecules, profiles)
assert [(row["cas"], row["text"]) for row in rows] == [
("100-52-7", "sweet almond"),
("SMILES:c1ccccc1", "aromatic"),
]
assert report == {
"profiles_with_rows": 2,
"description_rows": 2,
"ambiguous_tgsc_ids_rejected": 1,
"exact_structure_profiles": 1,
"ambiguous_structure_profiles_rejected": 0,
"identity_policy": (
"exact CAS first; otherwise exact full InChIKey with one profile and one source CAS; "
"ambiguous structures rejected"
),
}
def test_build_rows_rejects_structure_join_with_multiple_source_cas():
opl = [
{"TGSC ID": "a", "CAS Number": "71-43-2", "CID": "241"},
{"TGSC ID": "b", "CAS Number": "108-88-3", "CID": "999"},
]
odor = [
{"TGSC ID": "a", "Description": "aromatic"},
{"TGSC ID": "b", "Description": "sweet"},
]
molecules = [
{"CID": "241", "IsomericSMILES": "c1ccccc1"},
{"CID": "999", "IsomericSMILES": "c1ccccc1"},
]
profiles = [{"cas": "SMILES:c1ccccc1", "smiles": "c1ccccc1"}]
rows, report = source.build_rows(opl, odor, molecules, profiles)
assert rows == []
assert report["ambiguous_structure_profiles_rejected"] == 1