This commit is contained in:
parent
98f53d3448
commit
9db5991108
|
@ -1,5 +1,6 @@
|
||||||
import pylab
|
import pylab
|
||||||
import matplotlib
|
import matplotlib
|
||||||
|
import networkx as nx
|
||||||
|
|
||||||
def plot_corrloads(R, pc1=0,pc2=1,s=20, c='b', zorder=5,expvar=None,ax=None,drawback=True, labels=None):
|
def plot_corrloads(R, pc1=0,pc2=1,s=20, c='b', zorder=5,expvar=None,ax=None,drawback=True, labels=None):
|
||||||
""" Correlation loading plot."""
|
""" Correlation loading plot."""
|
||||||
|
@ -36,3 +37,21 @@ def plot_corrloads(R, pc1=0,pc2=1,s=20, c='b', zorder=5,expvar=None,ax=None,draw
|
||||||
for name, r in zip(labels, R):
|
for name, r in zip(labels, R):
|
||||||
pylab.text(r[pc1], r[pc2], " " + name)
|
pylab.text(r[pc1], r[pc2], " " + name)
|
||||||
#pylab.show()
|
#pylab.show()
|
||||||
|
|
||||||
|
def plot_dag(edge_dict, node_color='b', node_size=30,labels=None,nodelist=None,pos=None):
|
||||||
|
clean_edges = {}
|
||||||
|
for head, neigb in edge_dict.items():
|
||||||
|
head = head.replace(":", "_")
|
||||||
|
nei = [i.replace(":", "_") for i in neigb]
|
||||||
|
clean_edges[head] = nei
|
||||||
|
if pos==None:
|
||||||
|
G = nx.from_dict_of_lists(clean_edges, nx.DiGraph(name='GO'))
|
||||||
|
pos = nx.pydot_layout(G, prog='dot')
|
||||||
|
G = nx.from_dict_of_lists(edge_dict, nx.DiGraph(name='GO'))
|
||||||
|
if len(node_color)>1:
|
||||||
|
assert(len(node_color)==len(nodelist))
|
||||||
|
if labels!=None:
|
||||||
|
with_labels=True
|
||||||
|
|
||||||
|
nx.draw_networkx(G,pos, with_labels=with_labels, node_size=node_size, node_color=node_color, nodelist=nodelist)
|
||||||
|
|
||||||
|
|
|
@ -119,6 +119,10 @@ def parents_dag(go_terms, ontology=['BP']):
|
||||||
edges = rpy.r.edges(graph)
|
edges = rpy.r.edges(graph)
|
||||||
edges.pop('all')
|
edges.pop('all')
|
||||||
edge_dict = {}
|
edge_dict = {}
|
||||||
for head, nei in edges.items():
|
for head, neighbours in edges.items():
|
||||||
edge_dict[head] = nei.values()
|
for nn in neighbours.values():
|
||||||
|
if edge_dict.has_key(nn):
|
||||||
|
edge_dict[nn].append(head)
|
||||||
|
else:
|
||||||
|
edge_dict[nn] = [head]
|
||||||
return edge_dict
|
return edge_dict
|
||||||
|
|
Reference in New Issue