proef 0.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- proef/__init__.py +25 -0
- proef/acquisition.py +244 -0
- proef/ad.py +159 -0
- proef/adapters/__init__.py +0 -0
- proef/adapters/admet.py +196 -0
- proef/adapters/bio/__init__.py +0 -0
- proef/adapters/bio/rdkit_ops.py +52 -0
- proef/adapters/bio/safety_rules.json +146 -0
- proef/adapters/bio/seq_alerts.py +79 -0
- proef/adapters/bio/structure_score.py +85 -0
- proef/adapters/bio/tox_alerts.py +99 -0
- proef/adapters/data/__init__.py +0 -0
- proef/adapters/data/admet.py +62 -0
- proef/adapters/data/chembl.py +110 -0
- proef/adapters/data/frozen/admet/MANIFEST.json +48 -0
- proef/adapters/data/frozen/admet/bbb_martins/test.csv +407 -0
- proef/adapters/data/frozen/admet/bbb_martins/train_val.csv +1625 -0
- proef/adapters/data/frozen/admet/caco2_wang/test.csv +183 -0
- proef/adapters/data/frozen/admet/caco2_wang/train_val.csv +729 -0
- proef/adapters/data/frozen/admet/hia_hou/test.csv +118 -0
- proef/adapters/data/frozen/admet/hia_hou/train_val.csv +462 -0
- proef/adapters/data/moleculenet.py +60 -0
- proef/adapters/databases/__init__.py +0 -0
- proef/adapters/databases/chembl_gates.py +121 -0
- proef/adapters/databases/chembl_lookup.py +35 -0
- proef/adapters/databases/open_targets.py +102 -0
- proef/adapters/databases/pubmed.py +94 -0
- proef/adapters/devices/__init__.py +0 -0
- proef/adapters/devices/ezo_ph.py +251 -0
- proef/adapters/devices/hcs_microscope.py +143 -0
- proef/adapters/devices/lcms.py +123 -0
- proef/adapters/devices/scheduler.py +84 -0
- proef/adapters/devices/sila2.py +134 -0
- proef/adapters/genomics/alphagenome.py +146 -0
- proef/adapters/lab/__init__.py +0 -0
- proef/adapters/lab/bioprocess.py +32 -0
- proef/adapters/lab/devices.py +170 -0
- proef/adapters/lab/imaging.py +226 -0
- proef/adapters/lab/mhs_driver.py +124 -0
- proef/adapters/lab/opentrons.py +222 -0
- proef/adapters/lab/ot2_sim.py +174 -0
- proef/adapters/lab/plate_reader_share.py +108 -0
- proef/adapters/lab/protein_design.py +199 -0
- proef/adapters/lab/recording.py +119 -0
- proef/adapters/lab/replay.py +107 -0
- proef/adapters/lab/simulator.py +282 -0
- proef/adapters/lab/synthesis.py +92 -0
- proef/adapters/models/__init__.py +0 -0
- proef/adapters/models/anthropic_provider.py +157 -0
- proef/adapters/models/assayloop_ranker.py +67 -0
- proef/adapters/models/from_env.py +93 -0
- proef/adapters/models/gp_policy.py +93 -0
- proef/adapters/models/gp_policy_gp.py +36 -0
- proef/adapters/models/llm_policy.py +187 -0
- proef/adapters/models/openai_compat.py +150 -0
- proef/adapters/models/sklearn_policy.py +65 -0
- proef/adapters/retrosynthesis.py +247 -0
- proef/adapters/sandbox/__init__.py +20 -0
- proef/adapters/sandbox/agentenv.py +145 -0
- proef/adapters/sandbox/docker.py +217 -0
- proef/adapters/sandbox/local.py +164 -0
- proef/adapters/sandbox/opensandbox.py +122 -0
- proef/adapters/store/__init__.py +0 -0
- proef/adapters/store/sqlite.py +207 -0
- proef/adaptive.py +108 -0
- proef/advisory.py +76 -0
- proef/analysis_profiles/__init__.py +8 -0
- proef/analysis_profiles/measurements.py +266 -0
- proef/analysis_profiles/plate_assay.py +316 -0
- proef/analysis_report.py +195 -0
- proef/analysis_store.py +183 -0
- proef/anchor.py +154 -0
- proef/api/app.py +107 -0
- proef/api/launch.py +170 -0
- proef/api/v1/__init__.py +29 -0
- proef/api/v1/analyses.py +367 -0
- proef/api/v1/campaigns.py +802 -0
- proef/api/v1/deps.py +10 -0
- proef/api/v1/evals.py +16 -0
- proef/api/v1/evidence.py +132 -0
- proef/api/v1/governance.py +35 -0
- proef/api/v1/inbox.py +119 -0
- proef/api/v1/lab.py +110 -0
- proef/api/v1/pauses.py +77 -0
- proef/api/v1/programs.py +397 -0
- proef/api/v1/results.py +147 -0
- proef/api/v1/schemas.py +932 -0
- proef/api/v1/system.py +79 -0
- proef/api/v1/trees.py +216 -0
- proef/api/wizard_sessions.py +253 -0
- proef/approvals.py +102 -0
- proef/assays/__init__.py +15 -0
- proef/assays/dls.py +114 -0
- proef/assays/dsf.py +81 -0
- proef/assays/elisa.py +58 -0
- proef/assays/properties.py +65 -0
- proef/assays/simulate.py +157 -0
- proef/audit.py +152 -0
- proef/autoloop.py +1620 -0
- proef/benchmark.py +442 -0
- proef/campaign_fsm.py +151 -0
- proef/citations.py +141 -0
- proef/cli.py +1249 -0
- proef/connect.py +74 -0
- proef/core/__init__.py +0 -0
- proef/core/contracts/__init__.py +35 -0
- proef/core/contracts/analysis.py +100 -0
- proef/core/contracts/models.py +395 -0
- proef/core/device_card.py +125 -0
- proef/core/hypothesis.py +720 -0
- proef/core/interfaces.py +164 -0
- proef/core/registry.py +123 -0
- proef/core/safety.py +324 -0
- proef/core/workflow.py +159 -0
- proef/critic.py +62 -0
- proef/demo.py +164 -0
- proef/derivation.py +128 -0
- proef/diary.py +301 -0
- proef/eln.py +87 -0
- proef/evals/__init__.py +1 -0
- proef/evals/hallucination.py +86 -0
- proef/evals/harness.py +358 -0
- proef/evals/orchestration.py +254 -0
- proef/evals/tasks.py +1010 -0
- proef/evals/toolcalls.py +425 -0
- proef/experiment.py +172 -0
- proef/experiment_analysis.py +114 -0
- proef/experiments/__init__.py +0 -0
- proef/experiments/grounding_exp.py +689 -0
- proef/figures.py +218 -0
- proef/fitting.py +309 -0
- proef/fixtures.py +140 -0
- proef/flywheel.py +125 -0
- proef/followup.py +126 -0
- proef/governance.py +290 -0
- proef/groundedness.py +361 -0
- proef/grounding.py +202 -0
- proef/hypothesis_agent.py +369 -0
- proef/ingest.py +157 -0
- proef/instruments.json +173 -0
- proef/interpret.py +95 -0
- proef/kinetic.py +102 -0
- proef/labread/__init__.py +45 -0
- proef/labread/analysis.py +428 -0
- proef/labread/common.py +153 -0
- proef/labread/formats.py +190 -0
- proef/labread/layout.py +168 -0
- proef/labread/pubchem.py +179 -0
- proef/labselect.py +431 -0
- proef/materials.py +140 -0
- proef/mcp_instrument.py +396 -0
- proef/mcp_server.py +283 -0
- proef/modality.py +111 -0
- proef/model_guard.py +245 -0
- proef/output_blocks.py +183 -0
- proef/paths.py +32 -0
- proef/physfail.py +55 -0
- proef/plan.py +160 -0
- proef/plots.py +123 -0
- proef/predictors.py +217 -0
- proef/probes.py +79 -0
- proef/problem_tree.py +581 -0
- proef/program.py +308 -0
- proef/protocol_design.py +42 -0
- proef/proxy.py +78 -0
- proef/readiness.py +259 -0
- proef/reliability.py +49 -0
- proef/report.py +117 -0
- proef/reproduce.py +310 -0
- proef/reviewer.py +254 -0
- proef/sandbox_session.py +247 -0
- proef/sandboxd.py +109 -0
- proef/scaffold.py +195 -0
- proef/series.py +327 -0
- proef/skills.py +203 -0
- proef/sweep.py +83 -0
- proef/taste.py +177 -0
- proef/templates/confirmatory-followup.json +34 -0
- proef/templates/dose-response-screen.json +39 -0
- proef/templates/sar-exploration.json +38 -0
- proef/templates.py +124 -0
- proef/toolkit.py +433 -0
- proef/toolloop.py +133 -0
- proef/tools.py +441 -0
- proef/tpp.py +185 -0
- proef/views/__init__.py +14 -0
- proef/views/counts.py +102 -0
- proef/views/experiment.py +154 -0
- proef/views/ids.py +49 -0
- proef/views/narrative.py +294 -0
- proef/views/pipeline.py +370 -0
- proef/vision.py +165 -0
- proef/watch.py +790 -0
- proef/wizard_chain.py +25 -0
- proef/wizard_store.py +373 -0
- proef-0.2.0.dist-info/METADATA +662 -0
- proef-0.2.0.dist-info/RECORD +200 -0
- proef-0.2.0.dist-info/WHEEL +4 -0
- proef-0.2.0.dist-info/entry_points.txt +14 -0
- proef-0.2.0.dist-info/licenses/LICENSE +202 -0
proef/citations.py
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"""Citation verification — enforce the "never invent" rule.
|
|
2
|
+
|
|
3
|
+
A hypothesis may cite a PMID or DOI to ground its rationale. This module
|
|
4
|
+
checks that the citation EXISTS (PMID resolvable / DOI indexed) via PubMed
|
|
5
|
+
E-utilities, with a local content-addressed cache so repeat runs are free
|
|
6
|
+
and offline runs degrade to "check-failed" — never to a false "invalid".
|
|
7
|
+
|
|
8
|
+
Statuses:
|
|
9
|
+
verified citation resolves to a real publication
|
|
10
|
+
invalid checked online, no such publication (hallucination)
|
|
11
|
+
check-failed offline/timeout — unknown, treated as unverified (no bonus)
|
|
12
|
+
unverified never checked
|
|
13
|
+
"""
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
import json
|
|
17
|
+
import re
|
|
18
|
+
import urllib.parse
|
|
19
|
+
import urllib.error
|
|
20
|
+
import urllib.request
|
|
21
|
+
from pathlib import Path
|
|
22
|
+
|
|
23
|
+
CACHE = Path(".data/citations.json")
|
|
24
|
+
EUTILS = "https://eutils.ncbi.nlm.nih.gov/entrez/eutils"
|
|
25
|
+
|
|
26
|
+
CHEMBL_RE = re.compile(r"\b(CHEMBL\d+)\b", re.I)
|
|
27
|
+
PMID_RE = re.compile(r"\bpmid[:\s]*(\d{5,9})\b", re.I) # the label is required and the digits must not sit inside another token (CHEMBL428690)
|
|
28
|
+
DOI_RE = re.compile(r"\b(10\.\d{4,9}/[^\s\"')>]+)\b")
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def parse(citation: str) -> tuple[str, str] | None:
|
|
32
|
+
"""('pmid', '35377565') or ('doi', '10.1021/...') or None."""
|
|
33
|
+
citation = citation.strip()
|
|
34
|
+
m = DOI_RE.search(citation)
|
|
35
|
+
if m:
|
|
36
|
+
return ("doi", m.group(1).rstrip(".,;"))
|
|
37
|
+
m = PMID_RE.search(citation)
|
|
38
|
+
if m:
|
|
39
|
+
return ("pmid", m.group(1))
|
|
40
|
+
if citation.isdigit():
|
|
41
|
+
return ("pmid", citation)
|
|
42
|
+
m = CHEMBL_RE.search(citation)
|
|
43
|
+
if m: # a ChEMBL id (molecule, target, document or assay): the lookup endpoint resolves any of them
|
|
44
|
+
return ("chembl", m.group(1).upper())
|
|
45
|
+
return None
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def _default_fetch(url: str) -> bytes:
|
|
49
|
+
req = urllib.request.Request(url, headers={"Accept": "application/json"})
|
|
50
|
+
with urllib.request.urlopen(req, timeout=30) as r: # noqa: S310
|
|
51
|
+
return r.read()
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def _load_cache() -> dict:
|
|
55
|
+
try:
|
|
56
|
+
return json.loads(CACHE.read_text())
|
|
57
|
+
except Exception:
|
|
58
|
+
return {}
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def _save_cache(c: dict) -> None:
|
|
62
|
+
CACHE.parent.mkdir(parents=True, exist_ok=True)
|
|
63
|
+
CACHE.write_text(json.dumps(c, indent=1))
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def verify(citation: str, fetch: callable = _default_fetch) -> dict:
|
|
67
|
+
"""Resolve one citation. Returns {status, kind, detail}."""
|
|
68
|
+
parsed = parse(citation)
|
|
69
|
+
if not parsed:
|
|
70
|
+
return {"status": "invalid", "kind": "unparseable",
|
|
71
|
+
"detail": "not a PMID or DOI"}
|
|
72
|
+
kind, value = parsed
|
|
73
|
+
cache = _load_cache()
|
|
74
|
+
key = f"{kind}:{value}"
|
|
75
|
+
if key in cache:
|
|
76
|
+
return cache[key]
|
|
77
|
+
try:
|
|
78
|
+
if kind == "pmid":
|
|
79
|
+
url = (f"{EUTILS}/esummary.fcgi?version=2.0&id={value}"
|
|
80
|
+
"&db=pubmed&retmode=json")
|
|
81
|
+
data = json.loads(fetch(url))
|
|
82
|
+
rec = data.get("result", {}).get(value)
|
|
83
|
+
if rec and rec.get("title"):
|
|
84
|
+
out = {"status": "verified", "kind": kind,
|
|
85
|
+
"detail": f"{rec.get('pubdate', '')[:4]} · "
|
|
86
|
+
f"{(rec.get('source') or '')[:40]}"}
|
|
87
|
+
else:
|
|
88
|
+
out = {"status": "invalid", "kind": kind,
|
|
89
|
+
"detail": "PMID not found"}
|
|
90
|
+
elif kind == "chembl":
|
|
91
|
+
data = json.loads(fetch(f"https://www.ebi.ac.uk/chembl/api/data/chembl_id_lookup/{value}.json"))
|
|
92
|
+
out = ({"status": "verified", "kind": kind, "detail": str(data.get("entity_type") or "")[:40]} if data.get("chembl_id") else
|
|
93
|
+
{"status": "invalid", "kind": kind, "detail": "ChEMBL id not found"})
|
|
94
|
+
else:
|
|
95
|
+
term = urllib.parse.quote(f"{value}[DOI]")
|
|
96
|
+
url = f"{EUTILS}/esearch.fcgi?db=pubmed&retmode=json&term={term}"
|
|
97
|
+
data = json.loads(fetch(url))
|
|
98
|
+
ids = data.get("esearchresult", {}).get("idlist", [])
|
|
99
|
+
out = ({"status": "verified", "kind": kind,
|
|
100
|
+
"detail": f"PMID {ids[0]}"} if ids else
|
|
101
|
+
{"status": "invalid", "kind": kind,
|
|
102
|
+
"detail": "DOI not indexed"})
|
|
103
|
+
except urllib.error.HTTPError as exc:
|
|
104
|
+
if exc.code == 404: # the service answered: there is no such record (a fake id)
|
|
105
|
+
out = {"status": "invalid", "kind": kind, "detail": f"{kind} not found (HTTP 404)"}
|
|
106
|
+
else:
|
|
107
|
+
return {"status": "check-failed", "kind": kind, "detail": f"HTTP {exc.code}"}
|
|
108
|
+
except Exception as exc:
|
|
109
|
+
# network failure is NOT evidence of a fake citation
|
|
110
|
+
return {"status": "check-failed", "kind": kind,
|
|
111
|
+
"detail": str(exc)[:80]}
|
|
112
|
+
if out["status"] != "check-failed":
|
|
113
|
+
cache[key] = out
|
|
114
|
+
_save_cache(cache)
|
|
115
|
+
return out
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def ids_of(citation: str) -> list[tuple[str, str]]:
|
|
119
|
+
"""Every identifier in a citation string, in order, each as (kind, value): a model often writes several ('PMID 1; CHEMBL2; 10.x/y')."""
|
|
120
|
+
out: list[tuple[str, str]] = []
|
|
121
|
+
for m in re.finditer(r"(10\.\d{4,9}/[^\s\";,)>]+)|\bpmid[:\s]*(\d{5,9})\b|\b(CHEMBL\d+)\b", citation or "", re.I):
|
|
122
|
+
item = ("doi", m.group(1).rstrip(".,;")) if m.group(1) else ("pmid", m.group(2)) if m.group(2) else ("chembl", m.group(3).upper())
|
|
123
|
+
if item not in out:
|
|
124
|
+
out.append(item)
|
|
125
|
+
return out
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def verify_each(citation: str, fetch: callable = _default_fetch) -> dict:
|
|
129
|
+
"""A citation that names several things is verified only if EVERY one resolves: any id that does not exist makes it invalid; an unreachable
|
|
130
|
+
service on any makes it check-failed. (`verify` looks at the first identifier only.)"""
|
|
131
|
+
ids = ids_of(citation)
|
|
132
|
+
if not ids:
|
|
133
|
+
return verify(citation, fetch)
|
|
134
|
+
results = [verify(f"PMID {v}" if k == "pmid" else v, fetch) for k, v in ids]
|
|
135
|
+
status = ("invalid" if any(r["status"] == "invalid" for r in results) else "check-failed" if any(r["status"] == "check-failed" for r in results)
|
|
136
|
+
else "verified")
|
|
137
|
+
return {"status": status, "kind": "multi" if len(ids) > 1 else ids[0][0], "detail": f"{len(ids)} identifier(s): " + ", ".join(r["status"] for r in results)}
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def verify_many(citations: list[str], fetch=_default_fetch) -> dict[str, dict]:
|
|
141
|
+
return {c: verify(c, fetch) for c in citations if c}
|