Diff of /R/getLRAcluster.R [000000] .. [494cbf]

Switch to unified view

a b/R/getLRAcluster.R
1
#' @name getLRAcluster
2
#' @title Get subtypes from LRAcluster
3
#' @description This function wraps the LRAcluster (Integrated cancer omics data anlsysi by low rank approximation) algorithm and provides standard output for `getMoHeatmap()` and `getConsensusMOIC()`.
4
#' @param data List of matrices.
5
#' @param N.clust Number of clusters.
6
#' @param clusterAlg A string value to indicate the cluster algorithm for similarity matrix; 'ward.D' by default.
7
#' @param type Data type corresponding to the list of matrics, which can be gaussian, binomial or possion; 'gaussian' by default.
8
#' @return A list with the following components:
9
#'
10
#'         \code{fit}        an object returned by \link[LRAcluster]{LRAcluster}.
11
#'
12
#'         \code{clust.res}  a data.frame storing sample ID and corresponding clusters.
13
#'
14
#'         \code{clust.dend} a dendrogram of sample clustering.
15
#'
16
#'         \code{mo.method}  a string value indicating the method used for multi-omics integrative clustering.
17
#' @examples # There is no example and please refer to vignette.
18
#' @importFrom dplyr %>%
19
#' @export
20
#' @references Wu D, Wang D, Zhang MQ, Gu J (2015). Fast dimension reduction and integrative clustering of multi-omics data using low-rank approximation: application to cancer molecular classification. BMC Genomics, 16(1):1022.
21
getLRAcluster <- function(data       = NULL,
22
                          N.clust    = NULL,
23
                          type       = rep("gaussian", length(data)),
24
                          clusterAlg = "ward.D"){
25
26
  # check data
27
  n_dat <- length(data)
28
  if(n_dat > 6){
29
    stop('current verision of MOVICS can support up to 6 datasets.')
30
  }
31
  if(n_dat < 2){
32
    stop('current verision of MOVICS needs at least 2 omics data.')
33
  }
34
35
  data <- lapply(data, as.matrix)
36
37
  if(is.element("binomial",type)) {
38
    bindex <- which(type == "binomial")
39
    for (i in bindex) {
40
      a <- which(rowSums(data[[i]]) == 0)
41
      b <- which(rowSums(data[[i]]) == ncol(data[[i]]))
42
      if(length(a) > 0) {
43
        data[[i]] <- data[[i]][which(rowSums(data[[i]]) != 0),] # remove all zero
44
      }
45
46
      if(length(b) > 0) {
47
        data[[i]] <- data[[i]][which(rowSums(data[[i]]) != ncol(data[[i]])),] # remove all one
48
      }
49
50
      if(length(a) + length(b) > 0) {
51
        message(paste0("--", names(data)[i],": a total of ",length(a) + length(b), " features were removed due to the categories were not equal to 2!"))
52
      }
53
    }
54
    type[bindex] <- "binary"
55
  }
56
57
  fit <- LRAcluster(data, dimension = N.clust, types = as.list(type))
58
  dist <- fit$coordinate %>% t %>% dist
59
  clust.dend <- hclust(dist, method = clusterAlg)
60
61
  clustres <- data.frame(samID = colnames(data[[1]]),
62
                         clust = cutree(clust.dend,k = N.clust),
63
                         row.names = colnames(data[[1]]),
64
                         stringsAsFactors = FALSE)
65
  #clustres <- clustres[order(clustres$clust),]
66
67
  return(list(fit = fit, clust.res = clustres, clust.dend = clust.dend, mo.method = "LRAcluster"))
68
}