# NOT RUN {
# }
# NOT RUN {
library(DynClust)
## use fluorescence calcium imaging of neurons performed with Fura 2 excited at 340 nm
data('adu340_4small',package='DynClust')
## Gain of the CCD camera:
G <- 0.146
## readout variance of the CCD camera:
sro2 <- (16.4)^2
## Stabilization of the variance to get a normalized dataset (variance=1)
FT <- 2*sqrt(adu340_4small/G + sro2)
FT.range = range(FT)
## launches the denoising step on the dataset with a statistical level of 5%
FT.den.tmp <- RunDenoising(FT,1,mask.size=NA,nproc=2)
## launches the clustering step on the dataset with a statistical level of 5%
FT.clust.tmp <- RunClustering(FT,FT.den.tmp,nproc=2)
n.cluster <- length(FT.clust.tmp$clusters)
print(paste(n.cluster,'clusters using variance set to',sqrt(FT.den.tmp$var),'^2'))
## get the classified version of the data array and the map of the clusters
FT.clust.res <- GetClusteringResults(FT,FT.den.tmp,FT.clust.tmp)
## plotting results of the clusterization
par(mfrow=c(2,2))
image(FT.clust.res$clust.map,col=rainbow(n.cluster))
title('Cluster map')
matplot(FT.clust.res$clust.center,col=rainbow(n.cluster),type="l",lwd=0.1,lty=1)
title('Cluster centers')
## and more: original and clustered slices at time 50
image(FT[,,50],zlim=FT.range,col=grey(seq(0,1,length=n.cluster)))
title('Original sequence at time 50')
image(FT.clust.res$clust.array[,,50],zlim=FT.range,col=grey(seq(0,1,length=n.cluster)))
title('Clustered sequence at time 50')
####################################################################################
## reapply clustering with twice the nominal variance: forces stronger clustering ##
####################################################################################
## launches the denoising step on the dataset with a statistical level of 5%
FT.den.tmp <- RunDenoising(FT,2,mask.size=NA,nproc=2)
## launches the clustering step on the dataset with a statistical level of 5%
FT.clust.tmp <- RunClustering(FT,FT.den.tmp,nproc=2)
n.cluster <- length(FT.clust.tmp$clusters)
print(paste(n.cluster,'clusters using twice the nominal variance'))
## get the classified version of the data array and the map of the clusters
FT.clust.res <- GetClusteringResults(FT,FT.den.tmp,FT.clust.tmp)
## plotting results of the clusterization
par(mfrow=c(2,2))
image(FT.clust.res$clust.map,col=rainbow(n.cluster))
title('Cluster map')
matplot(FT.clust.res$clust.center,col=rainbow(n.cluster),type="l",lwd=0.1,lty=1)
title('Cluster centers')
## and more: original and clustered slices at time 50
image(FT[,,50],zlim=FT.range,col=grey(seq(0,1,length=n.cluster)))
title('Original sequence at time 50')
image(FT.clust.res$clust.array[,,50],zlim=FT.range,col=grey(seq(0,1,length=n.cluster)))
title('Clustered sequence at time 50')
# }
Run the code above in your browser using DataLab