a b/R/getSNF.R
1
#' @name getSNF
2
#' @title Get subtypes from SNF
3
#' @description This function wraps the SNF (Similarity Network Fusion) algorithm and provides standard output for `getMoHeatmap()` and `getConsensusMOIC()`.
4
#' @param data List of matrices.
5
#' @param N.clust Number of clusters.
6
#' @param K An integer value to indicate the number of neighbors in K-nearest neighbors part of the algorithm.
7
#' @param t An integer value to indicate the number of interations for the diffusion process.
8
#' @param sigma A numerical value to indicate the variance for local model.
9
#' @param type Data type corresponding to the list of matrics, which can be gaussian, binomial or possion.
10
#' @return A list with the following components:
11
#'
12
#'         \code{fit}       an object returned by \link[SNFtool]{SNF}.
13
#'
14
#'         \code{clust.res} a data.frame storing sample ID and corresponding clusters.
15
#'
16
#'         \code{mo.method} a string value indicating the method used for multi-omics integrative clustering.
17
#' @export
18
#' @examples # There is no example and please refer to vignette.
19
#' @import SNFtool
20
#' @importFrom dplyr %>%
21
#' @references Wang B, Mezlini AM, Demir F, et al (2014). Similarity network fusion for aggregating data types on a genomic scale. Nat Methods, 11(3):333-337.
22
getSNF <- function(data    = NULL,
23
                   N.clust = NULL,
24
                   type    = rep("gaussian", length(data)),
25
                   K       = 30,
26
                   t       = 20,
27
                   sigma   = 0.5){
28
29
  # check data
30
  n_dat <- length(data)
31
  if(n_dat > 6){
32
    stop('current verision of MOVICS can support up to 6 datasets.')
33
  }
34
  if(n_dat < 2){
35
    stop('current verision of MOVICS needs at least 2 omics data.')
36
  }
37
38
  useless.argument <- type
39
  data <- lapply(data, t)
40
41
  dat <- lapply(data, function (dd){
42
    dd <- dd %>% as.matrix
43
    W <- dd %>% SNFtool::dist2(dd) %>% SNFtool::affinityMatrix(K = K, sigma = sigma)
44
  })
45
  W <-  SNFtool::SNF(Wall = dat,
46
                     K    = K,
47
                     t    = t)
48
  clust.SNF = W %>% SNFtool::spectralClustering(N.clust)
49
50
  clustres <- data.frame(samID = rownames(data[[1]]),
51
                         clust = clust.SNF,
52
                         row.names = rownames(data[[1]]),
53
                         stringsAsFactors = FALSE)
54
  #clustres <- clustres[order(clustres$clust),]
55
56
  return(list(fit = W, clust.res = clustres, mo.method = "SNF"))
57
}