The purpose of this markdown is to walk though our process for calculating a c-Fos score at the regional level, and provide the code supporting the visualizations we provide in our manuscript https://docs.google.com/document/d/166X4o_6HegeS0uUHRa4ahKedkaVEMeiRagCm7T9nOVU/edit?usp=sharing. Specifically, here we demonstrate how to generate Figures 7k-r. First, we load relevant packages.
library(nat)
library(plyr)
library(cocoframer)
library(purrr)
library(rgl)
library(RNifti)
library(tidyverse)
library(ggplot2)
library(ggrepel)
library(RColorBrewer)
library(tidyr)
library(plotly)
library(dplyr)
library(reshape2)
library(data.table)
'%notin%' = Negate('%in%')
Our first step is to understand where the thalamus resides within the brain, and where the substructures of interest to us are located. First, we load in the Allen Brain Atlas mesh, and translate the whole brain mesh slightly, so that the Slideseq data and the ABA atlas are within the same reference space.
#Load the meshes
structures <- c("root", "TH", "PVT", "RE", "Xi")
mesh_list <- map(structures, ccf_2017_mesh)
names(mesh_list) <- structures
#Translate the ABA to fit the Slideseq space
for(x in structures){
mesh_list[[x]]$vb[2,] = mesh_list[[x]]$vb[2,] - 500
mesh_list[[x]]$vb[3,] = mesh_list[[x]]$vb[3,] - 500
}
Plot the whole brain, as well as the structure of the thalamus within the brain.
fig = plot_ly(type = 'mesh3d', x=mesh_list$root$vb[1,], y=mesh_list$root$vb[2,],z=mesh_list$root$vb[3,],i=mesh_list$root$it[1,]-1,j=mesh_list$root$it[2,]-1,k =mesh_list$root$it[3,]-1, facecolor = rep("lightgray", length(mesh_list$root$vb[2,])*2), opacity = 0.1) %>% add_trace(type = 'mesh3d', x=mesh_list$TH$vb[1,],
y=mesh_list$TH$vb[2,],z=mesh_list$TH$vb[3,], i=mesh_list$TH$it[1,]-1,j=mesh_list$TH$it[2,]-1, k =mesh_list$TH$it[3,]-1, facecolor = rep("darkslateblue",length(mesh_list$TH$vb[2,])*2 ),opacity = 1)
fig <- fig %>% layout(title = "Thalamus",scene = list(xaxis = list(title = '', showgrid = F , zerolinecolor = '#ffff', showticklabels=FALSE),yaxis = list(title = '', showgrid = F,zerolinecolor = '#ffff', showticklabels=FALSE),zaxis = list(title = '', showgrid = F, zerolinecolor = '#ffff', showticklabels=FALSE)))
fig