sortmethods {apcluster}  R Documentation 
Sort clusters
Description
Rearrange clusters according to sort criterion
Usage
## S4 method for signature 'ExClust'
sort(x, decreasing=FALSE,
sortBy=c("aggExCluster", "size",
"nameExemplar", "noExemplar"), ...)
Arguments
x 

decreasing 
logical indicating if sorting should be done in decreasing order, see details below 
sortBy 
sort criterion, see details below 
... 
further arguments are ignored; only defined for S3 method consistency 
Details
The function sort
takes an APResult
or ExClust
clustering object x
and creates
a new clustering object of the same class, but with clusters arranged
according to the sort criterion passed as argument sortBy
:
 “aggExCluster”
(default) order clusters as they would appear in the dendrogram produced by
aggExCluster
. This is also the same ordering in which the clusters are arranged byheatmap
. Note that this only works if the similarity matrix is included in the input objectx
, otherwise an error message is produced. “size”
sorts clusters according to their size (from small to large).
 “nameExemplar”
sorts clusters according to the names of the examplars (if available, otherwise an error is produced).
 “noExemplar”
sorts clusters according to the indices of the examplars.
If decreasing
is TRUE
, the order is reversed and, for
example, sortBy="size"
sorts clusters with such that the larger
clusters come first.
Note that the cluster numbers of x
are not preserved by
sort
, i.e. the cluster no. 1 of the object returned by
sort
is the one that has been ranked first by sort
,
which may not necessarily coincide with cluster no. 1 of the original
clustering object x
.
Note that this is an S3 method (whereas all other methods in this
package are S4 methods). This inconsistency has been introduced in
order to avoid interoperability problems with the BiocGenerics
package which may overwrite the definition of the sort
generic
if it is loaded after the apcluster package.
Value
returns a copy of x
, but with slots exemplars
and
clusters
(see APResult
or ExClust
) reordered.
Author(s)
Ulrich Bodenhofer
References
https://github.com/UBod/apcluster
Bodenhofer, U., Kothmeier, A., and Hochreiter, S. (2011) APCluster: an R package for affinity propagation clustering. Bioinformatics 27, 24632464. DOI: doi:10.1093/bioinformatics/btr406.
See Also
Examples
## create two Gaussian clouds
cl1 < cbind(rnorm(50,0.2,0.05),rnorm(50,0.8,0.06))
cl2 < cbind(rnorm(50,0.7,0.08),rnorm(50,0.3,0.05))
x < rbind(cl1,cl2)
## run affinity propagation
apres < apcluster(negDistMat(r=2), x, q=0.7)
show(apres)
## show dendrogram
plot(aggExCluster(x=apres))
## default sort order: like in heatmap or dendrogram
show(sort(apres))
## show dendrogram (note the different cluster numbers!)
plot(aggExCluster(x=sort(apres)))
## sort by size
show(sort(apres, decreasing=TRUE, sortBy="size"))