def drawSprings(corrMatrix, kclusters, initialPosFileName, mult=1.1, kMeansRuns=1000): """drawSprings draws two figures, one of the spring evolution at 9 timepoints, one of the initial vs. final. :param corrMatrix: a data object generated by kmeans cluster - has the correlations between objects. :type corrMatrix: dict - must have 'data' and 'proteins' :param kclusters: the number of kclusters used in the analysis (what was passed to kmeans) :type kclusters: int :param initialPosFileName: a string pointing to the initial positions of each node - see nierhausPositions.txt :type initialPosFileName: string :param mult: a float of the base of the exponent to exapand on in each spring interation :type mult: float :returns: an array of figures - first is the evolution, second is the start and end. """ G = nx.Graph() positions = qMS.readDataFile(initialPosFileName) initialNodePos = {positions['proteins'][i]: [float(positions['data'][i,0])/4.0, float(positions['data'][i,1])/5.0] for i in range(len(positions['proteins']))} [G.add_node(x) for x in corrMatrix['proteins']] connection = (lambda x,y: corrMatrix['data'][x][y]) [G.add_edge(corrMatrix['proteins'][x],corrMatrix['proteins'][y], weight=connection(x,y)) for x in range(len(corrMatrix['proteins'])) for y in range(len(corrMatrix['proteins'])) if (connection(x,y)!=0)] weights = [G.get_edge_data(x[0],x[1])['weight'] for x in G.edges()] notes = pylab.figure() notes.add_subplot(1,2,1, title="nierhaus positions_kclusters=" + str(kclusters)) drawNodePos = initialNodePos yDiff = [initialNodePos[x][1] - drawNodePos[x][1] for x in drawNodePos.keys()] nx.draw_networkx(G, pos = drawNodePos, node_size=600, node_color = yDiff, cmap = pylab.cm.RdBu, vmin=-1, vmax=1, edge_color=weights, edge_vmin = 0, edge_vmax = kMeansRuns, edge_cmap = pylab.cm.autumn_r, width=2, font_size=10, font_weight='bold') iters = int(mult**8) notes.add_subplot(1,2,2, title="spring iteration=" + str(iters) + "_kclusters=" + str(kclusters)) drawNodePos = nx.spring_layout(G, pos=initialNodePos, iterations=iters) yDiff = [initialNodePos[x][1] - drawNodePos[x][1] for x in drawNodePos.keys()] nx.draw_networkx(G, pos = drawNodePos, node_size=600, node_color = yDiff, cmap = pylab.cm.RdBu, vmin=-1, vmax=1, edge_color=weights, edge_vmin = 0, edge_vmax = kMeansRuns, edge_cmap = pylab.cm.autumn_r, width=2, font_size=10, font_weight='bold') cb1ax = notes.add_axes([0.025, 0.1, 0.05, 0.8]) pylab.colorbar(cmap=pylab.cm.autumn_r, cax=cb1ax) cb2ax = notes.add_axes([0.925, 0.1, 0.05, 0.8]) norm = mpl.colors.Normalize(vmin=-1, vmax=1) mpl.colorbar.ColorbarBase(cb2ax, cmap=pylab.cm.RdBu_r, norm=norm, orientation='vertical') notes2 = pylab.figure() drawNodePos = initialNodePos for i in range(9): notes2.add_subplot(3,3,i+1, title="iterations=" + str(int(mult**i)) + "_k=" + str(kclusters)) drawNodePos = nx.spring_layout(G, pos=drawNodePos, iterations=int(mult**i)) yDiff = [initialNodePos[x][1] - drawNodePos[x][1] for x in drawNodePos.keys()] nx.draw_networkx(G, pos = drawNodePos, node_size=600, node_color = yDiff, cmap = pylab.cm.RdBu, vmin=-1, vmax=1, edge_color=weights, edge_vmin = 0, edge_vmax = kMeansRuns, edge_cmap = pylab.cm.autumn_r, width=2, font_size=10, font_weight='bold')
correctedDFsDict, files1hrGrad, smallSubunit, num, den, normalization=1.0, offset=0.0) qMS.outputDataMatrixFile('/home/jhdavis/data/2013_08_08-JStokesESITOFAnalysis/1hrLarge.csv', correctedDFsDict, files1hrGrad, largeSubunit, num, den, normalization=1.0, offset=0.0) correctedDFsDict = qMS.correctListOfFiles(filesRefSet[1], files6hrGrad) qMS.outputDataMatrixFile('/home/jhdavis/data/2013_08_08-JStokesESITOFAnalysis/6hrSmall.csv', correctedDFsDict, files6hrGrad, smallSubunit, num, den, normalization=1.0, offset=0.0) qMS.outputDataMatrixFile('/home/jhdavis/data/2013_08_08-JStokesESITOFAnalysis/6hrLarge.csv', correctedDFsDict, files6hrGrad, largeSubunit, num, den, normalization=1.0, offset=0.0) ''' rawData = qMS.readDataFile('/home/jhdavis/data/2013_08_08-JStokesESITOFAnalysis/wtSmall.csv', 1.0) rawMap = vizLib.drawHeatMap(rawData, "wtGradient", nameList=wtFracNames, colors=pylab.cm.autumn, scale='14N/[14N+15N]', saveName='wtSmallHeat.png') rawData = qMS.readDataFile('/home/jhdavis/data/2013_08_08-JStokesESITOFAnalysis/wtLarge.csv', 1.0) rawMap = vizLib.drawHeatMap(rawData, "wtGradient", nameList=wtFracNames, colors=pylab.cm.autumn, scale='14N/[14N+15N]', saveName='wtLargeHeat.png') rawData = qMS.readDataFile('/home/jhdavis/data/2013_08_08-JStokesESITOFAnalysis/1hrSmall.csv', 1.0) rawMap = vizLib.drawHeatMap(rawData, "1hrGradient", nameList=fracNames1hr, colors=pylab.cm.autumn, scale='14N/[14N+15N]', saveName='1hrSmallHeat.png') rawData = qMS.readDataFile('/home/jhdavis/data/2013_08_08-JStokesESITOFAnalysis/1hrLarge.csv', 1.0) rawMap = vizLib.drawHeatMap(rawData, "1hrGradient", nameList=fracNames1hr, colors=pylab.cm.autumn, scale='14N/[14N+15N]', saveName='1hrLargeHeat.png') rawData = qMS.readDataFile('/home/jhdavis/data/2013_08_08-JStokesESITOFAnalysis/6hrSmall.csv', 1.0) rawMap = vizLib.drawHeatMap(rawData, "6hrGradient", nameList=fracNames6hr, colors=pylab.cm.autumn, scale='14N/[14N+15N]', saveName='6hrSmallHeat.png')
def drawSprings(corrMatrix, kclusters, initialPosFileName, mult=1.1, kMeansRuns=1000): """drawSprings draws two figures, one of the spring evolution at 9 timepoints, one of the initial vs. final. :param corrMatrix: a data object generated by kmeans cluster - has the correlations between objects. :type corrMatrix: dict - must have 'data' and 'proteins' :param kclusters: the number of kclusters used in the analysis (what was passed to kmeans) :type kclusters: int :param initialPosFileName: a string pointing to the initial positions of each node - see nierhausPositions.txt :type initialPosFileName: string :param mult: a float of the base of the exponent to exapand on in each spring interation :type mult: float :returns: an array of figures - first is the evolution, second is the start and end. """ G = nx.Graph() positions = qMS.readDataFile(initialPosFileName) initialNodePos = { positions['proteins'][i]: [ float(positions['data'][i, 0]) / 4.0, float(positions['data'][i, 1]) / 5.0 ] for i in range(len(positions['proteins'])) } [G.add_node(x) for x in corrMatrix['proteins']] connection = (lambda x, y: corrMatrix['data'][x][y]) [ G.add_edge(corrMatrix['proteins'][x], corrMatrix['proteins'][y], weight=connection(x, y)) for x in range(len(corrMatrix['proteins'])) for y in range(len(corrMatrix['proteins'])) if (connection(x, y) != 0) ] weights = [G.get_edge_data(x[0], x[1])['weight'] for x in G.edges()] notes = pylab.figure() notes.add_subplot(1, 2, 1, title="nierhaus positions_kclusters=" + str(kclusters)) drawNodePos = initialNodePos yDiff = [ initialNodePos[x][1] - drawNodePos[x][1] for x in drawNodePos.keys() ] nx.draw_networkx(G, pos=drawNodePos, node_size=600, node_color=yDiff, cmap=pylab.cm.RdBu, vmin=-1, vmax=1, edge_color=weights, edge_vmin=0, edge_vmax=kMeansRuns, edge_cmap=pylab.cm.autumn_r, width=2, font_size=10, font_weight='bold') iters = int(mult**8) notes.add_subplot(1, 2, 2, title="spring iteration=" + str(iters) + "_kclusters=" + str(kclusters)) drawNodePos = nx.spring_layout(G, pos=initialNodePos, iterations=iters) yDiff = [ initialNodePos[x][1] - drawNodePos[x][1] for x in drawNodePos.keys() ] nx.draw_networkx(G, pos=drawNodePos, node_size=600, node_color=yDiff, cmap=pylab.cm.RdBu, vmin=-1, vmax=1, edge_color=weights, edge_vmin=0, edge_vmax=kMeansRuns, edge_cmap=pylab.cm.autumn_r, width=2, font_size=10, font_weight='bold') cb1ax = notes.add_axes([0.025, 0.1, 0.05, 0.8]) pylab.colorbar(cmap=pylab.cm.autumn_r, cax=cb1ax) cb2ax = notes.add_axes([0.925, 0.1, 0.05, 0.8]) norm = mpl.colors.Normalize(vmin=-1, vmax=1) mpl.colorbar.ColorbarBase(cb2ax, cmap=pylab.cm.RdBu_r, norm=norm, orientation='vertical') notes2 = pylab.figure() drawNodePos = initialNodePos for i in range(9): notes2.add_subplot(3, 3, i + 1, title="iterations=" + str(int(mult**i)) + "_k=" + str(kclusters)) drawNodePos = nx.spring_layout(G, pos=drawNodePos, iterations=int(mult**i)) yDiff = [ initialNodePos[x][1] - drawNodePos[x][1] for x in drawNodePos.keys() ] nx.draw_networkx(G, pos=drawNodePos, node_size=600, node_color=yDiff, cmap=pylab.cm.RdBu, vmin=-1, vmax=1, edge_color=weights, edge_vmin=0, edge_vmax=kMeansRuns, edge_cmap=pylab.cm.autumn_r, width=2, font_size=10, font_weight='bold')