Skip to content

Commit d46c07a

Browse files
author
Dan-RAI
committed
Cauchy scorer
1 parent 1e1791c commit d46c07a

4 files changed

Lines changed: 77 additions & 13 deletions

File tree

python/PascalX/genescorer.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1810,7 +1810,6 @@ def __init__(self,window=50000,varcutoff=0.99,MAF=0.05,genome=None,gpu=False):
18101810
self._GENESYMB = genome._GENESYMB
18111811
self._GENEIDtoSYMB = genome._GENEIDtoSYMB
18121812
self._CHR = genome._CHR
1813-
18141813
self._SKIPPED = genome._SKIPPED
18151814

18161815

@@ -1832,7 +1831,6 @@ def _getSNPs(self,cr,gene,REF,useAll=False):
18321831
else:
18331832
if gene in self._MAP:
18341833
P = set(REF[str(cr)][0].getSNPsPos(list(self._MAP[gene].keys())))
1835-
useAll = True
18361834
else:
18371835
P = []
18381836

@@ -1872,7 +1870,6 @@ def _getSNPs_wAlleles(self,cr,gene,REF,useAll=False):
18721870
else:
18731871
if gene in self._MAP:
18741872
P = set(REF[str(cr)][0].getSNPsPos( list(self._MAP[gene].keys()) ))
1875-
useAll = True
18761873
else:
18771874
P = []
18781875

@@ -1893,9 +1890,29 @@ def _getSNPs_wAlleles(self,cr,gene,REF,useAll=False):
18931890
# Calc corr
18941891
RID = list(filtered.keys())
18951892

1896-
return C,np.array(RID)
1893+
return np.array(RID)
18971894

18981895

1896+
1897+
def _getChi2Sum_mapper(self,RIDs,gene):
1898+
#print([GWAS[x] for x in RIDs])
1899+
ps = np.zeros(len(RIDs))
1900+
for i in range(0,len(ps)):
1901+
#ps = chi2.ppf(1- np.array([GWAS[x] for x in RIDs]),1)
1902+
if RIDs[i] in self._MAP[gene] and self._MAP[gene][RIDs[i]][4] is not None:
1903+
ps[i] = self._MAP[gene][RIDs[i]][4]
1904+
else:
1905+
ps[i] = self._GWAS[RIDs[i]]
1906+
1907+
return ps
1908+
1909+
def _getChi2Sum(self,RIDs):
1910+
#print([GWAS[x] for x in RIDs])
1911+
ps = np.zeros(len(RIDs))
1912+
for i in range(0,len(ps)):
1913+
#ps = chi2.ppf(1- np.array([GWAS[x] for x in RIDs]),1)
1914+
ps[i] = self._GWAS[RIDs[i]]
1915+
return ps
18991916

19001917
def _scoremain(self,gene,unloadRef,label='',baroffset=0,nobar=False,lock=None):
19011918

@@ -1938,19 +1955,15 @@ def _scoremain(self,gene,unloadRef,label='',baroffset=0,nobar=False,lock=None):
19381955
R = self._getSNPs_wAlleles(cr,G[i],REF)
19391956

19401957
if len(R) > 0:
1941-
1942-
#hpstats.cauchytest_100d()
1943-
1944-
return
1945-
1958+
19461959
# Score
19471960
if self._MAP is not None and self._joint == False:
19481961

19491962
S = self._getChi2Sum_mapper(R,G[i])
19501963
else:
19511964
S = self._getChi2Sum(R)
19521965

1953-
#RES = self._scoreThread(self._calcAndFilterEV(C),S,G[i],method,mode,reqacc,intlimit)
1966+
RES = [G[i],[hpstats.cauchytest_300d(S)]]
19541967

19551968
RESULT.append( [self._GENEIDtoSYMB[RES[0]],float(RES[1][0]),len(R)])
19561969

python/PascalX/hpstats.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,38 @@ def onemin_norm_cdf_100d(x, m, s):
9696

9797
return lib.onemin_normcdf_100d(x,m,s)
9898

99-
99+
100+
def cauchytest_100d(x):
101+
"""
102+
cauchy test statistics
103+
104+
x : p-value input array
105+
106+
"""
107+
108+
_L = np.ascontiguousarray(x, dtype='float64')
109+
110+
res = lib.cauchytest_100d(
111+
ffi.cast("double *",_L.ctypes.data),
112+
len(_L))
113+
114+
115+
return max(res,1e-100)
116+
117+
118+
119+
def cauchytest_300d(x):
120+
"""
121+
cauchy test statistics
122+
123+
x : p-value input array
124+
125+
"""
126+
127+
_L = np.ascontiguousarray(x, dtype='float64')
128+
129+
res = lib.cauchytest_300d(
130+
ffi.cast("double *",_L.ctypes.data),
131+
len(_L))
132+
133+
return max(res,1e-300)

python/hpstats.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#include <boost/math/distributions/normal.hpp>
2727
using namespace boost::multiprecision;
2828
using namespace boost::math;
29-
using namespace boost::constants;
29+
using namespace boost::math::constants;
3030

3131
extern "C"
3232
double invchi2cdf_1mx(double x, int dof) {
@@ -118,5 +118,21 @@ double cauchytest_100d(double* x, int N) {
118118

119119
cpp_bin_float_100 t = 0.5 - atan(sum)/MP;
120120

121+
return t.convert_to<double>();
122+
}
123+
124+
extern "C"
125+
double cauchytest_300d(double* x, int N) {
126+
127+
number<cpp_bin_float<300>> MP = pi<number<cpp_bin_float<300>>>();
128+
129+
number<cpp_bin_float<300>> sum = 0;
130+
for(int i = 0; i < N; i++) {
131+
number<cpp_bin_float<300>> X = number<cpp_bin_float<300>> (x[i]);
132+
sum += tan((0.5-X)*MP);
133+
}
134+
135+
number<cpp_bin_float<300>> t = 0.5 - atan(sum)/MP;
136+
121137
return t.convert_to<double>();
122138
}

python/hpstats.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,5 @@ extern double onemin_chi2cdf_100d(double x, int dof);
3030
extern double normcdf_100d(double x, double m, double s);
3131
extern double onemin_normcdf_100d(double x, double m, double s);
3232

33-
extern double cauchytest_100d(double* x, int N);
33+
extern double cauchytest_100d(double* x, int N);
34+
extern double cauchytest_300d(double* x, int N);

0 commit comments

Comments
 (0)