forked from ryanbressler/GraphSpectrometer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parseByCol.py
executable file
·53 lines (40 loc) · 1.38 KB
/
parseByCol.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
import fiedler
import os.path
import sys
import json
def filename_parse(fn, filter_min=.001,col=2,filter_col=2):
"""Wraps file_parse and infers paramaters based on extensions.
Takes:
filename.
".out" files will be treated as rf-ace output and filtered by imortance
all other files will be treated as sif files.
returns:
The same tuple as filename_parse
"""
fo = open(fn)
out = ()
out = fiedler.file_parse(fo, node2=1, filter_col=filter_col, filter_min=filter_min, val_col=col)
fo.close()
return out
def main():
fn = sys.argv[1]
filter_min = ""
filter_min = float(sys.argv[2])
col = int(sys.argv[3])
filter_col = col
if len(sys.argv)>4:
filter_col=int(sys.argv[4])
print "Parseing %s min %s val_col %s filter_col %s"%(os.path.abspath(fn),filter_min,col,filter_col)
(adj_list, iByn, nByi) = filename_parse(fn, filter_min, col, filter_col)
fn = os.path.basename(fn)
fied = fiedler.fiedler(adj_list, fn=fn + str(filter_min), plot=False, n_fied=2)
fied["adj"] = adj_list
fied["iByn"] = iByn
fied["nByi"] = nByi
outfn=os.path.basename(fn) +".cutoff."+ str(filter_min) + ".json"
fo = open(outfn, "w")
print "Outputing fiedler results for %s to %s"%(os.path.abspath(fn),os.path.abspath(outfn))
json.dump(fied, fo)
fo.close()
if __name__ == '__main__':
main()