Nothing
# Convert a legacy NEArender adjacency list to a sparse indexed network.
# Weight preservation is reserved for public conversion; NEA needs only binary
# adjacency and avoids allocating a second sparse matrix.
index_sparse_network <- function(net, preserve_weights = FALSE) {
.assert_flag(preserve_weights, "preserve_weights")
weight_values <- NULL
if (igraph::is_igraph(net)) {
node_names <- igraph::vertex_attr(net, "name")
edge_ids <- igraph::as_edgelist(net, names = FALSE)
from <- c(edge_ids[, 1L], edge_ids[, 2L])
to <- c(edge_ids[, 2L], edge_ids[, 1L])
n_edges <- igraph::ecount(net)
if (preserve_weights && "weight" %in% igraph::edge_attr_names(net)) {
edge_weights <- as.numeric(igraph::edge_attr(net, "weight"))
weight_values <- c(edge_weights, edge_weights)
}
} else {
if (is.null(net$links) || !is.list(net$links) || is.null(names(net$links))) {
stop("net$links must be a named adjacency list.", call. = FALSE)
}
node_names <- unique(c(
names(net$links),
unlist(net$links, use.names = FALSE)
))
link_counts <- lengths(net$links)
from <- rep(match(names(net$links), node_names), link_counts)
to <- match(unlist(net$links, use.names = FALSE), node_names)
n_edges <- net$Ntotal
if (preserve_weights && !is.null(net$weights)) {
weight_values <- unlist(Map(function(node, adjacent) {
unname(net$weights[[node]][adjacent])
}, names(net$links), net$links), use.names = FALSE)
}
}
node_id <- seq_along(node_names)
names(node_id) <- node_names
valid <- !is.na(from) & !is.na(to)
adjacency <- Matrix::sparseMatrix(
i = from[valid],
j = to[valid],
x = 1,
dims = c(length(node_names), length(node_names)),
dimnames = list(node_names, node_names)
)
adjacency <- Matrix::drop0(sign(adjacency))
weights <- NULL
if (!is.null(weight_values)) {
weights <- Matrix::sparseMatrix(
i = from[valid],
j = to[valid],
x = weight_values[valid],
dims = c(length(node_names), length(node_names)),
dimnames = list(node_names, node_names)
)
}
indexed <- structure(
list(
adjacency = adjacency,
weights = weights,
node_names = node_names,
node_id = node_id,
n_edges = n_edges
),
class = c("nearender_sparse_network", "nearender_indexed_network")
)
metadata <- .normalization_metadata(net)
if (is.list(metadata) && identical(metadata$normalized, TRUE)) {
indexed <- .mark_normalized(indexed, metadata$case_sensitive)
}
.copy_identifier_metadata(indexed, net)
}
# Convert named gene sets to a sparse node-by-set membership matrix.
make_sparse_membership <- function(gene_sets, node_id) {
if (!is.list(gene_sets) || is.null(names(gene_sets))) {
stop("gene_sets must be a named list.", call. = FALSE)
}
mapped <- lapply(gene_sets, function(genes) {
ids <- unname(node_id[unique(genes)])
ids[!is.na(ids)]
})
mapped_sizes <- lengths(mapped)
membership <- Matrix::sparseMatrix(
i = unlist(mapped, use.names = FALSE),
j = rep(seq_along(mapped), mapped_sizes),
x = 1,
dims = c(length(node_id), length(gene_sets)),
dimnames = list(names(node_id), names(gene_sets))
)
list(
matrix = membership,
original_sizes = lengths(gene_sets),
mapped_sizes = mapped_sizes
)
}
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.