fix ClinVar header #AlleleID + GRCh38 filter (was UnboundLocalError)
- header lstrip # for #AlleleID, init ci_*=None, filter Assembly!=GRCh38 - loaded 3960956 GRCh38 variants (was 0) - offline now correctly maps P/LP vs VUS
This commit is contained in:
+8
-7
@@ -389,27 +389,32 @@ def _load_clinvar(clinvar_path):
|
||||
opener = gzip.open if str(clinvar_path).endswith(".gz") else open
|
||||
with opener(clinvar_path, "rt") as fh:
|
||||
header = None
|
||||
ci_chr = ci_start = ci_ref = ci_alt = ci_sig = ci_asm = None
|
||||
for line in fh:
|
||||
if line.startswith("#"):
|
||||
if header is None and line.lstrip("#").startswith("AlleleID"):
|
||||
line = line.lstrip("#")
|
||||
else:
|
||||
continue
|
||||
if header is None:
|
||||
header = line.rstrip("\n").split("\t")
|
||||
# Find column indices
|
||||
try:
|
||||
ci_chr = header.index("Chromosome")
|
||||
ci_start = header.index("Start")
|
||||
ci_ref = header.index("ReferenceAllele")
|
||||
ci_alt = header.index("AlternateAllele")
|
||||
ci_sig = header.index("ClinicalSignificance")
|
||||
ci_asm = header.index("Assembly") if "Assembly" in header else None
|
||||
except ValueError:
|
||||
# Fallback for older format: try different names
|
||||
header = None
|
||||
continue
|
||||
continue
|
||||
parts = line.rstrip("\n").split("\t")
|
||||
if len(parts) <= max(ci_chr, ci_start, ci_ref, ci_alt, ci_sig):
|
||||
continue
|
||||
if ci_asm is not None and parts[ci_asm] != "GRCh38":
|
||||
continue
|
||||
chrom = parts[ci_chr]
|
||||
# ClinVar Chromosome is 1,2.. not chr1
|
||||
chrom_norm = f"chr{chrom}" if not chrom.startswith("chr") else chrom
|
||||
try:
|
||||
pos = int(parts[ci_start])
|
||||
@@ -417,9 +422,6 @@ def _load_clinvar(clinvar_path):
|
||||
continue
|
||||
ref = parts[ci_ref]; alt = parts[ci_alt]
|
||||
sig = parts[ci_sig]
|
||||
# Normalize significance to ACMG
|
||||
# ClinVar: Pathogenic, Likely pathogenic, Uncertain significance, Likely benign, Benign, etc.
|
||||
# Map to our 5-tier
|
||||
sig_lower = sig.lower()
|
||||
if "pathogenic" in sig_lower and "likely" not in sig_lower:
|
||||
acmg = "Pathogenic"
|
||||
@@ -432,7 +434,6 @@ def _load_clinvar(clinvar_path):
|
||||
else:
|
||||
acmg = "Uncertain significance"
|
||||
key = (chrom_norm, pos, ref, alt)
|
||||
# Also add without chr prefix for matching
|
||||
key2 = (chrom, pos, ref, alt)
|
||||
m[key] = acmg
|
||||
m[key2] = acmg
|
||||
|
||||
Reference in New Issue
Block a user