-
Notifications
You must be signed in to change notification settings - Fork 2
/
CCC_simulMap.py
103 lines (85 loc) · 3.59 KB
/
CCC_simulMap.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# -*- coding: utf-8 -*-
import numpy as np
import copy
import scipy.integrate
from scipy import ndimage
import scipy.ndimage.filters
import subprocess
def make_simulated_map (pdb_file, rank, voxel_space, resolution ):
# subprocess.call("./kercon "+str(pdb_file)+" simulated_map.sit "+str(voxel_space)+" "+str(resolution))
subprocess.call("FilaSitus/bin/kercon "+str(pdb_file)+" simulated_map"+str(rank)+".sit "+str(voxel_space)+" "+str(resolution)+" > out", shell=True)
def compute_corr(exp_map, simul_map, resolution):
matrix1file = open(exp_map)
matrix2file = open(simul_map)
matrix1 = []
matrix2 = []
tempomatrix1 = []
tempomatrix2 = []
header1 = []
header2 = []
header_flag1 = 1
header_flag2 = 1
# reading the .srt file
while (1):
line = matrix1file.readline()
if (line and header_flag1):
noNewLine = line.replace('\n','')
header1.append(noNewLine.split(" "))
header_flag1 = 0
# sequence += [space.split(" ")]
#sequence[-1].remove('\n')
elif (line and header_flag1 == 0 ):
noNewLine = line.replace('\n','')
tempomatrix1.append(noNewLine.split(' '))
# extracting everything elements of the temporary matrix and cleaning:
for strings in tempomatrix1:
for element in strings:
if len(element) != 0:
matrix1.append(element)
tempomatrix1 = []
else:
break
tempoMat1 = np.float32(matrix1)
while (1):
line = matrix2file.readline()
if (line and header_flag2):
noNewLine = line.replace('\n','')
header2.append(noNewLine.split(" "))
header_flag2 = 0
# sequence += [space.split(" ")]
#sequence[-1].remove('\n')
elif (line and header_flag2 == 0 ):
noNewLine = line.replace('\n','')
tempomatrix2.append(noNewLine.split(' '))
# extracting everything elements of the temporary matrix and cleaning:
for string in tempomatrix2:
for element in string:
if len(element) != 0:
matrix2.append(element)
tempomatrix2 = []
else:
break
tempoMat2 = np.float32(matrix2)
if resolution < 10:
# leave the maps unchanged
numpyMat = copy.deepcopy(tempoMat1)
numpyMat2 = copy.deepcopy(tempoMat2)
elif resolution >= 10:
# apply laplacian filter on both density maps:
numpyMat = scipy.ndimage.filters.laplace(tempoMat1)
numpyMat2 = scipy.ndimage.filters.laplace(tempoMat2)
# Situs based cross correlation coefficient:
if len(numpyMat) <= len(numpyMat2):
numerator = scipy.integrate.quad(lambda r: (numpyMat[r] * numpyMat2[r]), 0, len(numpyMat))
Deno1 = scipy.integrate.quad(lambda r: (numpyMat[r] * numpyMat[r]), 0, len(numpyMat))
Deno2 = scipy.integrate.quad(lambda r: (numpyMat2[r] * numpyMat2[r]), 0, len(numpyMat))
else:
numerator = scipy.integrate.quad(lambda r: (numpyMat[r] * numpyMat2[r]), 0, len(numpyMat2))
Deno1 = scipy.integrate.quad(lambda r: (numpyMat[r] * numpyMat[r]), 0, len(numpyMat2))
Deno2 = scipy.integrate.quad(lambda r: (numpyMat2[r] * numpyMat2[r]), 0, len(numpyMat2))
if Deno2[0] != 0 and Deno1[0] != 0: # because denominator cannot be equal to 0
corr = numerator[0] / ( (Deno1[0] ** (0.5)) * (Deno2[0] ** (0.5)) )
else:
corr = 0.0
print ">>> CCC = "+str(corr)
return corr