This function returns a SummarizedExperiment with clustering information in its colData or rowData

getCluster(x, ...)

addCluster(x, ...)

# S4 method for class 'SummarizedExperiment'
addCluster(
  x,
  BLUSPARAM,
  assay.type = assay_name,
  assay_name = NULL,
  by = MARGIN,
  MARGIN = "rows",
  name = "clustering",
  clust.col = "cluster",
  full = FALSE,
  ...
)

# S4 method for class 'SingleCellExperiment'
addCluster(
  x,
  BLUSPARAM,
  assay.type = assay_name,
  assay_name = NULL,
  dimred = NULL,
  by = MARGIN,
  MARGIN = "rows",
  name = "clustering",
  clust.col = "cluster",
  full = FALSE,
  ...
)

# S4 method for class 'SummarizedExperiment'
getCluster(
  x,
  BLUSPARAM,
  assay.type = assay_name,
  assay_name = NULL,
  by = MARGIN,
  MARGIN = "rows",
  ...
)

# S4 method for class 'SingleCellExperiment'
getCluster(
  x,
  BLUSPARAM,
  assay.type = assay_name,
  assay_name = NULL,
  dimred = NULL,
  by = MARGIN,
  MARGIN = "rows",
  ...
)

# S4 method for class 'ANY'
getCluster(x, BLUSPARAM, by = MARGIN, MARGIN = "rows", full = FALSE, ...)

Arguments

x

A SummarizedExperiment object.

...

Additional parameters to use altExps for example

BLUSPARAM

A BlusterParam object specifying the algorithm to use.

assay.type

Character scalar. Specifies the name of assay used in calculation.

assay_name

Deprecated. Use assay.type instead.

by

Character scalar. Determines if association is calculated row-wise / for features ('rows') or column-wise / for samples ('cols'). Must be 'rows' or 'cols'.

MARGIN

Deprecated. Use by instead.

name

Character scalar. The name to store the result in metadata

clust.col

Character scalar. Indicates the name of the rowData (or colData) where the data will be stored. (Default: "clusters")

full

Logical scalar indicating whether the full clustering statistics should be returned for each method.

dimred

Character scalar or integer scalar. Specifies dimension reduction results used in calculation. Either dimred or assay.type must be specified.

Value

addCluster returns an object of the same type as the x parameter with clustering information named clusters stored in colData or rowData.

Details

This is a wrapper for the clusterRows function from the bluster package.

When setting full = TRUE, the clustering information will be stored in the metadata of the object.

By default, clustering is done on the features.

Examples

library(bluster)
data(GlobalPatterns, package = "mia")
tse <- GlobalPatterns

# Cluster on rows using Kmeans
tse <- addCluster(
    tse,
    assay.type = "counts",
    BLUSPARAM = KmeansParam(centers = 3)
)

# Clustering done on the samples using Hclust
res <- getCluster(
    tse,
    assay.type = "counts",
    by = "samples",
    BLUSPARAM = HclustParam(metric = "bray", dist.fun = vegan::vegdist)
)
res |> head()
#>     CL3     CC1     SV1 M31Fcsw M11Fcsw M31Plmr 
#>       1       2       3       4       5       6 
#> Levels: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21

# Apply clustering to PCA results
library(scater)
#> Loading required package: scuttle
#> Loading required package: ggplot2
tse <- transformAssay(tse, method = "rclr")
tse <- runPCA(tse, assay.type = "rclr")
#> Warning: more singular values/vectors requested than available
#> Warning: You're computing too large a percentage of total singular values, use a standard svd instead.
tse <- addCluster(
    tse,
    dimred = "PCA",
    BLUSPARAM = KmeansParam(centers = 3),
    by = 2
)
tse$cluster |> head()
#>     CL3     CC1     SV1 M31Fcsw M11Fcsw M31Plmr 
#>       1       1       1       2       2       3 
#> Levels: 1 2 3