forked from glennlawyer/ExpectedForce
-
Notifications
You must be signed in to change notification settings - Fork 1
/
de_converter.py
70 lines (51 loc) · 1.66 KB
/
de_converter.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
# -*- coding: utf-8 -*-
"""
Created on Mon Feb 21 16:22:02 2022
@author: Paolo
"""
import argparse
import os
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="Converts results from a mapping file")
parser.add_argument("--input-file",
help="input data")
parser.add_argument("--mapping",
help="input mapping")
parser.add_argument("--outfile",
help="converted file")
parser.add_argument("--delimiter", default=" ",
help="delimiter between parent and children node")
args = parser.parse_args()
input_file = args.input_file;
mapping_file = args.mapping;
outfile = args.outfile;
delimiter = args.delimiter;
def find_delimiter(file):
delimiters = [" ", " ", "-", "\t"]
with open(file) as f:
for delimiter in delimiters:
line = f.readline()
if len(line.split(delimiter)) == 2:
if line.split(delimiter)[0] != "" and line.split(delimiter)[1] != "":
return delimiter
delimiter = " "
mapping = {}
with open(mapping_file) as f:
n = 0;
inc = "!"
for line in f:
linesplit = line.split(delimiter)
node = int(linesplit[0]);
node_id = int(linesplit[1]);
mapping[node_id] = node;
delimiter = " "
with open(input_file) as f:
with open(outfile, "w") as o:
for line in f:
linesplit = line.split(delimiter);
node = int(linesplit[0])
value = linesplit[1]
towrite = str(mapping[node]) + delimiter + value;
o.writelines(towrite)
print("saved converted file to", outfile)