Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- R/Palettes.R +53 -0
- R/allenAnnotationsFunctions.R +151 -0
- R/includes.R +11 -0
R/Palettes.R
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
col_cluster <- list()
|
2 |
+
col_cluster[["SubType_Layer"]] <- c(
|
3 |
+
"L2/3 IT" = '#ffda11', "L4/5 IT" = '#f68d45', "L5 IT" = '#26d5ff', "L6 IT" = '#f05a9e',
|
4 |
+
"L5 PT" = '#6d92ff', "L5 NP" = '#8976ff', "L6 CT" = '#e01fff',
|
5 |
+
'Pvalb' = '#c48983', 'Sst' = '#c7b766', 'Vip' = '#0092b6', 'Lamp5' = '#a9d166',
|
6 |
+
"Astro" = '#d08fbe', "Endo" = '#bb7967', "Microglia" = '#00a7cf', "Oligo" = '#5e45a6',
|
7 |
+
"OPC" = '#1470d6')
|
8 |
+
col_cluster[["SubType"]] <- c(
|
9 |
+
"L2/3_IT_1"='#ffd600', "L2/3_IT_2"='#ffff8d',
|
10 |
+
"L4/5_IT_1"='#ff6d00', "L4/5_IT_2"='#ffd180',
|
11 |
+
"L5_IT_1"='#0091ea', "L5_IT_2"='#80d8ff',
|
12 |
+
"L6_IT_1"='#c51162', "L6_IT_2"='#ff80ab',
|
13 |
+
"L5_PT_1"='#304ffe', "L5_PT_2"='#8c9eff',
|
14 |
+
"L5_NP"='#8976ff',
|
15 |
+
"L6_CT_1"='#f05a9e', "L6_CT_2"="#d75ff6")
|
16 |
+
|
17 |
+
col_sample <- c('Adult1' = "#1e76b2", 'Adult2' = "#fd7e0c", 'Adult3' = "#2a9c67")
|
18 |
+
|
19 |
+
col_Glu_GABA <- c('Excitatory' = "#7570B3FF", 'Inhibitory' = "#E7298AFF",
|
20 |
+
'Non-neuron' = "#66A61EFF")
|
21 |
+
|
22 |
+
col_MainType <- c('Excitatory' = "#7570B3FF", 'Inhibitory' = "#E7298AFF",
|
23 |
+
'Astro' = "#d08fbe", 'Endo' = "#bb7967", 'Microglia' = "#00a7cf",
|
24 |
+
'Oligo' = "#5e45a6", 'OPC' = "#1470d6")
|
25 |
+
|
26 |
+
|
27 |
+
|
28 |
+
col_BC_label <- c(Barcoded = '#f8cb7f', Unbarcoded = '#90a5e1')
|
29 |
+
|
30 |
+
col_Barcode <- c(
|
31 |
+
'VIS-I'="#536dfe",'CP-I'="#448aff",'SSp-I'="#40c4ff",'AUD-I'="#18ffff",'RSP-I'="#84ffff",
|
32 |
+
'ACB-I'="#ff6e40",'BLA-I'="#ffab40",'ENTl-I'="#ffd740",'AId-I'="#ffff00",'ECT-I'="#ffff8d",
|
33 |
+
'CP-C'="#00bfa5",'PL-C'="#00c853",'RSP-C'="#64dd17",
|
34 |
+
'ACB-C'="#a7ffeb",'BLA-C'="#b9f6ca",'ENTl-C'="#ccff90",'AId-C'="#b2ff59",'ECT-C'="#69f0ae",
|
35 |
+
'MD-I'="#ff5252",'LHA-I'="#ff4081",'SC-I'="#e040fb",'DR-I'="#ff8a80",'RE-I'="#ff80ab",'VTA-I'="#ea80fc",
|
36 |
+
'none'="lightgray")
|
37 |
+
|
38 |
+
col_BC_num <- c('#5e4fa2','#3288bd','#66c2a5','#abdda4','#e6f598','#fee08b','#fdae61',
|
39 |
+
'#f46d43','#d53e4f','#9e0142')
|
40 |
+
|
41 |
+
col_Proj_module <- c('ITi-D'='#1f77b4', 'ITi-V'='#ff7f0e','ITc'='#2ca02c','PTi'='#d62728')
|
42 |
+
col_Proj_subtype <- c(
|
43 |
+
"1"="#304ffe","14"="#3d5afe","17"="#536dfe","22"="#8c9eff","23"="#2962ff","25"="#2979ff",
|
44 |
+
"26"="#448aff","27"="#82b1ff","28"="#80d8ff","29"="#0091ea","31"="#00b0ff",
|
45 |
+
"7"="#dd2c00","8"="#ff3d00","9"="#ff6e40","10"="#ff9e80","15"="#ff6d00","16"="#ff9100",
|
46 |
+
"18"="#ffab40","19"="#ffd180","20"="#ffab00","21"="#ffc400",
|
47 |
+
"2"="#00c853","3"="#00e676","11"="#69f0ae","12"="#b9f6ca","13"="#64dd17","24"="#76ff03",
|
48 |
+
"30"="#b2ff59","32"="#ccff90","33"="#aeea00",
|
49 |
+
"4"="#d50000","5"="#ff8a80","6"="#f50057")
|
50 |
+
|
51 |
+
col_Proj_ITPT <- c('IT'='#1f77b4', 'PT'='#d62728')
|
52 |
+
col_D_V <- c('Dorsal'='#1f77b4', 'Ventral'='#ff7f0e')
|
53 |
+
|
R/allenAnnotationsFunctions.R
ADDED
@@ -0,0 +1,151 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#------------------ Librairies ------------------
|
2 |
+
library(rjson)
|
3 |
+
|
4 |
+
|
5 |
+
|
6 |
+
#------------------ Ontology handling ------------------
|
7 |
+
|
8 |
+
get.id.from.acronym <- function(acronym){
|
9 |
+
|
10 |
+
rec.func <- function(acronym, json){
|
11 |
+
|
12 |
+
if(is.null(json))
|
13 |
+
return()
|
14 |
+
|
15 |
+
if(acronym == json$acronym)
|
16 |
+
return(json$id)
|
17 |
+
|
18 |
+
return(unlist(lapply(json$children, function(x){return(rec.func(acronym, x))})))
|
19 |
+
}
|
20 |
+
|
21 |
+
#Loading json data
|
22 |
+
json_data <- fromJSON(file= paste(path.matrices,'ontology.json',sep='/'))
|
23 |
+
json <- json_data$msg[[1]]
|
24 |
+
|
25 |
+
return(rec.func(acronym, json))
|
26 |
+
}
|
27 |
+
|
28 |
+
|
29 |
+
|
30 |
+
#------------------ 3D handling ------------------
|
31 |
+
|
32 |
+
mesh3d.allen.annot.from.id <- function(id, max.nrows = 349696, bregma = c(5200, 650, 5700)/1000, no.normals = F){ #5400, 650, 5700 In mm, AP/DV/ML
|
33 |
+
|
34 |
+
fpath <- sprintf('%s/%d.obj', allen.annot.path, id)
|
35 |
+
|
36 |
+
vert.start <- 0
|
37 |
+
vert.end <- 0
|
38 |
+
norm.start <- 0
|
39 |
+
norm.end <- 0
|
40 |
+
face.start <- 0
|
41 |
+
face.end <- 0
|
42 |
+
i <- 0
|
43 |
+
|
44 |
+
con <- file(fpath, 'r')
|
45 |
+
while(TRUE){
|
46 |
+
|
47 |
+
i <- i + 1
|
48 |
+
line = readLines(con, n = 1)
|
49 |
+
|
50 |
+
if (length(line) == 0)
|
51 |
+
break
|
52 |
+
|
53 |
+
if(startsWith(line, 'v ') & vert.start == 0)
|
54 |
+
vert.start <- i
|
55 |
+
|
56 |
+
if(vert.start != 0 & vert.end == 0 & !startsWith(line, 'v '))
|
57 |
+
vert.end <- i
|
58 |
+
|
59 |
+
if(startsWith(line, 'vn') & norm.start == 0)
|
60 |
+
norm.start <- i
|
61 |
+
|
62 |
+
if(norm.start !=0 & norm.end == 0 & !startsWith(line, 'vn'))
|
63 |
+
norm.end <- i
|
64 |
+
|
65 |
+
if(startsWith(line, 'f') & face.start == 0)
|
66 |
+
face.start <- i
|
67 |
+
|
68 |
+
if(face.start !=0 & face.end == 0 & !startsWith(line, 'f'))
|
69 |
+
face.end <- i
|
70 |
+
|
71 |
+
}
|
72 |
+
|
73 |
+
if(face.end == 0)
|
74 |
+
face.end <- i - 1
|
75 |
+
|
76 |
+
close(con)
|
77 |
+
|
78 |
+
con <- file(fpath, 'r')
|
79 |
+
line = readLines(con, n = (vert.start - 1))
|
80 |
+
line = readLines(con, n = vert.end - vert.start)
|
81 |
+
vertices <- strsplit(line, ' ')
|
82 |
+
vertices.ul <- unlist(vertices)
|
83 |
+
df.vertices <- data.frame(x = as.numeric(vertices.ul[seq(from = 2, to = 4*length(vertices), by = 4)]),
|
84 |
+
y = as.numeric(vertices.ul[seq(from = 3, to = 4*length(vertices), by = 4)]),
|
85 |
+
z = as.numeric(vertices.ul[seq(from = 4, to = 4*length(vertices), by = 4)]))
|
86 |
+
close(con)
|
87 |
+
|
88 |
+
con <- file(fpath, 'r')
|
89 |
+
line = readLines(con, n = (norm.start - 1))
|
90 |
+
line = readLines(con, n = norm.end - norm.start)
|
91 |
+
norm <- strsplit(line, ' ')
|
92 |
+
norm.ul <- unlist(vertices)
|
93 |
+
df.norm <- data.frame( x = as.numeric(norm.ul[seq(from = 2, to = 4*length(norm), by = 4)]),
|
94 |
+
y = as.numeric(norm.ul[seq(from = 3, to = 4*length(norm), by = 4)]),
|
95 |
+
z = as.numeric(norm.ul[seq(from = 4, to = 4*length(norm), by = 4)]))
|
96 |
+
close(con)
|
97 |
+
|
98 |
+
con <- file(fpath, 'r')
|
99 |
+
line = readLines(con, n = (face.start - 1))
|
100 |
+
line = readLines(con, n = face.end - face.start)
|
101 |
+
face <- strsplit(line, ' ')
|
102 |
+
face <- lapply(face, function(x){return(unlist(strsplit(x, '//')))})
|
103 |
+
face.ul <- unlist(face)
|
104 |
+
|
105 |
+
df.face <- data.frame( x = as.numeric(face.ul[seq(from = 2, to = 7*length(face), by = 7)]),
|
106 |
+
y = as.numeric(face.ul[seq(from = 4, to = 7*length(face), by = 7)]),
|
107 |
+
z = as.numeric(face.ul[seq(from = 6, to = 7*length(face), by = 7)]))
|
108 |
+
close(con)
|
109 |
+
|
110 |
+
if(!no.normals){
|
111 |
+
mesh <- tmesh3d(vertices = rbind(t(df.vertices),1),
|
112 |
+
indices = t(df.face),
|
113 |
+
normals = t(df.norm)[c(3,2,1),])
|
114 |
+
}else{
|
115 |
+
mesh <- tmesh3d(vertices = rbind(t(df.vertices),1),
|
116 |
+
indices = t(df.face))
|
117 |
+
}
|
118 |
+
|
119 |
+
mesh$vb[1:3,] <- mesh$vb[1:3,] / 1000
|
120 |
+
|
121 |
+
mesh$vb[1,] <- -mesh$vb[1,] + bregma[1]
|
122 |
+
mesh$vb[2,] <- -mesh$vb[2,] + 0.05 #Maybe not the +0.05
|
123 |
+
mesh$vb[3,] <- -mesh$vb[3,] + bregma[3]
|
124 |
+
|
125 |
+
tmp <- mesh$vb[1,]
|
126 |
+
mesh$vb[1,] <- mesh$vb[3,]
|
127 |
+
mesh$vb[3,] <- tmp
|
128 |
+
|
129 |
+
return(mesh)
|
130 |
+
|
131 |
+
}
|
132 |
+
|
133 |
+
|
134 |
+
|
135 |
+
mesh3d.show.outline <- function(col = 'lightgray', alpha = 0.1){
|
136 |
+
shade3d(mesh3d.allen.annot.from.id(get.id.from.acronym('root')), col = col, alpha = alpha)
|
137 |
+
}
|
138 |
+
|
139 |
+
mesh3d.new.window <- function(show.outline = TRUE){
|
140 |
+
|
141 |
+
rgl.open()
|
142 |
+
rgl.bg(color = 'white')
|
143 |
+
par3d(windowRect = c(0, 0, 1920, 1080))
|
144 |
+
|
145 |
+
if(show.outline)
|
146 |
+
mesh3d.show.outline()
|
147 |
+
}
|
148 |
+
|
149 |
+
|
150 |
+
|
151 |
+
|
R/includes.R
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
library(rgl)
|
2 |
+
#library(wholebrain)
|
3 |
+
|
4 |
+
path.bin <- 'R/'
|
5 |
+
path.matrices <-'data/3D_data/'
|
6 |
+
allen.annot.path <- paste(path.matrices , 'allen-mesh', sep = '/')
|
7 |
+
|
8 |
+
load(paste(path.matrices ,'atlasspots.RData',sep='/'))
|
9 |
+
load(paste(path.matrices , 'vivid-colors.RData', sep='/'))
|
10 |
+
|
11 |
+
source(paste(path.bin,'allenAnnotationsFunctions.R',sep='/'))
|