def main(): fn = sys.argv[1] col = int(sys.argv[2]) fo=open(fn) (adj_list, iByn, nByi) = fiedler.file_parse(fo, node2=1, val_col=col) fo.close() fn = os.path.basename(fn) fied = fiedler.fiedler(adj_list, fn=fn, plot=False, n_fied=2) fied["adj"] = adj_list fied["iByn"] = iByn fied["nByi"] = nByi fo = open(fn + ".json", "w") json.dump(fied, fo) fo.close()
def RequestHandler(info,outfo): """ Parse input,do caclulation, transform into proper format and dump json. info: a file like object containing a sif like file outfo: a file like object to write json to """ #Change 2 to 1 below to accept 2 column files. #Could also parse json of the form [["node1","node2"],...] with something like #(adj_list,iByn,nByi)=fiedler.file_parse(["%s\t%s"%(e[0],e[1]) for e in json.load(info)],0,2) (adj_list,iByn,nByi)=fiedler.file_parse(info,0,2) fied=fiedler.fiedler(adj_list,plot=False,n_fied=2) out = fied["f1"][:] for i,name in enumerate(nByi): out[i]={"name":name} for key in fied: if not key in ["iByn", "nByi"]: out[i][key]=fied[key][i] json.dump(out,outfo)
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