File: cluster_signatures.R

package info (click to toggle)
r-bioc-mutationalpatterns 3.16.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,360 kB
  • sloc: sh: 8; makefile: 2
file content (41 lines) | stat: -rw-r--r-- 1,334 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#' Signature clustering function
#'
#' Hierarchical clustering of signatures based on cosine similarity
#'
#' @param signatures Matrix with 96 trinucleotides (rows) and any number of
#' signatures (columns)
#' @param method     The agglomeration method to be used for hierarchical
#' clustering. This should be one of "ward.D", "ward.D2", "single", "complete",
#' "average" (= UPGMA), "mcquitty" (= WPGMA), "median" (= WPGMC) or
#' "centroid" (= UPGMC). Default = "complete".
#' @return hclust object
#'
#' @examples
#' ## Get signatures
#' signatures <- get_known_signatures()
#'
#' ## See the 'mut_matrix()' example for how we obtained the mutation matrix:
#' mut_mat <- readRDS(system.file("states/mut_mat_data.rds",
#'   package = "MutationalPatterns"
#' ))
#'
#'
#' ## Hierarchically cluster the cancer signatures based on cosine similarity
#' hclust_signatures <- cluster_signatures(signatures)
#'
#' ## Plot dendrogram
#' plot(hclust_signatures)
#' @seealso
#' \code{\link{plot_contribution_heatmap}}
#'
#' @export

cluster_signatures <- function(signatures, method = "complete") {
  # construct cosine similarity matrix
  sim <- cos_sim_matrix(signatures, signatures)
  # transform to distance
  dist <- as.dist(1 - sim)
  # perform hierarchical clustering
  hc_sig_cos <- hclust(dist, method = method)
  return(hc_sig_cos)
}