forked from greenelab/model-free-data
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmigrate.py
26 lines (19 loc) · 774 Bytes
/
migrate.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
import os
file_names = []
for (path, dirs, files) in os.walk('.'):
for file_name in files:
if 'accuracies' in file_name or '.tsv' not in file_name:
continue
file_names.append(path + '\\' + file_name)
for file_name in file_names:
lines = []
header = []
with open(file_name, 'r') as file:
lines = file.readlines()
header_len = len(lines[0].split('\t'))
cont_attrs = ['c' for val in range(header_len - 1)] + ['d'] + ['\n']
class_attr = ['' for val in range(header_len - 1)] + ['class'] + ['\n']
lines.insert(1, '\t'.join(cont_attrs))
lines.insert(2, '\t'.join(class_attr))
with open(file_name.replace('.tsv', '.tab'), 'wt') as file:
file.writelines(lines)