Skip to content

Commit

Permalink
run biocstyle
Browse files Browse the repository at this point in the history
  • Loading branch information
josschavezf committed Nov 16, 2024
1 parent 86bd01f commit 2a83ded
Show file tree
Hide file tree
Showing 45 changed files with 2,848 additions and 2,584 deletions.
124 changes: 60 additions & 64 deletions R/NN_network.R
Original file line number Diff line number Diff line change
Expand Up @@ -128,22 +128,21 @@ NULL

#' @rdname createNetwork
#' @export
createNetwork <- function(
x,
type = c("sNN", "kNN", "delaunay"),
method = c("dbscan", "geometry", "RTriangle", "deldir"),
node_ids = NULL,
include_distance = TRUE,
include_weight = TRUE,
as.igraph = TRUE,
verbose = NULL,
...) {
createNetwork <- function(x,
type = c("sNN", "kNN", "delaunay"),
method = c("dbscan", "geometry", "RTriangle", "deldir"),
node_ids = NULL,
include_distance = TRUE,
include_weight = TRUE,
as.igraph = TRUE,
verbose = NULL,
...) {
# NSE vars
from <- to <- NULL

# check params
type <- match.arg(type, choices = c("sNN", "kNN", "delaunay"))

mdef <- c("dbscan", "geometry", "RTriangle", "deldir")
if (type %in% c("sNN", "kNN")) {
mchoices <- c("dbscan")
Expand All @@ -153,7 +152,7 @@ createNetwork <- function(
mchoices <- c("geometry", "RTriangle", "deldir")
if (identical(method, mdef)) method <- mchoices
}

method <- switch(type,
"sNN" = match.arg(method, choices = mchoices, several.ok = TRUE),
"kNN" = match.arg(method, choices = mchoices, several.ok = TRUE),
Expand All @@ -162,9 +161,11 @@ createNetwork <- function(
match.arg(method, choices = mchoices, several.ok = TRUE)
}
)

vmsg(.is_debug = TRUE, sprintf("network\n type: %s\n method: %s",
type, method))

vmsg(.is_debug = TRUE, sprintf(
"network\n type: %s\n method: %s",
type, method
))

# get common params
alist <- list(
Expand Down Expand Up @@ -225,12 +226,11 @@ createNetwork <- function(


# x input is a matrix
.net_dt_knn <- function(
x, k = 30L, include_weight = TRUE, include_distance = TRUE,
filter = FALSE,
maximum_distance = NULL, minimum_k = 0L,
weight_fun = function(d) 1 / (1 + d),
verbose = NULL, ...) {
.net_dt_knn <- function(x, k = 30L, include_weight = TRUE, include_distance = TRUE,
filter = FALSE,
maximum_distance = NULL, minimum_k = 0L,
weight_fun = function(d) 1 / (1 + d),
verbose = NULL, ...) {
# NSE vars
from <- to <- distance <- NULL

Expand Down Expand Up @@ -283,11 +283,10 @@ createNetwork <- function(
}

# x input is a matrix
.net_dt_snn <- function(
x, k = 30L, include_weight = TRUE, include_distance = TRUE,
top_shared = 3L, minimum_shared = 5L,
weight_fun = function(d) 1 / (1 + d),
verbose = NULL, ...) {
.net_dt_snn <- function(x, k = 30L, include_weight = TRUE, include_distance = TRUE,
top_shared = 3L, minimum_shared = 5L,
weight_fun = function(d) 1 / (1 + d),
verbose = NULL, ...) {
# NSE vars
from <- to <- shared <- distance <- NULL

Expand Down Expand Up @@ -334,10 +333,9 @@ createNetwork <- function(
return(snn_network_dt)
}

.net_dt_del_geometry <- function(
x, include_weight = TRUE, options = "Pp", maximum_distance = "auto",
minimum_k = 0L, weight_fun = function(d) 1 / d,
...) {
.net_dt_del_geometry <- function(x, include_weight = TRUE, options = "Pp", maximum_distance = "auto",
minimum_k = 0L, weight_fun = function(d) 1 / d,
...) {
package_check("geometry", repository = "CRAN:geometry")

# data.table variables
Expand Down Expand Up @@ -388,10 +386,9 @@ createNetwork <- function(
return(out_object)
}

.net_dt_del_rtriangle <- function(
x, include_weight = TRUE, maximum_distance = "auto", minimum_k = 0L,
Y = TRUE, j = TRUE, S = 0, weight_fun = function(d) 1 / d,
...) {
.net_dt_del_rtriangle <- function(x, include_weight = TRUE, maximum_distance = "auto", minimum_k = 0L,
Y = TRUE, j = TRUE, S = 0, weight_fun = function(d) 1 / d,
...) {
# NSE vars
from <- to <- distance <- NULL

Expand Down Expand Up @@ -433,10 +430,9 @@ createNetwork <- function(
return(out_object)
}

.net_dt_del_deldir <- function(
x, include_weight = TRUE, maximum_distance = "auto", minimum_k = 0L,
weight_fun = function(d) 1 / d,
...) {
.net_dt_del_deldir <- function(x, include_weight = TRUE, maximum_distance = "auto", minimum_k = 0L,
weight_fun = function(d) 1 / d,
...) {
# NSE variables
from <- to <- distance <- NULL

Expand Down Expand Up @@ -625,23 +621,22 @@ edge_distances <- function(x, y, x_node_ids = NULL) {
#'
#' createNearestNetwork(g)
#' @export
createNearestNetwork <- function(
gobject,
spat_unit = NULL,
feat_type = NULL,
type = c("sNN", "kNN"),
dim_reduction_to_use = "pca",
dim_reduction_name = NULL,
dimensions_to_use = seq_len(10),
feats_to_use = NULL,
expression_values = c("normalized", "scaled", "custom"),
name = NULL,
return_gobject = TRUE,
k = 30,
minimum_shared = 5,
top_shared = 3,
verbose = TRUE,
...) {
createNearestNetwork <- function(gobject,
spat_unit = NULL,
feat_type = NULL,
type = c("sNN", "kNN"),
dim_reduction_to_use = "pca",
dim_reduction_name = NULL,
dimensions_to_use = seq_len(10),
feats_to_use = NULL,
expression_values = c("normalized", "scaled", "custom"),
name = NULL,
return_gobject = TRUE,
k = 30,
minimum_shared = 5,
top_shared = 3,
verbose = TRUE,
...) {
# Set feat_type and spat_unit
spat_unit <- set_default_spat_unit(
gobject = gobject,
Expand Down Expand Up @@ -882,15 +877,16 @@ createNearestNetwork <- function(
#'
#' addNetworkLayout(g)
#' @export
addNetworkLayout <- function(gobject,
spat_unit = NULL,
feat_type = NULL,
nn_network_to_use = "sNN",
network_name = "sNN.pca",
layout_type = c("drl"),
options_list = NULL,
layout_name = "layout",
return_gobject = TRUE) {
addNetworkLayout <- function(
gobject,
spat_unit = NULL,
feat_type = NULL,
nn_network_to_use = "sNN",
network_name = "sNN.pca",
layout_type = c("drl"),
options_list = NULL,
layout_name = "layout",
return_gobject = TRUE) {
## checks
if (is.null(nn_network_to_use) | is.null(network_name)) {
stop("\n first create a nearest network \n")
Expand Down
Loading

0 comments on commit 2a83ded

Please sign in to comment.