-
Notifications
You must be signed in to change notification settings - Fork 1
/
remove_dicts.py
29 lines (24 loc) · 1.07 KB
/
remove_dicts.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
import os
data_dir = '../data/'
# Iterate through the directory structure
for dirpath, dirnames, filenames in os.walk(data_dir):
for filename in filenames:
# Check if the file is a .txt file
if filename.endswith('.txt'):
# Parse the filename to get the number
num = filename.split('.')[0]
# Open the file
with open(os.path.join(dirpath, f'{num}_string.edges'), 'r') as f:
# Read the file contents and parse the lines
lines = f.readlines()
print(lines[0])
edges = []
for line in lines:
# Split the line by tabs and remove the third column
cols = line.strip().split('\t')
cols.pop(2)
# Append the remaining columns to the edges list
edges.append('\t'.join(cols))
# Write the edges list to a new file
with open(os.path.join(dirpath, f'{num}_string_cleaned.edges'), 'w') as f:
f.write('\n'.join(edges))