|
| 1 | +import numpy as np |
| 2 | +from scipy.stats.stats import pearsonr |
| 3 | +import sys |
| 4 | + |
| 5 | +print("Difference Parameters") |
| 6 | +mzdiff=0 |
| 7 | +rtdiff=0 |
| 8 | +corrthresh=0.99 |
| 9 | +print("Median MZ Diff: "+ str(mzdiff)) |
| 10 | +print("Median RT Diff: "+ str(rtdiff)) |
| 11 | +print("Correlation Threshold: "+ str(corrthresh)) |
| 12 | +if(len(sys.argv)<3): |
| 13 | + print("python csv_diff.csv file1.csv file2.csv") |
| 14 | + sys.exit(0) |
| 15 | + |
| 16 | +print("Programs gives the differences in file 2 with respect to file 1") |
| 17 | +file1=sys.argv[1] |
| 18 | +file2=sys.argv[2] |
| 19 | + |
| 20 | + |
| 21 | +line_array1=[] |
| 22 | +vec_array1=[] |
| 23 | +with open(file1) as f: |
| 24 | + first=0 |
| 25 | + for line in f: |
| 26 | + line=line.rstrip('\n') |
| 27 | + if(first==0): |
| 28 | + first=1 |
| 29 | + table_labels=line.split(',') |
| 30 | + print("Removing Blanks") |
| 31 | + continue |
| 32 | + temp_array=line.split(',') |
| 33 | + t=5 |
| 34 | + while(t!=0): |
| 35 | + temp_array.remove('') |
| 36 | + t-=1 |
| 37 | + line_array1.append(map(float,temp_array)) |
| 38 | + temp_array=temp_array[9:] |
| 39 | + vec_array1.append(map(float,temp_array)) |
| 40 | + |
| 41 | +line_array2=[] |
| 42 | +vec_array2=[] |
| 43 | +with open(file2) as f: |
| 44 | + first=0 |
| 45 | + for line in f: |
| 46 | + line=line.rstrip('\n') |
| 47 | + if(first==0): |
| 48 | + first=1 |
| 49 | + table_labels=line.split(',') |
| 50 | + print("Removing Blanks") |
| 51 | + continue |
| 52 | + temp_array=line.split(',') |
| 53 | + t=5 |
| 54 | + while(t!=0): |
| 55 | + temp_array.remove('') |
| 56 | + t-=1 |
| 57 | + line_array2.append(map(float,temp_array)) |
| 58 | + temp_array=temp_array[9:] |
| 59 | + vec_array2.append(map(float,temp_array)) |
| 60 | + |
| 61 | +line_array1=np.array(line_array1) |
| 62 | +line_array2=np.array(line_array2) |
| 63 | +vec_array1=np.array(vec_array1) |
| 64 | +vec_array2=np.array(vec_array2) |
| 65 | +print(vec_array1.shape) |
| 66 | +print(vec_array2.shape) |
| 67 | +reported_difference=[] |
| 68 | +for i in range(len(line_array2)): |
| 69 | + flag=0 |
| 70 | + for j in range(len(line_array1)): |
| 71 | + if(abs(line_array1[j][3]-line_array2[i][3])<=mzdiff and abs(line_array1[j][4]-line_array2[i][4])<=rtdiff): |
| 72 | + first_corr=pearsonr(vec_array2[i],vec_array1[j])[0] |
| 73 | + if(first_corr==1): |
| 74 | + flag=1 |
| 75 | + if(flag==0): |
| 76 | + reported_difference.append(line_array2[i]) |
| 77 | + |
| 78 | +print(len(reported_difference)) |
| 79 | +# for diff in reported_difference: |
| 80 | +# print(diff) |
| 81 | + |
| 82 | + |
| 83 | + |
| 84 | + |
0 commit comments