- fetch_sources.sh downloads ClinPGx clinicalVariants (CC BY-SA 4.0); pgx db build adds genotype-only variant-based genes (levels 1A-2B, level 3 for the parity list), rsIDs resolved from the manifest's probes: 70 genes in the DB. - pgx phenotype --guideline dpwg: CPIC mappings for CPIC genes (as ClinPGx curates DPWG), no phenotype for DPWG-only genes (flags dpwg_via_cpic_mapping / dpwg_mapping_not_available). K-029 updated.
76 lines
4.1 KiB
Bash
76 lines
4.1 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
|
|
|
|
# ---- ClinPGx (formerly PharmGKB; CC BY-SA 4.0): clinical-annotation variants (variant-based genes, genotype only)
|
|
CP="$OUT/clinpgx-$DATE"
|
|
mkdir -p "$CP"
|
|
curl -sSfL --retry 3 -o "$CP/clinicalVariants.zip" "https://api.clinpgx.org/v1/download/file/data/clinicalVariants.zip"
|
|
python3 - "$CP" <<'PY'
|
|
import hashlib, json, pathlib, sys, zipfile
|
|
d = pathlib.Path(sys.argv[1])
|
|
z = zipfile.ZipFile(d / "clinicalVariants.zip")
|
|
created = next((n.split("_", 1)[1].rsplit(".", 1)[0] for n in z.namelist() if n.startswith("CREATED_")), "")
|
|
(d / "source.json").write_text(json.dumps({"name": "ClinPGx clinical variants", "version": created,
|
|
"retrieved": d.name.split("-")[1], "url": "https://www.clinpgx.org",
|
|
"license": "CC BY-SA 4.0",
|
|
"files": {"clinicalVariants.zip": hashlib.sha256(
|
|
(d / "clinicalVariants.zip").read_bytes()).hexdigest()}}, indent=1))
|
|
print("ClinPGx clinical variants", created)
|
|
PY
|