-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_proper_input_file_for_mcmc_sample.py
48 lines (30 loc) · 1.13 KB
/
make_proper_input_file_for_mcmc_sample.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
import os;
import sys;
# @author: Tanay Kumar Saha
# @email: nataycse@gmail.com
# Parameter 1: input file (graph file)
# Each line contains a pair (st tab end);
inputfile = open (sys.argv[1]);
#Output file:
output_file = open (sys.argv[1]+"-mcmc-format","w");
input_mapping_file = open (sys.argv[1]+"-mappings","w");
node_list=[];
# read the file for the first pass
for line in inputfile:
lineelems = line.strip().split("\t");
node_list.append (int(lineelems[0]));
node_list.append (int(lineelems[1]));
uniq_nodeid_list = list (sorted(set (node_list)));
# read the input file for the second pass, build the correct input file
# write the mapping
inputfile = open (sys.argv[1]);
inputfile_mappings ={};
#populate the mapping
for pos in range (0,len(uniq_nodeid_list)):
inputfile_mappings [ uniq_nodeid_list[pos]]= pos;
input_mapping_file.write (str(uniq_nodeid_list[pos])+"\t"+str(pos)+os.linesep);
for line in inputfile:
lineelems = line.strip().split("\t");
st = inputfile_mappings[int(lineelems[0])];
end = inputfile_mappings [int (lineelems [1])];
output_file.write (str(st)+"\t"+str(end)+"\t"+"1"+"\t"+"1"+"\t"+"1"+os.linesep);