-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAssociated and Non-associated genes + Networks
134 lines (94 loc) · 3.53 KB
/
Associated and Non-associated genes + 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
122
123
124
125
126
127
128
129
130
131
132
#install packages
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")
#load packages
library("readr")
library("STRINGdb")
library("igraph")
library("rbioapi")
library("fitdistrplus")
library("gprofiler2")
library("MASS")
library("survival")
library("fitdistrplus")
#------------------------------------------------
#Associated
#Top lowest P-values
#upload magma p.r3 file
file_path <- file.choose()
data_matrix <- read.table(file_path, header = TRUE)
# Get the p-values from column X
p_values <- data_matrix[-1, X]
sorted_p_values <- sort(p_values)
top_500_p_values <- head(sorted_p_values, 500)
indices <- which(data_matrix[-1, X] %in% top_500_p_values)
related_names <- data_matrix[indices + 1, 1] # Adding 1 to indices due to header row
# Choose the file path to save the results
output_file <- file.choose()
write.table(related_names, file = output_file, col.names = FALSE, row.names = FALSE, quote = FALSE)
cat("Result saved to file:", output_file, "\n")
#Non-Associated
#Top highest P-values
file_path <- file.choose()
data_matrix <- read.table(file_path, header = TRUE)
p_values <- data_matrix[-1, X]
sorted_p_values <- sort(p_values, decreasing = TRUE)
top_500_p_values <- head(sorted_p_values, 500)
indices <- which(data_matrix[-1, X] %in% top_500_p_values)
related_names <- data_matrix[indices + 1, 1] # Adding 1 to indices due to header row
output_file <- file.choose()
write.table(related_names, file = output_file, col.names = FALSE, row.names = FALSE, quote = FALSE)
cat("Result saved to file:", output_file, "\n")
data_matrix <- read.table(file_path, header = TRUE)
p_values <- data_matrix[-1, X]
sorted_p_values <- sort(p_values)
top_500_p_values <- head(sorted_p_values, 500)
indices <- which(data_matrix[-1, X] %in% top_500_p_values)
related_names <- data_matrix[indices + 1, 1] # Adding 1 to indices due to header row
# Map the related names to IDs using the gconvert function
X <- gconvert(query = related_names, organism = "hsapiens", target = "ENSG")
proteins <- X$name
proteins <- as.character(proteins)
# Map protein symbols to IDs
proteins_mapped <- rba_string_map_ids(ids = proteins, species = 9606)
proteins_ids <- proteins_mapped$stringId
# Create the interaction network
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
folder_path <- dirname(file.choose())
# Plot the graph
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)
# Save the plot as PNG in the chosen folder
png(file.path(folder_path, "graph_plot.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()