Backend (make everything real, no stubs): - Implement all 10 Python engine scripts (scispacy, pymare, pytrials, minicheck, indra, openalex, paperqa, pykeen, storm, asreview) behind the existing lib/engines bridges. openalex + pytrials are zero-dep (stdlib urllib, work out of the box); the 8 heavy engines run the real library when installed and emit an honest structured error envelope when absent — no phantom capability, no faked outputs. - /api/verify: hard production guard so the offline fixture path can NEVER activate in production (MOCK_MODE gated to NODE_ENV!=production); prod always runs the real retrieve→extract→verify pipeline. - /api/auth/google: wrap the OAuth entrypoint in try/catch — fail closed to /login. - MoA: wire the previously-dangling design_priors artifact into the multivers cross-source verifier as a mean-preserving, clamped (+/-25%) design-credibility weight; exact no-op when absent, so the benchmark verdict mix is protected. Frontend (enterprise-grade polish): - New shared console UI kit (components/console/ui.tsx): Skeleton, Card, Badge, Button, StatCard, EmptyState — one source for the house tokens. - Skeleton shimmer keyframe; LoadingBanner now renders shimmer instead of plain text (propagates to ~29 tool pages, signature unchanged). - Real workspace overview landing page: live stats (fixes a phantom 'claims' field the old page always rendered as 0), recent verifications with permalinks, quick actions, skeleton loading + empty + error states. Verified: tsc clean, 10/10 verify integration tests pass, production build compiles all 417 pages.
111 lines
4.2 KiB
Python
Executable File
111 lines
4.2 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""INDRA mechanism assembly — stdin/stdout bridge.
|
|
|
|
Bridge: lib/engines/indra.ts (assembleMechanisms). Reads a JSON job on stdin
|
|
{"text"?: str, "genes"?: [str], "citation"?: str, "timeout"?: int,
|
|
"neighbor_limit"?: int, "max_statements"?: int} and emits exactly one JSON
|
|
object on stdout:
|
|
|
|
success: {"ok": true, "reader": "reach"|"pathway_commons",
|
|
"statements": [
|
|
{"type", "subj": str|null, "obj": str|null, "belief": float|null,
|
|
"evidence": [{"source": str|null, "text": str|null, "pmid": str|null}]},
|
|
...]}
|
|
handled error: {"ok": false, "error": "..."} (exit 1)
|
|
|
|
Dep-gated: requires `indra` (pip install indra). When absent the script emits an
|
|
honest error envelope and exits 1 — never fake statements. The text path reads
|
|
mechanisms via REACH; the genes path queries Pathway Commons. Claim/source text is
|
|
read from stdin only and is never logged.
|
|
"""
|
|
import json
|
|
import sys
|
|
|
|
DEFAULT_MAX_STATEMENTS = 100
|
|
|
|
|
|
def _agent_names(stmt):
|
|
"""Best-effort (subj, obj) names from an INDRA statement's agent list."""
|
|
try:
|
|
agents = stmt.agent_list()
|
|
except Exception: # noqa: BLE001 — some statement types expose no agent_list
|
|
agents = []
|
|
subj = agents[0].name if len(agents) >= 1 and agents[0] is not None else None
|
|
obj = agents[1].name if len(agents) >= 2 and agents[1] is not None else None
|
|
return subj, obj
|
|
|
|
|
|
def _digest_statement(stmt):
|
|
subj, obj = _agent_names(stmt)
|
|
belief = getattr(stmt, "belief", None)
|
|
evidence = []
|
|
for ev in getattr(stmt, "evidence", []) or []:
|
|
pmid = getattr(ev, "pmid", None)
|
|
evidence.append({
|
|
"source": getattr(ev, "source_api", None),
|
|
"text": getattr(ev, "text", None),
|
|
"pmid": str(pmid) if pmid is not None else None,
|
|
})
|
|
return {
|
|
"type": type(stmt).__name__,
|
|
"subj": subj,
|
|
"obj": obj,
|
|
"belief": float(belief) if isinstance(belief, (int, float)) else None,
|
|
"evidence": evidence,
|
|
}
|
|
|
|
|
|
def assemble(job):
|
|
text = job.get("text")
|
|
genes = job.get("genes")
|
|
has_text = isinstance(text, str) and text.strip()
|
|
has_genes = isinstance(genes, list) and len(genes) > 0
|
|
if not has_text and not has_genes:
|
|
return {"ok": False, "error": "indra: non-empty 'text' or 'genes' is required"}
|
|
|
|
max_statements = job.get("max_statements")
|
|
max_statements = max_statements if isinstance(max_statements, int) and max_statements > 0 else DEFAULT_MAX_STATEMENTS
|
|
|
|
if has_text:
|
|
try:
|
|
from indra.sources import reach
|
|
except ImportError:
|
|
return {"ok": False, "error": "indra not installed; install indra to enable this engine"}
|
|
|
|
citation = job.get("citation") if isinstance(job.get("citation"), str) else None
|
|
timeout = job.get("timeout") if isinstance(job.get("timeout"), int) else None
|
|
processor = reach.process_text(text, citation=citation, timeout=timeout)
|
|
reader = "reach"
|
|
else:
|
|
try:
|
|
from indra.sources import biopax
|
|
except ImportError:
|
|
return {"ok": False, "error": "indra not installed; install indra to enable this engine"}
|
|
|
|
gene_names = [g for g in genes if isinstance(g, str) and g.strip()]
|
|
neighbor_limit = job.get("neighbor_limit")
|
|
neighbor_limit = neighbor_limit if isinstance(neighbor_limit, int) and neighbor_limit > 0 else 1
|
|
processor = biopax.process_pc_neighborhood(gene_names, neighbor_limit=neighbor_limit)
|
|
reader = "pathway_commons"
|
|
|
|
statements = getattr(processor, "statements", None) or []
|
|
digested = [_digest_statement(stmt) for stmt in statements[:max_statements]]
|
|
|
|
return {"ok": True, "reader": reader, "statements": digested}
|
|
|
|
|
|
def main():
|
|
try:
|
|
raw = sys.stdin.read()
|
|
job = json.loads(raw) if raw.strip() else {}
|
|
out = assemble(job)
|
|
print(json.dumps(out))
|
|
return 0 if out.get("ok") else 1
|
|
except Exception as exc: # noqa: BLE001 — surface every failure as a JSON envelope
|
|
print(json.dumps({"ok": False, "error": f"{type(exc).__name__}: {exc}"}))
|
|
return 1
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|