Skip to content

Commit

Permalink
Merge pull request #1 from ycl6/add-seed-to-netEmbedding
Browse files Browse the repository at this point in the history
Add a 'seed' parameter to the netEmbedding function
  • Loading branch information
ycl6 authored Jun 27, 2024
2 parents 88c2e13 + 8f2e7c8 commit 23969ae
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
17 changes: 14 additions & 3 deletions R/analysis.R
Original file line number Diff line number Diff line change
Expand Up @@ -643,14 +643,15 @@ computeNetSimilarityPairwise <- function(object, slot.name = "netP", type = c("f
#' @param min_dist This controls how tightly the embedding is allowed compress points together.
#' Larger values ensure embedded points are moreevenly distributed, while smaller values allow the
#' algorithm to optimise more accurately with regard to local structure. Sensible values are in the range 0.001 to 0.5.
#' @param seed An integer value indicating the random seed passed to \code{\link[base]{set.seed}}, use `NULL` to re-initializes seed. Defaults to 42.
#' @param ... Parameters passing to umap
#' @importFrom methods slot
#' @return
#' @export
#'
#' @examples
netEmbedding <- function(object, slot.name = "netP", type = c("functional","structural"), comparison = NULL, pathway.remove = NULL,
umap.method = c("umap-learn", "uwot"), n_neighbors = NULL,min_dist = 0.3,...) {
umap.method = c("umap-learn", "uwot"), n_neighbors = NULL, min_dist = 0.3, seed = 42,...) {
umap.method <- match.arg(umap.method)
if (object@options$mode == "single") {
comparison <- "single"
Expand All @@ -674,11 +675,21 @@ netEmbedding <- function(object, slot.name = "netP", type = c("functional","stru
n_neighbors <- ceiling(sqrt(dim(Similarity)[1])) + 1
}
options(warn = -1)

if (is.numeric(seed)) {
seed <- as.integer(seed)
}

# dimension reduction
if (umap.method == "umap-learn") {
Y <- runUMAP(Similarity, min_dist = min_dist, n_neighbors = n_neighbors,...)
Y <- runUMAP(Similarity, min_dist = min_dist, n_neighbors = n_neighbors, seed.use = seed,...)
} else if (umap.method == "uwot") {
Y <- uwot::umap(Similarity, min_dist = min_dist, n_neighbors = n_neighbors,...)
if(packageVersion("uwot")<"0.1.15") {
set.seed(seed)
Y <- uwot::umap(Similarity, min_dist = min_dist, n_neighbors = n_neighbors,...)
} else {
Y <- uwot::umap(Similarity, min_dist = min_dist, n_neighbors = n_neighbors, seed = seed...)
}
colnames(Y) <- paste0('UMAP', 1:ncol(Y))
rownames(Y) <- colnames(Similarity)
}
Expand Down
3 changes: 3 additions & 0 deletions man/netEmbedding.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 23969ae

Please sign in to comment.