Make hierarchy of set of clusters

Share:

Description

Makes a dendrogram of a set of clusters based on hclust on the medoids of the cluster.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
## S4 method for signature 'ClusterExperiment'
makeDendrogram(x,
  whichCluster = "primaryCluster", dimReduce = c("none", "PCA", "var", "cv",
  "mad"), ndims = NA, ignoreUnassignedVar = FALSE,
  unassignedSamples = c("outgroup", "cluster"), ...)

## S4 method for signature 'matrix'
makeDendrogram(x, cluster,
  unassignedSamples = c("outgroup", "cluster", "remove"), ...)

## S4 method for signature 'ClusterExperiment'
plotDendrogram(x, leaves = c("clusters",
  "samples"), clusterNames = TRUE, main, sub, ...)

Arguments

x

data to define the medoids from. Matrix and ClusterExperiment supported.

whichCluster

an integer index or character string that identifies which cluster should be used to make the dendrogram. Default is primaryCluster.

dimReduce

character A character identifying what type of dimensionality reduction to perform before clustering. Options are "none","PCA", "var","cv", and "mad". See transform for more details.

ndims

integer An integer identifying how many dimensions to reduce to in the reduction specified by dimReduce

ignoreUnassignedVar

logical indicating whether dimensionality reduction via top feature variability (i.e. 'var','cv','mad') should ignore unassigned samples in the primary clustering for calculation of the top features.

unassignedSamples

how to handle unassigned samples("-1") ; only relevant for sample clustering. See details.

...

for makeDendrogram, if signature matrix, arguments passed to hclust; if signature ClusterExperiment passed to the method for signature matrix. For plotDendrogram, passed to plot.dendrogram.

cluster

A numeric vector with cluster assignments. If x is a ClusterExperiment object, cluster is automatically the primaryCluster(x). “-1” indicates the sample was not assigned to a cluster.

leaves

if "samples" the dendrogram has one leaf per sample, otherwise it has one per cluster.

clusterNames

logical. If leaves="clusters", then clusters will be identified with their 'name' value in legend; otherwise the 'clusterIds' value will be used.

main

passed to the plot function.

sub

passed to the plot function.

Details

The function returns two dendrograms (as a list if x is a matrix or in the appropriate slots if x is ClusterExperiment). The cluster dendrogram is created by applying hclust to the medoids of each cluster. In the sample dendrogram the clusters are again clustered, but now the samples are also part of the resulting dendrogram. This is done by giving each sample the value of the medoid of its cluster.

The argument unassignedSamples governs what is done with unassigned samples (defined by a -1 cluster value). If unassigned=="cluster", then the dendrogram is created by hclust of the expanded medoid data plus the original unclustered observations. If unassignedSamples is "outgroup", then all unassigned samples are put as an outgroup. If the x object is a matrix, then unassignedSamples can also be "remove", to indicate that samples with "-1" should be discarded. This is not a permitted option, however, when x is a ClusterExperiment object, because it would return a dendrogram with less samples than NCOL(x), which is not permitted for the @dendro_samples slot.

If leaves="clusters", the plotting function will work best if the clusters in the dendrogram correspond to the primary cluster. This is because the function colors the cluster labels based on the colors of the clusterIds of the primaryCluster

Value

If x is a matrix, a list with two dendrograms, one in which the leaves are clusters and one in which the leaves are samples. If x is a ClusterExperiment object, the dendrograms are saved in the appropriate slots.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
data(simData)

#create a clustering, for 8 clusters (truth was 3)
cl <- clusterSingle(simData, clusterFunction="pam", subsample=FALSE,
sequential=FALSE, clusterDArgs=list(k=8))

#create dendrogram of clusters:
hcl <- makeDendrogram(cl)
plotDendrogram(hcl)
plotDendrogram(hcl, leaves="samples")