Function to estimate RWR-based contact strength between samples from an input gene-sample data matrix, an input graph and its pre-computed affinity matrix


dRWRcontact is supposed to estimate sample relationships (ie. contact strength between samples) from an input gene-sample matrix, an input graph and its affinity matrix pre-computed according to random walk restart (RWR) of the input graph. It includes: 1) RWR-smoothed columns of input gene-sample matrix based on the pre-computed affinity matrix; 2) calculation of contact strength (inner products of RWR-smooth columns of input gene-sample matrix); 3) estimation of the contact signficance by a randomalisation procedure. Parallel computing is also supported for Linux or Mac operating systems.


dRWRcontact(data, g, Amatrix, permutation = c("random", "degree"), num.permutation = 10, 
  p.adjust.method = c("BH", "BY", "bonferroni", "holm", "hochberg", "hommel"), 
      adjp.cutoff = 0.05, parallel = TRUE, multicores = NULL, verbose = T)


an input gene-sample data matrix used for seeds. Each value in input gene-sample matrix does not necessarily have to be binary (non-zeros will be used as a weight, but should be non-negative for easy interpretation).
an object of class "igraph" or "graphNEL"
an affinity matrix pre-computed from the input graph. Notes: columns for starting nodes walking from, and rows for ending nodes walking to
how to do permutation. It can be 'degree' for degree-preserving permutation, 'random' for permutation purely in random
the number of permutations used to for generating the distribution of contact strength under randomalisation
the method used to adjust p-values. It can be one of "BH", "BY", "bonferroni", "holm", "hochberg" and "hommel". The first two methods "BH" (widely used) and "BY" control the false discovery rate (FDR: the expected proportion of false discoveries amongst the rejected hypotheses); the last four methods "bonferroni", "holm", "hochberg" and "hommel" are designed to give strong control of the family-wise error rate (FWER). Notes: FDR is a less stringent condition than FWER
the cutoff of adjusted pvalue to construct the contact graph
logical to indicate whether parallel computation with multicores is used. By default, it sets to true, but not necessarily does so. It will depend on whether these two packages "foreach" and "doParallel" have been installed. It can be installed via: source(""); biocLite(c("foreach","doParallel")). If not yet installed, this option will be disabled
an integer to specify how many cores will be registered as the multicore parallel backend to the 'foreach' package. If NULL, it will use a half of cores available in a user's computer. This option only works when parallel computation is enabled
logical to indicate whether the messages will be displayed in the screen. By default, it sets to true for display


an object of class "dContact", a list with following components:

  • ratio: a symmetric matrix storing ratio (the observed against the expected) between pairwise samples
  • zscore: a symmetric matrix storing zscore between pairwise samples
  • pval: a symmetric matrix storing pvalue between pairwise samples
  • adjpval: a symmetric matrix storing adjusted pvalue between pairwise samples
  • cgraph: the constructed contact graph (as a 'igraph' object) under the cutoff of adjusted value
  • call: the call that produced this result




# 1) generate a random graph according to the ER model g <-, 1/100) # 2) produce the induced subgraph only based on the nodes in query subg <- dNetInduce(g, V(g), knn=0) V(subg)$name <- 1:vcount(subg) # 3) pre-compute affinity matrix from the input graph Amatrix <- dRWR(g=subg, parallel=FALSE)
Start at 2018-01-19 12:36:55 First, get the adjacency matrix of the input graph (2018-01-19 12:36:55) ... Notes: using unweighted graph! Then, normalise the adjacency matrix using laplacian normalisation (2018-01-19 12:36:55) ... Third, RWR of 8 sets of seeds using 7.5e-01 restart probability (2018-01-19 12:36:55) ... 1 out of 8 seed sets (2018-01-19 12:36:55) 2 out of 8 seed sets (2018-01-19 12:36:55) 3 out of 8 seed sets (2018-01-19 12:36:55) 4 out of 8 seed sets (2018-01-19 12:36:55) 5 out of 8 seed sets (2018-01-19 12:36:55) 6 out of 8 seed sets (2018-01-19 12:36:55) 7 out of 8 seed sets (2018-01-19 12:36:55) 8 out of 8 seed sets (2018-01-19 12:36:55) Fourth, rescale steady probability vector (2018-01-19 12:36:55) ... Finally, output 8 by 8 affinity matrix normalised by none (2018-01-19 12:36:55) ... Finish at 2018-01-19 12:36:55 Runtime in total is: 0 secs
# 4) estimate RWR-based sample relationships # define sets of seeds as data # each seed with equal weight (i.e. all non-zero entries are '1') aSeeds <- c(1,0,1,0,1) bSeeds <- c(0,0,1,0,1) data <- data.frame(aSeeds,bSeeds) rownames(data) <- 1:5 # calcualte their two contacts dContact <- dRWRcontact(data=data, g=subg, Amatrix=Amatrix, parallel=FALSE)
Start at 2018-01-19 12:36:55 First, RWR on input graph (8 nodes and 8 edges) using input matrix (5 rows and 2 columns) as seeds and pre-computed affinity matrix (8 rows and 8 columns) (2018-01-19 12:36:55)... Second, calculate contact strength (2018-01-19 12:36:55)... Third, generate the distribution of contact strength based on 10 permutations on nodes respecting random (2018-01-19 12:36:55)... 1 out of 10 (2018-01-19 12:36:55) 2 out of 10 (2018-01-19 12:36:55) 3 out of 10 (2018-01-19 12:36:55) 4 out of 10 (2018-01-19 12:36:55) 5 out of 10 (2018-01-19 12:36:55) 6 out of 10 (2018-01-19 12:36:55) 7 out of 10 (2018-01-19 12:36:55) 8 out of 10 (2018-01-19 12:36:55) 9 out of 10 (2018-01-19 12:36:55) 10 out of 10 (2018-01-19 12:36:55) Last, estimate the significance of contact strength: zscore, pvalue, and BH adjusted-pvalue (2018-01-19 12:36:55)... Also, construct the contact graph under the cutoff 5.0e-02 of adjusted-pvalue (2018-01-19 12:36:55)... Finish at 2018-01-19 12:36:55 Runtime in total is: 0 secs
$ratio aSeeds bSeeds aSeeds 1.067951 1.085205 bSeeds 1.085205 1.065881 $zscore aSeeds bSeeds aSeeds 0.8876375 1.2074194 bSeeds 1.2074194 0.9311248 $pval aSeeds bSeeds aSeeds 0.3 0.1 bSeeds 0.1 0.2 $adjpval aSeeds bSeeds aSeeds 0.3 0.1 bSeeds 0.1 0.2 $cgraph IGRAPH a6b96ce UN-- 2 0 -- + attr: name (v/c) + edges from a6b96ce (vertex names): $call dRWRcontact(data = data, g = subg, Amatrix = Amatrix, parallel = FALSE) $method [1] "dnet" attr(,"class") [1] "dContact"