-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathr-wrapper_hd.py
71 lines (39 loc) · 1.02 KB
/
r-wrapper_hd.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# coding: utf-8
# In[1]:
from numpy import *
import scipy as sp
from pandas import *
from rpy2.robjects.packages import importr
import rpy2.robjects as ro
import pandas.rpy.common as com
import sys
import numpy as np
dim = int(sys.argv[2])
fn = sys.argv[1]
data = np.loadtxt(open(fn, "rb"), delimiter=",", skiprows=1)
x = data[:,0:dim]
p = data[:,dim]
h = data[:,dim+1]
n_samples = len(x)
from sklearn.cluster import KMeans
km = KMeans(n_clusters = 20)
group = km.fit_predict(x)
print(group.shape)
with open(fn+'.ihw', 'w') as f:
f.write('group, p_value, h\n')
for i in range(len(x)):
f.write("{}, {}, {}\n".format(group[i],p[i], h[i]))
ro.r('data = read.csv(\'{}\', head=TRUE)'.format(fn + '.ihw'))
# In[3]:
ro.r('source("https://bioconductor.org/biocLite.R")')
# In[4]:
ro.r("biocLite(\"IHW\")")
# In[6]:
ro.r("library(\"IHW\")")
# In[7]:
ro.r("ihwRes <- ihw(p_value ~ group , data = data, alpha = 0.1)")
# In[9]:
res = ro.r("rejections(ihwRes)")
# In[13]:
print(np.array(res))
print(sys.argv[1])