Skip to content

Commit

Permalink
run biocthis style
Browse files Browse the repository at this point in the history
  • Loading branch information
josschavezf committed May 6, 2024
1 parent 0bcbefd commit 17d0e12
Show file tree
Hide file tree
Showing 93 changed files with 2,844 additions and 2,989 deletions.
122 changes: 64 additions & 58 deletions R/NN_network.R
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,16 @@ 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

Expand Down Expand Up @@ -211,11 +212,12 @@ createNetwork <- function(x,


# 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 @@ -268,10 +270,11 @@ createNetwork <- function(x,
}

# 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 @@ -318,9 +321,10 @@ createNetwork <- function(x,
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 @@ -371,9 +375,10 @@ createNetwork <- function(x,
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 @@ -415,9 +420,10 @@ createNetwork <- function(x,
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 @@ -476,7 +482,7 @@ createNetwork <- function(x,
#' from = c(1, 1),
#' to = c(2, 3)
#' )
#'
#'
#' edge_distances(m, edges)
#' @export
edge_distances <- function(x, y, x_node_ids = NULL) {
Expand Down Expand Up @@ -606,25 +612,26 @@ edge_distances <- function(x, y, x_node_ids = NULL) {
#' }
#' @examples
#' g <- GiottoData::loadGiottoMini("visium")
#'
#'
#' 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 @@ -858,19 +865,18 @@ createNearestNetwork <- function(gobject,
#' This provides an alternative to tSNE or UMAP based visualizations.
#' @examples
#' g <- GiottoData::loadGiottoMini("visium")
#'
#'
#' 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 Expand Up @@ -915,7 +921,7 @@ addNetworkLayout <- function(
if (return_gobject == TRUE) {
nn_names <- names(gobject@nn_network[[spat_unit]][[nn_network_to_use]])
if (layout_name %in% nn_names) {
wrap_msg(layout_name," has already been used, will be overwritten")
wrap_msg(layout_name, " has already been used, will be overwritten")
}

gobject@nn_network[[spat_unit]][[
Expand All @@ -942,7 +948,7 @@ addNetworkLayout <- function(
#' @examples
#' g <- GiottoData::loadGiottoMini("visium")
#' g_nn <- getNearestNetwork(g, output = "data.table", name = "custom_NN")
#'
#'
#' nnDT_to_kNN(g_nn)
#' @export
nnDT_to_kNN <- function(nnDT) {
Expand Down
Loading

0 comments on commit 17d0e12

Please sign in to comment.