new file: pixi.toml
[GalaxyCodeBases.git] / projects / recombineMap / sperm_by_fw / crossover_prediction / HMM_method / compareData.py
blobe3227e963a6a98982efd6495d9ed6695a3a853ca
1 '''
2 Created on 2012-7-12
4 @author: LiJinsen
5 '''
6 import sys, os
8 filename = sys.argv[1]
9 filename2 = sys.argv[2]
11 #raw data
12 file = open(filename,'r')
13 content1 = file.read()
14 result1 = {}
15 for line in content1.split('\n'):
16 if len(line)<1:
17 continue
18 item = line.split('\t')
19 if not result1.has_key(item[0]):
20 result1.update({item[0]:{}})
21 if not result1[item[0]].has_key(item[1]):
22 result1[item[0]].update({item[1]:[0]})
23 result1[item[0]][item[1]][0]+=1
24 result1[item[0]][item[1]].append(item)
26 #HMM data
27 file = open(filename2,'r')
28 content2 = file.read()
29 result2 = {}
30 for line in content2.split('\n'):
31 if len(line)<1:
32 continue
33 item = line.split('\t')
34 if not result2.has_key(item[0]):
35 result2.update({item[0]:{}})
36 if not result2[item[0]].has_key(item[1]):
37 result2[item[0]].update({item[1]:[0]})
38 result2[item[0]][item[1]][0]+=1
39 result2[item[0]][item[1]].append(item)
41 #print result1
43 w = open('difference.txt','w')
44 w1 = open('differenceDetail.raw.txt','w')
45 w2 = open('differenceDetail.new.txt','w')
46 def writeData(item1, item2):
47 for obj in item1:
48 flag = False
49 for tmpobj in item2:
50 if obj[2]==tmpobj[2]:
51 flag = True
52 break
53 if flag==True:
54 continue
55 for c in obj:
56 w2.write(c)
57 w2.write('\t')
58 w2.write('\n')
60 for itemkey1 in result1.keys():
61 for itemkey2 in result1[itemkey1].keys():
62 if not result2[itemkey1].has_key(itemkey2):
63 w.write(itemkey1)
64 w.write('\t')
65 w.write(itemkey2)
66 w.write('\tNot In\n')
67 continue
68 if result1[itemkey1][itemkey2][0] != result2[itemkey1][itemkey2][0]:
69 w.write(itemkey1)
70 w.write('\t')
71 w.write(itemkey2)
72 w.write('\t')
73 if result1[itemkey1][itemkey2] < result2[itemkey1][itemkey2]:
74 w.write('More')
75 else:
76 w.write('Less')
77 w.write('\n')
78 writeData(result2[itemkey1][itemkey2][1:], result1[itemkey1][itemkey2][1:])