Title: | Inferring Cell-Specific Gene Regulatory Network |
---|---|
Description: | An R package for inferring cell-type specific gene regulatory network from single-cell RNA data. |
Authors: | Meng Xu [aut, cre] |
Maintainer: | Meng Xu <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.0.8 |
Built: | 2024-11-18 06:26:46 UTC |
Source: | https://github.com/mengxu98/infercsn |
An R package for inferring Cell-Specific gene regulatory Network from single-cell RNA data
Meng xu (Maintainer), [email protected]
https://github.com/mengxu98/inferCSN
Useful links:
This operator returns the left side if it's not NULL, otherwise it returns the right side.
a %s% b
a %s% b
a |
The left side value to check |
b |
The right side value to use if a is NULL |
NULL %s% 10 5 %s% 10
NULL %s% 10 5 %s% 10
Convert sparse matrix into dense matrix
as_matrix(x, parallel = FALSE, sparse = FALSE)
as_matrix(x, parallel = FALSE, sparse = FALSE)
x |
A matrix. |
parallel |
Logical value, default is |
sparse |
Logical value, default is |
sparse_matrix <- simulate_sparse_matrix( 2000, 2000, density = 0.01 ) system.time(as.matrix(sparse_matrix)) system.time(as_matrix(sparse_matrix)) system.time(as_matrix(sparse_matrix, parallel = TRUE)) identical( as.matrix(sparse_matrix), as_matrix(sparse_matrix) ) identical( as.matrix(sparse_matrix), as_matrix(sparse_matrix, parallel = TRUE) ) identical( sparse_matrix, as_matrix(as.matrix(sparse_matrix), sparse = TRUE) ) ## Not run: network_table_0 <- inferCSN(example_matrix) network_table_1 <- inferCSN( as_matrix(example_matrix, sparse = TRUE) ) network_table_2 <- inferCSN( as(example_matrix, "sparseMatrix") ) plot_scatter( data.frame( network_table_0$weight, network_table_1$weight ), legend_position = "none" ) plot_scatter( data.frame( network_table_1$weight, network_table_2$weight ), legend_position = "none" ) ## End(Not run)
sparse_matrix <- simulate_sparse_matrix( 2000, 2000, density = 0.01 ) system.time(as.matrix(sparse_matrix)) system.time(as_matrix(sparse_matrix)) system.time(as_matrix(sparse_matrix, parallel = TRUE)) identical( as.matrix(sparse_matrix), as_matrix(sparse_matrix) ) identical( as.matrix(sparse_matrix), as_matrix(sparse_matrix, parallel = TRUE) ) identical( sparse_matrix, as_matrix(as.matrix(sparse_matrix), sparse = TRUE) ) ## Not run: network_table_0 <- inferCSN(example_matrix) network_table_1 <- inferCSN( as_matrix(example_matrix, sparse = TRUE) ) network_table_2 <- inferCSN( as(example_matrix, "sparseMatrix") ) plot_scatter( data.frame( network_table_0$weight, network_table_1$weight ), legend_position = "none" ) plot_scatter( data.frame( network_table_1$weight, network_table_2$weight ), legend_position = "none" ) ## End(Not run)
Rank TFs and genes in network
calculate_gene_rank( network_table, regulators = NULL, targets = NULL, directed = FALSE )
calculate_gene_rank( network_table, regulators = NULL, targets = NULL, directed = FALSE )
network_table |
The weight data table of network. |
regulators |
Regulators list. |
targets |
Targets list. |
directed |
Whether the network is directed. |
A table of gene rank.
data("example_matrix") network_table <- inferCSN(example_matrix) head(calculate_gene_rank(network_table)) head(calculate_gene_rank(network_table, regulators = "g1")) head(calculate_gene_rank(network_table, targets = "g1"))
data("example_matrix") network_table <- inferCSN(example_matrix) head(calculate_gene_rank(network_table)) head(calculate_gene_rank(network_table, regulators = "g1")) head(calculate_gene_rank(network_table, targets = "g1"))
Calculates comprehensive performance metrics for evaluating predicted network structures, including classification performance, precision-recall metrics, and network topology metrics.
calculate_metrics( network_table, ground_truth, type = "all", plot = FALSE, line_color = "#1563cc", line_width = 1 )
calculate_metrics( network_table, ground_truth, type = "all", plot = FALSE, line_color = "#1563cc", line_width = 1 )
network_table |
A data frame of predicted network structure containing:
|
ground_truth |
A data frame of ground truth network with the same format as |
type |
The type of metric to return, default is
|
plot |
Logical value, default is
|
line_color |
The color for plot lines, default is |
line_width |
The width for plot lines, default is |
If type="all": A data frame with all metrics
If specific type: A single numeric value with the requested metric
If plot=TRUE: Displays relevant visualization plots
data("example_matrix") data("example_ground_truth") inferCSN(example_matrix) |> calculate_metrics(example_ground_truth, plot = TRUE)
data("example_matrix") data("example_ground_truth") inferCSN(example_matrix) |> calculate_metrics(example_ground_truth, plot = TRUE)
Check sparsity of matrix
check_sparsity(x)
check_sparsity(x)
x |
A matrix. |
Sparsity of matrix
Extracts a specific solution in the regularization path
## S3 method for class 'srm' coef(object, lambda = NULL, gamma = NULL, regulators_num = NULL, ...) ## S3 method for class 'srm_cv' coef(object, lambda = NULL, gamma = NULL, ...)
## S3 method for class 'srm' coef(object, lambda = NULL, gamma = NULL, regulators_num = NULL, ...) ## S3 method for class 'srm_cv' coef(object, lambda = NULL, gamma = NULL, ...)
object |
The output of |
lambda |
The value of lambda at which to extract the solution. |
gamma |
The value of gamma at which to extract the solution. |
regulators_num |
The number of non-zore coefficients, this value will affect the final performance. The maximum support size at which to terminate the regularization path. |
... |
Other parameters |
Return the specific solution
Filter and sort matrix
filter_sort_matrix(network_matrix, regulators = NULL, targets = NULL)
filter_sort_matrix(network_matrix, regulators = NULL, targets = NULL)
network_matrix |
The matrix of network weight. |
regulators |
Regulators list. |
targets |
Targets list. |
Filtered and sorted matrix
data("example_matrix") network_table <- inferCSN(example_matrix) network_matrix <- table_to_matrix(network_table) filter_sort_matrix(network_matrix)[1:6, 1:6] filter_sort_matrix( network_matrix, regulators = c("g1", "g2"), targets = c("g3", "g4") )
data("example_matrix") network_table <- inferCSN(example_matrix) network_matrix <- table_to_matrix(network_table) filter_sort_matrix(network_matrix)[1:6, 1:6] filter_sort_matrix( network_matrix, regulators = c("g1", "g2"), targets = c("g3", "g4") )
Computes the regularization path for the specified loss function and penalty function.
fit_sparse_regression( x, y, penalty = "L0", algorithm = "CD", regulators_num = ncol(x), cross_validation = FALSE, n_folds = 10, seed = 1, loss = "SquaredError", nLambda = 100, nGamma = 5, gammaMax = 10, gammaMin = 1e-04, partialSort = TRUE, maxIters = 200, rtol = 1e-06, atol = 1e-09, activeSet = TRUE, activeSetNum = 3, maxSwaps = 100, scaleDownFactor = 0.8, screenSize = 1000, autoLambda = NULL, lambdaGrid = list(), excludeFirstK = 0, intercept = TRUE, lows = -Inf, highs = Inf, verbose = TRUE, ... )
fit_sparse_regression( x, y, penalty = "L0", algorithm = "CD", regulators_num = ncol(x), cross_validation = FALSE, n_folds = 10, seed = 1, loss = "SquaredError", nLambda = 100, nGamma = 5, gammaMax = 10, gammaMin = 1e-04, partialSort = TRUE, maxIters = 200, rtol = 1e-06, atol = 1e-09, activeSet = TRUE, activeSetNum = 3, maxSwaps = 100, scaleDownFactor = 0.8, screenSize = 1000, autoLambda = NULL, lambdaGrid = list(), excludeFirstK = 0, intercept = TRUE, lows = -Inf, highs = Inf, verbose = TRUE, ... )
x |
The matrix of regulators. |
y |
The vector of target. |
penalty |
The type of regularization, default is |
algorithm |
The type of algorithm used to minimize the objective function, default is |
regulators_num |
The number of non-zore coefficients, this value will affect the final performance. The maximum support size at which to terminate the regularization path. |
cross_validation |
Logical value, default is |
n_folds |
The number of folds for cross-validation, default is |
seed |
The random seed for cross-validation, default is |
loss |
The loss function. |
nLambda |
The number of Lambda values to select. |
nGamma |
The number of Gamma values to select. |
gammaMax |
The maximum value of Gamma when using the |
gammaMin |
The minimum value of Gamma when using the |
partialSort |
If |
maxIters |
The maximum number of iterations (full cycles) for |
rtol |
The relative tolerance which decides when to terminate optimization, based on the relative change in the objective between iterations. |
atol |
The absolute tolerance which decides when to terminate optimization, based on the absolute L2 norm of the residuals. |
activeSet |
If |
activeSetNum |
The number of consecutive times a support should appear before declaring support stabilization. |
maxSwaps |
The maximum number of swaps used by |
scaleDownFactor |
This parameter decides how close the selected Lambda values are. |
screenSize |
The number of coordinates to cycle over when performing initial correlation screening. |
autoLambda |
Ignored parameter. Kept for backwards compatibility. |
lambdaGrid |
A grid of Lambda values to use in computing the regularization path. |
excludeFirstK |
This parameter takes non-negative integers. |
intercept |
If |
lows |
Lower bounds for coefficients. |
highs |
Upper bounds for coefficients. |
verbose |
Logical value, default is |
... |
Parameters for other methods. |
An S3 object describing the regularization path
Hazimeh, Hussein et al. “L0Learn: A Scalable Package for Sparse Learning using L0 Regularization.” J. Mach. Learn. Res. 24 (2022): 205:1-205:8.
Hazimeh, Hussein and Rahul Mazumder. “Fast Best Subset Selection: Coordinate Descent and Local Combinatorial Optimization Algorithms.” Oper. Res. 68 (2018): 1517-1537.
https://github.com/hazimehh/L0Learn/blob/master/R/fit.R
data("example_matrix") fit <- fit_sparse_regression( example_matrix[, -1], example_matrix[, 1] ) head(coef(fit))
data("example_matrix") fit <- fit_sparse_regression( example_matrix[, -1], example_matrix[, 1] ) head(coef(fit))
inferring Cell-Specific gene regulatory Network
inferCSN( object, penalty = "L0", algorithm = "CD", cross_validation = FALSE, seed = 1, n_folds = 10, subsampling_method = "sample", subsampling_ratio = 1, r_threshold = 0, regulators = NULL, targets = NULL, cores = 1, verbose = TRUE, ... ) ## S4 method for signature 'matrix' inferCSN( object, penalty = "L0", algorithm = "CD", cross_validation = FALSE, seed = 1, n_folds = 10, subsampling_method = "sample", subsampling_ratio = 1, r_threshold = 0, regulators = NULL, targets = NULL, cores = 1, verbose = TRUE, ... ) ## S4 method for signature 'sparseMatrix' inferCSN( object, penalty = "L0", algorithm = "CD", cross_validation = FALSE, seed = 1, n_folds = 10, subsampling_method = "sample", subsampling_ratio = 1, r_threshold = 0, regulators = NULL, targets = NULL, cores = 1, verbose = TRUE, ... ) ## S4 method for signature 'data.frame' inferCSN( object, penalty = "L0", algorithm = "CD", cross_validation = FALSE, seed = 1, n_folds = 10, subsampling_method = "sample", subsampling_ratio = 1, r_threshold = 0, regulators = NULL, targets = NULL, cores = 1, verbose = TRUE, ... )
inferCSN( object, penalty = "L0", algorithm = "CD", cross_validation = FALSE, seed = 1, n_folds = 10, subsampling_method = "sample", subsampling_ratio = 1, r_threshold = 0, regulators = NULL, targets = NULL, cores = 1, verbose = TRUE, ... ) ## S4 method for signature 'matrix' inferCSN( object, penalty = "L0", algorithm = "CD", cross_validation = FALSE, seed = 1, n_folds = 10, subsampling_method = "sample", subsampling_ratio = 1, r_threshold = 0, regulators = NULL, targets = NULL, cores = 1, verbose = TRUE, ... ) ## S4 method for signature 'sparseMatrix' inferCSN( object, penalty = "L0", algorithm = "CD", cross_validation = FALSE, seed = 1, n_folds = 10, subsampling_method = "sample", subsampling_ratio = 1, r_threshold = 0, regulators = NULL, targets = NULL, cores = 1, verbose = TRUE, ... ) ## S4 method for signature 'data.frame' inferCSN( object, penalty = "L0", algorithm = "CD", cross_validation = FALSE, seed = 1, n_folds = 10, subsampling_method = "sample", subsampling_ratio = 1, r_threshold = 0, regulators = NULL, targets = NULL, cores = 1, verbose = TRUE, ... )
object |
The input data for |
penalty |
The type of regularization, default is |
algorithm |
The type of algorithm used to minimize the objective function, default is |
cross_validation |
Logical value, default is |
seed |
The random seed for cross-validation, default is |
n_folds |
The number of folds for cross-validation, default is |
subsampling_method |
The method to use for subsampling. Options are "sample" or "meta_cells". |
subsampling_ratio |
The percent of all samples used for |
r_threshold |
Threshold of |
regulators |
The regulator genes for which to infer the regulatory network. |
targets |
The target genes for which to infer the regulatory network. Recommend setting this to a small fraction of min(n,p) (e.g. 0.05 * min(n,p)) as L0 regularization typically selects a small portion of non-zeros. |
cores |
The number of cores to use for parallelization with |
verbose |
Logical value, default is |
... |
Parameters for other methods. |
A data table of regulator-target regulatory relationships
data("example_matrix") data("example_ground_truth") network_table_1 <- inferCSN( example_matrix ) network_table_2 <- inferCSN( example_matrix, cores = 2 ) head(network_table_1) identical( network_table_1, network_table_2 ) inferCSN( example_matrix, regulators = c("g1", "g2"), targets = c("g3", "g4") ) inferCSN( example_matrix, regulators = c("g1", "g2"), targets = c("g3", "g0") ) ## Not run: network_table_07 <- inferCSN( example_matrix, r_threshold = 0.7 ) calculate_metrics( network_table_1, example_ground_truth, plot = TRUE ) calculate_metrics( network_table_07, example_ground_truth, plot = TRUE ) ## End(Not run) ## Not run: data("example_matrix") network_table <- inferCSN(example_matrix) head(network_table) network_table_sparse_1 <- inferCSN( as(example_matrix, "sparseMatrix") ) head(network_table_sparse_1) network_table_sparse_2 <- inferCSN( as(example_matrix, "sparseMatrix"), cores = 2 ) identical( network_table, network_table_sparse_1 ) identical( network_table_sparse_1, network_table_sparse_2 ) plot_scatter( data.frame( network_table$weight, network_table_sparse_1$weight ), legend_position = "none" ) plot_weight_distribution( network_table ) + plot_weight_distribution( network_table_sparse_1 ) ## End(Not run)
data("example_matrix") data("example_ground_truth") network_table_1 <- inferCSN( example_matrix ) network_table_2 <- inferCSN( example_matrix, cores = 2 ) head(network_table_1) identical( network_table_1, network_table_2 ) inferCSN( example_matrix, regulators = c("g1", "g2"), targets = c("g3", "g4") ) inferCSN( example_matrix, regulators = c("g1", "g2"), targets = c("g3", "g0") ) ## Not run: network_table_07 <- inferCSN( example_matrix, r_threshold = 0.7 ) calculate_metrics( network_table_1, example_ground_truth, plot = TRUE ) calculate_metrics( network_table_07, example_ground_truth, plot = TRUE ) ## End(Not run) ## Not run: data("example_matrix") network_table <- inferCSN(example_matrix) head(network_table) network_table_sparse_1 <- inferCSN( as(example_matrix, "sparseMatrix") ) head(network_table_sparse_1) network_table_sparse_2 <- inferCSN( as(example_matrix, "sparseMatrix"), cores = 2 ) identical( network_table, network_table_sparse_1 ) identical( network_table_sparse_1, network_table_sparse_2 ) plot_scatter( data.frame( network_table$weight, network_table_sparse_1$weight ), legend_position = "none" ) plot_weight_distribution( network_table ) + plot_weight_distribution( network_table_sparse_1 ) ## End(Not run)
Print diagnostic message
log_message(..., verbose = TRUE, message_type = "info", cli_model = TRUE)
log_message(..., verbose = TRUE, message_type = "info", cli_model = TRUE)
... |
Text to print. |
verbose |
Logical value, default is |
message_type |
Type of message, default is |
cli_model |
Logical value, default is |
log_message("Hello, ", "world!") suppressMessages(log_message("Hello, ", "world!")) log_message("Hello, world!", verbose = FALSE) log_message("Hello, world!", verbose = TRUE, message_type = "warning")
log_message("Hello, ", "world!") suppressMessages(log_message("Hello, ", "world!")) log_message("Hello, world!", verbose = FALSE) log_message("Hello, world!", verbose = TRUE, message_type = "warning")
Switch matrix to network table
matrix_to_table(network_matrix, regulators = NULL, targets = NULL)
matrix_to_table(network_matrix, regulators = NULL, targets = NULL)
network_matrix |
The matrix of network weight. |
regulators |
Regulators list. |
targets |
Targets list. |
Network table
data("example_matrix") network_table <- inferCSN(example_matrix) network_matrix <- table_to_matrix(network_table) network_table_new <- matrix_to_table(network_matrix) head(network_table) head(network_table_new) identical( network_table, network_table_new )
data("example_matrix") network_table <- inferCSN(example_matrix) network_matrix <- table_to_matrix(network_table) network_table_new <- matrix_to_table(network_matrix) head(network_table) head(network_table_new) identical( network_table, network_table_new )
This function detects metacells from a single-cell gene expression matrix using dimensionality reduction and clustering techniques.
meta_cells( matrix, genes_use = NULL, genes_exclude = NULL, var_genes_num = min(1000, nrow(matrix)), gamma = 10, knn_k = 5, do_scale = TRUE, pc_num = 25, fast_pca = FALSE, do_approx = FALSE, approx_num = 20000, directed = FALSE, use_nn2 = TRUE, seed = 1, cluster_method = "walktrap", block_size = 10000, weights = NULL, do_median_norm = FALSE, ... )
meta_cells( matrix, genes_use = NULL, genes_exclude = NULL, var_genes_num = min(1000, nrow(matrix)), gamma = 10, knn_k = 5, do_scale = TRUE, pc_num = 25, fast_pca = FALSE, do_approx = FALSE, approx_num = 20000, directed = FALSE, use_nn2 = TRUE, seed = 1, cluster_method = "walktrap", block_size = 10000, weights = NULL, do_median_norm = FALSE, ... )
matrix |
A gene expression matrix where rows represent genes and columns represent cells. |
genes_use |
Default is |
genes_exclude |
Default is |
var_genes_num |
Default is |
gamma |
Default is |
knn_k |
Default is |
do_scale |
Default is |
pc_num |
Default is |
fast_pca |
Default is |
do_approx |
Default is |
approx_num |
Default is |
directed |
Default is |
use_nn2 |
Default is |
seed |
Default is |
cluster_method |
Default is |
block_size |
Default is |
weights |
Default is |
do_median_norm |
Default is |
... |
Additional arguments passed to internal functions. |
A matrix where rows represent metacells and columns represent genes.
https://github.com/GfellerLab/SuperCell https://github.com/kuijjerlab/SCORPION
data("example_matrix") meta_cells_matrix <- meta_cells( example_matrix ) dim(meta_cells_matrix) meta_cells_matrix[1:6, 1:6]
data("example_matrix") meta_cells_matrix <- meta_cells( example_matrix ) dim(meta_cells_matrix) meta_cells_matrix[1:6, 1:6]
Format network table
network_format( network_table, regulators = NULL, targets = NULL, abs_weight = TRUE )
network_format( network_table, regulators = NULL, targets = NULL, abs_weight = TRUE )
network_table |
The weight data table of network. |
regulators |
Regulators list. |
targets |
Targets list. |
abs_weight |
Logical value, default is |
Formated network table
data("example_matrix") network_table <- inferCSN(example_matrix) network_format( network_table, regulators = "g1" ) network_format( network_table, regulators = "g1", abs_weight = FALSE ) network_format( network_table, targets = "g3" ) network_format( network_table, regulators = c("g1", "g3"), targets = c("g3", "g5") )
data("example_matrix") network_table <- inferCSN(example_matrix) network_format( network_table, regulators = "g1" ) network_format( network_table, regulators = "g1", abs_weight = FALSE ) network_format( network_table, targets = "g3" ) network_format( network_table, regulators = c("g1", "g3"), targets = c("g3", "g5") )
Sifting network
network_sift( network_table, matrix = NULL, meta_data = NULL, pseudotime_column = NULL, method = c("entropy", "max"), entropy_method = c("Shannon", "Renyi"), effective_entropy = FALSE, shuffles = 100, entropy_nboot = 300, lag_value = 1, entropy_p_value = 0.05, cores = 1, verbose = TRUE )
network_sift( network_table, matrix = NULL, meta_data = NULL, pseudotime_column = NULL, method = c("entropy", "max"), entropy_method = c("Shannon", "Renyi"), effective_entropy = FALSE, shuffles = 100, entropy_nboot = 300, lag_value = 1, entropy_p_value = 0.05, cores = 1, verbose = TRUE )
network_table |
The weight data table of network. |
matrix |
The expression matrix. |
meta_data |
The meta data for cells or samples. |
pseudotime_column |
The column of pseudotime. |
method |
The method used for filter edges.
Could be choose |
entropy_method |
If setting |
effective_entropy |
Default is |
shuffles |
Default is |
entropy_nboot |
Default is |
lag_value |
Default is |
entropy_p_value |
P value used to filter edges by entropy. |
cores |
The number of cores to use for parallelization with |
verbose |
Logical value, default is |
Sifted network table
## Not run: data("example_matrix") data("example_meta_data") data("example_ground_truth") network_table <- inferCSN(example_matrix) network_table_sifted <- network_sift(network_table) network_table_sifted_entropy <- network_sift( network_table, matrix = example_matrix, meta_data = example_meta_data, pseudotime_column = "pseudotime", lag_value = 2, shuffles = 0, entropy_nboot = 0 ) plot_network_heatmap( example_ground_truth[, 1:3], heatmap_title = "Ground truth", show_names = TRUE, rect_color = "gray70" ) plot_network_heatmap( network_table, heatmap_title = "Raw", show_names = TRUE, rect_color = "gray70" ) plot_network_heatmap( network_table_sifted, heatmap_title = "Filtered", show_names = TRUE, rect_color = "gray70" ) plot_network_heatmap( network_table_sifted_entropy, heatmap_title = "Filtered by entropy", show_names = TRUE, rect_color = "gray70" ) calculate_metrics( network_table, example_ground_truth, plot = TRUE ) calculate_metrics( network_table_sifted, example_ground_truth, plot = TRUE ) calculate_metrics( network_table_sifted_entropy, example_ground_truth, plot = TRUE ) ## End(Not run)
## Not run: data("example_matrix") data("example_meta_data") data("example_ground_truth") network_table <- inferCSN(example_matrix) network_table_sifted <- network_sift(network_table) network_table_sifted_entropy <- network_sift( network_table, matrix = example_matrix, meta_data = example_meta_data, pseudotime_column = "pseudotime", lag_value = 2, shuffles = 0, entropy_nboot = 0 ) plot_network_heatmap( example_ground_truth[, 1:3], heatmap_title = "Ground truth", show_names = TRUE, rect_color = "gray70" ) plot_network_heatmap( network_table, heatmap_title = "Raw", show_names = TRUE, rect_color = "gray70" ) plot_network_heatmap( network_table_sifted, heatmap_title = "Filtered", show_names = TRUE, rect_color = "gray70" ) plot_network_heatmap( network_table_sifted_entropy, heatmap_title = "Filtered by entropy", show_names = TRUE, rect_color = "gray70" ) calculate_metrics( network_table, example_ground_truth, plot = TRUE ) calculate_metrics( network_table_sifted, example_ground_truth, plot = TRUE ) calculate_metrics( network_table_sifted_entropy, example_ground_truth, plot = TRUE ) ## End(Not run)
Normalize numeric vector
normalization(x, method = "max_min", na_rm = TRUE, ...)
normalization(x, method = "max_min", na_rm = TRUE, ...)
x |
Input numeric vector. |
method |
Method used for normalization. |
na_rm |
Whether to remove |
... |
Parameters for other methods. |
Normalized numeric vector
nums <- c(runif(2), NA, -runif(2)) nums normalization(nums, method = "max_min") normalization(nums, method = "maximum") normalization(nums, method = "sum") normalization(nums, method = "softmax") normalization(nums, method = "z_score") normalization(nums, method = "mad") normalization(nums, method = "unit_vector") normalization(nums, method = "unit_vector", na_rm = FALSE)
nums <- c(runif(2), NA, -runif(2)) nums normalization(nums, method = "max_min") normalization(nums, method = "maximum") normalization(nums, method = "sum") normalization(nums, method = "softmax") normalization(nums, method = "z_score") normalization(nums, method = "mad") normalization(nums, method = "unit_vector") normalization(nums, method = "unit_vector", na_rm = FALSE)
Parallelize a function
parallelize_fun(x, fun, cores = 1, export_fun = NULL, verbose = TRUE)
parallelize_fun(x, fun, cores = 1, export_fun = NULL, verbose = TRUE)
x |
A vector or list to apply over. |
fun |
The function to be applied to each element. |
cores |
The number of cores to use for parallelization with |
export_fun |
The functions to export the function to workers. |
verbose |
Logical value, default is |
A list of computed results
Correlation and covariance calculation for sparse matrix
pearson_correlation(x, y = NULL)
pearson_correlation(x, y = NULL)
x |
Sparse matrix or character vector. |
y |
Sparse matrix or character vector. |
Plot coefficients
plot_coefficient( data, style = "continuous", positive_color = "#3d67a2", negative_color = "#c82926", neutral_color = "#cccccc", bar_width = 0.7, text_size = 3, show_values = TRUE )
plot_coefficient( data, style = "continuous", positive_color = "#3d67a2", negative_color = "#c82926", neutral_color = "#cccccc", bar_width = 0.7, text_size = 3, show_values = TRUE )
data |
Input data. |
style |
Plotting style: "binary", "gradient", or "continuous". |
positive_color |
Color for positive weights. |
negative_color |
Color for negative weights. |
neutral_color |
Color for weights near zero (used in "continuous" style). |
bar_width |
Width of the bars. |
text_size |
Size of the text for weight values. |
show_values |
Logical, whether to show weight values on bars. |
A ggplot object
data("example_matrix") network_table <- inferCSN(example_matrix, targets = "g1") plot_coefficient(network_table) plot_coefficient(network_table, style = "binary")
data("example_matrix") network_table <- inferCSN(example_matrix, targets = "g1") plot_coefficient(network_table) plot_coefficient(network_table, style = "binary")
Plot coefficients for multiple targets
plot_coefficients(data, targets = NULL, nrow = NULL, ...)
plot_coefficients(data, targets = NULL, nrow = NULL, ...)
data |
Input data. |
targets |
Targets to plot. |
nrow |
Number of rows for the plot. |
... |
Other arguments passed to |
A list of ggplot objects
data("example_matrix") network_table <- inferCSN( example_matrix, targets = c("g1", "g2", "g3") ) plot_coefficients(network_table, show_values = FALSE) plot_coefficients(network_table, targets = "g1")
data("example_matrix") network_table <- inferCSN( example_matrix, targets = c("g1", "g2", "g3") ) plot_coefficients(network_table, show_values = FALSE) plot_coefficients(network_table, targets = "g1")
Plot contrast networks
plot_contrast_networks( network_table, degree_value = 0, weight_value = 0, legend_position = "bottom" )
plot_contrast_networks( network_table, degree_value = 0, weight_value = 0, legend_position = "bottom" )
network_table |
The weight data table of network. |
degree_value |
Degree value to filter nodes. |
weight_value |
Weight value to filter edges. |
legend_position |
The position of legend. |
A ggplot2 object
data("example_matrix") network_table <- inferCSN(example_matrix) plot_contrast_networks(network_table[1:50, ])
data("example_matrix") network_table <- inferCSN(example_matrix) plot_contrast_networks(network_table[1:50, ])
Plot dynamic networks
plot_dynamic_networks( network_table, celltypes_order, ntop = 10, title = NULL, theme_type = "theme_void", plot_type = "ggplot", layout = "fruchtermanreingold", nrow = 2, figure_save = FALSE, figure_name = NULL, figure_width = 6, figure_height = 6, seed = 1 )
plot_dynamic_networks( network_table, celltypes_order, ntop = 10, title = NULL, theme_type = "theme_void", plot_type = "ggplot", layout = "fruchtermanreingold", nrow = 2, figure_save = FALSE, figure_name = NULL, figure_width = 6, figure_height = 6, seed = 1 )
network_table |
The weight data table of network. |
celltypes_order |
The order of cell types. |
ntop |
The number of top genes to plot. |
title |
The title of figure. |
theme_type |
Default is |
plot_type |
Default is |
layout |
Default is |
nrow |
The number of rows of figure. |
figure_save |
Default is |
figure_name |
The name of figure file. |
figure_width |
The width of figure. |
figure_height |
The height of figure. |
seed |
Default is |
A dynamic figure object
data("example_matrix") network <- inferCSN(example_matrix)[1:100, ] network$celltype <- c( rep("cluster1", 20), rep("cluster2", 20), rep("cluster3", 20), rep("cluster5", 20), rep("cluster6", 20) ) celltypes_order <- c( "cluster5", "cluster3", "cluster2", "cluster1", "cluster6" ) plot_dynamic_networks( network, celltypes_order = celltypes_order ) plot_dynamic_networks( network, celltypes_order = celltypes_order[1:3] ) plot_dynamic_networks( network, celltypes_order = celltypes_order, plot_type = "ggplotly" ) ## Not run: # If setting `plot_type = "animate"` to plot and save `gif` figure, # please install `gifski` package first. plot_dynamic_networks( network, celltypes_order = celltypes_order, plot_type = "animate" ) ## End(Not run)
data("example_matrix") network <- inferCSN(example_matrix)[1:100, ] network$celltype <- c( rep("cluster1", 20), rep("cluster2", 20), rep("cluster3", 20), rep("cluster5", 20), rep("cluster6", 20) ) celltypes_order <- c( "cluster5", "cluster3", "cluster2", "cluster1", "cluster6" ) plot_dynamic_networks( network, celltypes_order = celltypes_order ) plot_dynamic_networks( network, celltypes_order = celltypes_order[1:3] ) plot_dynamic_networks( network, celltypes_order = celltypes_order, plot_type = "ggplotly" ) ## Not run: # If setting `plot_type = "animate"` to plot and save `gif` figure, # please install `gifski` package first. plot_dynamic_networks( network, celltypes_order = celltypes_order, plot_type = "animate" ) ## End(Not run)
Plot embedding
plot_embedding( matrix, labels = NULL, method = "pca", colors = RColorBrewer::brewer.pal(length(unique(labels)), "Set1"), seed = 1, point_size = 1, cores = 1 )
plot_embedding( matrix, labels = NULL, method = "pca", colors = RColorBrewer::brewer.pal(length(unique(labels)), "Set1"), seed = 1, point_size = 1, cores = 1 )
matrix |
Input matrix. |
labels |
Input labels. |
method |
Method to use for dimensionality reduction. |
colors |
Colors to use for the plot. |
seed |
Seed for the random number generator. |
point_size |
Size of the points. |
cores |
Set the number of threads when setting |
An embedding plot
data("example_matrix") samples_use <- 1:200 plot_data <- example_matrix[samples_use, ] labels <- sample( c("A", "B", "C", "D", "E"), nrow(plot_data), replace = TRUE ) plot_embedding( plot_data, labels, method = "pca", point_size = 2 ) plot_embedding( plot_data, labels, method = "tsne", point_size = 2 )
data("example_matrix") samples_use <- 1:200 plot_data <- example_matrix[samples_use, ] labels <- sample( c("A", "B", "C", "D", "E"), nrow(plot_data), replace = TRUE ) plot_embedding( plot_data, labels, method = "pca", point_size = 2 ) plot_embedding( plot_data, labels, method = "tsne", point_size = 2 )
Plot histogram
plot_histogram( data, binwidth = 0.01, show_border = FALSE, border_color = "black", alpha = 1, theme = "viridis", theme_begin = 0, theme_end = 0.5, theme_direction = -1, legend_position = "right" )
plot_histogram( data, binwidth = 0.01, show_border = FALSE, border_color = "black", alpha = 1, theme = "viridis", theme_begin = 0, theme_end = 0.5, theme_direction = -1, legend_position = "right" )
data |
A numeric vector. |
binwidth |
Width of the bins. |
show_border |
Logical value, whether to show border of the bins. |
border_color |
Color of the border. |
alpha |
Alpha value of the bins. |
theme |
Theme of the bins. |
theme_begin |
Begin value of the theme. |
theme_end |
End value of the theme. |
theme_direction |
Direction of the theme. |
legend_position |
The position of legend. |
A ggplot object
data("example_matrix") network_table <- inferCSN(example_matrix) plot_histogram(network_table[, 3])
data("example_matrix") network_table <- inferCSN(example_matrix) plot_histogram(network_table[, 3])
Plot network heatmap
plot_network_heatmap( network_table, regulators = NULL, targets = NULL, switch_matrix = TRUE, show_names = FALSE, heatmap_size_lock = TRUE, heatmap_size = 5, heatmap_height = NULL, heatmap_width = NULL, heatmap_title = NULL, heatmap_color = c("#1966ad", "white", "#bb141a"), border_color = "gray", rect_color = NA, anno_width = 1, anno_height = 1, row_anno_type = NULL, column_anno_type = NULL, legend_name = "Weight", row_title = "Regulators" )
plot_network_heatmap( network_table, regulators = NULL, targets = NULL, switch_matrix = TRUE, show_names = FALSE, heatmap_size_lock = TRUE, heatmap_size = 5, heatmap_height = NULL, heatmap_width = NULL, heatmap_title = NULL, heatmap_color = c("#1966ad", "white", "#bb141a"), border_color = "gray", rect_color = NA, anno_width = 1, anno_height = 1, row_anno_type = NULL, column_anno_type = NULL, legend_name = "Weight", row_title = "Regulators" )
network_table |
The weight data table of network. |
regulators |
Regulators list. |
targets |
Targets list. |
switch_matrix |
Logical value, default is |
show_names |
Logical value, default is |
heatmap_size_lock |
Lock the size of heatmap. |
heatmap_size |
Default is |
heatmap_height |
The height of heatmap. |
heatmap_width |
The width of heatmap. |
heatmap_title |
The title of heatmap. |
heatmap_color |
Colors of heatmap. |
border_color |
Default is |
rect_color |
Default is |
anno_width |
Width of annotation. |
anno_height |
Height of annotation. |
row_anno_type |
Default is |
column_anno_type |
Default is |
legend_name |
The name of legend. |
row_title |
The title of row. |
A heatmap
data("example_matrix") data("example_ground_truth") network_table <- inferCSN(example_matrix) p1 <- plot_network_heatmap( example_ground_truth[, 1:3], heatmap_title = "Ground truth", legend_name = "Ground truth" ) p2 <- plot_network_heatmap( network_table, heatmap_title = "inferCSN", legend_name = "inferCSN" ) ComplexHeatmap::draw(p1 + p2) p3 <- plot_network_heatmap( network_table, heatmap_title = "inferCSN", legend_name = "Weight1", heatmap_color = c("#20a485", "#410054", "#fee81f") ) p4 <- plot_network_heatmap( network_table, heatmap_title = "inferCSN", legend_name = "Weight2", heatmap_color = c("#20a485", "white", "#fee81f") ) ComplexHeatmap::draw(p3 + p4) plot_network_heatmap( network_table, show_names = TRUE, rect_color = "gray90", row_anno_type = "density", column_anno_type = "barplot" ) plot_network_heatmap( network_table, regulators = c("g1", "g2"), show_names = TRUE ) plot_network_heatmap( network_table, targets = c("g1", "g2"), row_anno_type = "boxplot", column_anno_type = "histogram", show_names = TRUE ) plot_network_heatmap( network_table, regulators = c("g1", "g3", "g5"), targets = c("g3", "g6", "g9"), show_names = TRUE )
data("example_matrix") data("example_ground_truth") network_table <- inferCSN(example_matrix) p1 <- plot_network_heatmap( example_ground_truth[, 1:3], heatmap_title = "Ground truth", legend_name = "Ground truth" ) p2 <- plot_network_heatmap( network_table, heatmap_title = "inferCSN", legend_name = "inferCSN" ) ComplexHeatmap::draw(p1 + p2) p3 <- plot_network_heatmap( network_table, heatmap_title = "inferCSN", legend_name = "Weight1", heatmap_color = c("#20a485", "#410054", "#fee81f") ) p4 <- plot_network_heatmap( network_table, heatmap_title = "inferCSN", legend_name = "Weight2", heatmap_color = c("#20a485", "white", "#fee81f") ) ComplexHeatmap::draw(p3 + p4) plot_network_heatmap( network_table, show_names = TRUE, rect_color = "gray90", row_anno_type = "density", column_anno_type = "barplot" ) plot_network_heatmap( network_table, regulators = c("g1", "g2"), show_names = TRUE ) plot_network_heatmap( network_table, targets = c("g1", "g2"), row_anno_type = "boxplot", column_anno_type = "histogram", show_names = TRUE ) plot_network_heatmap( network_table, regulators = c("g1", "g3", "g5"), targets = c("g3", "g6", "g9"), show_names = TRUE )
Plot expression data in a scatter plot
plot_scatter( data, smoothing_method = "lm", group_colors = RColorBrewer::brewer.pal(9, "Set1"), title_color = "black", title = NULL, col_title = NULL, row_title = NULL, legend_title = NULL, legend_position = "bottom", margins = "both", marginal_type = NULL, margins_size = 10, compute_correlation = TRUE, compute_correlation_method = "pearson", keep_aspect_ratio = TRUE, facet = FALSE, se = FALSE, pointdensity = TRUE )
plot_scatter( data, smoothing_method = "lm", group_colors = RColorBrewer::brewer.pal(9, "Set1"), title_color = "black", title = NULL, col_title = NULL, row_title = NULL, legend_title = NULL, legend_position = "bottom", margins = "both", marginal_type = NULL, margins_size = 10, compute_correlation = TRUE, compute_correlation_method = "pearson", keep_aspect_ratio = TRUE, facet = FALSE, se = FALSE, pointdensity = TRUE )
data |
Input data. |
smoothing_method |
Method for smoothing curve, |
group_colors |
Colors for different groups. |
title_color |
Color for the title. |
title |
Main title for the plot. |
col_title |
Title for the x-axis. |
row_title |
Title for the y-axis. |
legend_title |
Title for the legend. |
legend_position |
The position of legend. |
margins |
The position of marginal figure ("both", "x", "y"). |
marginal_type |
The type of marginal figure ( |
margins_size |
The size of marginal figure, note the bigger size the smaller figure. |
compute_correlation |
Whether to compute and print correlation on the figure. |
compute_correlation_method |
Method to compute correlation ( |
keep_aspect_ratio |
Logical value, whether to set aspect ratio to 1:1. |
facet |
Faceting variable. If setting TRUE, all settings about margins will be inalidation. |
se |
Display confidence interval around smooth. |
pointdensity |
Plot point density when only provide 1 cluster. |
ggplot object
data("example_matrix") test_data <- data.frame( example_matrix[1:200, c(1, 7)], c = c( rep("c1", 40), rep("c2", 40), rep("c3", 40), rep("c4", 40), rep("c5", 40) ) ) p1 <- plot_scatter( test_data ) p2 <- plot_scatter( test_data, marginal_type = "boxplot" ) p1 + p2 p3 <- plot_scatter( test_data, facet = TRUE ) p3 p4 <- plot_scatter( test_data[, 1:2], marginal_type = "histogram" ) p4
data("example_matrix") test_data <- data.frame( example_matrix[1:200, c(1, 7)], c = c( rep("c1", 40), rep("c2", 40), rep("c3", 40), rep("c4", 40), rep("c5", 40) ) ) p1 <- plot_scatter( test_data ) p2 <- plot_scatter( test_data, marginal_type = "boxplot" ) p1 + p2 p3 <- plot_scatter( test_data, facet = TRUE ) p3 p4 <- plot_scatter( test_data[, 1:2], marginal_type = "histogram" ) p4
Plot dynamic networks
plot_static_networks( network_table, regulators = NULL, targets = NULL, legend_position = "right" )
plot_static_networks( network_table, regulators = NULL, targets = NULL, legend_position = "right" )
network_table |
The weight data table of network. |
regulators |
Regulators list. |
targets |
Targets list. |
legend_position |
The position of legend. |
A ggplot2 object
data("example_matrix") network_table <- inferCSN(example_matrix) plot_static_networks( network_table, regulators = "g1" ) plot_static_networks( network_table, targets = "g1" ) plot_static_networks( network_table, regulators = "g1", targets = "g2" )
data("example_matrix") network_table <- inferCSN(example_matrix) plot_static_networks( network_table, regulators = "g1" ) plot_static_networks( network_table, targets = "g1" ) plot_static_networks( network_table, regulators = "g1", targets = "g2" )
Predicts response for a given sample
## S3 method for class 'srm' predict(object, newx, lambda = NULL, gamma = NULL, ...) ## S3 method for class 'srm_cv' predict(object, newx, lambda = NULL, gamma = NULL, ...)
## S3 method for class 'srm' predict(object, newx, lambda = NULL, gamma = NULL, ...) ## S3 method for class 'srm_cv' predict(object, newx, lambda = NULL, gamma = NULL, ...)
object |
The output of fit_sparse_regression. |
newx |
A matrix on which predictions are made. The matrix should have p columns |
lambda |
The value of lambda to use for prediction.
A summary of the lambdas in the regularization path can be obtained using |
gamma |
The value of gamma to use for prediction.
A summary of the gammas in the regularization path can be obtained using |
... |
Other parameters |
If both lambda and gamma are not supplied, then a matrix of predictions for all the solutions in the regularization path is returned. If lambda is supplied but gamma is not, the smallest value of gamma is used. In case of logistic regression, probability values are returned.
Return predict value
fit_sparse_regression
Prints a summary of fit_sparse_regression
## S3 method for class 'srm' print(x, ...) ## S3 method for class 'srm_cv' print(x, ...)
## S3 method for class 'srm' print(x, ...) ## S3 method for class 'srm_cv' print(x, ...)
x |
The output of |
... |
Other parameters |
Return information of fit_sparse_regression
(coefficient of determination) (coefficient of determination)
r_square(y_true, y_pred)
r_square(y_true, y_pred)
y_true |
A numeric vector with ground truth values. |
y_pred |
A numeric vector with predicted values. |
Generate a simulated sparse matrix for single-cell data testing
simulate_sparse_matrix( nrow, ncol, density = 0.1, distribution_fun = function(n) stats::rpois(n, lambda = 0.5) + 1, seed = 1 )
simulate_sparse_matrix( nrow, ncol, density = 0.1, distribution_fun = function(n) stats::rpois(n, lambda = 0.5) + 1, seed = 1 )
nrow |
Number of rows (genes) in the matrix. |
ncol |
Number of columns (cells) in the matrix. |
density |
Density of non-zero elements (default: 0.1, representing 90 sparsity). |
distribution_fun |
Function to generate non-zero values. |
seed |
Random seed for reproducibility. |
A sparse matrix of class "dgCMatrix"
simulate_sparse_matrix(2000, 500) |> check_sparsity()
simulate_sparse_matrix(2000, 500) |> check_sparsity()
Construct network for single target gene
single_network( matrix, regulators, target, cross_validation = FALSE, seed = 1, penalty = "L0", algorithm = "CD", regulators_num = (ncol(matrix) - 1), n_folds = 10, subsampling_ratio = 1, r_threshold = 0, verbose = TRUE, ... )
single_network( matrix, regulators, target, cross_validation = FALSE, seed = 1, penalty = "L0", algorithm = "CD", regulators_num = (ncol(matrix) - 1), n_folds = 10, subsampling_ratio = 1, r_threshold = 0, verbose = TRUE, ... )
matrix |
An expression matrix. |
regulators |
The regulator genes for which to infer the regulatory network. |
target |
The target gene. |
cross_validation |
Logical value, default is |
seed |
The random seed for cross-validation, default is |
penalty |
The type of regularization, default is |
algorithm |
The type of algorithm used to minimize the objective function, default is |
regulators_num |
The number of non-zore coefficients, this value will affect the final performance. The maximum support size at which to terminate the regularization path. |
n_folds |
The number of folds for cross-validation, default is |
subsampling_ratio |
The percent of all samples used for |
r_threshold |
Threshold of |
verbose |
Logical value, default is |
... |
Parameters for other methods. |
The weight data table of sub-network
data("example_matrix") head( single_network( example_matrix, regulators = colnames(example_matrix), target = "g1" ) ) single_network( example_matrix, regulators = c("g1", "g2", "g3"), target = "g1" ) single_network( example_matrix, regulators = c("g1", "g2"), target = "g1" )
data("example_matrix") head( single_network( example_matrix, regulators = colnames(example_matrix), target = "g1" ) ) single_network( example_matrix, regulators = c("g1", "g2", "g3"), target = "g1" ) single_network( example_matrix, regulators = c("g1", "g2"), target = "g1" )
Safe correlation function which returns a sparse matrix without missing values
sparse_cor( x, y = NULL, method = "pearson", allow_neg = TRUE, remove_na = TRUE, remove_inf = TRUE, ... )
sparse_cor( x, y = NULL, method = "pearson", allow_neg = TRUE, remove_na = TRUE, remove_inf = TRUE, ... )
x |
Sparse matrix or character vector. |
y |
Sparse matrix or character vector. |
method |
Method to use for calculating the correlation coefficient. |
allow_neg |
Logical. Whether to allow negative values or set them to 0. |
remove_na |
Logical. Whether to replace NA values with 0. |
remove_inf |
Logical. Whether to replace infinite values with 1. |
... |
Other arguments passed to |
A correlation matrix.
m1 <- simulate_sparse_matrix( 1000, 1000, density = 0.01 ) m2 <- simulate_sparse_matrix( 1000, 500, density = 0.01 ) all.equal( as.matrix(sparse_cor(m1)), cor(as_matrix(m1)) ) all.equal( as.matrix(sparse_cor(m1, m2)), cor(as_matrix(m1), as_matrix(m2)) ) system.time( sparse_cor(m1) ) system.time( cor(as_matrix(m1)) ) system.time( sparse_cor(m1, m2) ) system.time( cor(as_matrix(m1), as_matrix(m2)) ) # add missing values m1[sample(1:500, 10)] <- NA m2[sample(1:500, 10)] <- NA sparse_cor(m1, m2)[1:5, 1:5]
m1 <- simulate_sparse_matrix( 1000, 1000, density = 0.01 ) m2 <- simulate_sparse_matrix( 1000, 500, density = 0.01 ) all.equal( as.matrix(sparse_cor(m1)), cor(as_matrix(m1)) ) all.equal( as.matrix(sparse_cor(m1, m2)), cor(as_matrix(m1), as_matrix(m2)) ) system.time( sparse_cor(m1) ) system.time( cor(as_matrix(m1)) ) system.time( sparse_cor(m1, m2) ) system.time( cor(as_matrix(m1), as_matrix(m2)) ) # add missing values m1[sample(1:500, 10)] <- NA m2[sample(1:500, 10)] <- NA sparse_cor(m1, m2)[1:5, 1:5]
Sparse regression model
sparse_regression( x, y, cross_validation = FALSE, seed = 1, penalty = "L0", algorithm = "CD", regulators_num = ncol(x), n_folds = 10, subsampling_ratio = 1, r_threshold = 0, computation_method = "cor", verbose = TRUE, ... )
sparse_regression( x, y, cross_validation = FALSE, seed = 1, penalty = "L0", algorithm = "CD", regulators_num = ncol(x), n_folds = 10, subsampling_ratio = 1, r_threshold = 0, computation_method = "cor", verbose = TRUE, ... )
x |
The matrix of regulators. |
y |
The vector of target. |
cross_validation |
Logical value, default is |
seed |
The random seed for cross-validation, default is |
penalty |
The type of regularization, default is |
algorithm |
The type of algorithm used to minimize the objective function, default is |
regulators_num |
The number of non-zore coefficients, this value will affect the final performance. The maximum support size at which to terminate the regularization path. |
n_folds |
The number of folds for cross-validation, default is |
subsampling_ratio |
The percent of all samples used for |
r_threshold |
Threshold of |
computation_method |
The method used to compute 'r“. |
verbose |
Logical value, default is |
... |
Parameters for other methods. |
Coefficients
data("example_matrix") sparse_regression( x = example_matrix[, -1], y = example_matrix[, 1] )
data("example_matrix") sparse_regression( x = example_matrix[, -1], y = example_matrix[, 1] )
An optimised version of split for the special case of splitting row indices into groups.
split_indices(group, n = 0L)
split_indices(group, n = 0L)
group |
Integer indices |
n |
The largest integer (may not appear in index).
This is hint: if the largest value of |
A list of vectors of indices.
https://github.com/hadley/plyr/blob/d57f9377eb5d56107ba3136775f2f0f005f33aa3/src/split-numeric.cpp#L20
split_indices(sample(10, 100, rep = TRUE)) split_indices(sample(10, 100, rep = TRUE), 10)
split_indices(sample(10, 100, rep = TRUE)) split_indices(sample(10, 100, rep = TRUE), 10)
This function subsamples a matrix using either random sampling or meta cells method.
subsampling( matrix, subsampling_method = "sample", subsampling_ratio = 1, seed = 1, verbose = TRUE, ... )
subsampling( matrix, subsampling_method = "sample", subsampling_ratio = 1, seed = 1, verbose = TRUE, ... )
matrix |
The input matrix to be subsampled. |
subsampling_method |
The method to use for subsampling. Options are "sample" or "meta_cells". |
subsampling_ratio |
The percent of all samples used for |
seed |
The random seed for cross-validation, default is |
verbose |
Logical value, default is |
... |
Parameters for other methods. |
The subsampled matrix.
data("example_matrix") data("example_ground_truth") subsample_matrix <- subsampling( example_matrix, subsampling_ratio = 0.5 ) subsample_matrix_2 <- subsampling( example_matrix, subsampling_method = "meta_cells", subsampling_ratio = 0.5, fast_pca = FALSE ) subsample_matrix_3 <- subsampling( example_matrix, subsampling_method = "pseudobulk", subsampling_ratio = 0.5 ) calculate_metrics( inferCSN(example_matrix), example_ground_truth, plot = TRUE ) calculate_metrics( inferCSN(subsample_matrix), example_ground_truth, plot = TRUE ) calculate_metrics( inferCSN(subsample_matrix_2), example_ground_truth, plot = TRUE ) calculate_metrics( inferCSN(subsample_matrix_3), example_ground_truth, plot = TRUE )
data("example_matrix") data("example_ground_truth") subsample_matrix <- subsampling( example_matrix, subsampling_ratio = 0.5 ) subsample_matrix_2 <- subsampling( example_matrix, subsampling_method = "meta_cells", subsampling_ratio = 0.5, fast_pca = FALSE ) subsample_matrix_3 <- subsampling( example_matrix, subsampling_method = "pseudobulk", subsampling_ratio = 0.5 ) calculate_metrics( inferCSN(example_matrix), example_ground_truth, plot = TRUE ) calculate_metrics( inferCSN(subsample_matrix), example_ground_truth, plot = TRUE ) calculate_metrics( inferCSN(subsample_matrix_2), example_ground_truth, plot = TRUE ) calculate_metrics( inferCSN(subsample_matrix_3), example_ground_truth, plot = TRUE )
Switch network table to matrix
table_to_matrix(network_table, regulators = NULL, targets = NULL)
table_to_matrix(network_table, regulators = NULL, targets = NULL)
network_table |
The weight data table of network. |
regulators |
Regulators list. |
targets |
Targets list. |
Weight matrix
data("example_matrix") network_table <- inferCSN(example_matrix) head(network_table) table_to_matrix(network_table)[1:6, 1:6] table_to_matrix( network_table, regulators = c("g1", "g2"), targets = c("g3", "g4") )
data("example_matrix") network_table <- inferCSN(example_matrix) head(network_table) table_to_matrix(network_table)[1:6, 1:6] table_to_matrix( network_table, regulators = c("g1", "g2"), targets = c("g3", "g4") )
Remove edges with smaller weights in the reverse direction.
weight_sift(table)
weight_sift(table)
table |
A data frame with three columns: "regulator", "target", and "weight". |
data("example_matrix") network_table <- inferCSN(example_matrix) weight_sift(network_table) |> head()
data("example_matrix") network_table <- inferCSN(example_matrix) weight_sift(network_table) |> head()