Пример #1
0
def drawGraph(genes_names_list, network_as_list):
    G = nx.MultiDiGraph()

    G.add_nodes_from(genes_names_list)
    val_map = {'ARR23': 1.0, 'CRF2': 0.5714285714285714}

    values = [val_map.get(node, 0.85) for node in G.nodes()]

    #ajout des aretes et des noeuds
    for i in range(len(network_as_list)):
        gene_source = network_as_list[i][0]
        gene_target = network_as_list[i][2]
        interaction = network_as_list[i][1]
        G.add_edge(gene_source, gene_target, arrowstyle=interaction)

    # if gene_source not in G.nodes :
    #     if gene_target == gene_source :
    #         G.add_node(gene_source, regulation = "auto")
    #     else:
    #         G.add_node(gene_source, regulation = "none")

    print(G.adj)

    pos = nx.circular_layout(G)
    nx.draw_networkx_nodes(G, pos, node_size=1500, node_color=values)
    nx.draw_networkx_labels(G, pos)
    for edge in G.edges(data=True):
        if edge[2]['arrowstyle'] == "-1":
            arrowstyle = "-["
        else:
            arrowstyle = "-|>"
        nx.draw_networkx_edges(G,
                               pos,
                               edgelist=[(edge[0], edge[1])],
                               arrowstyle=arrowstyle,
                               node_size=1900)
# plt.show()

    plt.gca().yaxis.set_minor_formatter(NullFormatter())
    plt.subplots_adjust(top=1,
                        bottom=0,
                        left=0,
                        right=1,
                        hspace=0.25,
                        wspace=0.35)
    fig = plt.gcf()
    art = plot_network(G,
                       node_style=use_attributes(),
                       edge_style=use_attributes())

    art.set_picker(10)  # if using Pyplot then get the figure from the plot

    return fig
def draw_workflow(dol, simulations):
    graph = nx.from_dict_of_lists(dol, create_using=None)
    
    fig, ax = plt.subplots()
    art = plot_network(graph, ax=ax, node_style=use_attributes(),
            edge_style=use_attributes(), 
            #layout="kamada_kawai",
            #node_label_style = {'font_weight': 'bold', 'font_size': 15}
            )
    art.set_picker(10)
    ax.set_title('workflow simulations, click on the nodes to see structure')
    fig.canvas.mpl_connect('pick_event', hilighter)
    plt.show()
    plt.close()
    return 
Пример #3
0
def test_use_style_attributes_default(style_key, barbell_network):
    for node, node_attr in barbell_network.nodes.data():
        node_attr[style_key] = 'TEST'

    node_styles = generate_node_styles(barbell_network,
                                       use_attributes())

    for node, style in node_styles.items():
        assert node in barbell_network
        assert style[style_key] == 'TEST'
Пример #4
0
def test_use_style_attributes_filter_single(barbell_network):
    for node, node_attr in barbell_network.nodes.data():
        for style_key in _ALL_STYLE_KEYS:
            node_attr[style_key] = 'TEST'

    node_styles = generate_node_styles(barbell_network,
                                       use_attributes('color'))

    expected = default_node_style()
    expected['color'] = 'TEST'
    for node, style in node_styles.items():
        assert node in barbell_network
        assert style == expected
Пример #5
0
    def plotGraph(self):

        G = self.graph[0]
        largest_node = self.graph[1]
        G.add_edge(largest_node, largest_node)

        for node in G.nodes:
            G.nodes[node]["size"] = 200
            G.nodes[node]["color"] = 'C0'

        G.nodes[largest_node]["size"] = 400
        G.nodes[largest_node]["color"] = "red"
        self.app.axes.clear()
        self.app.selectedDocument.setText("")

        graph = plot_network(G,
                             layout="spring",
                             ax=self.app.axes,
                             node_style=use_attributes(),
                             edge_style=use_attributes())
        graph.set_picker(10)
        self.app.canvas.mpl_connect('pick_event', self.app.selectNode)

        self.app.update_graph.emit()
Пример #6
0
    def set_graph(self):
        """
        Draws current graph on canvas
        """
        # add dummy edge if no edges
        # circumvent the fact that drawing graph with no edges is not supported
        if self.graph.number_of_edges() == 0:
            for n in self.graph.nodes:
                self.graph.add_edge(n, n)
        if args.dataset == "clevr":
            layout = "circular"
        else:
            layout = self.g_layout
        self._static_ax.clear()
        self.art = plot_network(
            self.graph,
            layout=layout,
            ax=self._static_ax,  #self.g_layout, "spring"
            node_style=use_attributes(
            ),  # use_attributes(), #node_options, #dict(node_size=50),
            edge_style=use_attributes(),  # ) #edge_options) # #,
            node_label_style={
                'font_size': '10',
                'font_weight': 'bold'
            })  # layout=self.g_layout

        self.art.set_picker(10)
        self._static_ax.figure.canvas.draw_idle()

        # reset combobox for node choices and update with new object list
        for i in range(self.comboBox_obj2.count()):
            self.comboBox_obj2.removeItem(0)

        for obj in self.graph.nodes:
            if obj.split(".")[0] in objs:
                self.comboBox_obj2.addItem(obj)
Пример #7
0
    # clear any non-default color on nodes
    for node, attributes in graph.nodes.data():
        attributes.pop('color', None)

    for u, v, attributes in graph.edges.data():
        attributes.pop('width', None)

    for node in event.nodes:
        graph.nodes[node]['color'] = 'C1'

        for edge_attribute in graph[node].values():
            edge_attribute['width'] = 3

    # update the screen
    event.artist.stale = True
    event.artist.figure.canvas.draw_idle()


graph = nx.barbell_graph(10, 14)

fig, ax = plt.subplots()
art = plot_network(graph,
                   ax=ax,
                   node_style=use_attributes(),
                   edge_style=use_attributes())

art.set_picker(10)
ax.set_title('Click on the nodes!')
fig.canvas.mpl_connect('pick_event', hilighter)
plt.show()
Пример #8
0
    # clear any non-default color on nodes
    for node, attributes in graph.nodes.data():
        attributes.pop('color', None)

    for u, v, attributes in graph.edges.data():
        attributes.pop('width', None)

    for node in event.nodes:
        graph.nodes[node]['color'] = 'C1'

        for edge_attribute in graph[node].values():
            edge_attribute['width'] = 3

    # update the screen
    event.artist.stale = True
    event.artist.figure.canvas.draw_idle()


graph = nx.barbell_graph(10, 14)

pos = nx.circular_layout(graph)
fig, ax = plt.subplots()
art = plot_network(graph, ax=ax,node_style=use_attributes(),
                   edge_style=use_attributes(), node_size = 500)


art.set_picker(10)
ax.set_title('Click on the nodes!')
fig.canvas.mpl_connect('pick_event', hilighter)
plt.show()