-
Notifications
You must be signed in to change notification settings - Fork 1
/
FigureS4.Rmd
108 lines (102 loc) · 4.33 KB
/
FigureS4.Rmd
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
---
title: "Figure4"
author: "Mike"
---
#For plotting Figure S4
Load up the required functions and libraries
```{r, echo=FALSE, results="hide"}
library(here)
library(dplyr)
library(ggplot2)
library(reshape2)
library(NMF) # aheatmap()
library(nat)
library(elmr)
library(nat.templatebrains)
library(nat.flybrains)
download_jefferislab_registrations()
readin<-function(file) {
as.matrix(read.table(file, header=TRUE,row.names=1))
} #For reading in the text files containing LM overlap data
set3d <- function(pos = c("front", "left", "back", "right",
"ventral", "dorsal"), zoom = 0.7, ...) {
pos <- match.arg(pos)
m <- diag(c(1, -1, -1, 1)) # front
if (pos == "left") {
m <- diag(c(0, -1, 0, 1))
m[1, 3] <- 1
m[3, 1] <- 1
}
if (pos == "back") {
m <- diag(c(-1, -1, 1, 1))
}
if (pos == "right") {
m <- diag(c(0, -1, 0, 1))
m[1, 3] <- m[3, 1] <- -1
}
if (pos == "ventral") {
m <- diag(c(1, -1, -1, 1))
}
if (pos == "dorsal") {
m <- diag(c(1, 1, 1, 1))
}
4
view3d(userMatrix = m, zoom = zoom, ...)
}
here()
file.symlink("/Users/dolanm/Google Drive/SplitGAL4_Paper/Figures/FigureS4", here())
```
Plot the overlap matrix of LHON axons by neuropil regions as a heatmap
```{r, echo=FALSE}
LHON_neuropil<-readin("FigureS4/Output_axonmemb_x_nc82_nc82.txt")
NAmaster<-read.xlsx(file="/Users/dolanm/Dropbox/JFRCvisitorProject/Neuroanatomy_Master.xlsx", sheetIndex = 1)
LHnts<-select(NAmaster,LHClusters., Neurotransmitter)
LHnewnames<-select(NAmaster,LHClusters., FinalNames)
#Define the colours for NT annotations
transmitter_col<-c("red", "dodgerblue", "forestgreen", "dark magenta", "gold")
names(transmitter_col)<-c("Acetylcholine", "GABA", "Glutamate", "Acetylcholine, GABA", "Acetylcholine, Glutamate" )
#The types need to be in the same order as the dimnames in the matrix to be read in correctly. Need to match
#up these two dataframes.
LHONs<-dimnames(LHON_neuropil)[[1]] #Pull in the cell-types in question and get their order
LHONs<-data.frame(Type=LHONs)
LHnts$LHClusters.<-paste0("CellType_", LHnts$LHClusters.) #Add CellType to all the names to match them with left_join, remove this with new naming system
names(LHnts)<-c("Type", "Neurotransmitter")
#Now join the dimnames with the annotation::cell-types to find matches but maintain matrix order.
#Note you just feed aheatmap the ordered annotations, not the annotation::cell-types pairs.
#Use different columns to add more tracks
LHONtransmitter<-left_join(x = LHONs, y = LHnts, "Type")
LHONtransmitter<-data.frame(Neurotransmitter=as.character(LHONtransmitter$Neurotransmitter))
#Change the names of LH anatomy groups to their cell-types
oldnames<-lapply(X = dimnames(LHON_neuropil), FUN = gsub, pattern = "CellType_", replacement = "", fixed = TRUE)
oldname1<-data.frame(oldnames=oldnames[[1]]) #For the row names
oldname1<-merge(x=oldname1, by.x ="oldnames", y=LHnewnames, by.y = "LHClusters.", sort =FALSE)
newname1<-as.character(oldname1$FinalNames)
dimnames(LHON_neuropil)[[1]]<-newname1
aheatmap(x = LHON_neuropil, filename=paste0("FigureS4/LHON_neuropil.pdf"), annRow = LHONtransmitter, annColors = list(transmitter_col)
, fontsize = 10, Colv = FALSE, cexRow = 2, cexCol = 5, treeheight = 10, col="black", annLegend = FALSE)
```
Determine if there is a correlation between axon overlap and dendrite overlap
```{r, echo=FALSE}
LHONaxon<-melt(readin("FigureS4/Output_axonmemb_x_Output_axonmemb.txt"))
LHONden<-melt(readin("FigureS4/Output_den_x_Output_den.txt"))
LHONaxon$Combo<-paste0(LHONaxon$Var1, LHONaxon$Var2)
LHONaxon<-select(LHONaxon, Combo, value)
LHONden$Combo<-paste0(LHONden$Var1, LHONden$Var2)
LHONden<-select(LHONden, Combo, value)
#Merge the two dfs into one and remove the 100% match for each cell-type onto itself
names(LHONden)<-c("Combo", "den_value")
names(LHONaxon)<-c("Combo", "axon_value")
LHONfull<-merge(x = LHONaxon, y=LHONden, by = "Combo")
LHONfull<-filter(LHONfull, axon_value!=100 | den_value!=100)
#Run a regression
fit <- lm(formula = axon_value~den_value, data = LHONfull)
summary(fit)
#Plot of the data with regression line
g<-ggplot(data = LHONfull, mapping = aes(x=axon_value, y=den_value))
g<-g+geom_point(alpha=0.1, size=2)
g<-g+geom_smooth(method='lm', formula = y ~ x)
g<-g+xlab("LHON axonal overlap %")
g<-g+ylab("LHON dendritic overlap %")
g
ggsave(filename = "FigureS4/LHONaxon_LHONden_corr.pdf")
```