dRWR
is supposed to implement Random Walk with Restart (RWR) on
the input graph. If the seeds (i.e. a set of starting nodes) are given,
it intends to calculate the affinity score of all nodes in the graph to
the seeds. If the seeds are not given, it will pre-compute affinity
matrix for nodes in the input graph with respect to each starting node
(as a seed) by looping over every node in the graph. Parallel computing
is also supported for Linux or Mac operating systems.
dRWR(g, normalise = c("laplacian", "row", "column", "none"), setSeeds = NULL, restart = 0.75, normalise.affinity.matrix = c("none", "quantile"), parallel = TRUE, multicores = NULL, verbose = T)
source("http://bioconductor.org/biocLite.R");
biocLite(c("foreach","doParallel"))
. If not yet installed, this option
will be disabledIt returns a sparse matrix, called 'PTmatrix':
The input graph will treat as an unweighted graph if there is no 'weight' edge attribute associated with
# 1) generate a random graph according to the ER model g <- erdos.renyi.game(100, 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) obtain the pre-computated affinity matrix PTmatrix <- dRWR(g=subg, normalise="laplacian", restart=0.75, parallel=FALSE)Start at 2018-01-19 12:36:53 First, get the adjacency matrix of the input graph (2018-01-19 12:36:53) ... Notes: using unweighted graph! Then, normalise the adjacency matrix using laplacian normalisation (2018-01-19 12:36:53) ... Third, RWR of 10 sets of seeds using 7.5e-01 restart probability (2018-01-19 12:36:53) ... 1 out of 10 seed sets (2018-01-19 12:36:53) 2 out of 10 seed sets (2018-01-19 12:36:53) 3 out of 10 seed sets (2018-01-19 12:36:53) 4 out of 10 seed sets (2018-01-19 12:36:53) 5 out of 10 seed sets (2018-01-19 12:36:53) 6 out of 10 seed sets (2018-01-19 12:36:53) 7 out of 10 seed sets (2018-01-19 12:36:53) 8 out of 10 seed sets (2018-01-19 12:36:53) 9 out of 10 seed sets (2018-01-19 12:36:53) 10 out of 10 seed sets (2018-01-19 12:36:54) Fourth, rescale steady probability vector (2018-01-19 12:36:54) ... Finally, output 10 by 10 affinity matrix normalised by none (2018-01-19 12:36:54) ... Finish at 2018-01-19 12:36:54 Runtime in total is: 1 secs# visualise affinity matrix visHeatmapAdv(PTmatrix, Rowv=FALSE, Colv=FALSE, colormap="wyr", KeyValueName="Affinity")[ ] : .M.sub.i.logical() maybe inefficient [ ] : .M.sub.i.logical() maybe inefficient # 4) obtain affinity matrix given sets of seeds # define sets of seeds # 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) setSeeds <- data.frame(aSeeds,bSeeds) rownames(setSeeds) <- 1:5 # calcualte affinity matrix PTmatrix <- dRWR(g=subg, normalise="laplacian", setSeeds=setSeeds, restart=0.75, parallel=FALSE)Start at 2018-01-19 12:36:54 First, get the adjacency matrix of the input graph (2018-01-19 12:36:54) ... Notes: using unweighted graph! Then, normalise the adjacency matrix using laplacian normalisation (2018-01-19 12:36:54) ... Warning message: The row names of input setSeeds do not contain all those in the input graph. Third, RWR of 2 sets of seeds using 7.5e-01 restart probability (2018-01-19 12:36:54) ... 1 out of 2 seed sets (2018-01-19 12:36:54) 2 out of 2 seed sets (2018-01-19 12:36:54) Fourth, rescale steady probability vector (2018-01-19 12:36:54) ... Finally, output 10 by 2 affinity matrix normalised by none (2018-01-19 12:36:54) ... Finish at 2018-01-19 12:36:54 Runtime in total is: 0 secsPTmatrix10 x 2 sparse Matrix of class "dgCMatrix" [1,] 0.273208494 0.001135635 [2,] 0.002865975 0.004204153 [3,] 0.270493764 0.401098697 [4,] 0.025633941 0.037603003 [5,] 0.274441716 0.408020940 [6,] 0.053002619 0.006424149 [7,] 0.048514885 0.072128580 [8,] 0.002865975 0.004204153 [9,] 0.046106655 0.060976538 [10,] 0.002865975 0.004204153