-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathload_paga_graph.R
39 lines (31 loc) · 1.05 KB
/
load_paga_graph.R
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
library(GGally)
library(network)
library(sna)
library(ggraph)
library(igraph)
library(tidygraph)
connectivity.mtx <- fread(io$paga.connectivity) %>%
matrix.please %>% .[opts$celltypes,opts$celltypes]
df.coordinates <- fread(io$paga.coordinates) %>%
matrix.please %>% .[opts$celltypes,]
# Parse data
connectivity.mtx[connectivity.mtx<0.20] <- 0
connectivity.mtx[connectivity.mtx>=0.20] <- 1
# Create igraph object
igraph.paga <- graph_from_adjacency_matrix(connectivity.mtx, mode = "undirected")
# Create tbl_graph object
igraph.paga.tbl <- as_tbl_graph(igraph.paga) %>%
activate(nodes) %>%
mutate(celltype=rownames(connectivity.mtx)) %>%
mutate(x=df.coordinates[,1]) %>% mutate(y=df.coordinates[,2])
# Create network object
net.paga = network(connectivity.mtx)
net.paga %v% "x" = connectivity.mtx[, 1]
net.paga %v% "y" = connectivity.mtx[, 2]
##########
## TEST ##
##########
# sum(connectivity.mtx==1)
# connectivity.mtx["Epiblast","Rostral_neurectoderm"]
# igraph.paga.tbl %>% activate(edges) %>% as.data.table() %>% nrow
# filter(celltype=="Epiblast")