-
Notifications
You must be signed in to change notification settings - Fork 1
/
pearson.py
58 lines (32 loc) · 817 Bytes
/
pearson.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
#!/usr/bin/python
import sys
import scipy.stats as sp
f=open(sys.argv[1],'r')
g=open(sys.argv[2],'w')
thresh = float(sys.argv[3])
x=f.readline() #ignore first row
names=[]
for i in f:
names.append(i.split("\t")[0]) #NB first row of names has no tab at start
f.seek(0)
x=f.readline() #ignore first row
len1=len(names)
data={}
for i in f:
k=i.rstrip("\n").split("\t")
data[k[0]]=[]
for p in k[1:]:
data[k[0]].append(float(p))
g.write('gene1\tgene2\tR\tp\n')
c=0
t=0
for i in names:
c=c+1
for j in range(c,len1):
r=sp.pearsonr(data[i],data[names[j]])
#print i+"\t"+names[j]+"\t"+str(r[0])+"\t"+str(r[1])+"\n"
#raw_input()
if r[0] < -thresh or r[0] > thresh:
t=t+1
g.write(i+"\t"+names[j]+"\t"+str(r[0])+"\t"+str(r[1])+"\n")
print 'done',t,'interactions'