Neuron Search fig

Panels for Neuron Search figure.

neuron_search_score_mat <- load_si_data("neuron_search_score_mat.rds")
options(flycircuit.scoremat="neuron_search_score_mat")

Scale bar

imscalebar(seq(0,1,len=11),col=jet.colors(10),horizontal=F, mar=c(0,0,0,0))

Panel B: Pair of same raw image, different segmentation

Plot the query neuron

nopen3d()
## glX 
##   4
plot3d(FCWB)
op=structure(list(FOV = 0, userMatrix = structure(c(1, 0, 0, 0, 0, -1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1), .Dim = c(4L, 4L)), scale = c(1, 1, 1), zoom = 0.218791082501411), .Names = c("FOV", "userMatrix", "scale", "zoom"))
par3d(op)
plot3d("FruMARCM-M001629_seg001", col='black', lwd=4, soma=T)

Plot the query and the top hit.

clear3d()
par3d(op)
par3d(zoom=0.631736993789673)
plot3d("FruMARCM-M001629_seg001", col='black', lwd=1, soma=T)
plot3d(names(sort(fc_nblast("FruMARCM-M001629_seg001"), decreasing=T)[2]), col='red', lwd=4, soma=T)

Plot the top 8.

clear3d()
par3d(op)
par3d(zoom=0.631736993789673)
plot3d("FruMARCM-M001629_seg001", col='black', lwd=1, soma=T)
plot3d(names(sort(fc_nblast("FruMARCM-M001629_seg001"), decreasing=T)[2]), col='red', lwd=4, soma=T)
plot3d(names(sort(fc_nblast("FruMARCM-M001629_seg001"), decreasing=T)[3:11]), soma=T)

For C panels

Plot histogram of scores, showing all hits. It is an inset in another graph.

par(mar=c(0,2,0,0))
qq=qplot(fc_nblast("FruMARCM-M001629_seg001"), binwidth=200, xlab="Forward score", ylab="Count")
qq+ theme(panel.background=element_rect(fill="grey80"), panel.grid.minor=element_line(colour='grey80'), axis.text.x=element_text(size=22), axis.text.y=element_text(size=22), axis.title.x=element_text(size=26), axis.title.y=element_text(size=26)) + geom_vline(xintercept = 0, colour="red", linetype=2, size=1)

# the probability for values under 0 is:
fwdfru=sort(fc_nblast("FruMARCM-M001629_seg001"), decreasing=T)
ecdf(fwdfru)(0)
## [1] 0.9652179

Plot histogram with xlim at -5000 in zoomed version.

same2zoom=qplot(fc_nblast("FruMARCM-M001629_seg001"), bindwidth=60, ylim=c(0,10), xlim=c(6500, 10000), xlab="Forward score", ylab="Count") + theme(panel.background=element_rect(fill="grey80"), panel.grid.minor=element_line(colour='grey80'), axis.text.x=element_text(size=22), axis.text.y=element_text(size=22), axis.title.x=element_text(size=26), axis.title.y=element_text(size=26))
par(mar=c(0,2,0,0))
plot(same2zoom,lwd=.3)
## Warning: position_stack requires constant width: output may be incorrect

Show example search with auditory neuron with raw scores.

Histogram of scores coloured by score bins.

fwdfru_5000=fwdfru[fwdfru>-5000]
bb2=cut(fwdfru_5000, breaks=c(-5000,seq(0, max(fwdfru), len=10)))
cols2=mixOmics::jet.colors(10)[bb2]
names(cols2)=names(fwdfru_5000)
m<-cbind(fwdfru_5000,cols2)
m<-as.data.frame(m, stringsAsFactors=F)
m$cols2=factor(m$cols2)
rownames(m)=names(fwdfru_5000)
#Replace "#00008E" (dark blue) for "#000000" (black)
levels(m$cols2)=c("#000000", "#0000FF", "#0070FF", "#00DFFF", "#50FFAE", "#7F0000", "#BFFF3F", "#FF5F00", "#FFCE00")
qq=qplot(fwdfru_5000, geom="histogram", binwidth=180, xlab="Foward score", ylab="Count", colour=factor(cols2), fill=factor(cols2))
scoreplot=qq+scale_colour_manual(values=c("#000000", "#0000FF", "#0070FF", "#00DFFF", "#50FFAE", "#7F0000", "#BFFF3F", "#FF5F00", "#FFCE00"))+scale_fill_manual(values=c("#000000", "#0000FF", "#0070FF", "#00DFFF", "#50FFAE", "#7F0000", "#BFFF3F", "#FF5F00", "#FFCE00"))+ theme(axis.text.x=element_text(size=22), axis.text.y=element_text(size=22), axis.title.x=element_text(size=26), axis.title.y=element_text(size=26), legend.position="none")
par(mar=c(0,2,0,0))
plot(scoreplot)

