Learn R Programming

apcluster (version 1.4.11)

sort-methods: Sort clusters

Description

Rearrange clusters according to sort criterion

Usage

# S4 method for ExClust
sort(x, decreasing=FALSE,
                   sortBy=c("aggExCluster", "size",
                            "nameExemplar", "noExemplar"), ...)

Value

returns a copy of x, but with slots exemplars and

clusters (see APResult

or ExClust) reordered.

Arguments

x

object of class APResult or ExClust

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

Author

Ulrich Bodenhofer apcluster@bioinf.jku.at

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 by heatmap. Note that this only works if the similarity matrix is included in the input object x, 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.

References

http://www.bioinf.jku.at/software/apcluster/

Bodenhofer, U., Kothmeier, A., and Hochreiter, S. (2011) APCluster: an R package for affinity propagation clustering. Bioinformatics 27, 2463-2464. DOI: tools:::Rd_expr_doi("10.1093/bioinformatics/btr406").

See Also

APResult, ExClust

Examples

Run this code
## 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"))

Run the code above in your browser using DataLab