-
Notifications
You must be signed in to change notification settings - Fork 1
/
Figure4.Rmd
180 lines (161 loc) · 7.22 KB
/
Figure4.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
---
title: "Figure4"
author: "Mike"
---
#For plotting the heatmaps and brain regions in Figure 4
First load up the required libraries and functions
```{r, echo=FALSE, results="hide"}
library(here)
library(dplyr)
library(NMF) # aheatmap()
library(nat)
library(elmr)
library(xlsx)
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/Figure4", here())
```
Plot the SLP and the LH
```{r, echo=FALSE}
clear3d()
LHmask<-subset(FCWBNP.surf, "LH_L")
LHmask.jfrc2013<-xform_brain(x=LHmask, sample = FCWB, reference = JFRC2013)
SLPmask<-subset(FCWBNP.surf, "SLP_L")
SLPmask.jfrc2013<-xform_brain(x=SLPmask, sample = FCWB, reference = JFRC2013)
plot3d(SLPmask.jfrc2013, alpha=0.2, col="magenta")
plot3d(LHmask.jfrc2013, alpha=0.2, col="red")
plot3d(JFRC2013, alpha=0.15)
set3d("front", 0.7, zoom = 0.8) #Function that sets the angle and zoom
snapshot3d("Figure4/SLP.png")
```
Plot the SIP and the LH
```{r, echo=FALSE}
clear3d()
LHmask<-subset(FCWBNP.surf, "LH_L")
LHmask.jfrc2013<-xform_brain(x=LHmask, sample = FCWB, reference = JFRC2013)
SLPmask<-subset(FCWBNP.surf, "SIP_L")
SLPmask.jfrc2013<-xform_brain(x=SLPmask, sample = FCWB, reference = JFRC2013)
plot3d(SLPmask.jfrc2013, alpha=0.2, col="green")
plot3d(LHmask.jfrc2013, alpha=0.2, col="red")
plot3d(JFRC2013, alpha=0.15)
set3d("front", 0.7, zoom = 0.8) #Function that sets the angle and zoom
snapshot3d("Figure4/SIP.png")
```
Plot the SMP and the LH
```{r, echo=FALSE}
clear3d()
LHmask<-subset(FCWBNP.surf, "LH_L")
LHmask.jfrc2013<-xform_brain(x=LHmask, sample = FCWB, reference = JFRC2013)
SLPmask<-subset(FCWBNP.surf, "SMP")
SLPmask.jfrc2013<-xform_brain(x=SLPmask, sample = FCWB, reference = JFRC2013)
plot3d(SLPmask.jfrc2013, alpha=0.2, col="cyan")
plot3d(LHmask.jfrc2013, alpha=0.2, col="red")
plot3d(JFRC2013, alpha=0.15)
set3d("front", 0.7, zoom = 0.8) #Function that sets the angle and zoom
snapshot3d("Figure4/SMP.png")
```
Pull up the new nomenclature and the NTs for LHONs
```{r, echo=FALSE}
LHON_LHONs<-readin("Figure4/Output_axonmemb_x_Output_axonmemb.txt")
NAmaster<-read.xlsx(file="/Users/dolanm/Dropbox/JFRCvisitorProject/Neuroanatomy_Master.xlsx", sheetIndex = 1)
LHnts<-select(NAmaster,LHClusters., Neurotransmitter)
LHnewnames<-select(NAmaster,LHClusters., FinalNames)
#To rename the LH cell-types
oldnames<-lapply(X = dimnames(LHON_LHONs), 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)
#For LHON neurotransmitters
LHONs<-dimnames(LHON_LHONs)[[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
names(LHnts)<-c("Type", "Neurotransmitter")
LHONtransmitter<-left_join(x = LHONs, y = LHnts, "Type")
LHONtransmitter<-data.frame(Neurotransmitter=as.character(LHONtransmitter$Neurotransmitter))
#Define the colours for annotations
transmitter_col<-c("red", "dodgerblue", "forestgreen", "dark magenta", "gold", "grey")
names(transmitter_col)<-c("Acetylcholine", "GABA", "Glutamate", "Acetylcholine, GABA", "Acetylcholine, Glutamate", "GABA, Dopamine" )
```
Calculate the major neuropil output zone as a track for the LHONxLHON heatmap. This is an optional add-on, I didn't like the way it looked
```{r, echo=FALSE}
LHON_nc82<-readin(file = "FigureS4/Output_axonmemb_x_nc82_nc82.txt")
main_np<-data.frame(Type=dimnames(LHON_nc82)[[1]], main_np=NA)
for(i in 1:nrow(LHON_nc82)) {
type<-row.names(LHON_nc82)[i]
row<-LHON_nc82[i,]
row<-data.frame(neuropil=names(row), values=row)
main_np[i,2]<-as.character(row[which.max(row$values), ]$neuropil)
} #Calculate the max neuropil for each cell-type
LHON_np<-data.frame(Output=main_np$main_np)
```
For plotting the overlap analysis of LHONs by LHONs, with modified matrix presentation and NT information. Note remove the 29A modification when I rerun everything with the final dataset
```{r, echo=FALSE}
LHON_LHON<-readin("Figure4/Output_axonmemb_x_Output_axonmemb.txt")
diag(LHON_LHON)<--1
dimnames(LHON_LHON)<-list(newname1, newname1)
#LHON_LHON<-subset(LHON_LHON, colnames(LHON_LHON)!="CellType_29A")
#LHON_LHON<-LHON_LHON[,-23]
aheatmap(x = LHON_LHON, filename=paste0("Figure4/LHON_LHON.pdf")
,fontsize = 9, col="black", cexRow = 1, cexCol =1, Rowv = FALSE, treeheight = 10
,annRow = LHONtransmitter, annCol = LHONtransmitter, cellwidth = 8, cellheight = 8
,annColors = list(transmitter_col), annLegend = FALSE)
```
For plotting the overlap analysis of LHON dendrites and local LH neurons with NT annotation tracks
```{r, echo=FALSE}
LHON_LHLN<-readin("Figure4/Local_memb_x_Output_den.txt")
#Redefine the colours for annotations
transmitter_col<-c("red", "dodgerblue", "forestgreen", "dark magenta", "gold", "grey")
names(transmitter_col)<-c("Acetylcholine", "GABA", "Glutamate", "Acetylcholine, GABA", "Acetylcholine, Glutamate", "GABA, Dopamine" )
#For LHONs
LHONs<-dimnames(LHON_LHLN)[[2]] #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
names(LHnts)<-c("Type", "Neurotransmitter")
LHONtransmitter<-left_join(x = LHONs, y = LHnts, "Type")
LHONtransmitter<-data.frame(Neurotransmitter=as.character(LHONtransmitter$Neurotransmitter))
#For the LHLNs
LHLNs<-dimnames(LHON_LHLN)[[1]] #Pull in the cell-types in question and get their order
LHLNs<-data.frame(Type=LHLNs)
LHLNtransmitter<-left_join(x = LHLNs, y = LHnts, "Type")
LHLNtransmitter<-data.frame(Neurotransmitter=as.character(LHLNtransmitter$Neurotransmitter))
#Calculate the LHLN new names
oldnames<-lapply(X = dimnames(LHON_LHLN), FUN = gsub, pattern = "CellType_", replacement = "", fixed = TRUE)
oldname2<-data.frame(oldnames=oldnames[[1]]) #For the row names
oldname2<-merge(x=oldname2, by.x ="oldnames", y=LHnewnames, by.y = "LHClusters.", sort =FALSE)
newname2<-as.character(oldname2$FinalNames)
dimnames(LHON_LHLN)<-list(newname2, newname1)
#Plot the heatmap
aheatmap(x = LHON_LHLN, filename="Figure4/LHON_LHLN.pdf"
,fontsize = 10, cexRow = .7, cexCol = 7, treeheight = 9, col="black"
,annRow = LHLNtransmitter, annCol = LHONtransmitter, annColors = list(transmitter_col), annLegend = FALSE, cellwidth = 12)
```