From 9db59911085196cebeafe4a9fee9e8b74bc7cc42 Mon Sep 17 00:00:00 2001 From: flatberg Date: Fri, 20 Jul 2007 15:48:59 +0000 Subject: [PATCH] --- scripts/lpls/plots_lpls.py | 19 +++++++++++++++++++ scripts/lpls/rpy_go.py | 8 ++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/scripts/lpls/plots_lpls.py b/scripts/lpls/plots_lpls.py index 7b5cd08..a350b86 100644 --- a/scripts/lpls/plots_lpls.py +++ b/scripts/lpls/plots_lpls.py @@ -1,5 +1,6 @@ import pylab 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): """ 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): pylab.text(r[pc1], r[pc2], " " + name) #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) + diff --git a/scripts/lpls/rpy_go.py b/scripts/lpls/rpy_go.py index ad49008..14ada26 100644 --- a/scripts/lpls/rpy_go.py +++ b/scripts/lpls/rpy_go.py @@ -119,6 +119,10 @@ def parents_dag(go_terms, ontology=['BP']): edges = rpy.r.edges(graph) edges.pop('all') edge_dict = {} - for head, nei in edges.items(): - edge_dict[head] = nei.values() + for head, neighbours in edges.items(): + for nn in neighbours.values(): + if edge_dict.has_key(nn): + edge_dict[nn].append(head) + else: + edge_dict[nn] = [head] return edge_dict