PGx: ClinPGx variant-based genes (PGX-008) and --guideline dpwg (PGX-025)
- 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.
This commit is contained in:
1 parent
dfba22496a
commit
e1cfb3dfd0
8 files changed
+161
-10
No files matched your search
@@ -254,6 +254,47 @@ def run_db_build(o: PgxDbOptions, rep: Reporter) -> int:
|
||||
hg = full_hgvs(ps.contig, f"g.{ps.pos}{ps.ref}>{alt}")
|
||||
tag_rows[(gene, allele)] = (gene, allele, "GRCh38", ps.contig, ps.pos, ps.ref, alt, hg, rsid, -1, alt)
|
||||
rows["probe_map"].append((name, ps.name, ps.contig, ps.pos, ps.ref, alt))
|
||||
# ClinPGx clinical-annotation variants of genes no definition source covers: genotype-only variant-based genes
|
||||
cp_src = None
|
||||
cdir2 = _latest(o.sources, "clinpgx")
|
||||
if cdir2 is not None:
|
||||
import zipfile
|
||||
|
||||
from simurg.pgx.db import clinpgx_variant_genes
|
||||
|
||||
cp_src = json.loads((cdir2 / "source.json").read_text())
|
||||
with zipfile.ZipFile(cdir2 / "clinicalVariants.zip") as z:
|
||||
tsv = z.read("clinicalVariants.tsv").decode()
|
||||
known = {g for g, *_ in rows["genes"]} | {g for g, *_ in TAGS}
|
||||
cp_genes = clinpgx_variant_genes(tsv, known)
|
||||
resolved: dict[tuple[str, str], tuple[Any, ...]] = {}
|
||||
want = {rs for v in cp_genes.values() for rs in v}
|
||||
for bpm_path in o.manifests:
|
||||
name = read_bpm(bpm_path).manifest_name
|
||||
for ps in _probe_sites(bpm_path, csvs.get(bpm_path), genome, cmap, {}, rep, want):
|
||||
alts = [a for a in ps.alleles if a != ps.ref]
|
||||
if len(alts) != 1 or ps.ref not in ps.alleles:
|
||||
continue
|
||||
for rs in re.findall(r"rs\d+", ps.name):
|
||||
if rs in want:
|
||||
hg = full_hgvs(ps.contig, f"g.{ps.pos}{ps.ref}>{alts[0]}")
|
||||
resolved.setdefault((rs, ps.contig), (ps.contig, ps.pos, ps.ref, alts[0], hg))
|
||||
rows["probe_map"].append((name, ps.name, ps.contig, ps.pos, ps.ref, alts[0]))
|
||||
by_rs = {rs: v for (rs, _), v in resolved.items()}
|
||||
lid2 = 950_000_000
|
||||
for gene in sorted(cp_genes):
|
||||
chrom = None
|
||||
rows["alleles"].append((gene, "Reference", "reference", None, None, 0, 1))
|
||||
for rs in sorted(cp_genes[gene], key=lambda r: int(r[2:])):
|
||||
v = by_rs.get(rs)
|
||||
rows["alleles"].append((gene, rs, "rsid_variant_allele", None, None, 0, int(v is not None)))
|
||||
if v is not None:
|
||||
lid2 += 1
|
||||
chrom = v[0]
|
||||
rows["allele_variants"].append((gene, rs, "GRCh38", v[0], v[1], v[2], v[3], v[4], rs, lid2, v[3]))
|
||||
rows["genes"].append((gene, "variant_based", chrom))
|
||||
rep.info(f"ClinPGx: {len(cp_genes)} variant-based gene(s), {len(by_rs)} of {len(want)} rsID(s) resolved "
|
||||
f"on the manifest(s)") # fmt: skip
|
||||
if tag_rows: # PGX-007: tag alleles become defined single-variant alleles
|
||||
rows["allele_variants"] += list(tag_rows.values())
|
||||
rows["alleles"] = [(g, a, k, f, act, sv, 1 if (g, a) in tag_rows else d) for g, a, k, f, act, sv, d in
|
||||
@@ -270,7 +311,10 @@ def run_db_build(o: PgxDbOptions, rep: Reporter) -> int:
|
||||
"license": csrc.get("license")}]
|
||||
+ ([{"name": "PharmVar", "version": pv_src["version"],
|
||||
"retrieved": pv_src["retrieved"], "license": pv_src.get("license")}]
|
||||
if pv_src else [])),
|
||||
if pv_src else [])
|
||||
+ ([{"name": "ClinPGx clinical variants", "version": cp_src["version"],
|
||||
"retrieved": cp_src["retrieved"], "license": cp_src.get("license")}]
|
||||
if cp_src else [])),
|
||||
"phenotype_sources": json.dumps([{"name": "CPIC", "version": csrc["version"]}]),
|
||||
"cpic_files_sha256": json.dumps(csrc.get("files", {}), sort_keys=True),
|
||||
"manifests": json.dumps(sorted(manifests)), "definition_notes": json.dumps(problems)} # fmt: skip
|
||||
@@ -301,8 +345,9 @@ def run_db_build(o: PgxDbOptions, rep: Reporter) -> int:
|
||||
rep.info(f"identical PGx DB already present: {final}")
|
||||
return ExitCode.OK
|
||||
tmp.replace(final)
|
||||
rep.info(f"PGx DB: {len(defs)} genes, {len(rows['alleles'])} alleles, {len(rows['allele_variants'])} variant "
|
||||
f"rows, {len(rows['probe_map'])} probe links → {final} (content sha256 {sha})") # fmt: skip
|
||||
n_g, n_a, n_v, n_p = (len(rows[k]) for k in ("genes", "alleles", "allele_variants", "probe_map"))
|
||||
rep.info(f"PGx DB: {n_g} genes, {n_a} alleles, {n_v} variant rows, {n_p} probe links → {final} "
|
||||
f"(content sha256 {sha})") # fmt: skip
|
||||
return ExitCode.OK
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user