-
Notifications
You must be signed in to change notification settings - Fork 0
/
labels.py
67 lines (45 loc) · 2.03 KB
/
labels.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Dec 18 16:56:10 2020
@author: georgiabaltsou
"""
import csv
csv_Infile = 'netScLCEdgeList.csv'
csv_Outfile = 'numsToNames.csv'
csvNames = 'netScLCNodes.csv'
finalNames_txt = 'final.txt' # the edgeList file with edges as Newman, M Park L in txt format
with open(csv_Infile, 'r') as edges:
readerEdges = csv.reader(edges, delimiter=',')
for rowEdge in readerEdges: # 0 30
line = []
for node in rowEdge: # 0
with open(csvNames, 'r') as csvInfile:
readerNames = csv.reader(csvInfile, delimiter=',')
for row in readerNames:
if node == row[0]:
line.append(row[1])
with open(csv_Outfile, 'a') as out_file:
writer = csv.writer(out_file, delimiter=',')
writer.writerow([line])
with open(csv_Outfile, 'r') as infile, \
open(finalNames_txt, 'a') as outfile:
data = infile.read()
data = data.replace("'", "")
data = data.replace("[", "")
data = data.replace(", ", ",")
data = data.replace("]", "")
outfile.write(data)
csv_file = 'finalA.csv' # the edgeList csv file with edges as "Newman M Park L"
csv_fileB = 'finalB.csv' # the final edgeList csv file with edges as Newman M Park L
with open(finalNames_txt, 'r') as in_file:
stripped = (line.strip() for line in in_file)
lines = (line.split(",") for line in stripped if line) #change split to "\t" for tabbed txt file
with open(csv_file, 'w') as out_file:
writer = csv.writer(out_file, delimiter = ',')
writer.writerows(lines)
with open(csv_file, 'r') as infile, \
open(csv_fileB, 'a') as outfile:
data = infile.read()
data = data.replace('"', "")
outfile.write(data)