# HG changeset patch # User bornea # Date 1508355252 14400 # Node ID 4324d3f925feeab277d10ad2bfc3a933eaa72d70 Uploaded diff -r 000000000000 -r 4324d3f925fe plotForce.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plotForce.py Wed Oct 18 15:34:12 2017 -0400 @@ -0,0 +1,409 @@ +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 + '{"id":'+'"'+i[0]+'", "size":'+str(float(i[2])*1)+', "score":'+i[1]+',"type":"circle"},' + start = start[:-1] + start = start+"""], "links": [""" + for i in edges: + start = start + """{"source":"""+str(node_numbers[i[0]])+""","target":"""+str(node_numbers[i[1]])+"""},""" + start = start[:-1] + start = start + """]}""" + return start + + +output = """ + + +
+ +""" + +with open(sys.argv[3],"w") as x: + x.write(output)