From 42a987cf09aeb7184822480dc0474cdea70a547c Mon Sep 17 00:00:00 2001 From: leoxnard Date: Tue, 24 Nov 2026 17:31:54 +0100 Subject: [PATCH] Accept different SNP ids apart from rsIds --- python/PascalX/genescorer.py | 6 +++++- python/PascalX/refpanel.py | 14 ++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/python/PascalX/genescorer.py b/python/PascalX/genescorer.py index 0fb692b..25c4dc1 100755 --- a/python/PascalX/genescorer.py +++ b/python/PascalX/genescorer.py @@ -225,7 +225,7 @@ def load_GWAS(self,file,rscol=0,pcol=1,bcol=None,a1col=None,a2col=None,delimiter if log10p: p = 10**(-p) - if p > 0 and p < 1 and L[rscol][:2]=='rs': + if p > 0 and p < 1 and refpanel.valid_snp_id(L[rscol]): self._GWAS[L[rscol]] = p else: continue @@ -1106,6 +1106,8 @@ def score(self,gene,parallel=1,unloadRef=False,method='saddle',mode='auto',reqac print(len(R[1]),"genes failed (try to .rescore with other settings)") if len(R[2])>0: print(len(R[2]),"genes can not be scored (check annotation)") + if len(R[0]) == 0 and len(R[2]) > 0 and all(X[1] == "No SNPs" for X in R[2]): + print("[WARNING]: No GWAS SNP ids found in reference panel. Check that both use the same id format (e.g. rsid or chr:pos:ref:alt)") # Store in _SCORES: for X in R[0]: @@ -2051,6 +2053,8 @@ def score(self,gene,parallel=1,unloadRef=False,method='saddle',mode='auto',reqac print(len(R[1]),"genes failed (try to .rescore with other settings)") if len(R[2])>0: print(len(R[2]),"genes can not be scored (check annotation)") + if len(R[0]) == 0 and len(R[2]) > 0 and all(X[1] == "No SNPs" for X in R[2]): + print("[WARNING]: No GWAS SNP ids found in reference panel. Check that both use the same id format (e.g. rsid or chr:pos:ref:alt)") # Store in _SCORES: for X in R[0]: diff --git a/python/PascalX/refpanel.py b/python/PascalX/refpanel.py index 11ea506..4e0dbfe 100755 --- a/python/PascalX/refpanel.py +++ b/python/PascalX/refpanel.py @@ -33,6 +33,16 @@ import re +def valid_snp_id(rid): + """ + Checks if a variant id is usable (non-empty and not the VCF missing value '.') + + Args: + rid(string): Variant id (e.g. rsid or chr:pos:ref:alt) + """ + return len(rid) > 0 and rid != '.' + + class refpanel: def __init__(self): @@ -137,7 +147,7 @@ def _import_reference_thread_tped(self,i): L = line.split() # [chr,rid,irrelevant,pos,genotype] # Get genotype and dephase - if L[1][0:2] == 'rs': + if valid_snp_id(L[1]): dephased = (np.array(L[4:],dtype='b') - 1) genotype = np.sum(dephased.reshape((int(len(dephased)/2),2)),axis=1) @@ -243,7 +253,7 @@ def _import_reference_thread_vcf(self,i,keepfile,qualityT,SNPonly,regEx=None): break # Checks - if (GT == -1) or (data[2][:2] != 'rs') or (data[6] != 'PASS' and qualityT is not None and (int(data[5]) < qualityT)): + if (GT == -1) or (not valid_snp_id(data[2])) or (data[6] != 'PASS' and qualityT is not None and (int(data[5]) < qualityT)): continue # Read genotype