Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion python/PascalX/genescorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]:
Expand Down Expand Up @@ -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]:
Expand Down
14 changes: 12 additions & 2 deletions python/PascalX/refpanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down