Description Usage Arguments Examples
K-function on networks
1 |
g |
|
nperm |
|
distmethod |
|
prob |
|
phenotype |
|
verbose |
|
parallel |
|
... |
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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | ##---- Should be DIRECTLY executable !! ----
##-- ==> Define data, use random,
##-- or do help(data=index) for the standard data sets.
## The function is currently defined as
function (g, nperm = 100, distmethod = "shortest.paths", prob = c(0,
0.05, 0.5, 0.95, 1), phenotype = "hits", verbose = TRUE,
parallel = NULL, ...)
{
if (verbose)
cat("Computing distances on graph\n")
D <- dist.graph(g, method = distmethod)
K <- Knet.fct(g, distmethod = distmethod, phenotype = phenotype,
D = D, ...)
K.obs <- K$K
AUK.obs <- K$AUK
if (!is.null(nperm) && nperm > 1) {
if (verbose)
cat(paste("Knet with", nperm, "permutations\n"))
if (verbose)
if (nperm < 50)
cat("Don't be shy! Try some more permutations next time ...\n")
if (is.null(parallel)) {
K.perm <- sapply(1:nperm, function(i) Knet.fct(permute.hits(g,
phenotype), phenotype = phenotype, D = D, ...)$K)
}
else {
if (!is.wholenumber(parallel))
stop("Argument 'parallel' is not a whole number")
if (verbose)
cat("Setting up cluster of size", parallel)
cl <- makeCluster(parallel, type = "SOCK")
clusterEvalQ(cl, source("/Users/markow01/Dropbox/Papers in preparation/Network Enrichment Analysis/functions_2010-12-10.R"))
clusterExport(cl, c("g", "D", "phenotype"))
if (verbose)
cat("Running permutations on cluster\n")
K.perm <- parSapply(cl, 1:nperm, function(i) Knet.fct(permute.hits(g,
phenotype), phenotype = phenotype, D = D)$K)
stopCluster(cl)
}
K.quan <- apply(K.perm, 1, function(x) quantile(x, prob = prob))
AUK.perm <- apply(K.perm, 2, function(x) sum(x)/length(x))
pval <- max(sum(AUK.perm > AUK.obs), 1)/nperm
}
else {
if (verbose)
cat(paste("Knet without permutations\n"))
K.perm <- NA
K.quan <- NA
AUK.perm <- NA
pval <- NA
}
res <- list(graph = K$g, K.obs = K.obs, AUK.obs = AUK.obs,
K.perm = K.perm, AUK.perm = AUK.perm, K.quan = K.quan,
nodeK = K$nodeK, nodeAUK = K$nodeAUK, pval = pval)
class(res) <- "Knet"
invisible(res)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.