-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
79 lines (64 loc) · 2.78 KB
/
main.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
import reader,analyzer,config
import matplotlib as mpl
mpl.use('Agg') #helps with the X server not connected issue.
import matplotlib.pyplot as plt
import numpy as np
import gc
import sys,os
'''def get_jaccard(cNum):
meta_data,pos_dic = reader.load_map_data(config.get_map_address(cNum))
print "map file loaded."
haps,meta = reader.load_hap_data(config.get_hap_address(cNum))
print "haps loaded"
match_dic,count = reader.load_ilash(config.get_iLash_address(cNum),pos_dic)
print "ilash results loaded"
analyzer.add_jaccard_to_dic(match_dic,haps,config.shingler,20,0)
print "jaccard results added"
return match_dic,count
def rewrite(cNum):
get_jaccard(cNum)
reader.write_to_csv()
def ibd_distro(match_list):
dic = []
for ind1, key1 in enumerate(match_list):
for ind2, key2 in enumerate(match_list[key1]):
total = 0
for i in range(len(match_list[key1][key2])):
total += (match_list[key1][key2][i][1] - match_list[key1][key2][i][0])/350
dic.append(total)
return dic
def print_jaccards(addr):
for i in range(1,23):
print "Chr #"+str(i)
match_dic,count = get_jaccard(i)
temp_array = np.zeros((count),dtype="float")
counter = 0
for ind1,key1 in enumerate(match_dic):
for ind2,key2 in enumerate(match_dic[key1]):
for item in match_dic[key1][key2]:
temp_array[counter] = item[3]
counter += 1
print "starting to draw the histogram!"
plt.hist(temp_array, normed=True, bins=12)
plt.ylabel("probability on Chr"+str(i))
plt.savefig("fig"+str(i)+".png")
reader.write_to_csv(match_dic,config.get_jacc_address(i))
gc.collect()
def print_length()'''
if __name__ == "__main__":
output = open("concord_res",'w')
for i in range(1, 23):
print("chrom: "+str(i))
map_data, pos_dic = reader.load_map_data(config.get_map_address(i))
match_dic,count = reader.load_ilash(config.get_iLash_address(i),pos_dic,5,0.2)
germ_dic,germ_count = reader.load_germline(config.get_germline_address(i),pos_dic,5)
overlap_count7 = analyzer.simple_concordance(germ_dic,match_dic,map_data,0.7)
overlap_count1 =analyzer.simple_concordance(germ_dic,match_dic,map_data,1.0)
output.write(str(i)+'\t'+str(germ_count)+'\t'+str(count)+'\t'+str(overlap_count1)+'\t'+str(overlap_count7)+'\n')
'''print "Analyzer starting"
prob_res = []
for i in range(1, 23):
map_data, pos_dic = reader.load_map_data(config.get_map_address(i))
match_dic,count = reader.load_ilash(config.get_iLash_address(cNum),pos_dic)
prob_res.append(ibd_distro(match_dic))
cPickle.dump(prob_res,"wow")'''