Network 1#
[2]:
import matplotlib.pyplot as plt
import networkx as nx
import pandas as pd
import matplotlib as mpl
mpl.rcParams['pdf.fonttype']=42
mpl.rcParams['ps.fonttype']=42
plt.figure(1, figsize=(7, 6.5))
G = nx.Graph()
#G = nx.star_graph(12)
df = pd.read_table("sugar-gene.txt",header=None)
df[4] = abs(df[2])
df[5] = '-'
df[df[4] < 0.6][5] = '-.-'
df[6] = round(df[2],2)
for i,row in df.iterrows():
G.add_edge(row[1], row[0], length=row[6], weight=7)
pos = nx.spring_layout(G, seed=63)
#nx.draw(G, pos)
elarge = [(u, v) for (u, v, d) in G.edges(data=True) if ((d["length"] >= 0.6) or (d["length"] <= -0.6))]
esmall = [(u, v) for (u, v, d) in G.edges(data=True) if ((d["length"] > -0.6) and (d["length"] < 0.6))]
node_edgecolors = ['#07CCD2' if i<0 else '#E0CCD2' for i in df[2]]
node_edgecolors.insert(0, '#C7442A')
#pos = nx.spring_layout(G, seed=12) # positions for all nodes - seed for reproducibility
#pos = nx.spring_layout(G, seed=13)
# nodes
nx.draw_networkx_nodes(G, pos, node_size=700,
node_color=['#C7442A', "#A0CBE2", "#A0CBE2", "#A0CBE2", "#A0CBE2",
"#A0CBE2", "#A0CBE2", "#A0CBE2",
"#A0CBE2", "#A0CBE2", "#A0CBE2", "#A0CBE2", "#A0CBE2"],
#edgecolors=node_edgecolors
)
# edges
nx.draw_networkx_edges(G, pos, edgelist=elarge, width=3, edge_color='#E0CCD2')
nx.draw_networkx_edges(
G, pos, edgelist=esmall, width=3, alpha=0.5, edge_color='#07CCD2', style="dashed"
)
# node labels
nx.draw_networkx_labels(G, pos, font_size=10, font_family="sans-serif")
# edge weight labels
edge_labels = nx.get_edge_attributes(G, "length")
#font_color = ['#07CCD2' if i<0 else '#E0CCD2' for i in df[2]]
nx.draw_networkx_edge_labels(G, pos, edge_labels, font_size=8, font_family="sans-serif")
ax = plt.gca()
ax.margins(0.15)
plt.axis("off")
plt.tight_layout()
plt.savefig("sugar-gene.pdf")
/Users/yuanzan/anaconda3/lib/python3.8/site-packages/pandas/core/computation/expressions.py:20: UserWarning: Pandas requires version '2.7.3' or newer of 'numexpr' (version '2.7.1' currently installed).
from pandas.core.computation.check import NUMEXPR_INSTALLED
<ipython-input-2-74c007cbb4fb>:15: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
df[df[4] < 0.6][5] = '-.-'
[5]:
pos
[5]:
{'Suc': array([-0.00445015, 0.00211237]),
'Solyc04g076960.4': array([-1. , 0.15390925]),
'Solyc05g007190.4': array([-0.87084574, -0.34897587]),
'Solyc06g072620.4': array([-0.69126574, 0.52293721]),
'Solyc06g072630.4': array([ 0.36578484, -0.88810311]),
'Solyc02g071520.3': array([-0.57781417, -0.75451513]),
'Solyc03g005880.3': array([0.86730542, 0.34989004]),
'Solyc03g097600.3': array([ 0.71832309, -0.55112103]),
'Solyc03g097610.3': array([-0.12289208, -0.96105373]),
'Solyc04g064630.3': array([ 0.99466028, -0.13976562]),
'Solyc04g064640.4': array([0.58747402, 0.76039752]),
'Solyc01g103940.3': array([0.12045707, 0.94882179]),
'Solyc04g074500.3': array([-0.38673685, 0.90546632])}
[6]:
df
[6]:
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | |
|---|---|---|---|---|---|---|---|
| 0 | Solyc04g076960.4 | Suc | 0.788059 | 4.410000e-38 | 0.788059 | - | 0.79 |
| 1 | Solyc05g007190.4 | Suc | 0.574347 | 1.170000e-16 | 0.574347 | - | 0.57 |
| 2 | Solyc06g072620.4 | Suc | -0.772010 | 1.100000e-35 | 0.772010 | - | -0.77 |
| 3 | Solyc06g072630.4 | Suc | -0.705140 | 1.780000e-27 | 0.705140 | - | -0.71 |
| 4 | Solyc02g071520.3 | Suc | 0.580767 | 4.450000e-17 | 0.580767 | - | 0.58 |
| 5 | Solyc03g005880.3 | Suc | -0.631408 | 9.610000e-21 | 0.631408 | - | -0.63 |
| 6 | Solyc03g097600.3 | Suc | -0.666118 | 1.130000e-23 | 0.666118 | - | -0.67 |
| 7 | Solyc03g097610.3 | Suc | -0.674703 | 1.850000e-24 | 0.674703 | - | -0.67 |
| 8 | Solyc04g064630.3 | Suc | 0.530913 | 4.850000e-14 | 0.530913 | - | 0.53 |
| 9 | Solyc04g064640.4 | Suc | 0.485328 | 1.140000e-11 | 0.485328 | - | 0.49 |
| 10 | Solyc01g103940.3 | Suc | 0.718192 | 6.870000e-29 | 0.718192 | - | 0.72 |
| 11 | Solyc04g074500.3 | Suc | 0.651717 | 2.060000e-22 | 0.651717 | - | 0.65 |
[6]: