-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVisualization Gene-Gene Interaction Networks
121 lines (85 loc) · 5.89 KB
/
Visualization Gene-Gene Interaction Networks
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
In Python:
import pandas as pd
import networkx as nx
import matplotlib.pyplot as plt
from matplotlib.backends.backend_pdf import PdfPages
def create_and_save_network(csv_file, pdf_pages):
adj_matrix = pd.read_csv(csv_file, index_col=0)
G = nx.from_pandas_adjacency(adj_matrix)
G.remove_nodes_from(list(nx.isolates(G)))
plt.figure(figsize=(10, 9))
pos = nx.spring_layout(G, k=0.17) # Larger k means more space between nodes
nx.draw(G, pos, with_labels=True, node_color='gray', edge_color='black',
node_size=300, font_color='black', font_size=5,
edgecolors='black') # Use edgecolors for node borders
pdf_pages.savefig()
plt.close()
file = r'Path to_adjacency matrix (A)\adj_matrix_col_num_X.csv'
with PdfPages('network_A_X.pdf') as pdf_pages:
create_and_save_network(file, pdf_pages)
-------------------------------------------------------------------------------------------
#in R:
install.packages("readr")
if (!requireNamespace("BiocManager", quietly = TRUE))
install.packages("BiocManager")
BiocManager::install("STRINGdb")
install.packages("STRINGdb")
install.packages("igraph")
install.packages("rbioapi")
install.packages("fitdistrplus")
install.packages("gprofiler2")
install.packages("MASS")
install.packages("survival")
library("readr")
library("STRINGdb")
library("igraph")
library("rbioapi")
library("fitdistrplus")
library("gprofiler2")
library("MASS")
library("survival")
library("fitdistrplus")
file_path <- file.choose()
data_matrix <- read.table(file_path, header = TRUE)
# Define the list of columns A (traits=columns-1)
A <- c(10, 11 ,12 ,14 ,42 ,47 ,54 ,62 ,63 ,64 ,68 ,69 ,70 ,71 ,72 ,73 ,74 ,75 ,95 ,96 ,97 ,109 ,114 ,119 ,127 ,128 ,143 ,144 ,147 ,156 ,157 ,162 ,163 ,168 ,169 ,174 ,175 ,192 ,194 ,207 ,209 ,1005 ,1068 ,1194 ,1195 ,1203 ,1204 ,1205 ,2025 ,2030 ,2031 ,2032 ,2035 ,2038 ,2053 ,2176 ,3186 ,3187 ,3188 ,3189 ,3191 ,3192 ,3196 ,3201 ,3202 ,3211 ,3218 ,3220 ,3221 ,3229 ,3230 ,3231 ,3232 ,3233 ,3234 ,3237 ,3242 ,3243 ,3245 ,3247 ,3251 ,3252 ,3254 ,3255 ,3256 ,3257 ,3258 ,3259 ,3262 ,3271 ,3272 ,3274 ,3275 ,3276 ,3277 ,3283 ,3284 ,3285 ,3286 ,3287 ,3288 ,3289 ,3290 ,3291 ,3292 ,3293 ,3301 ,3302 ,3305 ,3306 ,3308 ,3309 ,3311 ,3313 ,3314 ,3315 ,3316 ,3320 ,3325 ,3329 ,3333 ,3340 ,3341 ,3343 ,3344 ,3367 ,3373 ,3380 ,3381 ,3410 ,3413 ,3414 ,3415 ,3416 ,3418 ,3419 ,3426 ,3432 ,3436 ,3437 ,3438 ,3439 ,3441 ,3442 ,3443 ,3444 ,3445 ,3446 ,3447 ,3448 ,3449 ,3450 ,3451 ,3452 ,3453 ,3454 ,3455 ,3456 ,3457 ,3458 ,3459 ,3460 ,3461 ,3462 ,3463 ,3464 ,3465 ,3466 ,3467 ,3468 ,3469 ,3470 ,3471 ,3472 ,3486 ,3495 ,3496 ,3497 ,3498 ,3499 ,3500 ,3501 ,3504 ,3530 ,3532 ,3540 ,3545 ,3550 ,3552 ,3553 ,3554 ,3555 ,3556 ,3560 ,3571 ,3579 ,3591 ,3592 ,3598 ,3600 ,3602 ,3603 ,3606 ,3607 ,3609 ,3614 ,3626 ,3655 ,3659 ,3661 ,3666 ,3669 ,3686 ,3687 ,3689 ,3692 ,3696 ,3786 ,3790 ,3792 ,3794 ,3795 ,3796 ,3798 ,3799 ,3816 ,3819 ,3820 ,3821 ,3823 ,3824 ,3825 ,3833 ,3834 ,3835 ,3836 ,3837 ,3838 ,3839 ,3840 ,3841 ,3842 ,3843 ,3844 ,3845 ,3846 ,3847 ,3848 ,3849 ,3850 ,3851 ,3852 ,3853 ,3854 ,3855 ,3856 ,3857 ,3858 ,3859 ,3860 ,3861 ,3862 ,3863 ,3864 ,3865 ,3866 ,3867 ,3868 ,3869 ,3870 ,3871 ,3872 ,3873 ,3874 ,3875 ,3876 ,3877 ,3878 ,3879 ,3880 ,3881 ,3882 ,3883 ,3884 ,3885 ,3886 ,3887 ,3888 ,3889 ,3890 ,3891 ,3892 ,3893 ,3894 ,3895 ,3896 ,3897 ,3898 ,3899 ,3900 ,3901 ,3902 ,3903 ,3904 ,3905 ,3909 ,3911 ,3926 ,3940 ,3944 ,3967 ,3968 ,3969 ,3972 ,3980 ,3983 ,3991 ,3992 ,3993 ,3994 ,3995 ,3996 ,3997 ,3998 ,4000 ,4003 ,4012 ,4019 ,4039 ,4041 ,4044 ,4045 ,4046 ,4051 ,4064 ,4067 ,4068 ,4069 ,4070 ,4071 ,4072 ,4073 ,4074 ,4075 ,4076 ,4077 ,4078 ,4079 ,4080 ,4081 ,4082 ,4083 ,4086 ,4087 ,4088 ,4092 ,4093 ,4094 ,4095 ,4099 ,4100 ,4101 ,4102 ,4105 ,4107 ,4108 ,4109 ,4110 ,4111 ,4112 ,4120 ,4121 ,4122 ,4123 ,4127 ,4130 ,4136 ,4139 ,4140 ,4141 ,4142 ,4143 ,4145 ,4167 ,4168 ,4176 ,4177 ,4179 ,4182 ,4184 ,4185 ,4188 ,4201 ,4206 ,4207 ,4208 ,4209 ,4216 ,4218 ,4222 ,4223 ,4224 ,4225 ,4226 ,4227 ,4228 ,4233 ,4236 ,4237 ,4267 ,4268 ,4269 ,4270 ,4273 ,4276 ,4279 ,4280 ,4281 ,4282 ,4283 ,4284 ,4285 ,4286 ,4291 ,4294 ,4295 ,4296 ,4300 ,4302 ,4303 ,4304 ,4305 ,4306 ,4307 ,4308 ,4309 ,4310 ,4312 ,4315 ,4316 ,4318 ,4322 ,4323 ,4326 ,4327 ,4328 ,4329 ,4346 ,4347 ,4348 ,4349 ,4352 ,4353 ,4358 ,4359 ,4362 ,4364 ,4366 ,4373 ,4378 ,4379)
for (col_num in A) {
p_values <- data_matrix[-1, col_num]
sorted_p_values <- sort(p_values)
#, decreasing = TRUE
top_500_p_values <- head(sorted_p_values, 500)
indices <- which(data_matrix[-1, col_num] %in% top_500_p_values)
related_names <- data_matrix[indices + 1, 1] # Adding 1 to indices due to header row
X <- gconvert(query = related_names, organism = "hsapiens", target = "ENSG")
proteins <- X$name
proteins <- as.character(proteins)
proteins_mapped <- rba_string_map_ids(ids = proteins, species = 9606)
proteins_ids <- proteins_mapped$stringId
int_net <- rba_string_interactions_network(ids = proteins_ids,
species = 9606,
network_type = "functional",
required_score = 900)
matrix <- int_net[, c(3, 4, 6)] # Assuming the columns are for gene names, scores, and IDs
library(igraph)
graph <- graph_from_data_frame(matrix, directed = FALSE)
E(graph)$weight <- matrix$score
graph <- simplify(graph)
node_color <- "#808080" # Gray
edge_color <- "#000000" # Black
plot(graph,
vertex.size = 8,
vertex.label.cex = 0.5,
vertex.label.color = "black",
vertex.color = node_color,
edge.color = edge_color,
edge.width = 5)
png(file.path(folder_path, paste0("graph_plot_", col_num-1, ".png")))
plot(graph,
vertex.size = 8,
vertex.label.cex = 0.5,
vertex.label.color = "black",
vertex.color = node_color,
edge.color = edge_color,
edge.width = 5)
dev.off()
}