Skip to content

Commit

Permalink
renaming plot function
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnovanHilten committed Aug 1, 2021
1 parent 56dbac8 commit 669dc1f
Show file tree
Hide file tree
Showing 9 changed files with 221 additions and 215 deletions.
2 changes: 1 addition & 1 deletion GenNet.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def main(args):
parser_plot.add_argument(
"-type",
type=str,
choices=['layer_weight', 'sunburst', 'raw_importance'],
choices=['layer_weight', 'sunburst', 'manhattan_relative_importance'],
)
parser_plot.add_argument(
"-layer_n",
Expand Down
30 changes: 18 additions & 12 deletions GenNet_utils/Create_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,18 @@ def plot_layer_weight(resultpath, importance_csv, layer=0, num_annotated=10):
if 'chr' in csv_file.columns:
columns = ["node_layer_" + str(layer), "node_layer_" + str(layer + 1), "weights_" + str(layer),
'layer' + str(layer) + '_name', 'layer' + str(layer + 1) + '_name', 'chr']
csv_file = csv_file[columns]
csv_file = csv_file.drop_duplicates()

csv_file = csv_file.sort_values(by=['chr', 'node_layer_' + str(layer)], ascending=True)
else:
columns = ["node_layer_" + str(layer), "node_layer_" + str(layer + 1), "weights_" + str(layer),
'layer' + str(layer) + '_name', 'layer' + str(layer + 1) + '_name']
csv_file = csv_file[columns]
csv_file = csv_file.drop_duplicates()
csv_file = csv_file[columns]
csv_file = csv_file.drop_duplicates()

csv_file = csv_file.sort_values(by=['node_layer_' + str(layer)], ascending=True)

csv_file = csv_file.sort_values(by=['chr', 'node_layer_' + str(layer)], ascending=True)
csv_file["pos"] = np.arange(len(csv_file))
weights = abs(csv_file["weights_" + str(layer)].values)
weights = weights / max(weights)
Expand Down Expand Up @@ -150,23 +155,24 @@ def plot_layer_weight(resultpath, importance_csv, layer=0, num_annotated=10):
plt.savefig(resultpath + "Weights_layer_" + str(layer) + ".png", bbox_inches='tight', pad_inches=0)


def manhattan_importance(resultpath, importance_csv, num_annotated=10):
# ToDO compute importance based on all layers
def manhattan_relative_importance(resultpath, importance_csv, num_annotated=10):
csv_file = importance_csv.copy()
plt.figure(figsize=(20, 10))

gene_middle = []

csv_file = csv_file.sort_values(by=['chr', 'node_layer_0'], ascending=True)
csv_file["pos"] = np.arange(len(csv_file))

if "chr" in csv_file.columns:
csv_file = csv_file.sort_values(by=['chr', 'node_layer_0'], ascending=True)
csv_file["pos"] = np.arange(len(csv_file))
color_end = np.sort(csv_file.groupby("chr")["pos"].max().values)
print('coloring per chromosome')
color_end = np.insert(color_end, 0, 0)
for i in range(len(color_end) - 1):
gene_middle.append((color_end[i] + color_end[i + 1]) / 2)
else:
csv_file = csv_file.sort_values(by=['node_layer_0'], ascending=True)
csv_file["pos"] = np.arange(len(csv_file))
color_end = np.sort(csv_file.groupby("node_layer_1")["pos"].max().values)
color_end = np.insert(color_end, 0, 0)
print("no chr information continuing by coloring per group in node_layer_1")
Expand All @@ -184,13 +190,13 @@ def manhattan_importance(resultpath, importance_csv, num_annotated=10):

plt.ylim(bottom=0, top=1.2)
plt.xlim(0, len(weights) + int(len(weights) / 100))
plt.title("Node importance", size=36)
plt.title("Relative importance of all SNPs", size=36)
if len(gene_middle) > 1:
plt.xticks(gene_middle, np.arange(len(gene_middle)) + 1, size=16)
plt.xlabel("Chromosome", size=18)
else:
plt.xlabel("Chromosome position", size=18)
plt.ylabel("Weights", size=18)
plt.ylabel("Relative importance", size=18)

offset = len(csv_file) / 200
offset = np.clip(offset, 0.1, 100)
Expand All @@ -208,7 +214,7 @@ def manhattan_importance(resultpath, importance_csv, num_annotated=10):
plt.gca().spines['right'].set_color('none')
plt.gca().spines['top'].set_color('none')

plt.savefig(resultpath + "Importance_manhattan_plot.png", bbox_inches='tight', pad_inches=0)
plt.savefig(resultpath + "Manhattan_relative_importance_SNPs.png", bbox_inches='tight', pad_inches=0)
plt.show()


Expand All @@ -221,8 +227,8 @@ def plot(args):
plot_layer_weight(resultpath, importance_csv, layer=layer, num_annotated=10)
elif args.type == "sunburst":
sunburst_plot(resultpath=resultpath, importance_csv=importance_csv)
elif args.type == "raw_importance":
manhattan_importance(resultpath=resultpath, importance_csv=importance_csv)
elif args.type == "manhattan_relative_importance":
manhattan_relative_importance(resultpath=resultpath, importance_csv=importance_csv)
else:
print("invalid type:", args.type)
exit()
202 changes: 101 additions & 101 deletions examples/example_classification/topology.csv
Original file line number Diff line number Diff line change
@@ -1,101 +1,101 @@
layer0_node,layer0_name,layer1_node,layer1_name,layer2_node,layer2_name
0 ,SNP0 ,0 ,HERC2 ,0 ,Causal_path
1 ,SNP1 ,0 ,HERC2 ,0 ,Causal_path
2 ,SNP2 ,0 ,HERC2 ,0 ,Causal_path
3 ,SNP3 ,0 ,HERC2 ,0 ,Causal_path
4 ,SNP4 ,0 ,HERC2 ,0 ,Causal_path
5 ,SNP5 ,1 ,BRCA2 ,0 ,Causal_path
6 ,SNP6 ,1 ,BRCA2 ,0 ,Causal_path
7 ,SNP7 ,1 ,BRCA2 ,0 ,Causal_path
8 ,SNP8 ,1 ,BRCA2 ,0 ,Causal_path
9 ,SNP9 ,1 ,BRCA2 ,0 ,Causal_path
10 ,SNP10 ,2 ,ApoE ,0 ,Causal_path
11 ,SNP11 ,2 ,ApoE ,0 ,Causal_path
12 ,SNP12 ,2 ,ApoE ,0 ,Causal_path
13 ,SNP13 ,2 ,ApoE ,0 ,Causal_path
14 ,SNP14 ,2 ,ApoE ,0 ,Causal_path
15 ,SNP15 ,2 ,ApoE ,0 ,Causal_path
16 ,SNP16 ,2 ,ApoE ,0 ,Causal_path
17 ,SNP17 ,2 ,ApoE ,0 ,Causal_path
18 ,SNP18 ,2 ,ApoE ,0 ,Causal_path
19 ,SNP19 ,2 ,ApoE ,0 ,Causal_path
20 ,SNP20 ,3 ,NRG ,0 ,Causal_path
21 ,SNP21 ,3 ,NRG ,0 ,Causal_path
22 ,SNP22 ,3 ,NRG ,0 ,Causal_path
23 ,SNP23 ,3 ,NRG ,0 ,Causal_path
24 ,SNP24 ,3 ,NRG ,0 ,Causal_path
25 ,SNP25 ,3 ,NRG ,0 ,Causal_path
26 ,SNP26 ,3 ,NRG ,0 ,Causal_path
27 ,SNP27 ,3 ,NRG ,0 ,Causal_path
28 ,SNP28 ,3 ,NRG ,0 ,Causal_path
29 ,SNP29 ,3 ,NRG ,0 ,Causal_path
30 ,SNP30 ,4 ,RGS-4 ,0 ,Causal_path
31 ,SNP31 ,4 ,RGS-4 ,0 ,Causal_path
32 ,SNP32 ,4 ,RGS-4 ,0 ,Causal_path
33 ,SNP33 ,4 ,RGS-4 ,0 ,Causal_path
34 ,SNP34 ,4 ,RGS-4 ,0 ,Causal_path
35 ,SNP35 ,4 ,RGS-4 ,0 ,Causal_path
36 ,SNP36 ,4 ,RGS-4 ,0 ,Causal_path
37 ,SNP37 ,4 ,RGS-4 ,0 ,Causal_path
38 ,SNP38 ,4 ,RGS-4 ,0 ,Causal_path
39 ,SNP39 ,4 ,RGS-4 ,0 ,Causal_path
40 ,SNP40 ,4 ,RGS-4 ,0 ,Causal_path
41 ,SNP41 ,4 ,RGS-4 ,0 ,Causal_path
42 ,SNP42 ,4 ,RGS-4 ,0 ,Causal_path
43 ,SNP43 ,4 ,RGS-4 ,0 ,Causal_path
44 ,SNP44 ,4 ,RGS-4 ,0 ,Causal_path
45 ,SNP45 ,4 ,RGS-4 ,0 ,Causal_path
46 ,SNP46 ,4 ,RGS-4 ,0 ,Causal_path
47 ,SNP47 ,4 ,RGS-4 ,0 ,Causal_path
48 ,SNP48 ,4 ,RGS-4 ,0 ,Causal_path
49 ,SNP49 ,4 ,RGS-4 ,0 ,Causal_path
50 ,SNP50 ,5 ,VEGFA ,1 ,Control_path
51 ,SNP51 ,5 ,VEGFA ,1 ,Control_path
52 ,SNP52 ,5 ,VEGFA ,1 ,Control_path
53 ,SNP53 ,5 ,VEGFA ,1 ,Control_path
54 ,SNP54 ,5 ,VEGFA ,1 ,Control_path
55 ,SNP55 ,5 ,VEGFA ,1 ,Control_path
56 ,SNP56 ,5 ,VEGFA ,1 ,Control_path
57 ,SNP57 ,5 ,VEGFA ,1 ,Control_path
58 ,SNP58 ,5 ,VEGFA ,1 ,Control_path
59 ,SNP59 ,5 ,VEGFA ,1 ,Control_path
60 ,SNP60 ,5 ,VEGFA ,1 ,Control_path
61 ,SNP61 ,5 ,VEGFA ,1 ,Control_path
62 ,SNP62 ,5 ,VEGFA ,1 ,Control_path
63 ,SNP63 ,5 ,VEGFA ,1 ,Control_path
64 ,SNP64 ,5 ,VEGFA ,1 ,Control_path
65 ,SNP65 ,5 ,VEGFA ,1 ,Control_path
66 ,SNP66 ,5 ,VEGFA ,1 ,Control_path
67 ,SNP67 ,5 ,VEGFA ,1 ,Control_path
68 ,SNP68 ,5 ,VEGFA ,1 ,Control_path
69 ,SNP69 ,5 ,VEGFA ,1 ,Control_path
70 ,SNP70 ,6 ,EGFR ,1 ,Control_path
71 ,SNP71 ,6 ,EGFR ,1 ,Control_path
72 ,SNP72 ,6 ,EGFR ,1 ,Control_path
73 ,SNP73 ,6 ,EGFR ,1 ,Control_path
74 ,SNP74 ,6 ,EGFR ,1 ,Control_path
75 ,SNP75 ,6 ,EGFR ,1 ,Control_path
76 ,SNP76 ,6 ,EGFR ,1 ,Control_path
77 ,SNP77 ,6 ,EGFR ,1 ,Control_path
78 ,SNP78 ,6 ,EGFR ,1 ,Control_path
79 ,SNP79 ,6 ,EGFR ,1 ,Control_path
80 ,SNP80 ,7 ,TGFBI ,1 ,Control_path
81 ,SNP81 ,7 ,TGFBI ,1 ,Control_path
82 ,SNP82 ,7 ,TGFBI ,1 ,Control_path
83 ,SNP83 ,7 ,TGFBI ,1 ,Control_path
84 ,SNP84 ,7 ,TGFBI ,1 ,Control_path
85 ,SNP85 ,7 ,TGFBI ,1 ,Control_path
86 ,SNP86 ,7 ,TGFBI ,1 ,Control_path
87 ,SNP87 ,7 ,TGFBI ,1 ,Control_path
88 ,SNP88 ,7 ,TGFBI ,1 ,Control_path
89 ,SNP89 ,7 ,TGFBI ,1 ,Control_path
90 ,SNP90 ,8 ,TNF ,1 ,Control_path
91 ,SNP91 ,8 ,TNF ,1 ,Control_path
92 ,SNP92 ,8 ,TNF ,1 ,Control_path
93 ,SNP93 ,8 ,TNF ,1 ,Control_path
94 ,SNP94 ,8 ,TNF ,1 ,Control_path
95 ,SNP95 ,9 ,IL6 ,1 ,Control_path
96 ,SNP96 ,9 ,IL6 ,1 ,Control_path
97 ,SNP97 ,9 ,IL6 ,1 ,Control_path
98 ,SNP98 ,9 ,IL6 ,1 ,Control_path
99 ,SNP99 ,9 ,IL6 ,1 ,Control_path
chr,layer0_node,layer0_name,layer1_node,layer1_name,layer2_node,layer2_name
0,0,SNP0 ,0,HERC2 ,0,Causal_path
0,1,SNP1 ,0,HERC2 ,0,Causal_path
0,2,SNP2 ,0,HERC2 ,0,Causal_path
0,3,SNP3 ,0,HERC2 ,0,Causal_path
0,4,SNP4 ,0,HERC2 ,0,Causal_path
1,5,SNP5 ,1,BRCA2 ,0,Causal_path
1,6,SNP6 ,1,BRCA2 ,0,Causal_path
1,7,SNP7 ,1,BRCA2 ,0,Causal_path
1,8,SNP8 ,1,BRCA2 ,0,Causal_path
1,9,SNP9 ,1,BRCA2 ,0,Causal_path
2,10,SNP10 ,2,ApoE ,0,Causal_path
2,11,SNP11 ,2,ApoE ,0,Causal_path
2,12,SNP12 ,2,ApoE ,0,Causal_path
2,13,SNP13 ,2,ApoE ,0,Causal_path
2,14,SNP14 ,2,ApoE ,0,Causal_path
2,15,SNP15 ,2,ApoE ,0,Causal_path
2,16,SNP16 ,2,ApoE ,0,Causal_path
2,17,SNP17 ,2,ApoE ,0,Causal_path
2,18,SNP18 ,2,ApoE ,0,Causal_path
2,19,SNP19 ,2,ApoE ,0,Causal_path
3,20,SNP20 ,3,NRG ,0,Causal_path
3,21,SNP21 ,3,NRG ,0,Causal_path
3,22,SNP22 ,3,NRG ,0,Causal_path
3,23,SNP23 ,3,NRG ,0,Causal_path
3,24,SNP24 ,3,NRG ,0,Causal_path
3,25,SNP25 ,3,NRG ,0,Causal_path
3,26,SNP26 ,3,NRG ,0,Causal_path
3,27,SNP27 ,3,NRG ,0,Causal_path
3,28,SNP28 ,3,NRG ,0,Causal_path
3,29,SNP29 ,3,NRG ,0,Causal_path
4,30,SNP30 ,4,RGS-4 ,0,Causal_path
4,31,SNP31 ,4,RGS-4 ,0,Causal_path
4,32,SNP32 ,4,RGS-4 ,0,Causal_path
4,33,SNP33 ,4,RGS-4 ,0,Causal_path
4,34,SNP34 ,4,RGS-4 ,0,Causal_path
4,35,SNP35 ,4,RGS-4 ,0,Causal_path
4,36,SNP36 ,4,RGS-4 ,0,Causal_path
4,37,SNP37 ,4,RGS-4 ,0,Causal_path
4,38,SNP38 ,4,RGS-4 ,0,Causal_path
4,39,SNP39 ,4,RGS-4 ,0,Causal_path
4,40,SNP40 ,4,RGS-4 ,0,Causal_path
4,41,SNP41 ,4,RGS-4 ,0,Causal_path
4,42,SNP42 ,4,RGS-4 ,0,Causal_path
4,43,SNP43 ,4,RGS-4 ,0,Causal_path
4,44,SNP44 ,4,RGS-4 ,0,Causal_path
4,45,SNP45 ,4,RGS-4 ,0,Causal_path
4,46,SNP46 ,4,RGS-4 ,0,Causal_path
4,47,SNP47 ,4,RGS-4 ,0,Causal_path
4,48,SNP48 ,4,RGS-4 ,0,Causal_path
4,49,SNP49 ,4,RGS-4 ,0,Causal_path
5,50,SNP50 ,5,VEGFA ,1,Control_path
5,51,SNP51 ,5,VEGFA ,1,Control_path
5,52,SNP52 ,5,VEGFA ,1,Control_path
5,53,SNP53 ,5,VEGFA ,1,Control_path
5,54,SNP54 ,5,VEGFA ,1,Control_path
5,55,SNP55 ,5,VEGFA ,1,Control_path
5,56,SNP56 ,5,VEGFA ,1,Control_path
5,57,SNP57 ,5,VEGFA ,1,Control_path
5,58,SNP58 ,5,VEGFA ,1,Control_path
5,59,SNP59 ,5,VEGFA ,1,Control_path
5,60,SNP60 ,5,VEGFA ,1,Control_path
5,61,SNP61 ,5,VEGFA ,1,Control_path
5,62,SNP62 ,5,VEGFA ,1,Control_path
5,63,SNP63 ,5,VEGFA ,1,Control_path
5,64,SNP64 ,5,VEGFA ,1,Control_path
5,65,SNP65 ,5,VEGFA ,1,Control_path
5,66,SNP66 ,5,VEGFA ,1,Control_path
5,67,SNP67 ,5,VEGFA ,1,Control_path
5,68,SNP68 ,5,VEGFA ,1,Control_path
5,69,SNP69 ,5,VEGFA ,1,Control_path
6,70,SNP70 ,6,EGFR ,1,Control_path
6,71,SNP71 ,6,EGFR ,1,Control_path
6,72,SNP72 ,6,EGFR ,1,Control_path
6,73,SNP73 ,6,EGFR ,1,Control_path
6,74,SNP74 ,6,EGFR ,1,Control_path
6,75,SNP75 ,6,EGFR ,1,Control_path
6,76,SNP76 ,6,EGFR ,1,Control_path
6,77,SNP77 ,6,EGFR ,1,Control_path
6,78,SNP78 ,6,EGFR ,1,Control_path
6,79,SNP79 ,6,EGFR ,1,Control_path
7,80,SNP80 ,7,TGFBI ,1,Control_path
7,81,SNP81 ,7,TGFBI ,1,Control_path
7,82,SNP82 ,7,TGFBI ,1,Control_path
7,83,SNP83 ,7,TGFBI ,1,Control_path
7,84,SNP84 ,7,TGFBI ,1,Control_path
7,85,SNP85 ,7,TGFBI ,1,Control_path
7,86,SNP86 ,7,TGFBI ,1,Control_path
7,87,SNP87 ,7,TGFBI ,1,Control_path
7,88,SNP88 ,7,TGFBI ,1,Control_path
7,89,SNP89 ,7,TGFBI ,1,Control_path
8,90,SNP90 ,8,TNF ,1,Control_path
8,91,SNP91 ,8,TNF ,1,Control_path
8,92,SNP92 ,8,TNF ,1,Control_path
8,93,SNP93 ,8,TNF ,1,Control_path
8,94,SNP94 ,8,TNF ,1,Control_path
9,95,SNP95 ,9,IL6 ,1,Control_path
9,96,SNP96 ,9,IL6 ,1,Control_path
9,97,SNP97 ,9,IL6 ,1,Control_path
9,98,SNP98 ,9,IL6 ,1,Control_path
9,99,SNP99 ,9,IL6 ,1,Control_path
Loading

0 comments on commit 669dc1f

Please sign in to comment.