## ------------------------------------------------
## load data and retrieve two samples
## ------------------------------------------------
library(healthyFlowData)
data(hd)
sample1 = exprs(hd.flowSet[[1]])
sample2 = exprs(hd.flowSet[[2]])
## ------------------------------------------------
## cluster sample using kmeans algorithm
## ------------------------------------------------
clust1 = kmeans(sample1, centers=4, nstart=20)
clust2 = kmeans(sample2, centers=4, nstart=20)
cluster.labels1 = clust1$cluster
cluster.labels2 = clust2$cluster
## ------------------------------------------------
## Create ClusteredSample object
## and compute mahalanobis distance between two clsuters
## ------------------------------------------------
clustSample1 = ClusteredSample(labels=cluster.labels1, sample=sample1)
clustSample2 = ClusteredSample(labels=cluster.labels2, sample=sample2)
## compute the dissimilarity matrix
DM = dist.matrix(clustSample1, clustSample2, dist.type='Mahalanobis')
## ------------------------------------------------
## Computing matching of clusteres
## An object of class "ClusterMatch" is returned
## ------------------------------------------------
mec = match.clusters(clustSample1, clustSample2, dist.type="Mahalanobis", unmatch.penalty=99999)
## show the matching
summary(mec)
## **********************************************************************
## ************** Now matching meta-clusters across templates ***********
## **********************************************************************
## ------------------------------------------------
## Retrieve each sample, clsuter it and store the
## clustered samples in a list
## ------------------------------------------------
cat('Clustering samples: ')
clustSamples = list()
for(i in 1:10) # read 10 samples and cluster them
{
cat(i, ' ')
sample1 = exprs(hd.flowSet[[i]])
clust1 = kmeans(sample1, centers=4, nstart=20)
cluster.labels1 = clust1$cluster
clustSample1 = ClusteredSample(labels=cluster.labels1, sample=sample1)
clustSamples = c(clustSamples, clustSample1)
}
## ------------------------------------------------
## Create two templates each from five samples
## ------------------------------------------------
template1 = create.template(clustSamples[1:5])
template2 = create.template(clustSamples[6:10])
## ------------------------------------------------
## Match meta-clusters across templates
## ------------------------------------------------
mec = match.clusters(template1, template2, dist.type="Mahalanobis", unmatch.penalty=99999)
summary(mec)
## ------------------------------------------------
## Another example of matching meta-clusters & clusters
## across a template and a sample
## ------------------------------------------------
mec = match.clusters(template1, clustSample1, dist.type="Mahalanobis", unmatch.penalty=99999)
summary(mec)
Run the code above in your browser using DataLab