-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocessData.py
131 lines (124 loc) · 3.2 KB
/
processData.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import sys
def ReadFASTA_pos(filename):
fp = open(filename, 'r')
wp1 = open('data/positive_776_train.fasta', 'w')
wp2 = open('data/positive_776_test.fasta', 'w')
pre = ""
cnt = 0
for line in fp:
if line[0] == ">":
pre = line
else:
if cnt < 2000:
wp1.write(pre)
wp1.write(line)
else:
wp2.write(pre)
wp2.write(line)
cnt += 1
fp.close()
wp1.close()
wp2.close()
def ReadFASTA_neg(filename):
fp = open(filename, 'r')
wp1 = open('data/negative_776_train.fasta', 'w')
wp2 = open('data/negative_776_test.fasta', 'w')
pre = ""
cnt = 0
for line in fp:
if line[0] == ">":
pre = line
else:
if cnt < 6000:
wp1.write(pre)
wp1.write(line)
else:
wp2.write(pre)
wp2.write(line)
cnt += 1
fp.close()
wp1.close()
wp2.close()
def ReadFASTA_folds_pos(filename):
fp = open(filename, 'r')
wp1 = open('data/positive_folds_train.fasta', 'w')
wp2 = open('data/positive_folds_test.fasta', 'w')
pre = ""
cnt = 0
for line in fp:
if line[0] == ">":
pre = line
else:
if cnt < 2000:
wp1.write(pre)
wp1.write(line)
else:
wp2.write(pre)
wp2.write(line)
cnt += 1
fp.close()
wp1.close()
wp2.close()
def ReadFASTA_folds_neg(filename):
fp = open(filename, 'r')
wp1 = open('data/negative_folds_train.fasta', 'w')
wp2 = open('data/negative_folds_test.fasta', 'w')
pre = ""
cnt = 0
for line in fp:
if line[0] == ">":
pre = line
else:
if cnt < 6000:
wp1.write(pre)
wp1.write(line)
else:
wp2.write(pre)
wp2.write(line)
cnt += 1
fp.close()
wp1.close()
wp2.close()
def split_pos():
fp = open('data/coverage_pos_776_norm.txt', 'r')
wp1 = open('data/cov_pos_776_train.fasta', 'w')
wp2 = open('data/cov_pos_776_test.fasta', 'w')
cnt = 0
for line in fp:
strs = line.split()
idx = line.find(strs[3])
if cnt < 1000:
wp1.write(line[idx:])
else:
wp2.write(line[idx:])
cnt += 1
fp.close()
wp1.close()
wp2.close()
def split_neg():
fp = open('data/coverage_neg_776_norm.txt', 'r')
wp1 = open('data/cov_neg_776_train.fasta', 'w')
wp2 = open('data/cov_neg_776_test.fasta', 'w')
cnt = 0
for line in fp:
strs = line.split()
idx = line.find(strs[3])
if cnt < 3000:
wp1.write(line[idx:])
else:
wp2.write(line[idx:])
cnt += 1
fp.close()
wp1.close()
wp2.close()
if __name__ == "__main__":
if len(sys.argv) > 1:
cov_file = sys.argv[1]
fp = open(cov_file, 'r')
wp = open('data/mouse_pos_cov_norm.fasta', 'w')
for line in fp:
strs = line.split()
idx = line.find(strs[3])
wp.write(line[idx:])
fp.close()
wp.close()