Title: | Consensus Clustering of Omic Data |
---|---|
Description: | Procedures to perform consensus clustering starting from a dissimilarity matrix or a data matrix. It's allowed to select if the subsampling has to be by samples or features. In case of computational heavy load, the procedures can run in parallel. |
Authors: | Stefano Maria Pagnotta [aut, cre, cph] |
Maintainer: | Stefano Maria Pagnotta <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.0 |
Built: | 2024-11-07 03:56:12 UTC |
Source: | https://github.com/stefanomp/yaconsensus |
Computes the consensus dissimilarity according to the algorithm of Monti et al. (2003).
consensus.diss(cclusters, similarity = FALSE)
consensus.diss(cclusters, similarity = FALSE)
cclusters |
a matrix of integers where the column are the samples, and the rows are different clusterings of the samples. |
similarity |
a logical value signaling if the similarity matrix is required. |
In any row of the ccluster matrix, the value 0 means that the corresponding sample is not assigned to any cluster. In this case, the dissimilarity is computed consistently.
An object of the 'dist' class.
Stefano M. Pagnotta
Monti et al. (2003) - Consensus Clustering: A Resampling-Based Method for Class Discovery and Visualization of Gene Expression Microarray Data - Machine Learning 52(1-2):91-118 <DOI: 10.1023/A:1023949509487>
clusters <- rep(1:3, c(3, 9, 18)) clusterings <- matrix(NA, ncol = 30, nrow = 50) for(k in 1:50) clusterings[k,] <- sample(clusters) ddist <- consensus.diss(clusterings) class(ddist) attr(ddist, "method")
clusters <- rep(1:3, c(3, 9, 18)) clusterings <- matrix(NA, ncol = 30, nrow = 50) for(k in 1:50) clusterings[k,] <- sample(clusters) ddist <- consensus.diss(clusterings) class(ddist) attr(ddist, "method")
This function processes the ouput of yaConsensus and acts as a wrapper to the pheatmap function.
## S3 method for class 'yaConsensus' plot(x, G = 2, annotation = NULL, annotation.colorCode = NULL, matching_clustering = NULL, consensus_colors = NULL,...)
## S3 method for class 'yaConsensus' plot(x, G = 2, annotation = NULL, annotation.colorCode = NULL, matching_clustering = NULL, consensus_colors = NULL,...)
x |
an object coming from yaConsensus(). |
G |
an integer value indicating the number of clusters required for the consensus clustering. Default is 2. |
annotation |
a data frame where the variables are annotations (as labels) of samples. The row-names have to match the names of the samples. |
annotation.colorCode |
a string named list of color names. The names have to be values stored in the annotation data-frame. |
matching_clustering |
a string value matching one of the annotation valiables in the annotation data-frame. The function tries to match at best the color coding of the selected variable in the data-frame. |
consensus_colors |
a list of color provided to annotate the consensus clustering. If provided, the matching_clustering is overrided. |
... |
parameters compatible with pheatmap function. |
In the slot 'statistics', the function returns the same statistics of yaConsensus().
A named list with the following slots:
annotation |
a data frame. It is the same given in input, with 'consensus' and 'consensus.col' more variables. |
ann_colors |
a named list of colors associated with each variable in the annotation data-frame. |
hclust |
an object of hclust clust. It's the result of the hclust() applied to the consensus dissimilarity with the complete linkage. |
statistics |
see Note |
In case an 'annotation' is provided, with summary(), additional statistics are provided.
The variable specified as given in summary(..., given = "some clustering") is assumed as a theoretical clustering, while the consensus clustering is the empirical one. The entropy accuracy, precision, and average (Risso and Pagnotta, 2021) are computed with the former assumptions. summary() itself returns all the statistics. "some clustering" has to be one of the column of the annotation data.frame.
Stefano M. Pagnotta
Risso and Pagnotta (2021) - Per-sample standardization and asymmetric winsorization lead to accurate clustering of RNA-seq expression profiles - Bioinformatics, btab091, <DOI: 10.1093/bioinformatics/btab091>
# see the examples in yaConsensus help.
# see the examples in yaConsensus help.
This function mainly generates a list of "hclust" objects for downstream analysis.
yaConsensus(ddata, runs = 1000, epsilon = 0.65, is_by_sample = TRUE, distMethod = "euclidean", hcMethod = "ward.D2", prefix = NULL)
yaConsensus(ddata, runs = 1000, epsilon = 0.65, is_by_sample = TRUE, distMethod = "euclidean", hcMethod = "ward.D2", prefix = NULL)
ddata |
either a data matrix (samples in rows, and features in columns), or a "dist" object. |
runs |
an integer value for the number of samplings. |
epsilon |
a real value indicating the sampling rate. |
is_by_sample |
a logical value indicating if the sampling is by samples (TRUE) or features (FALSE). |
distMethod |
a character indicating the kind of distance for the inner clustering. It can be any of the methods from the |
hcMethod |
a character indicating the linkage mathod of the inner clustering. It can be any of the methods from the |
prefix |
string specifying a prefix to store the results in a .RData file. |
This function can run sequentially or in parallel. In this case, it is necessary to register a cluster of CPUs according to doParallel protocol.
To get the consensus clustering, the output of the function has to be processed with the plot() function. The consensus dissimilarity follows from the algorithm of Monti et al. (2003). The consensus clustering is from a hierarchical procedure (hclust) with "complete" linkage (outer hc method).
A named list with the following slots:
distMethod |
matches the input |
hcMethod |
matches the input |
lables |
a string list with the names of the samples |
bySample |
matches 'is_by_sample' input parameter |
epsilon |
matches the input |
subsetDimension |
actual dimension of the subsets |
runs |
matches the input |
hclust |
a list of 'hclust' objects |
elapsed_time |
time (in seconds) required |
ncores |
the number of cores used |
The plot function in the example provides an invisible result with detail ans statistics of the experiment.
Stefano M. Pagnotta
Monti et al. (2003) - Consensus Clustering: A Resampling-Based Method for Class Discovery and Visualization of Gene Expression Microarray Data - Machine Learning 52(1-2):91-118 <DOI: 10.1023/A:1023949509487>
## Generate data and annotation n <- 50; m <- 3000 ddata <- matrix(rnorm(n * m), ncol = m) ddata[1:20, ] <- ddata[1:20, ] + 0.2 row.names(ddata) <- c(paste0("A", 1:20), paste0("B", 1:30)) ddist <- dist(ddata) annotation <- data.frame(row.names = rownames(ddata), clust = substr(rownames(ddata), 1, 1)) annotation.colorCode <- c("red", "blue") names(annotation.colorCode) <- c("A", "B") ####### run in sequential mode ####### sampling the samples .... (aConsensus <- yaConsensus(ddist)) plot(aConsensus, G = 2) ans <- plot(aConsensus, G = 2, annotation = annotation, annotation.colorCode = annotation.colorCode) summary(ans) summary(ans, given = "clust") ####### sampling the features .... (aConsensus <- yaConsensus(ddata, runs= 20, epsilon = 0.2, is_by_sample = FALSE)) ans <- plot(aConsensus, G = 2, annotation = annotation, annotation.colorCode = annotation.colorCode, matching_clustering = "clust") summary(ans, given = "clust") ####### run in parallel mode ## uncomment to run # require(doParallel) # cpu_cluster <- makeCluster(3) # registerDoParallel(cpu_cluster) # (aConsensus <- yaConsensus(ddist)) # plot(aConsensus, G = 2) #stopCluster(cpu_cluster)
## Generate data and annotation n <- 50; m <- 3000 ddata <- matrix(rnorm(n * m), ncol = m) ddata[1:20, ] <- ddata[1:20, ] + 0.2 row.names(ddata) <- c(paste0("A", 1:20), paste0("B", 1:30)) ddist <- dist(ddata) annotation <- data.frame(row.names = rownames(ddata), clust = substr(rownames(ddata), 1, 1)) annotation.colorCode <- c("red", "blue") names(annotation.colorCode) <- c("A", "B") ####### run in sequential mode ####### sampling the samples .... (aConsensus <- yaConsensus(ddist)) plot(aConsensus, G = 2) ans <- plot(aConsensus, G = 2, annotation = annotation, annotation.colorCode = annotation.colorCode) summary(ans) summary(ans, given = "clust") ####### sampling the features .... (aConsensus <- yaConsensus(ddata, runs= 20, epsilon = 0.2, is_by_sample = FALSE)) ans <- plot(aConsensus, G = 2, annotation = annotation, annotation.colorCode = annotation.colorCode, matching_clustering = "clust") summary(ans, given = "clust") ####### run in parallel mode ## uncomment to run # require(doParallel) # cpu_cluster <- makeCluster(3) # registerDoParallel(cpu_cluster) # (aConsensus <- yaConsensus(ddist)) # plot(aConsensus, G = 2) #stopCluster(cpu_cluster)