
K-means Clustering for Glycomics and Glycoproteomics Data
gly_kmeans.RdPerform k-means clustering on the expression data.
The function uses stats::kmeans() to perform clustering and provides
tidy results with cluster assignments.
Usage
gly_kmeans(
exp,
on = "variable",
centers = 3,
scale = TRUE,
add_info = TRUE,
...,
log_transform = TRUE
)Arguments
- exp
A
glyexp::GlycomicSE()orglyexp::GlycoproteomicSE()object, or anotherSummarizedExperimentcontaining an expression matrix and sample information.- on
A character string specifying what to cluster. Either "variable" (default) to cluster variables/features, or "sample" to cluster samples/observations.
- centers
Either the number of clusters (integer) or a set of initial cluster centers. Default is 3.
- scale
A logical indicating whether to scale the data before clustering. Default is TRUE.
- add_info
A logical value. If TRUE (default), sample information from the experiment will be added to the result tibbles. If FALSE, only the clustering results are returned.
- ...
Additional arguments passed to
stats::kmeans().- log_transform
A single logical value indicating whether to transform expression values using
log2(x + 1e-6)before analysis. Default isTRUE. Set toFALSEfor data that are already log-transformed.
Value
A list with three elements:
tidy_result: A tibble with cluster assignments containing the following columns:variableorsample: Variable or sample name (depending ononparameter)cluster: Cluster assignment
raw_result: The raw kmeans object fromstats::kmeans().meta_data: A list containing metadata from the input experiment
Details
Set log_transform = FALSE to use the expression values as supplied, for
example when they are already log-transformed.
By default, the function performs log2 transformation on the expression data
(log2(x + 1e-6)) before clustering. When on = "variable" (default), variables are clustered based on their
expression patterns across samples. When on = "sample", samples are clustered based
on their expression profiles across variables.
Data Preparation:
Data is log2-transformed when log_transform = TRUE and optionally scaled
before clustering.
Clustering Method:
K-means clustering is performed using stats::kmeans() with the specified parameters.
Required packages
This function only uses base R packages and does not require additional dependencies.