I want to draw a single networkX graph with items inside the tuple 'new'. My graph nodes will have labels such as "AXIN", and color will be green or yellow.
I want the node to be green color, if 'UNREPORTED'. If item[2] within tuple 'reported', I want this node to be yellow color.
> new = (('AXIN', 37, 'reported'), ('LGR', 30, 'reported'), ('NKD',
> 24, 'reported'), ('TNFRSF', 23, 'UNREPORTED'), ('CCND', 19,
> 'reported'), ('APCDD', 18, 'reported'), ('TR', 16, 'UNREPORTED'),
> ('TOX', 15, 'UNREPORTED'), ('LEF', 15, 'reported'), ('MME', 13,
> 'reported'))
>
> X, Y, _ = zip(*new) import seaborn as sns sns.set() import
> matplotlib.pyplot as plt %matplotlib inline plt.figure(figsize = (20,
> 10)) mytitle = "Most common genes coexpressed with {gene1}, {gene2},
> {gene3}, {gene4}".format(gene1="axin2", gene2="lef", gene3="nkd1",
> gene4="lgr5") plt.title(mytitle, fontsize=40) plt.ylabel('Number of
> same gene encounters across studies', fontsize=20) ax =
> plt.bar(range(len(X)), Y, 0.6, align='center', tick_label = X,
> color="red") ax = plt.xticks(rotation=90) new = tuple(new)
>
> import networkx as nx children = sorted(new, key=lambda x: x[1])
> parent = children.pop()[0]
>
> G = nx.Graph() for child, weight, _ in children: G.add_edge(parent,
> child, weight=weight) width = list(nx.get_edge_attributes(G,
> 'weight').values()) colors = [] for i in new:
> if i[2] == 'UNREPORTED':
> colors.append('green')
> elif i[2] == 'reported':
> colors.append('yellow') print(colors) plt.savefig("plt.gene-expression.pdf") plt.figure(figsize = (20, 10))
> mytitle = "Most common genes coexpressed with {gene1}, {gene2},
> {gene3}, {gene4}".format(gene1="axin2", gene2="lef", gene3="nkd1",
> gene4="lgr5") plt.title(mytitle, fontsize=40)
>
> nx.draw_networkx(G, font_size=10, node_size=2000, alpha=0.6,
> node_color=colors) plt.savefig("gene-expression-graph.pdf")
With this code, I get two different graphs, with yellow nodes, other with green nodes.
