#!/usr/bin/env bash # Download the public PGx sources for `simurg pgx db build` (spec PGX-001) into a dated folder. # bash scripts/pgx/fetch_sources.sh [OUT_DIR] (default data/pgx/sources) # CPIC (CC0): tables from the CPIC API (https://api.cpicpgx.org, PostgREST) as JSON; the newest change-log date is # recorded as the data version. Never committed (data/ is ignored). set -euo pipefail OUT=${1:-data/pgx/sources} DATE=$(date -u +%Y%m%d) D="$OUT/cpic-$DATE" mkdir -p "$D" API=https://api.cpicpgx.org/v1 for t in gene allele allele_definition allele_location_value sequence_location gene_result gene_result_lookup \ gene_result_diplotype population change_log; do curl -sSf --retry 3 -H "Accept: application/json" "$API/$t" -o "$D/$t.json" python3 -c "import json,sys; print(sys.argv[1], len(json.load(open(sys.argv[2]))))" "$t" "$D/$t.json" done python3 - "$D" <<'PY' import hashlib, json, pathlib, sys d = pathlib.Path(sys.argv[1]) log = json.loads((d / "change_log.json").read_text()) ver = max(e["date"] for e in log if e.get("date")) files = {p.name: hashlib.sha256(p.read_bytes()).hexdigest() for p in sorted(d.glob("*.json")) if p.name != "source.json"} (d / "source.json").write_text(json.dumps({"name": "CPIC", "version": ver, "retrieved": d.name.split("-")[1], "url": "https://api.cpicpgx.org/v1", "license": "CC0-1.0", "files": files}, indent=1)) print("CPIC data version", ver) PY