clusterTracks {celltrackR}R Documentation

Cluster Tracks

Description

Perform a quick clustering visualization of a set of tracks according to a given vector of track measures.

Usage

clusterTracks(
  tracks,
  measures,
  scale = TRUE,
  labels = NULL,
  method = "hclust",
  return.clust = FALSE,
  ...
)

Arguments

tracks

the tracks that are to be clustered.

measures

a function, or a vector of functions (see TrackMeasures). Each function is expected to return a single number given a single track.

scale

logical indicating whether the measures values shall be scaled using the function scale before the clustering.

labels

optional: a vector of labels of the same length as the track object. These are used to color points in the visualization.

method

"hclust" for hierarchical clustering, or "kmeans" for k-means clustering.

return.clust

logical: return the clustering object instead of only the plot? (defaults to FALSE).

...

additional parameters to be passed to the corresponding clustering function: hclust or kmeans.

Details

The measures are applied to each of the tracks in the given tracks object. According to the resulting values, the tracks are clustered using the chosen clustering method. If scale is TRUE, the measure values are scaled to mean value 0 and standard deviation 1 (per measure) before the clustering.

Method hclust plots a dendrogram of the clustering.

Method kmeans plots each computed cluster (x-axis) versus each of the track measures in the measures vector, producing one panel per measure. If labels are given, points are colored according to their "true" label.

Value

By default, only returns a plot. If return.clust=TRUE, also returns a clustering object as returned by hclust or kmeans. output object.

See Also

getFeatureMatrix to obtain a feature matrix that can be used for manual clustering and plotting, and trackFeatureMap to visualize high-dimensional track feature data via dimensionality reduction.

Examples

## Cluster tracks according to the mean of their Hust exponents along X and Y
## using hierarchical clustering

cells <- c(TCells,Neutrophils)
real.celltype <- rep(c("T","N"),c(length(TCells),length(Neutrophils)))
## Prefix each track ID with its cell class to evaluate the clustering visually
names(cells) <- paste0(real.celltype,seq_along(cells))
clust <- clusterTracks( cells, hurstExponent, method = "hclust",
 return.clust = TRUE  )

## How many cells are "correctly" clustered?
sum( real.celltype == c("T","N")[cutree(clust,2)] )


[Package celltrackR version 1.2.0 Index]