Skip to content

Commit

Permalink
Mapper improved; version tag added
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan-RAI committed Jan 14, 2023
1 parent 414a366 commit 2e7ab3e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion python/PascalX/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = "0.0.3"
__version__ = "0.0.4"

16 changes: 10 additions & 6 deletions 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:
if p > 0 and p < 1 and L[rscol][:2]=='rs':
self._GWAS[L[rscol]] = p
else:
continue
Expand Down Expand Up @@ -706,12 +706,11 @@ def _calcGeneSNPcorr(self,cr,gene,REF,useAll=False):
else:
if gene in self._MAP:
P = set(REF[str(cr)][0].getSNPsPos(list(self._MAP[gene].keys())))
useAll = True
else:
P = []

DATA = REF[str(cr)][0].get(list(P))

filtered = {}

#use = []
Expand Down Expand Up @@ -763,7 +762,6 @@ def _calcGeneSNPcorr_wAlleles(self,cr,gene,REF,useAll=False):
else:
if gene in self._MAP:
P = set(REF[str(cr)][0].getSNPsPos( list(self._MAP[gene].keys()) ))
useAll = True
else:
P = []

Expand Down Expand Up @@ -809,8 +807,11 @@ def _getChi2Sum_mapper(self,RIDs,gene):
ps = np.zeros(len(RIDs))
for i in range(0,len(ps)):
#ps = chi2.ppf(1- np.array([GWAS[x] for x in RIDs]),1)
if RIDs[i] in self._MAP[gene]:
if RIDs[i] in self._MAP[gene] and self._MAP[gene][RIDs[i]][0] is not None:
ps[i] = tools.chiSquared1dfInverseCumulativeProbabilityUpperTail(self._MAP[gene][RIDs[i]][0])
else:
ps[i] = tools.chiSquared1dfInverseCumulativeProbabilityUpperTail(self._GWAS[RIDs[i]])

return np.sum(ps)

def _getChi2Sum(self,RIDs):
Expand Down Expand Up @@ -942,8 +943,11 @@ def _scoremain(self,gene,unloadRef=False,method='saddle',mode='auto',reqacc=1e-1

if len(R) == 1:
if self._MAP is not None and self._joint == False:
if R[0] in self._MAP[G[i]]:
if R[0] in self._MAP[G[i]] and self._MAP[G[i]][R[0]][0] is not None:
RESULT.append( [self._GENEIDtoSYMB[G[i]],float(self._MAP[G[i]][R[0]][0]),1] )
else:
RESULT.append( [self._GENEIDtoSYMB[G[i]],float(self._GWAS[R[0]]),1] )

else:
RESULT.append( [self._GENEIDtoSYMB[G[i]],float(self._GWAS[R[0]]),1] )
else:
Expand Down
5 changes: 4 additions & 1 deletion python/PascalX/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def load_mapping(self,file,gcol=0,rcol=1,wcol=None,a1col=None,a2col=None,bcol=No
f.readline()

c = 0
s = 0
for line in f:
line = line.rstrip().split(delimiter)

Expand Down Expand Up @@ -99,5 +100,7 @@ def load_mapping(self,file,gcol=0,rcol=1,wcol=None,a1col=None,a2col=None,bcol=No
self._SNPtoGENEID[line[rcol]] = [gid]
else:
self._SNPtoGENEID[line[rcol]].append(gid)

s += 1

print(c,"gene to SNP mappings loaded")
print(c,"gene to SNP mappings loaded (# SNPs: "+str(s)+")")

0 comments on commit 2e7ab3e

Please sign in to comment.