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

Switch to unified view

a b/R/getCIMLR.R
1
#' @name getCIMLR
2
#' @title Get subtypes from CIMLR
3
#' @description This function wraps the CIMLR (Cancer Integration via Multikernel Learning) algorithm and provides standard output for `getMoHeatmap()` and `getConsensusMOIC()`.
4
#' @param data List of matrices.
5
#' @param N.clust Number of clusters.
6
#' @param cores.ratio Ratio of the number of cores to be used when computing the multi-kernel.
7
#' @param verbose A logic value to indicate if supressing progression.
8
#' @param type Data type corresponding to the list of matrics, which can be gaussian, binomial or possion.
9
#' @return A list with the following components:
10
#'
11
#'         \code{fit}       an object returned by \link[CIMLR]{CIMLR}.
12
#'
13
#'         \code{clust.res} a data.frame storing sample ID and corresponding clusters.
14
#'
15
#'         \code{feat.res}  the results of features selection process.
16
#'
17
#'         \code{mo.method} a string value indicating the method used for multi-omics integrative clustering.
18
#' @import CIMLR
19
#' @export
20
#' @examples # There is no example and please refer to vignette.
21
#' @references Ramazzotti D, Lal A, Wang B, Batzoglou S, Sidow A (2018). Multi-omic tumor data reveal diversity of molecular mechanisms that correlate with survival. Nat Commun, 9(1):4453.
22
getCIMLR <- function(data        = NULL,
23
                     N.clust     = NULL,
24
                     type        = rep("gaussian", length(data)),
25
                     cores.ratio = 0,
26
                     verbose     = TRUE){
27
28
  # check data
29
  n_dat <- length(data)
30
  if(n_dat > 6){
31
    stop('current verision of MOVICS can support up to 6 datasets.')
32
  }
33
  if(n_dat < 2){
34
    stop('current verision of MOVICS needs at least 2 omics data.')
35
  }
36
37
  useless.argument <- type
38
  if(verbose) {
39
    fit <- quiet(CIMLR(data,
40
                       c= N.clust,
41
                       cores.ratio = cores.ratio))
42
  } else {
43
    fit <- CIMLR(data,
44
                 c= N.clust,
45
                 cores.ratio = cores.ratio)
46
  }
47
48
  message("clustering done...")
49
  input_dat <- do.call(rbind,lapply(seq(along = data), function(x){
50
    ddd <- data[[x]]
51
    rownames(ddd) <- paste(rownames(ddd), names(data)[x], sep = "+")
52
    ddd
53
  }))
54
55
  if(verbose) {
56
    ranks <- quiet(CIMLR_Feature_Ranking(A = fit$S, X = input_dat))
57
  } else {
58
    ranks <- CIMLR_Feature_Ranking(A = fit$S, X = input_dat)
59
  }
60
  ranks$names <- rownames(input_dat)[ranks$aggR]
61
  fit$selectfeatures <- ranks
62
  message("feature selection done...")
63
64
  clustres <- data.frame(samID = colnames(data[[1]]),
65
                         clust = fit$y$cluster,
66
                         row.names = colnames(data[[1]]),
67
                         stringsAsFactors = FALSE)
68
  #clustres <- clustres[order(clustres$clust),]
69
70
  f <- sapply(strsplit(ranks$name, "+",fixed = TRUE), "[",1)
71
  d <- sapply(strsplit(ranks$name, "+",fixed = TRUE), "[",2)
72
73
  featres <- data.frame(feature = f,
74
                        dataset = d,
75
                        pvalue = ranks$pval,
76
                        stringsAsFactors = FALSE)
77
  feat.res <- NULL
78
  for (d in unique(featres$dataset)) {
79
    tmp <- featres[which(featres$dataset == d),]
80
    tmp <- tmp[order(tmp$pvalue, decreasing = FALSE),]
81
    tmp$rank <- 1:nrow(tmp)
82
    feat.res <- rbind.data.frame(feat.res,tmp)
83
  }
84
85
  return(list(fit = fit, clust.res = clustres, feat.res = feat.res, mo.method = "CIMLR"))
86
}