-
Notifications
You must be signed in to change notification settings - Fork 0
/
csv_diff.py
84 lines (73 loc) · 1.84 KB
/
csv_diff.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
import numpy as np
from scipy.stats.stats import pearsonr
import sys
print("Difference Parameters")
mzdiff=0
rtdiff=0
corrthresh=0.99
print("Median MZ Diff: "+ str(mzdiff))
print("Median RT Diff: "+ str(rtdiff))
print("Correlation Threshold: "+ str(corrthresh))
if(len(sys.argv)<3):
print("python csv_diff.csv file1.csv file2.csv")
sys.exit(0)
print("Programs gives the differences in file 2 with respect to file 1")
file1=sys.argv[1]
file2=sys.argv[2]
line_array1=[]
vec_array1=[]
with open(file1) as f:
first=0
for line in f:
line=line.rstrip('\n')
if(first==0):
first=1
table_labels=line.split(',')
print("Removing Blanks")
continue
temp_array=line.split(',')
t=5
while(t!=0):
temp_array.remove('')
t-=1
line_array1.append(map(float,temp_array))
temp_array=temp_array[9:]
vec_array1.append(map(float,temp_array))
line_array2=[]
vec_array2=[]
with open(file2) as f:
first=0
for line in f:
line=line.rstrip('\n')
if(first==0):
first=1
table_labels=line.split(',')
print("Removing Blanks")
continue
temp_array=line.split(',')
t=5
while(t!=0):
temp_array.remove('')
t-=1
line_array2.append(map(float,temp_array))
temp_array=temp_array[9:]
vec_array2.append(map(float,temp_array))
line_array1=np.array(line_array1)
line_array2=np.array(line_array2)
vec_array1=np.array(vec_array1)
vec_array2=np.array(vec_array2)
print(vec_array1.shape)
print(vec_array2.shape)
reported_difference=[]
for i in range(len(line_array2)):
flag=0
for j in range(len(line_array1)):
if(abs(line_array1[j][3]-line_array2[i][3])<=mzdiff and abs(line_array1[j][4]-line_array2[i][4])<=rtdiff):
first_corr=pearsonr(vec_array2[i],vec_array1[j])[0]
if(first_corr==1):
flag=1
if(flag==0):
reported_difference.append(line_array2[i])
print(len(reported_difference))
# for diff in reported_difference:
# print(diff)