Files
SimurgArray/scripts/pgx/fetch_sources.sh
T
kemal 7e9ff28501 PGx DB: pgx db build from CPIC (PGX-001..005, IN-053, CLI-035)
- scripts/pgx/fetch_sources.sh: CPIC API tables (CC0) into a dated folder with version and hashes.
- simurg/pgx/db.py: CPIC HGVS locations and values -> left-normalised VCF variants (SNV, del, ins, dup,
  repeats, delins, chrM); IUPAC values are core-allele wildcards; alleles without definitions are flagged.
- pipeline/pgx_db.py: deterministic SQLite (content-hash name), probe_map via the SNV VCF site mapper;
  GSA v4 PGx: 22 genes, 1354 alleles, 5002 probe links; two builds byte-identical.
2026-09-29 13:24:54 +01:00

28 lines
1.5 KiB
Bash

#!/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