-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathfilter_mapping_file.py
More file actions
82 lines (64 loc) · 1.22 KB
/
filter_mapping_file.py
File metadata and controls
82 lines (64 loc) · 1.22 KB
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
import unittest
import sys
pos_list = []
pos_set = ()
if (len(sys.argv) < 3):
print ("Usage:\npython filter_mapping_file.py <input_map_file> <output_file>")
sys.exit()
input_file = sys.argv[1]
output_file = sys.argv[2]
f = open(input_file)
for line in f:
if ('Position' in line):
continue
vals = line.split()
_pos = int(vals[1])
if (_pos in pos_set):
print ("duplicate positions in the file" + "\t" + str(_pos))
sys.exit(1)
pos_list.append(_pos)
f.close()
f_o = open(output_file,'w+')
def LIS(X):
n = len(X)
X = [None] + X
M = [None] * (n + 1)
P = [None] * (n + 1)
L = 0
for i in range(1, n + 1):
if L == 0 or X[M[1]] >= X[i]:
j = 0
else:
lo = 1
hi = L + 1
while lo < hi - 1:
mid = (lo + hi) // 2
if X[M[mid]] < X[i]:
lo = mid
else:
hi = mid
j = lo
P[i] = M[j]
if j == L or X[i] < X[M[j + 1]]:
M[j + 1] = i
L = max(L, j + 1)
output = []
pos = M[L]
while L > 0:
output.append(X[pos])
pos = P[pos]
L -= 1
output.reverse()
return output
r = LIS(pos_list)
pos_set = set(r)
f = open(input_file)
for line in f:
if ('Position' in line):
continue
vals = line.split()
_pos = int(vals[1])
if (_pos in pos_set):
f_o.write(line)
f.close()
f_o.close()