-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetNamesPVPair.py
More file actions
57 lines (53 loc) · 1.72 KB
/
Copy pathgetNamesPVPair.py
File metadata and controls
57 lines (53 loc) · 1.72 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import os
if __name__ == "__main__":
if len(sys.argv) != 3:
print("Usage: {} in_file out_file"
.format(sys.argv[0]))
sys.exit(-1)
in_file = sys.argv[1]
out_file = sys.argv[2]
if not os.path.exists(in_file):
print("in file not exists")
sys.exit(-1)
if not os.path.exists(os.path.dirname(out_file)):
print("out file directory not exist")
sys.exit(-1)
outLines = []
with open(in_file) as fp:
lastid = ""
PV = ""
QQPV = ""
name = ""
for line in fp:
fields = line.split("\t")
if len(fields) != 5:
continue
if lastid != fields[0].strip():
lastid = fields[0].strip()
if PV == "" and QQPV == "":
continue
if PV != "":
outLines.append(name + "\t" + PV + "\n")
elif QQPV != "":
outLines.append(name + "\t" + QQPV + "\n")
PV = ""
QQPV = ""
name = fields[1].strip()
if fields[2].strip() == "PV":
PV = fields[4].strip()
elif fields[2].strip() == "QQPV":
QQPV = fields[4].strip()
if PV != "":
outLines.append(name + "\t" + PV + "\n")
elif QQPV != "":
outLines.append(name + "\t" + QQPV + "\n")
step = 10000
with open(out_file, "w") as fp:
for i in range(0, len(outLines), step):
fp.writelines(outLines[i:i+step])
if len(outLines) % step > 0:
start = len(outLines)/step*step
fp.writelines(outLines[start:])