Make neuron plots of each coloured group in the histogram (score bins), except for last group (in black, <0).

First group (red)

clear3d()
op=structure(list(FOV = 0, userMatrix = structure(c(1, 0, 0, 0, 0, -1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1), .Dim = c(4L, 4L)), scale = c(1, 1, 1), zoom = 0.633195042610168), .Names = c("FOV", "userMatrix", "scale", "zoom"))
par3d(op)
plot3d(rownames(subset(m, cols2==as.character(unique(m$cols2)[1]))), soma=T, col=as.character(unique(m$cols2)[1]), lwd=2)

Second group.

clear3d()
par3d(op)
plot3d(rownames(subset(m, cols2==as.character(unique(m$cols2)[2]))), soma=T, col=as.character(unique(m$cols2)[2]))

Third group.

clear3d()
par3d(op)
plot3d(rownames(subset(m, cols2==as.character(unique(m$cols2)[3]))), soma=T, col=as.character(unique(m$cols2)[3]))

Fourth group.

clear3d()
par3d(op, zoom=0.6648548)
plot3d(rownames(subset(m, cols2==as.character(unique(m$cols2)[4]))), soma=T, col=as.character(unique(m$cols2)[4]))

Fifth group.

clear3d()
par3d(op, zoom=0.6648548)
plot3d(rownames(subset(m, cols2==as.character(unique(m$cols2)[5]))), soma=T, col=as.character(unique(m$cols2)[5]))

Sixth group.

clear3d()
par3d(op)
plot3d(rownames(subset(m, cols2==as.character(unique(m$cols2)[6]))), soma=T, col=as.character(unique(m$cols2)[6]))

Seventh group.

clear3d()
par3d(op)
plot3d(rownames(subset(m, cols2==as.character(unique(m$cols2)[7]))), soma=T, col=as.character(unique(m$cols2)[7]))

Eight group.

clear3d()
par3d(op, zoom=0.5743266)
plot3d(rownames(subset(m, cols2==as.character(unique(m$cols2)[8]))), soma=T, col=as.character(unique(m$cols2)[8]))

Last B panel

Plot all target neurons coloured by score for >0, query in red.

clear3d()
plot3d(FCWB)
par3d(op)
plot3d("FruMARCM-M001629_seg001", lwd=2, soma=T, col="red")
plot3d(names(fwdfru_5000[fwdfru_5000>0]), soma=T, col=cols2[fwdfru_5000>0])

For D panels

Plotting of neurons for panels D, explaining the different scores. Comparing normalised and non normalised score for big neuron vs small neuron.

Plot big neuron.

clear3d()
plot3d(FCWB, alpha=0)
op=structure(list(FOV = 0, userMatrix = structure(c(1, 0, 0, 0, 
0, -1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1), .Dim = c(4L, 4L)), scale = c(1, 
1, 1), zoom = 0.472224056720734), .Names = c("FOV", "userMatrix", 
"scale", "zoom"))
par3d(op)
plot3d("dTdc2MARCM-F000115_seg001")

Plot small neuron in red.

clear3d()
plot3d(FCWB, alpha=0)
op=structure(list(FOV = 0, userMatrix = structure(c(1, 0, 0, 0, 0, -1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1), .Dim = c(4L, 4L)), scale = c(1, 1, 1), zoom = 0.472224056720734), .Names = c("FOV", "userMatrix", "scale", "zoom"))
par3d(op)
plot3d("FruMARCM-M002574_seg002", col='red')

Plot another small neuron in black.

clear3d()
plot3d(FCWB, alpha=0)
op=structure(list(FOV = 0, userMatrix = structure(c(1, 0, 0, 0, 0, -1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1), .Dim = c(4L, 4L)), scale = c(1, 1, 1), zoom = 0.472224056720734), .Names = c("FOV", "userMatrix", "scale", "zoom"))
par3d(op)
plot3d("DvGlutMARCM-F004164_seg001", col='black')

Get scores for panels.

