-
Notifications
You must be signed in to change notification settings - Fork 3
/
03-flat2ld.py
57 lines (50 loc) · 1.55 KB
/
03-flat2ld.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
# Append module path.
import sys, os
sys.path.append(os.getcwd())
# Import module
from coding import *
# Current work directory
CWD = os.getcwd()
# Flat data directory
FDD = CWD + "/data/01-flat"
# LD data directory
LDDD = CWD + "/data/04-ld"
# Files
FILES = [
"Supp-A-36630-HPRD-positive-interaction.txt",
"Supp-B-36480-HPRD-negative-interaction.txt",
"Supp-C-3899-HPRD-positive-interaction-below-0.25.txt",
"Supp-D-4262-HPRD-negative-interaction-below-0.25.txt",
"Supp-E-1882-interacting-0.5-non-interacting-0.5.txt",
]
def numbers_to_str(NUMBERS):
return ' '.join([str(NUMBER) for NUMBER in NUMBERS])
def generate_ld_file(INPUT_FILE, OUTPUT_FILE):
input_file = open(INPUT_FILE)
output_file = open(OUTPUT_FILE, 'w')
index = 1
line = input_file.readline()
while line:
line=line.strip()
# print(index, "=", line)
if line:
pairs = line.split(',')
result = numbers_to_str(ld_code_of(pairs[0])+ld_code_of(pairs[1]))
output_file.write(result+'\n')
else:
output_file.write('\n')
# output_file.write(line+'\n')
if index%1000 == 0:
print("finish index==" + str(index//1000))
index = index + 1
line = input_file.readline()
input_file.close()
output_file.close()
if __name__=="__main__":
if not os.path.exists(LDDD):
os.makedirs(LDDD)
for FILE in FILES:
print("Processing "+FILE+" ...")
generate_ld_file(FDD+"/"+FILE, LDDD+"/"+FILE)
print("Processed!")
print("Finished!!!")