View source: R/network_functions.R
scaleFreeNet | R Documentation |
Apply scale-free topology transform to shared-nearest neighbor graph
scaleFreeNet(
object,
graph_name = "RNA_snn",
sf = c(seq(1, 5, by = 0.5), seq(6, 10)),
sf_threshold = 0.9,
umap_knn = 10,
n_dim = 30,
binary_threshold = 0.9,
n_workers = 1,
verbose = T
)
object |
Seurat object |
sf |
soft thresholds (sf) that are evaluated in search for optimal soft threshold (used to transform SNN to scale-free topology). Default is sf = c(seq(1, 5, by = 0.5), seq(6, 10)). |
sf_threshold |
R2 threshold [0,1] for identifying optimal soft threshold. Default is 0.9 (recommended 0.8-0.9). |
umap_knn |
This determines the number of neighboring points used in local approximations of UMAP manifold structure. Larger values will result in more global structure being preserved at the loss of detailed local structure. In general this parameter should often be in the range 5 to 50. default is 10. |
n_dim |
Number of PC dimensions to use in generating UMAP. Default is PCA. |
binary_threshold |
Numeric threshold used to binarize SNN graph. Default is 0.9. |
n_workers |
Number of workers used for parallel implementation. Default is 1. |
verbose |
Show progress. Default is T. |
graph.name |
name of SNN graph in 'object'. Default is "RNA_snn". |
list containing
"object" - scale-free SNN and binarized graph are stored in 'object' graph slot, and umap embedding is stored in 'object' reduction slot.
"st.res" - soft threshold optimization results.
Nicholas Mikolajewicz
https://nmikolajewicz.github.io/scMiko/articles/Module_Detection.html
runSSN
# load human gastrulation data
so.query <- readRDS("../data/demo/so_tyser2021_220621.rds")
# Expression-based feature selection
features_expr <- findNetworkFeatures(object = so.query, method = "expr",
min_pct = 0.5)
# Highly-variable genes
features_hvg <- findNetworkFeatures(object = so.query, method = "hvg",
n_features = 2000)
# run SSN
so.gene <- runSSN(object = so.query ,
features = unique(c(features_hvg, features_dev)),
scale_free = T,
robust_pca = F,
data_type = "pearson",
reprocess_sct = T,
slot = c("scale"),
batch_feature = NULL,
pca_var_explained = 0.9,
optimize_resolution = T,
target_purity = 0.8,
step_size = 0.05,
n_workers = parallel::detectCores(),
verbose = F)
# get network connectivity plot
plt_connectivity <- SSNConnectivity(so.gene, quantile_threshold = 0.85, raster_dpi = 500)
# visualize
plt_connectivity$plot_edge + labs(title = "Network Connectivity")
# specify pruning threshold [0,1] (low values = less pruning, high values = more pruning)
prune.threshold <- 0.1
get feature-specific connectivities (wi)
df.wi <- pruneSSN(object = so.gene,
graph = "RNA_snn_power",
prune.threshold = prune.threshold,
return.df = T)
# visualize
plt.prune <- df.wi %>%
ggplot(aes(x = wi_l2)) +
geom_histogram(bins = 30) +
geom_vline(xintercept = prune.threshold, linetype = "dashed", color = "tomato") +
labs(x = "Degree (L2 norm)", y = "Count",
title = "Network Pruning",
subtitle = paste0(signif(100*sum(df.wi$wi_l2 <= prune.threshold)/nrow(df.wi), 3),
"% (", sum(df.wi$wi_l2 <= prune.threshold), "/", nrow(df.wi), ") genes pruning" )) +
theme_miko(grid = T)
print(plt.prune)
# get (pruned) gene module list
mod.list <- pruneSSN(object = so.gene, graph = "RNA_snn_power", prune.threshold = prune.threshold)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.