APClustering fig

Panels for cluster statistics and hierarchical clustering of exemplars, focusing on central brain and some other examples.

## glX 
##   1
# This score matrix is loaded in DivideVPNsCentralBrain.R
options(flycircuit.scoremat="AP_score_mat")

Use affinity propagaton to cluster the Flycircuit neurons.

Plot mean cluster score vs cluster size.

csize=table(as.integer(clusterp0$exemplar))

clustersim<-function(gns,summaryfun=mean){
     if(length(gns)==1) return(NA)
      summaryfun=match.fun(summaryfun)
      dmat=fc_nblast(gns,gns,normalisation="mean")
      dmat[upper.tri(dmat)]
      summaryfun(dmat)
   }
mcsim=by(clusterp0$item,clusterp0$exemplar,clustersim)
summary(mcsim)
##     Min.  1st Qu.   Median     Mean  3rd Qu.     Max.     NA's 
## -0.06287  0.48660  0.56240  0.55850  0.63750  0.95550        1
clstats=qplot(as.vector(mcsim),as.vector(csize), size=I(8), alpha=I(0.3), xlab="Mean cluster score", ylab="Cluster size  (log)")+scale_y_sqrt()+ 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))
par(mar=c(0,2,0,0))
plot(clstats)
## Warning: Removed 1 rows containing missing values (geom_point).

The 5 clusters (exemplars) with the lower mean similarity are:

mcsim[names(which(mcsim<0.25))]
## clusterp0$exemplar
##    ChaMARCM-F001583_seg001 DvGlutMARCM-F002938_seg001 
##               0.2441217262              -0.0002144194 
## DvGlutMARCM-F004312_seg001    FruMARCM-F001388_seg001 
##               0.0517236085               0.2071676465 
##    FruMARCM-M002200_seg001 
##              -0.0628653561

Plot all exemplars.

ex=names(apres16k.p0@exemplars)
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.52093118429184), .Names = c("FOV", "userMatrix", "scale", "zoom"))
par3d(op)
plot3d(ex)

To improve distinction of major neuronal subtypes obtained in the dendrogram groups, we’ll do the hierarchical clustering in only the central brain neurons, removing all optic lobe ones.

Dividing between central brain neurons (cb neurons) and optic lobe ones, k=3:

par(mar=c(0,2,0,0))
plot(exemhcd)
abline(h=height_for_ngroups(exemhc, k=3), lty='dashed')

Plot group 1.

clear3d()
plot3d(FCWB)
par3d(op)
plot3d(subset(exemhc, k=3, groups=1), soma=T, col="red")

Plot group 2.

clear3d()
plot3d(FCWB)
par3d(op)
plot3d(subset(exemhc, k=3, groups=2), soma=T, col="green")

Plot group 3.

clear3d()
plot3d(FCWB)
par3d(op)
plot3d(subset(exemhc, k=3, groups=3), soma=T, col="blue")

Central brain neurons are in groups 2 and 3.

From the central brain group, there only a few exemplars in OL that still need to be removed (details in DivideVPNsCentralBrain.R): olextra neurons

clear3d()
plot3d(FCWB)
par3d(op)
plot3d(olextra, soma=T)
olextra
##  [1] "FruMARCM-F000057_seg001"    "TPHMARCM-F001806_seg001"   
##  [3] "THMARCM-466F_seg2"          "DvGlutMARCM-F003807_seg001"
##  [5] "DvGlutMARCM-F002964_seg001" "FruMARCM-F001388_seg001"   
##  [7] "TPHMARCM-1126M_seg1"        "TPHMARCM-1098F_seg1"       
##  [9] "DvGlutMARCM-F1088_seg1"     "DvGlutMARCM-F004312_seg001"
## [11] "FruMARCM-M002003_seg001"

The central brain exemplars that will be used from here on.

There are 544 exemplars corresponding to 11372 neurons.

cbg2=setdiff(subset(exemhc, k=3, groups=2), olextra)
cbg3=setdiff(subset(exemhc, k=3, groups=3), olextra)
clear3d()
plot3d(FCWB)
par3d(op)
plot3d(cbg2, soma=T, col='green')
plot3d(cbg3, soma=T, col='blue')

Organise these central brain exemplars by hierarchical clustering.

Looking at dendrogram, divided it at h=3. This resulted in similar groups to using all neurons and cutting at h=3 (24 groups). Also tried cutting further, at h=2.5 (19 groups).

But changed cutting level to get large superclasses, using k=14.

excbhc=hclustfc(excb)
excbhc$height=sqrt(excbhc$height)
excbhch=colour_clusters(excbhc, k=14, groupLabels=as.roman)
labels(excbhch)=NULL
par(mar=c(0,2,0,0))
plot(excbhch)
abline(h=height_for_ngroups(excbhc, k=14), lty='dashed')