fc_nblast("dTdc2MARCM-F000115_seg001", "FruMARCM-M002574_seg002") # big vs small 1
## [1] -167916.1
fc_nblast("FruMARCM-M002574_seg002","dTdc2MARCM-F000115_seg001") # small 1 vs big
## [1] 7987.298
fc_nblast("FruMARCM-M002574_seg002","DvGlutMARCM-F004164_seg001") # small 1 vs small 2
## [1] 6438.097
fc_nblast("DvGlutMARCM-F004164_seg001","FruMARCM-M002574_seg002") # small 2 vs small 1
## [1] 5551.83
fc_nblast("dTdc2MARCM-F000115_seg001", "FruMARCM-M002574_seg002", norm="mean") # mean score big vs small 1
## [1] 0.1359932
fc_nblast("DvGlutMARCM-F004164_seg001","FruMARCM-M002574_seg002", norm="mean") # mean score small 2 vs small 1
## [1] 0.5788994
fc_nblast("dTdc2MARCM-F000115_seg001","dTdc2MARCM-F000115_seg001") #self score big
## [1] 400149.2
fc_nblast("DvGlutMARCM-F004164_seg001","DvGlutMARCM-F004164_seg001") #self score small 2
## [1] 9248.055
fc_nblast("FruMARCM-M002574_seg002","FruMARCM-M002574_seg002") #self score small 1
## [1] 11548.68

Get normalised scores.

fc_nblast("dTdc2MARCM-F000115_seg001", "FruMARCM-M002574_seg002")/fc_nblast("dTdc2MARCM-F000115_seg001","dTdc2MARCM-F000115_seg001") # normalised big vs small 1
## [1] -0.4196336
fc_nblast("FruMARCM-M002574_seg002","dTdc2MARCM-F000115_seg001")/fc_nblast("FruMARCM-M002574_seg002","FruMARCM-M002574_seg002") # normalised small 1 vs big
## [1] 0.6916201
fc_nblast("DvGlutMARCM-F004164_seg001","FruMARCM-M002574_seg002")/fc_nblast("DvGlutMARCM-F004164_seg001","DvGlutMARCM-F004164_seg001") # normalised small 2 vs small 1
## [1] 0.6003241
fc_nblast("FruMARCM-M002574_seg002","DvGlutMARCM-F004164_seg001")/fc_nblast("FruMARCM-M002574_seg002","FruMARCM-M002574_seg002") # normalised small 1 vs small 2
## [1] 0.5574747

Plots for E panels

Collect the tophit for each neuron (rank 2) from dataframe tophits and plot forward normalised scores as histogram.

tophits2=subset(tophits, query%in%good_images)
normscoresall=mapply(fc_nblast, tophits2[,'target'], tophits2[,'query'], normalisation='mean')
summary(normscoresall)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
## -0.8774  0.5195  0.6618  0.5847  0.7178  1.0000
quantile(normscoresall, probs=0.99)
##     99% 
## 0.80191
qq=qplot(normscoresall, binwidth=0.01, ylab="Count", xlab="Forward score of top hit")
par(mar=c(0,2,0,0))
qq+theme(axis.text.x=element_text(size=22), axis.text.y=element_text(size=22), axis.title.x=element_text(size=26), axis.title.y=element_text(size=26)) + geom_vline(xintercept = mean(normscoresall), colour="red", linetype=2, size=2) + geom_vline(xintercept = quantile(normscoresall, 0.99), colour="green", linetype=2, size=2)
## Warning: position_stack requires constant width: output may be incorrect

Plot of neuron images divided by type: same raw image, same segmentation, same specimen or different specimen

qq2=ggplot(data=subset(top80sym,!duplicated(pair.number) | is.na(pair.number)), aes(x=revscore.norm, y=value.norm)) + geom_point(aes(colour=type), size=10) + labs(x="Reverse score", y="Forward score", colour="Image Type")+theme(axis.text.x=element_text(size=22), axis.text.y=element_text(size=22), axis.title.x=element_text(size=26), axis.title.y=element_text(size=26), legend.text=element_text(size=26), legend.title=element_text(size=26),legend.position=c(0.86, 0.11))
levels(qq2$data$type)<-c("Same segmentation", "Same raw image", "Same specimen", "Different specimen")
plot(qq2)

Inset showing all neuron hits, forward vs reverse normalised scores.

qq3=qplot(data=subset(tophits2, !duplicated(qp)), y=value.norm, x=revscore.norm, xlab="Reverse score", ylab="Forward score")+ geom_vline(xintercept=0.8) +geom_hline(yintercept=0.8)+ theme(panel.background=element_rect(fill="grey80"), panel.grid.minor=element_line(colour='grey80'), axis.text.x=element_text(size=22), axis.text.y=element_text(size=22), axis.title.x=element_text(size=26), axis.title.y=element_text(size=26))
par(mar=c(0,2,0,0))
plot(qq3)