Skip to content

Commit 72ec4ef

Browse files
author
William Ryan
committed
Add subnetworks by seed gene
1 parent 1bb36b0 commit 72ec4ef

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

networks.qmd

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,48 @@ generate_subnetwork <- function(kinograte_res, genes) {
4646
plot
4747
4848
}
49+
50+
generate_seeded_network <- function(kinograte_res, gene, degree=1) {
51+
network <- kinograte_res$network
52+
nodes <- kinograte_res$nodes
53+
54+
subnet <- make_ego_graph(network, gene, order = degree)[[1]] %>%
55+
delete_vertices(V(.)[degree(.) == 0]) %>%
56+
asNetwork()
57+
58+
plot_data <- ggnetwork(subnet, layout = "fruchtermanreingold") %>%
59+
inner_join(nodes, by = c("vertex.names" = "Protein")) %>%
60+
mutate(RNA = as.numeric(str_detect(type.y, "RNA")),
61+
Kinase = as.numeric(str_detect(type.y, "Kinase")),
62+
Hidden = as.numeric(str_detect(type.y, "Hidden")),
63+
Protein = as.numeric(str_detect(type.y, "Protein")),
64+
Peptide = as.numeric(str_detect(type.y, "Peptide")),
65+
TF = as.numeric(str_detect(type.y, "TF")))
66+
67+
plot = plot_data %>%
68+
ggplot(aes(x = x, y = y, xend = xend, yend = yend)) +
69+
geom_edges(color = "grey50", curvature = 0.05) +
70+
geom_scatterpie(data = plot_data %>% distinct(vertex.names, .keep_all = TRUE), cols = c("RNA", "Kinase", "Hidden", "Protein", "Peptide", "TF"), pie_scale = .5) +
71+
geom_nodetext_repel(aes(label = vertex.names), family = "Arial Narrow", fontface = "bold.italic", size = 9 / ggplot2:::.pt, box.padding = unit(.25, "lines")) +
72+
coord_equal() +
73+
theme_blank() +
74+
theme(legend.position = "none")
75+
76+
plot
77+
}
78+
4979
```
5080

5181
```{r}
5282
genes_input <- names(combined) %>% sample(100)
5383
5484
plot <- generate_subnetwork(kinograte_res, genes_input)
5585
86+
plot
87+
88+
gene_input <- names(combined) %>% sample(1)
89+
90+
plot <- generate_seeded_network(kinograte_res, gene_input, 1)
91+
5692
plot
5793
```

0 commit comments

Comments
 (0)