### Install and load example data Source: https://github.com/satijalab/seurat-wrappers/blob/master/docs/miQC.md Install the 'pbmc3k' dataset from SeuratData and load it into an R object. ```r InstallData("pbmc3k") data("pbmc3k") pbmc3k ``` -------------------------------- ### Setup Seurat Data Source: https://github.com/satijalab/seurat-wrappers/blob/master/docs/schex.md Installs and loads the pbmc3k dataset into a Seurat object for demonstration purposes. ```r InstallData("pbmc3k") pbmc <- pbmc3k ``` -------------------------------- ### Install Presto Package Source: https://github.com/satijalab/seurat-wrappers/blob/master/docs/presto.rmd Installs the Presto package from GitHub if it is not already installed. Set `upgrade = FALSE` to avoid upgrading if already installed. ```r if (!requireNamespace("presto")) { remotes::install_github("immunogenomics/presto", upgrade = FALSE) } ``` -------------------------------- ### Run CoGAPS for Cell Lineage Identification (3 Patterns) Source: https://github.com/satijalab/seurat-wrappers/blob/master/docs/cogaps.md Installs and loads the pbmc3k dataset, then configures and runs CoGAPS to identify three distinct cell lineage patterns. This example is designed for cloud execution and uses a high number of iterations for robust convergence. ```r InstallData("pbmc3k") data("pbmc3k.final") params <- CogapsParams(singleCell = TRUE, sparseOptimization = TRUE, seed = 123, nIterations = 50000, nPatterns = 3, distributed = "genome-wide") params <- setDistributedParams(params, nSets = 5) pbmc3k.final <- RunCoGAPS(pbmc3k.final, temp.file = TRUE, params = params) ``` -------------------------------- ### Install SeuratWrappers using remotes Source: https://github.com/satijalab/seurat-wrappers/blob/master/README.md Use this command to install the SeuratWrappers package from GitHub. Ensure you have the 'remotes' package installed. ```R remotes::install_github('satijalab/seurat-wrappers') ``` -------------------------------- ### Install CIPR Package Source: https://github.com/satijalab/seurat-wrappers/blob/master/docs/cipr.md Installs the CIPR package from GitHub. Use build_vignettes = TRUE if you want to build vignettes, which can take a long time. ```r if (!requireNamespace("devtools", quietly = TRUE)) install.packages("devtools") # Use this option if you want to build vignettes during installation This can take a long time # due to the installation of suggested packages. remotes::install_github("atakanekiz/CIPR-Package", build_vignettes = TRUE) # Use this if you would like to install the package without vignettes # remotes::install_github('atakanekiz/CIPR-Package') ``` -------------------------------- ### Load Example Data and Create Seurat Object Source: https://github.com/satijalab/seurat-wrappers/blob/master/docs/tricycle.md Load the neurosphere example dataset from the tricycle package and convert it into a Seurat object. The original 'logcounts' assay is preserved as 'data' in the Seurat object. ```r data(neurosphere_example, package = "tricycle") neurosphere_example <- as.Seurat(neurosphere_example) neurosphere_example ``` -------------------------------- ### Load and Initialize Seurat Object Source: https://github.com/satijalab/seurat-wrappers/blob/master/docs/cipr.md Installs the 'pbmc3k' dataset and initializes a Seurat object named 'pbmc'. ```r # Load data InstallData("pbmc3k") pbmc <- pbmc3k ``` -------------------------------- ### Run CoGAPS for Cell Type Identification (10 Patterns) Source: https://github.com/satijalab/seurat-wrappers/blob/master/docs/cogaps.md Installs and loads the pbmc3k dataset, then configures and runs CoGAPS to identify ten distinct patterns for cell type classification. This example is also suited for cloud execution with a high iteration count. ```r InstallData("pbmc3k") data("pbmc3k.final") params <- CogapsParams(singleCell = TRUE, sparseOptimization = TRUE, seed = 123, nIterations = 50000, nPatterns = 10, distributed = "genome-wide") params <- setDistributedParams(params, nSets = 5) pbmc3k.final <- RunCoGAPS(object = pbmc3k.final, temp.file = TRUE, params = params) ``` -------------------------------- ### Install and Load pbmc3k Dataset Source: https://github.com/satijalab/seurat-wrappers/blob/master/docs/alra.md Installs the pbmc3k dataset and loads it into the R environment for analysis. This dataset is used to demonstrate scRNA-seq imputation. ```r InstallData("pbmc3k") data("pbmc3k") ``` -------------------------------- ### Running CoGAPS Locally with Seurat Source: https://github.com/satijalab/seurat-wrappers/blob/master/docs/cogaps.md Execute the CoGAPS algorithm on a Seurat object locally. Ensure necessary data is installed and loaded before running. This example uses specific parameters for iterations, output frequency, and optimization. ```r InstallData("pbmc3k") data("pbmc3k.final") pbmc3k.final <- RunCoGAPS(object = pbmc3k.final, nPatterns = 3, nIterations = 5000, outputFrequency = 1000, sparseOptimization = TRUE, nThreads = 1, distributed = "genome-wide", singleCell = TRUE, seed = 891) ``` -------------------------------- ### Load necessary libraries Source: https://github.com/satijalab/seurat-wrappers/blob/master/docs/conos.md Load the Conos, Seurat, SeuratData, and SeuratWrappers libraries. Ensure these packages are installed before running. ```r library(conos) library(Seurat) library(SeuratData) library(SeuratWrappers) ``` -------------------------------- ### Install and Load HCA Bone Marrow Data Source: https://github.com/satijalab/seurat-wrappers/blob/master/docs/monocle3.md Installs and loads the 'hcabm40k' dataset for analysis. ```r InstallData("hcabm40k") data("hcabm40k") ``` -------------------------------- ### Load Required Libraries Source: https://github.com/satijalab/seurat-wrappers/blob/master/docs/alevin.md Load the SeuratWrappers and tximport libraries. Ensure these packages are installed before running. ```r library(SeuratWrappers) library(tximport) ``` -------------------------------- ### Install and load mouse hippocampus dataset Source: https://github.com/satijalab/seurat-wrappers/blob/master/docs/banksy.md Install the 'ssHippo' dataset from SeuratData and load it into an R object named 'ss.hippo'. This dataset is used for demonstrating BANKSY within Seurat's spatial framework. ```r InstallData('ssHippo') ss.hippo <- LoadData("ssHippo") ``` -------------------------------- ### Load Seurat and tricycle Libraries Source: https://github.com/satijalab/seurat-wrappers/blob/master/docs/tricycle.md Load the necessary libraries for Seurat, SeuratWrappers, and tricycle. Ensure these packages are installed before running. ```r library(Seurat) library(SeuratWrappers) library(tricycle) ``` -------------------------------- ### Import Nebulosa and Seurat Libraries Source: https://github.com/satijalab/seurat-wrappers/blob/master/docs/nebulosa.md Load the necessary R libraries for Nebulosa, Seurat, and BiocFileCache. Ensure these packages are installed before running. ```r library("Nebulosa") library("Seurat") library("BiocFileCache") ``` -------------------------------- ### Load Libraries Source: https://github.com/satijalab/seurat-wrappers/blob/master/docs/harmony.md Load the necessary R libraries for Harmony, Seurat, and SeuratData. Ensure these packages are installed before running. ```r library(harmony) library(Seurat) library(SeuratData) ``` -------------------------------- ### Create and Activate Conda Environment for PaCMAP Source: https://github.com/satijalab/seurat-wrappers/blob/master/docs/pacmap.md Installs PaCMAP within a new conda environment named 'pacmap'. Ensure you have Anaconda or Miniconda installed. ```bash conda create -n "pacmap" python=3.12 # Install in the environment called "pacmap" conda activate pacmap conda install -y conda-forge::pacmap ``` -------------------------------- ### Load R Libraries Source: https://github.com/satijalab/seurat-wrappers/blob/master/docs/scvelo.md Load the required R libraries for Seurat, SeuratDisk, and SeuratWrappers. Ensure these packages are installed before running. ```r library(Seurat) library(SeuratDisk) library(SeuratWrappers) ``` -------------------------------- ### Load Libraries for Seurat and Velocyto Source: https://github.com/satijalab/seurat-wrappers/blob/master/docs/velocity.md Load the necessary libraries for Seurat, velocyto.R, and SeuratWrappers. Ensure these packages are installed before running. ```r library(Seurat) library(velocyto.R) library(SeuratWrappers) ``` -------------------------------- ### Load and Process PBMC3k Dataset Source: https://github.com/satijalab/seurat-wrappers/blob/master/docs/pacmap.md Installs, loads, and performs initial processing on the PBMC3k dataset, including updating the Seurat object and finding variable features. ```r InstallData("pbmc3k") pbmc3k.final <- LoadData("pbmc3k",type="pbmc3k.final") # Initial processing to select variable features pbmc3k.final <- UpdateSeuratObject(pbmc3k.final) pbmc3k.final <- FindVariableFeatures(pbmc3k.final) ``` -------------------------------- ### Load Required Libraries Source: https://github.com/satijalab/seurat-wrappers/blob/master/docs/liger.md Loads the necessary R libraries for Seurat, LIGER, SeuratWrappers, and SeuratData. Ensure these packages are installed before running. ```r library(rliger) library(Seurat) library(SeuratData) library(SeuratWrappers) ``` -------------------------------- ### Prepare and Run GLM-PCA on PBMC3k Dataset Source: https://github.com/satijalab/seurat-wrappers/blob/master/docs/glmpca.md Installs and loads the pbmc3k dataset, performs initial processing including deviance feature selection, and then runs GLM-PCA. It also finds neighbors, clusters, and runs UMAP based on the GLM-PCA reduction. ```r InstallData("pbmc3k") data("pbmc3k") # Initial processing to select variable features m <- GetAssayData(pbmc3k, slot = "counts", assay = "RNA") devs <- scry::devianceFeatureSelection(m) dev_ranked_genes <- rownames(pbmc3k)[order(devs, decreasing = TRUE)] topdev <- head(dev_ranked_genes, 2000) # run GLM-PCA on Seurat object. # Uses Poisson model by default # Note that data in the counts slot is used # We choose 10 dimensions for computational efficiency ndims <- 10 pbmc3k <- RunGLMPCA(pbmc3k, features = topdev, L = ndims) pbmc3k <- FindNeighbors(pbmc3k, reduction = 'glmpca', dims = 1:ndims, verbose = FALSE) pbmc3k <- FindClusters(pbmc3k, verbose = FALSE) pbmc3k <- RunUMAP(pbmc3k, reduction = 'glmpca', dims = 1:ndims, verbose = FALSE) ``` -------------------------------- ### Load necessary R libraries Source: https://github.com/satijalab/seurat-wrappers/blob/master/docs/cogaps.rmd Loads the required libraries for Seurat, SeuratWrappers, SeuratData, and CoGAPS. Ensure these packages are installed before running. ```r library(Seurat) library(SeuratWrappers) library(SeuratData) library(CoGAPS) ``` -------------------------------- ### Export Seurat Object to Cell Browser Source: https://github.com/satijalab/seurat-wrappers/blob/master/docs/cellbrowser.md Install and load the 'pbmc3k' dataset, then export it to a Cell Browser compatible format. Specify the output directory, Cell Browser directory, and the reduction method for visualization. The Cell Browser will be accessible via the specified port. ```r InstallData("pbmc3k") pbmc3k <- LoadData("pbmc3k", type = "pbmc3k.final") ExportToCellbrowser(pbmc3k, dir = "out", cb.dir = "cb_out", port = 8080, reductions = "umap") ``` -------------------------------- ### Process and integrate Interferon-stimulated PBMC dataset Source: https://github.com/satijalab/seurat-wrappers/blob/master/docs/conos.md Installs and loads the ifnb dataset, splits it by 'stim', normalizes, scales, and runs PCA on each subset. It then builds a graph using Conos, finds communities, embeds the graph, and converts it back to a Seurat object for visualization. ```r InstallData("ifnb") data("ifnb") ifnb.panel <- SplitObject(ifnb, split.by = "stim") for (i in 1:length(ifnb.panel)) { ifnb.panel[[i]] <- NormalizeData(ifnb.panel[[i]]) %>% FindVariableFeatures() %>% ScaleData() %>% RunPCA(verbose = FALSE) } ifnb.con <- Conos$new(ifnb.panel) ifnb.con$buildGraph(k = 15, k.self = 5, space = "PCA", ncomps = 30, n.odgenes = 2000, matching.method = "mNN", metric = "angular", score.component.variance = TRUE, verbose = TRUE) ifnb.con$findCommunities() ifnb.con$embedGraph() ifnb <- as.Seurat(ifnb.con) DimPlot(ifnb, reduction = "largeVis", group.by = c("stim", "ident", "seurat_annotations"), ncol = 3) ``` -------------------------------- ### Run CoGAPS for 10 patterns (AWS) Source: https://github.com/satijalab/seurat-wrappers/blob/master/docs/cogaps.rmd Configures and runs CoGAPS to identify 10 patterns in single-cell data using high iteration count and distributed computing. This example is intended for AWS execution and requires `eval = FALSE`. ```r InstallData("pbmc3k") data("pbmc3k.final") params <- CogapsParams( singleCell = TRUE, sparseOptimization = TRUE, seed = 123, nIterations = 50000, nPatterns = 10, distributed='genome-wide' ) params <- setDistributedParams(params, nSets = 5) pbmc3k.final <- RunCoGAPS(object = pbmc3k.final, temp.file = TRUE, params = params) ``` -------------------------------- ### Run CoGAPS for 3 patterns (AWS) Source: https://github.com/satijalab/seurat-wrappers/blob/master/docs/cogaps.rmd Configures and runs CoGAPS to identify 3 patterns in single-cell data using high iteration count and distributed computing. This example is intended for AWS execution and requires `eval = FALSE`. ```r InstallData("pbmc3k") data("pbmc3k.final") params <- CogapsParams( singleCell = TRUE, sparseOptimization = TRUE, seed = 123, nIterations = 50000, nPatterns = 3, distributed = 'genome-wide' ) params <- setDistributedParams(params, nSets = 5) pbmc3k.final <- RunCoGAPS(pbmc3k.final, temp.file = TRUE, params = params) ``` -------------------------------- ### Load Required Libraries Source: https://github.com/satijalab/seurat-wrappers/blob/master/docs/schex.html Loads necessary R libraries for Seurat data manipulation, plotting, and the schex package. Ensure these packages are installed prior to loading. ```r library(Seurat) library(SeuratData) library(ggplot2) library(ggrepel) library(dplyr) theme_set(theme_classic()) library(schex) ``` -------------------------------- ### Process and integrate PBMC dataset Source: https://github.com/satijalab/seurat-wrappers/blob/master/docs/conos.md Installs and loads the pbmcsca dataset, splits it by 'Method', normalizes, scales, and runs PCA on each subset. It then builds a graph using Conos, finds communities, embeds the graph, and converts it back to a Seurat object for visualization. ```r InstallData("pbmcsca") data("pbmcsca") pbmcsca.panel <- SplitObject(pbmcsca, split.by = "Method") for (i in 1:length(pbmcsca.panel)) { pbmcsca.panel[[i]] <- NormalizeData(pbmcsca.panel[[i]]) %>% FindVariableFeatures() %>% ScaleData() %>% RunPCA(verbose = FALSE) } pbmcsca.con <- Conos$new(pbmcsca.panel) pbmcsca.con$buildGraph(k = 15, k.self = 5, space = "PCA", ncomps = 30, n.odgenes = 2000, matching.method = "mNN", metric = "angular", score.component.variance = TRUE, verbose = TRUE) pbmcsca.con$findCommunities() pbmcsca.con$embedGraph() pbmcsca <- as.Seurat(pbmcsca.con) DimPlot(pbmcsca, reduction = "largeVis", group.by = c("Method", "ident", "CellType"), ncol = 3) ``` -------------------------------- ### Process and integrate eight human pancreatic islet datasets Source: https://github.com/satijalab/seurat-wrappers/blob/master/docs/conos.md Installs and loads the panc8 dataset, splits it by 'replicate', normalizes, scales, and runs PCA on each subset. It then builds a graph using Conos, finds communities, embeds the graph, and converts it back to a Seurat object for visualization. ```r InstallData("panc8") data("panc8") panc8.panel <- SplitObject(panc8, split.by = "replicate") for (i in 1:length(panc8.panel)) { panc8.panel[[i]] <- NormalizeData(panc8.panel[[i]]) %>% FindVariableFeatures() %>% ScaleData() %>% RunPCA(verbose = FALSE) } panc8.con <- Conos$new(panc8.panel) panc8.con$buildGraph(k = 15, k.self = 5, space = "PCA", ncomps = 30, n.odgenes = 2000, matching.method = "mNN", metric = "angular", score.component.variance = TRUE, verbose = TRUE) panc8.con$findCommunities() panc8.con$embedGraph() panc8 <- as.Seurat(panc8.con) DimPlot(panc8, reduction = "largeVis", group.by = c("replicate", "ident", "celltype"), ncol = 3) ``` -------------------------------- ### Dummy Documentation for Imported Generics (R) Source: https://github.com/satijalab/seurat-wrappers/wiki/Code-Guidelines Use this pattern to create dummy documentation for methods of generics imported from other packages. This ensures proper parameter inheritance and searchability. ```R NULL ``` -------------------------------- ### Download and Prepare Spatial Data Source: https://github.com/satijalab/seurat-wrappers/blob/master/docs/banksy.md Loads spatial data using ExperimentHub and spatialLIBD, then preprocesses it by removing unnecessary assays and metadata, and subsets to specific samples. ```r library(spatialLIBD) library(ExperimentHub) library(harmony) ehub <- ExperimentHub::ExperimentHub() spe <- spatialLIBD::fetch_data(type = "spe", eh = ehub) imgData(spe) <- NULL assay(spe, "logcounts") <- NULL reducedDims(spe) <- NULL rowData(spe) <- NULL colData(spe) <- DataFrame( sample_id = spe$sample_id, clust_annotation = factor( addNA(spe$layer_guess_reordered_short), exclude = NULL, labels = seq(8) ), in_tissue = spe$in_tissue, row.names = colnames(spe) ) invisible(gc()) # Subset to first sample of each subject sample_names <- c("151507", "151669", "151673") spe_list <- lapply(sample_names, function(x) spe[, spe$sample_id == x]) rm(spe) invisible(gc()) ``` -------------------------------- ### Run miQC with backup option Source: https://github.com/satijalab/seurat-wrappers/blob/master/docs/miQC.md Runs the miQC analysis with a specified posterior cutoff and a backup option for filtering when only one distribution is detected. This is useful when the standard two-distribution assumption is not met. The backup option 'percentile' with a 0.95 percentile cutoff is demonstrated. ```r pbmc3k_extreme <- RunMiQC(pbmc3k_extreme, percent.mt = "percent.mt", nFeature_RNA = "nFeature_RNA", posterior.cutoff = 0.9, model.slot = "flexmix_model", backup.option = "percentile", backup.percentile = 0.95) ``` -------------------------------- ### RunPrestoAll Source: https://context7.com/satijalab/seurat-wrappers/llms.txt Computes all-vs-all differential expression markers using `presto::wilcoxauc`. ```APIDOC ## RunPrestoAll ### Description Computes all-vs-all differential expression markers using `presto::wilcoxauc`. ### Parameters - **object** (Seurat Object) - The input Seurat object. - **logfc.threshold** (numeric) - Log2 fold change threshold. - **return.thresh** (numeric) - Threshold for returning markers. ### Request Example ```r library(SeuratWrappers) data("pbmc_small") pbmc_small <- NormalizeData(pbmc_small) pbmc_small <- FindVariableFeatures(pbmc_small) pbmc_small <- ScaleData(pbmc_small) pbmc_small <- RunPCA(pbmc_small) pbmc_small <- FindNeighbors(pbmc_small, dims = 1:10) pbmc_small <- FindClusters(pbmc_small, resolution = 0.5) # All-vs-all markers all_markers <- RunPrestoAll( object = pbmc_small, logfc.threshold = 0.25, return.thresh = 0.01 ) ``` ### Response - **all_markers** (data.frame) - A data frame containing all-vs-all differential expression results. ``` -------------------------------- ### RunPresto Source: https://context7.com/satijalab/seurat-wrappers/llms.txt Accelerates `Seurat::FindMarkers` by substituting the built-in Wilcoxon test with `presto::wilcoxauc`, which is orders of magnitude faster on large datasets. ```APIDOC ## RunPresto ### Description Accelerates `Seurat::FindMarkers` by substituting the built-in Wilcoxon test with `presto::wilcoxauc`, which is orders of magnitude faster on large datasets. ### Parameters - **object** (Seurat Object) - The input Seurat object. - **ident.1** (string or vector) - Feature identifying the first group of cells. - **logfc.threshold** (numeric) - Log2 fold change threshold. - **min.pct** (numeric) - Minimum fraction of cells expressing the feature. - **only.pos** (boolean) - Whether to return only positive markers. ### Request Example ```r library(SeuratWrappers) data("pbmc_small") pbmc_small <- NormalizeData(pbmc_small) pbmc_small <- FindVariableFeatures(pbmc_small) pbmc_small <- ScaleData(pbmc_small) pbmc_small <- RunPCA(pbmc_small) pbmc_small <- FindNeighbors(pbmc_small, dims = 1:10) pbmc_small <- FindClusters(pbmc_small, resolution = 0.5) # Fast markers for cluster 1 vs all others markers <- RunPresto( object = pbmc_small, ident.1 = "1", logfc.threshold = 0.25, min.pct = 0.1, only.pos = TRUE ) ``` ### Response - **markers** (data.frame) - A data frame containing differential expression results. ``` -------------------------------- ### Connect R Console to Conda Environment Source: https://github.com/satijalab/seurat-wrappers/blob/master/docs/pacmap.md Configures the reticulate package in R to use the specified conda environment. Adjust the 'conda' path if your installation is non-standard. ```r reticulate::use_condaenv(condaenv = "pacmap", conda = "auto") ``` -------------------------------- ### Run CoGAPS Locally with Seurat Data Source: https://github.com/satijalab/seurat-wrappers/blob/master/docs/cogaps.rmd Executes the CoGAPS algorithm locally on Seurat data with specified parameters for pattern discovery. Ensure data is installed and loaded before running. ```r InstallData("pbmc3k") data("pbmc3k.final") pbmc3k.final <- RunCoGAPS( object = pbmc3k.final, nPatterns = 3, nIterations = 5000, outputFrequency = 1000, sparseOptimization = TRUE, nThreads = 1, distributed = "genome-wide", singleCell = TRUE, seed = 891 ) ``` -------------------------------- ### RunQuantileNorm for LIGER Factor Normalization Source: https://context7.com/satijalab/seurat-wrappers/llms.txt Applies quantile normalization to LIGER factor embeddings across datasets. Produces a joint low-dimensional embedding for downstream analysis. Continues from RunOptimizeALS example. ```r # Continues from RunOptimizeALS example above ifnb <- RunQuantileNorm( object = ifnb, split.by = "stim", reduction = "iNMF_raw", reduction.name = "iNMF", reduction.key = "iNMF_", quantiles = 50, ref_dataset = NULL, # automatically picks largest dataset min_cells = 20, knn_k = 20 ) # Cluster identities are set automatically from Louvain result Idents(ifnb) ``` -------------------------------- ### scVIIntegration for Seurat v5 IntegrateLayers Source: https://context7.com/satijalab/seurat-wrappers/llms.txt Integrates data using scVI, a deep generative model, within Seurat v5's IntegrateLayers. Requires a conda environment with scvi-tools installed. Can be used with raw counts or SCTransform output. ```r library(SeuratWrappers) library(SeuratData) obj <- LoadData("pbmcsca") obj[["RNA"]] <- split(obj[["RNA"]], f = obj$Method) obj <- NormalizeData(obj) obj <- FindVariableFeatures(obj) obj <- ScaleData(obj) obj <- RunPCA(obj) # Integrate with scVI (specify your conda env) obj <- IntegrateLayers( object = obj, method = scVIIntegration, new.reduction = "integrated.scvi", conda_env = "~/miniconda3/envs/scvi-env", ndims = 30, nlayers = 2, gene_likelihood = "nb", # "zinb", "nb", or "poisson" verbose = FALSE ) # Works with SCTransform too obj <- SCTransform(obj) obj <- IntegrateLayers( object = obj, method = scVIIntegration, orig.reduction = "pca", new.reduction = "integrated.scvi", assay = "SCT", conda_env = "~/miniconda3/envs/scvi-env", verbose = FALSE ) obj <- FindNeighbors(obj, reduction = "integrated.scvi", dims = 1:30) obj <- FindClusters(obj) ``` -------------------------------- ### RunPresto: Fast differential expression with Presto Source: https://context7.com/satijalab/seurat-wrappers/llms.txt Accelerates Seurat's FindMarkers by using presto::wilcoxauc for faster Wilcoxon tests on large datasets. Can find markers for a specific cluster or all pairwise comparisons. ```r library(SeuratWrappers) data("pbmc_small") pbmc_small <- NormalizeData(pbmc_small) pbmc_small <- FindVariableFeatures(pbmc_small) pbmc_small <- ScaleData(pbmc_small) pbmc_small <- RunPCA(pbmc_small) pbmc_small <- FindNeighbors(pbmc_small, dims = 1:10) pbmc_small <- FindClusters(pbmc_small, resolution = 0.5) # Fast markers for cluster 1 vs all others markers <- RunPresto( object = pbmc_small, ident.1 = "1", logfc.threshold = 0.25, min.pct = 0.1, only.pos = TRUE ) head(markers) # p_val avg_log2FC pct.1 pct.2 p_val_adj # LDHB 3.40e-10 1.35 0.89 0.45 5.84e-08 # ... # All-vs-all markers all_markers <- RunPrestoAll( object = pbmc_small, logfc.threshold = 0.25, return.thresh = 0.01 ) ``` -------------------------------- ### R Session Information Source: https://github.com/satijalab/seurat-wrappers/blob/master/docs/cipr.md Displays the R version, platform, and loaded packages. Useful for reproducibility and debugging. ```r sessionInfo() ``` -------------------------------- ### Load required libraries Source: https://github.com/satijalab/seurat-wrappers/blob/master/docs/miQC.md Load the necessary R libraries for Seurat, SeuratData, SeuratWrappers, and flexmix. ```r library(Seurat) library(SeuratData) library(SeuratWrappers) library(flexmix) ``` -------------------------------- ### Split Data into Groups Source: https://github.com/satijalab/seurat-wrappers/blob/master/docs/banksy.md Demonstrates splitting the dataset into a specified number of groups for multi-sample analysis. Defines group names and sizes. ```r # Number of groups n_groups = 3 group_names = paste0('group', seq(n_groups)) group_size = 1000 starts = seq(1, by=group_size, length.out=n_groups) ends = starts + group_size - 1 ``` -------------------------------- ### RunOptimizeALS for LIGER NMF Integration Source: https://context7.com/satijalab/seurat-wrappers/llms.txt Performs integrative non-negative matrix factorization (NMF) using LIGER's optimizeALS. Stores factor loadings and dataset-specific W matrices. Requires scaled Seurat object split by a grouping variable. ```r library(SeuratWrappers) library(SeuratData) data("ifnb") ifnb <- NormalizeData(ifnb) ifnb <- FindVariableFeatures(ifnb, nfeatures = 2000) ifnb <- ScaleData(ifnb, split.by = "stim", do.center = FALSE) ifnb <- RunOptimizeALS( object = ifnb, k = 20, # number of factors split.by = "stim", lambda = 5, reduction.name = "iNMF_raw", rand.seed = 42 ) # Followed by quantile normalization: ifnb <- RunQuantileNorm( object = ifnb, split.by = "stim", reduction = "iNMF_raw", reduction.name = "iNMF" ) ifnb <- RunUMAP(ifnb, reduction = "iNMF", dims = 1:ncol(Embeddings(ifnb, "iNMF"))) DimPlot(ifnb, group.by = "stim") ``` -------------------------------- ### Load Required Libraries Source: https://github.com/satijalab/seurat-wrappers/blob/master/docs/presto.rmd Loads the necessary R libraries for Seurat, Presto, SeuratData, and SeuratWrappers. ```r library(presto) library(Seurat) library(SeuratData) library(SeuratWrappers) ``` -------------------------------- ### Download and Prepare PBMC 3k Data Source: https://github.com/satijalab/seurat-wrappers/blob/master/docs/nebulosa.md Download a 3k PBMCs dataset using BiocFileCache and extract it to a temporary directory. This prepares the raw count data for Seurat object creation. ```r bfc <- BiocFileCache(ask = FALSE) data_file <- bfcrpath(bfc, file.path("https://s3-us-west-2.amazonaws.com/10x.files/samples/cell", "pbmc3k", "pbmc3k_filtered_gene_bc_matrices.tar.gz")) untar(data_file, exdir = tempdir()) ``` -------------------------------- ### Load necessary libraries for BANKSY and Seurat analysis Source: https://github.com/satijalab/seurat-wrappers/blob/master/docs/banksy.md Load the required R libraries for BANKSY, Seurat, SeuratData, SeuratWrappers, and visualization tools. The `kelly()` palette is loaded for visualization purposes. ```r library(Banksy) library(Seurat) library(SeuratData) library(SeuratWrappers) library(ggplot2) library(gridExtra) library(pals) # Kelly palette for visualization mypal <- kelly()[-1] ``` -------------------------------- ### Load Libraries for Seurat Wrappers Source: https://github.com/satijalab/seurat-wrappers/blob/master/docs/alra.md Load necessary libraries including Seurat, SeuratData, SeuratWrappers, and dplyr for data manipulation. ```r library(Seurat) library(SeuratData) library(SeuratWrappers) library(dplyr) ``` -------------------------------- ### Load Libraries for Seurat and schex Source: https://github.com/satijalab/seurat-wrappers/blob/master/docs/schex.md Loads necessary libraries including Seurat, SeuratData, ggplot2, ggrepel, and schex. Sets the default ggplot2 theme. ```r library(Seurat) library(SeuratData) library(ggplot2) library(ggrepel) theme_set(theme_classic()) library(schex) ``` -------------------------------- ### Load Required Libraries Source: https://github.com/satijalab/seurat-wrappers/blob/master/docs/glmpca.md Loads the necessary R libraries for Seurat, SeuratData, SeuratWrappers, glmpca, and scry. ```r library(Seurat) library(SeuratData) library(SeuratWrappers) library(glmpca) library(scry) ``` -------------------------------- ### Simulate extreme case for miQC analysis Source: https://github.com/satijalab/seurat-wrappers/blob/master/docs/miQC.md Simulates an extreme case of compromised cells in the 'pbmc3k' dataset to demonstrate a scenario where the two-distribution assumption of miQC may not be met. Use FeatureScatter to visualize the distribution of mitochondrial percentage against gene counts. ```r set.seed(2021) pbmc3k_extreme <- pbmc3k simulated_percent_mt <- rnorm(mean = 2.5, sd = 0.2, n = ncol(pbmc3k_extreme)) pbmc3k_extreme$percent.mt <- ifelse(pbmc3k_extreme$nFeature_RNA > 400, simulated_percent_mt, pbmc3k_extreme$percent.mt) simulated_percent_mt_2 <- runif(min = 0, max = 60, n = ncol(pbmc3k_extreme)) pbmc3k_extreme$percent.mt <- ifelse(pbmc3k_extreme$nFeature_RNA < 400, simulated_percent_mt_2, pbmc3k_extreme$percent.mt) FeatureScatter(pbmc3k_extreme, feature1 = "nFeature_RNA", feature2 = "percent.mt") ``` -------------------------------- ### Run CIPR with Selected Reference Subsets Source: https://github.com/satijalab/seurat-wrappers/blob/master/docs/cipr.md Performs CIPR analysis using the 'logfc_dot_product' method, limiting the analysis to specified reference cell types. This can improve discrimination and simplify graphical outputs. Ensure 'allmarkers' is defined and the 'reference' dataset is available. ```r CIPR(input_dat = allmarkers, comp_method = "logfc_dot_product", reference = "hsrnaseq", plot_ind = T, plot_top = F, global_results_obj = T, global_plot_obj = T, select_ref_subsets = c("CD4+ T cell", "CD8+ T cell", "Monocyte", "NK cell")) ``` -------------------------------- ### Run UMAP with LIGER reduction and Plot Dimensions Source: https://github.com/satijalab/seurat-wrappers/blob/master/docs/liger.md Run UMAP using dimensions from the iNMF reduction provided by LIGER. Visualize the results by plotting dimensions, grouping by replicate, identity, and cell type. ```r panc8 <- RunUMAP(panc8, dims = 1:ncol(panc8[["iNMF"]]), reduction = "iNMF") DimPlot(panc8, group.by = c("replicate", "ident", "celltype"), ncol = 3) ``` -------------------------------- ### Logging Seurat Command Calls (R) Source: https://github.com/satijalab/seurat-wrappers/wiki/Code-Guidelines Encourages storing command call and parameters for each method using LogSeuratCommand. This automatically captures function name, parameters, and the exact call string for storage within the Seurat object. ```R MyFunction <- function(object, ...) { object <- LogSeuratCommand(object = object) return(object) } ``` -------------------------------- ### as.Seurat.list Source: https://context7.com/satijalab/seurat-wrappers/llms.txt Builds a Seurat object from a named list of matrices, where each matrix becomes an assay. ```APIDOC ## as.Seurat.list — Build a Seurat object from a named list of matrices Convenience constructor: each matrix in the list becomes an assay in the resulting Seurat object. Supports mixed `counts`/`data` slots and per-assay cell/feature filtering. ```r library(SeuratWrappers) # Named list of sparse matrices: one per modality mat_list <- list( RNA = rna_counts_matrix, # dgCMatrix genes x cells ATAC = atac_counts_matrix # dgCMatrix peaks x cells ) obj <- as.Seurat( x = mat_list, default.assay = "RNA", slot = c("counts", "counts"), min.cells = c(3, 0), min.features = c(200, 0) ) Assays(obj) # "RNA" "ATAC" DefaultAssay(obj) # "RNA" ``` ``` -------------------------------- ### Import Alevin Counts Source: https://github.com/satijalab/seurat-wrappers/blob/master/docs/alevin.md Use the ReadAlevin function to import alevin quantified counts and generate a Seurat object. Specify the path to your alevin output file. ```r pbmc <- ReadAlevin("~/alevin_out/alevin/quants_mat.gz") ``` -------------------------------- ### Integrate Human PBMC Data with LIGER Source: https://github.com/satijalab/seurat-wrappers/blob/master/docs/liger.md Integrates human PBMC data using LIGER. This involves normalization, finding variable features, scaling data while splitting by 'Method', running LIGER's OptimizeALS for integration, and performing quantile normalization. Louvain clustering and UMAP visualization are performed on the integrated latent space. ```r InstallData("pbmcsca") data("pbmcsca") # Please update your `liger` version to 0.5.0 or above before following this tutorial pbmcsca <- NormalizeData(pbmcsca) pbmcsca <- FindVariableFeatures(pbmcsca) pbmcsca <- ScaleData(pbmcsca, split.by = "Method", do.center = FALSE) pbmcsca <- RunOptimizeALS(pbmcsca, k = 20, lambda = 5, split.by = "Method") pbmcsca <- RunQuantileNorm(pbmcsca, split.by = "Method") # You can optionally perform Louvain clustering (`FindNeighbors` and `FindClusters`) after # `RunQuantileNorm` according to your needs pbmcsca <- FindNeighbors(pbmcsca, reduction = "iNMF", dims = 1:20) pbmcsca <- FindClusters(pbmcsca, resolution = 0.3) # Dimensional reduction and plotting pbmcsca <- RunUMAP(pbmcsca, dims = 1:ncol(pbmcsca[["iNMF"]]), reduction = "iNMF") DimPlot(pbmcsca, group.by = c("Method", "ident", "CellType"), ncol = 3) ``` -------------------------------- ### Load AnnData in Python Source: https://github.com/satijalab/seurat-wrappers/blob/master/docs/scvelo.md Load the .h5ad file into an AnnData object using scVelo in Python. This object will contain the processed data for further analysis. ```python # In Python import scvelo as scv adata = scv.read("mouseBM.h5ad") adata ``` -------------------------------- ### Load Required Libraries Source: https://github.com/satijalab/seurat-wrappers/blob/master/docs/cellbrowser.md Load the necessary R libraries for Seurat, SeuratData, and SeuratWrappers to enable data manipulation and export functionalities. ```r library(Seurat) library(SeuratData) library(SeuratWrappers) ``` -------------------------------- ### Run Presto for All Cell Type Comparisons Source: https://github.com/satijalab/seurat-wrappers/blob/master/docs/presto.md Execute differential expression analysis for all possible pairwise comparisons between cell clusters using RunPrestoAll. This provides a comprehensive overview of gene expression differences. ```r diffexp.all <- RunPrestoAll(pbmc3k) head(diffexp.all[diffexp.all$cluster == "B", ], 10) ``` -------------------------------- ### Run PCA, UMAP, and Clustering on Integrated Data Source: https://github.com/satijalab/seurat-wrappers/blob/master/docs/monocle3.md Scales data, runs PCA and UMAP, finds neighbors and clusters, and visualizes the results. ```r integrated <- ScaleData(integrated) integrated <- RunPCA(integrated) integrated <- RunUMAP(integrated, dims = 1:30, reduction.name = "UMAP") integrated <- FindNeighbors(integrated, dims = 1:30) integrated <- FindClusters(integrated) DimPlot(integrated, group.by = c("orig.ident", "ident")) ``` -------------------------------- ### Load Required Libraries Source: https://github.com/satijalab/seurat-wrappers/blob/master/docs/cipr.md Loads necessary R libraries for data manipulation, Seurat analysis, Seurat data handling, and CIPR. ```r library(dplyr) library(Seurat) library(SeuratData) library(CIPR) ``` -------------------------------- ### Run Presto for All Clusters Source: https://github.com/satijalab/seurat-wrappers/blob/master/docs/presto.rmd Performs differential expression analysis across all clusters in the dataset using RunPrestoAll. The head of the results filtered for the 'B' cluster is then displayed. ```r diffexp.all <- RunPrestoAll(pbmc3k) head(diffexp.all[diffexp.all$cluster=='B', ], 10) ``` -------------------------------- ### RunMiQC: Probabilistic quality control for Seurat objects Source: https://context7.com/satijalab/seurat-wrappers/llms.txt Fits a mixture model to identify compromised cells based on mitochondrial percentage and unique gene count. Appends 'miQC.probability' and 'miQC.keep' to metadata. Use 'percentile' as a fallback if the model fails. ```r library(SeuratWrappers) pbmc <- CreateSeuratObject(counts = pbmc_counts) pbmc[["percent.mt"]] <- PercentageFeatureSet(pbmc, pattern = "^MT-") pbmc <- RunMiQC( object = pbmc, percent.mt = "percent.mt", nFeature_RNA = "nFeature_RNA", posterior.cutoff = 0.75, model.type = "linear", # "linear", "spline", or "polynomial" backup.option = "percentile" # fallback if model fails ) # Filter to keep only high-quality cells pbmc_clean <- subset(pbmc, miQC.keep == "keep") # Visualize the mixture model PlotMiQC(pbmc, color.by = "miQC.probability") ``` -------------------------------- ### Inspect MiQC Model Posterior Probabilities Source: https://github.com/satijalab/seurat-wrappers/blob/master/docs/miQC.md View the head of the posterior probabilities calculated by the MiQC model for each cell. ```r head(flexmix::posterior(Misc(pbmc3k, "flexmix_model"))) ``` -------------------------------- ### Visualize MiQC Model Results Source: https://github.com/satijalab/seurat-wrappers/blob/master/docs/miQC.md Plot the cells colored by their posterior probability of belonging to the compromised condition, using a gradient from grey to purple. ```r PlotMiQC(pbmc3k, color.by = "miQC.probability") + ggplot2::scale_color_gradient(low = "grey", high = "purple") ``` -------------------------------- ### Cluster Cells using Louvain Algorithm Source: https://github.com/satijalab/seurat-wrappers/blob/master/docs/nebulosa.md Construct a Shared Nearest Neighbor (SNN) graph using the first 30 principal components and apply the Louvain algorithm to cluster the cells. This helps in identifying cell types. ```r pbmc <- FindNeighbors(pbmc, dims = 1:30) pbmc <- FindClusters(pbmc) ``` -------------------------------- ### Visualize Cells to Keep Based on MiQC Source: https://github.com/satijalab/seurat-wrappers/blob/master/docs/miQC.md Visualize which cells are marked to be kept based on the MiQC analysis, typically after applying a posterior cutoff. ```r PlotMiQC(pbmc3k, color.by = "miQC.keep") ``` -------------------------------- ### Identify and Scale Highly Variable Features Source: https://github.com/satijalab/seurat-wrappers/blob/master/docs/cipr.md Identifies the top 2000 highly variable features using the 'vst' method and scales the entire dataset. ```r pbmc <- FindVariableFeatures(pbmc, selection.method = "vst", nfeatures = 2000) all.genes <- rownames(pbmc) pbmc <- ScaleData(pbmc, features = all.genes) ```