dRWR: Function to implement Random Walk with Restart (RWR) on the...

Description Usage Arguments Value Note See Also Examples

View source: R/dRWR.r

Description

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.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
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
)

Arguments

g

an object of class "igraph" or "graphNEL"

normalise

the way to normalise the adjacency matrix of the input graph. It can be 'laplacian' for laplacian normalisation, 'row' for row-wise normalisation, 'column' for column-wise normalisation, or 'none'

setSeeds

an input matrix used to define sets of starting seeds. One column corresponds to one set of seeds that a walker starts with. The input matrix must have row names, coming from node names of input graph, i.e. V(g)$name, since there is a mapping operation. The non-zero entries mean that the corresonding rows (i.e. the gene/row names) are used as the seeds, and non-zero values can be viewed as how to weight the relative importance of seeds. By default, this option sets to "NULL", suggesting each node in the graph will be used as a set of the seed to pre-compute affinity matrix for the input graph. This default does not scale for large input graphs since it will loop over every node in the graph; however, the pre-computed affinity matrix can be extensively reused for obtaining affinity scores between any combinations of nodes/seeds, allows for some flexibility in the downstream use, in particular when sampling a large number of random node combinations for statistical testing

restart

the restart probability used for RWR. The restart probability takes the value from 0 to 1, controlling the range from the starting nodes/seeds that the walker will explore. The higher the value, the more likely the walker is to visit the nodes centered on the starting nodes. At the extreme when the restart probability is zero, the walker moves freely to the neighbors at each step without restarting from seeds, i.e., following a random walk (RW)

normalise.affinity.matrix

the way to normalise the output affinity matrix. It can be 'none' for no normalisation, 'quantile' for quantile normalisation to ensure that columns (if multiple) of the output affinity matrix have the same quantiles

parallel

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("http://bioconductor.org/biocLite.R"); biocLite(c("foreach","doParallel")). If not yet installed, this option will be disabled

multicores

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

verbose

logical to indicate whether the messages will be displayed in the screen. By default, it sets to true for display

Value

It returns a sparse matrix, called 'PTmatrix':

Note

The input graph will treat as an unweighted graph if there is no 'weight' edge attribute associated with

See Also

dRWRcontact, dRWRpipeline, dCheckParallel

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
## Not run: 
# 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)
# visualise affinity matrix
visHeatmapAdv(PTmatrix, Rowv=FALSE, Colv=FALSE, colormap="wyr",
KeyValueName="Affinity")

# 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)
PTmatrix

## End(Not run)

Example output

Loading required package: igraph

Attaching package: 'igraph'

The following objects are masked from 'package:stats':

    decompose, spectrum

The following object is masked from 'package:base':

    union

Loading required package: supraHex
Loading required package: hexbin
Start at 2017-11-08 20:43:14

First, get the adjacency matrix of the input graph (2017-11-08 20:43:14) ...
	Notes: using unweighted graph!
Then, normalise the adjacency matrix using laplacian normalisation (2017-11-08 20:43:14) ...
Third, RWR of 6 sets of seeds using 7.5e-01 restart probability (2017-11-08 20:43:14) ...
	1 out of 6 seed sets (2017-11-08 20:43:14)
	2 out of 6 seed sets (2017-11-08 20:43:14)
	3 out of 6 seed sets (2017-11-08 20:43:14)
	4 out of 6 seed sets (2017-11-08 20:43:14)
	5 out of 6 seed sets (2017-11-08 20:43:14)
	6 out of 6 seed sets (2017-11-08 20:43:14)
Fourth, rescale steady probability vector (2017-11-08 20:43:14) ...
Finally, output 6 by 6 affinity matrix normalised by none (2017-11-08 20:43:14) ...

Finish at 2017-11-08 20:43:14
Runtime in total is: 0 secs

<sparse>[ <logic> ] : .M.sub.i.logical() maybe inefficient
<sparse>[ <logic> ] : .M.sub.i.logical() maybe inefficient
Start at 2017-11-08 20:43:15

First, get the adjacency matrix of the input graph (2017-11-08 20:43:15) ...
	Notes: using unweighted graph!
Then, normalise the adjacency matrix using laplacian normalisation (2017-11-08 20:43:15) ...
Third, RWR of 2 sets of seeds using 7.5e-01 restart probability (2017-11-08 20:43:15) ...
	1 out of 2 seed sets (2017-11-08 20:43:15)
	2 out of 2 seed sets (2017-11-08 20:43:15)
Fourth, rescale steady probability vector (2017-11-08 20:43:15) ...
Finally, output 6 by 2 affinity matrix normalised by none (2017-11-08 20:43:15) ...

Finish at 2017-11-08 20:43:15
Runtime in total is: 0 secs

Warning message:
In dRWR(g = subg, normalise = "laplacian", setSeeds = setSeeds,  :
  The row names of input setSeeds do not contain all those in the input graph.

6 x 2 sparse Matrix of class "dgCMatrix"
                            
[1,] 0.302448845 0.059856293
[2,] 0.085486932 0.078275655
[3,] 0.297211352 0.400574774
[4,] 0.006779353 0.009137083
[5,] 0.269723654 0.400469149
[6,] 0.038349865 0.051687047

dnet documentation built on Feb. 20, 2020, 5:08 p.m.

Related to dRWR in dnet...