# HG changeset patch # User bornea # Date 1508354962 14400 # Node ID 65551439a6bb5ed803722ae4869786c9218ed7bf # Parent 8adf6ccd1077ea5316752c6dbd79c0635fa893ef Uploaded diff -r 8adf6ccd1077 -r 65551439a6bb plot_adjacency.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plot_adjacency.py Wed Oct 18 15:29:22 2017 -0400 @@ -0,0 +1,240 @@ +import sys +def readTab(infile): # read in txt file + with open(infile, 'r') as input_file: + # read in tab-delim text + output = [] + for input_line in input_file: + input_line = input_line.strip() + temp = input_line.split('\t') + output.append(temp) + return output +def network2JSON(nodes_att_file, edge_file): + nodes = readTab(nodes_att_file) + edges = readTab(edge_file) + + start = """{"nodes": [""" + node_numbers = {} + cnt=0 + for i in nodes[1:]: + node_numbers[i[0]] = cnt + cnt+=1 + start = start + '{"name":'+'"'+i[0]+'", "EV":'+i[2]+', "group":'+i[1]+"}," + start = start[:-1] + start = start+"""], "links": [""" + for i in edges: + start = start + """{"source":"""+str(node_numbers[i[0]])+""","target":"""+str(node_numbers[i[1]])+""","value":1},""" + start = start[:-1] + start = start + """]}""" + return start +def labelCentrality(nodes_att_file): + nodes = readTab(nodes_att_file) + if nodes[0][2] == "eigen": + return "Eigenvector Centrality" + if nodes[0][2] == "closeness": + return "Closeness Centrality" + if nodes[0][2] == "betweenness": + return "Betweenness Centrality" + if nodes[0][2] == "page": + return "Page Rank" + + + +adjacency_start = """ + + + + + + + + + + + + + + +""" +with open(sys.argv[3],"w") as x: + x.write(adjacency_start+jsondata+adjacency_end)