fetch_sources.sh downloads PharmVar per-gene zips; pgx db build adds core alleles for genes CPIC does not define (normalised against the FASTA, *1 = reference). Masks re-derived with the new variants. GeT-RM: CYP3A4 15/15, CYP2A6 7/9; all comparable genes 154/168 (CYP1A2/CYP2C8 definitions differ from GeT-RM's).
59 lines
3.0 KiB
Bash
59 lines
3.0 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. PharmVar (https://www.pharmvar.org; cite Gaedigk et al. 2018 CPT 103:399): per-gene
|
|
# zips (haplotype VCFs, GRCh37/GRCh38) for the star-allele genes CPIC does not define. Never committed (data/ is
|
|
# ignored); the DB records each source's version and file hashes.
|
|
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
|
|
|
|
# ---- PharmVar: star-allele genes without CPIC definitions
|
|
PV="$OUT/pharmvar-$DATE"
|
|
mkdir -p "$PV"
|
|
PV_GENES=${PV_GENES:-"CYP1A2 CYP2A6 CYP2A13 CYP2C8 CYP3A4"} # the PharmVar genes CPIC does not define (2026-09)
|
|
for g in $PV_GENES; do
|
|
if curl -sSf --retry 3 -o "$PV/$g.zip" \
|
|
"https://www.pharmvar.org/get-download-file?name=$g&refSeq=ALL&fileType=zip&version=current"; then
|
|
echo "PharmVar $g $(unzip -l "$PV/$g.zip" | awk 'NR==4{print $4}' | cut -d/ -f1)"
|
|
else
|
|
echo "PharmVar $g: not available"; rm -f "$PV/$g.zip"
|
|
fi
|
|
done
|
|
python3 - "$PV" <<'PY'
|
|
import hashlib, json, pathlib, re, sys, zipfile
|
|
d = pathlib.Path(sys.argv[1])
|
|
vers = set()
|
|
for z in sorted(d.glob("*.zip")):
|
|
top = zipfile.ZipFile(z).namelist()[0].split("/")[0]
|
|
m = re.search(r"-(\d+\.\d+\.\d+)$", top)
|
|
if m:
|
|
vers.add(m.group(1))
|
|
files = {p.name: hashlib.sha256(p.read_bytes()).hexdigest() for p in sorted(d.glob("*.zip"))}
|
|
(d / "source.json").write_text(json.dumps({"name": "PharmVar", "version": ",".join(sorted(vers)),
|
|
"retrieved": d.name.split("-")[1], "url": "https://www.pharmvar.org",
|
|
"license": "PharmVar terms of use (cite Gaedigk et al. 2018)",
|
|
"files": files}, indent=1))
|
|
print("PharmVar version", ",".join(sorted(vers)))
|
|
PY
|