### Harmony Integration Example Source: https://cbib.github.io/Seurat-Integrate/reference/HarmonyIntegration.html Example demonstrating the usage of HarmonyIntegration. This code is intended for non-production environments and requires specific setup. ```R if (FALSE) { # \dontrun{ ``` -------------------------------- ### Install SeuratIntegrate Source: https://cbib.github.io/Seurat-Integrate/index.html Installs the SeuratIntegrate package from GitHub. Ensure remotes and BiocManager are installed first if necessary. ```r install.packages(c("remotes", "BiocManager")) # if not installed remotes::install_github("cbib/Seurat-Integrate", repos = BiocManager::repositories()) ``` -------------------------------- ### Example Usage of CombatIntegration Source: https://cbib.github.io/Seurat-Integrate/reference/CombatIntegration.html Demonstrates how to use the CombatIntegration function for integrating Seurat layers, including examples with default parameters and custom configurations like using scaled data and specifying the ComBat implementation. ```APIDOC ## Examples ```R if (FALSE) { # \dontrun{ # Preprocessing obj <- UpdateSeuratObject(SeuratData::LoadData("pbmcsca")) obj[["RNA"]] <- split(obj[["RNA"]], f = obj$Method) obj <- NormalizeData(obj) obj <- FindVariableFeatures(obj) obj <- ScaleData(obj) obj <- RunPCA(obj) # After preprocessing, we integrate layers based on the "Method" variable: obj <- IntegrateLayers(object = obj, method = CombatIntegration, verbose = TRUE, layers = "data", scale.layer = NULL, features = VariableFeatures( FindVariableFeatures(obj, nfeatures = 5e3) )) # We can also change parameters such as the input data. # Here we use the scale data, the ComBat implementation and we use the cell # labels as a "biological condition of interest" (/!\ long): obj <- IntegrateLayers(object = obj, method = CombatIntegration, verbose = TRUE, features = VariableFeatures(obj), use.scaled = FALSE, combat.function = 'combat_seq', group = obj[[]]$CellType, groups = obj[[]], groups.name = "Method", layers = "counts") } # } ``` ``` -------------------------------- ### Install Additional Packages Source: https://cbib.github.io/Seurat-Integrate/index.html Installs auxiliary packages for enhanced functionality, including fast distance computation, kBET, and lisi. ```r # fast distance computation install.packages('distances') # required to test for k-nearest neighbour batch effects remotes::install_github('theislab/kBET') # faster Local Inverse Simpson’s Index computation remotes::install_github('immunogenomics/lisi') ``` -------------------------------- ### Install and Load pbmcsca Dataset Source: https://cbib.github.io/Seurat-Integrate/articles/introduction.html Installs the SeuratData package if not present and then loads the pbmcsca dataset. A subset of 1,000 cells is used to speed up execution. The timeout for downloading is increased to 300 seconds. ```r # install `SeuratData` package (if not yet) if (! requireNamespace("SeuratData", quietly = TRUE)) { devtools::install_github('satijalab/seurat-data') } # increase download timeout and install the dataset options(timeout = 300) SeuratData::InstallData('pbmcsca') ``` ```r # load the dataset (take 1,000 first cells to speed-up execution) seu <- SeuratData::LoadData('pbmcsca')[,1:1e3] ``` -------------------------------- ### Load Example Dataset Source: https://cbib.github.io/Seurat-Integrate/articles/SeuratIntegrate.html Load the small liver dataset included with SeuratIntegrate. This dataset contains 200 immune liver cells and approximately 6,500 genes. ```r data("liver_small") ``` -------------------------------- ### Load SeuratIntegrate Library Source: https://cbib.github.io/Seurat-Integrate/articles/setup_and_tips.html Loads the SeuratIntegrate package into the R session. Ensure the package is installed before running. ```r library(SeuratIntegrate) ``` -------------------------------- ### Integrate Layers with CombatIntegration Source: https://cbib.github.io/Seurat-Integrate/reference/CombatIntegration.html Example of integrating Seurat layers using the CombatIntegration method after preprocessing. This demonstrates basic integration. ```R obj <- IntegrateLayers(object = obj, method = CombatIntegration, verbose = TRUE, layers = "data", scale.layer = NULL, features = VariableFeatures( FindVariableFeatures(obj, nfeatures = 5e3) )) ``` -------------------------------- ### Integrate Seurat layers using MNNIntegration Source: https://cbib.github.io/Seurat-Integrate/reference/MNNIntegration.html Example of integrating Seurat layers using the MNNIntegration method. This demonstrates basic preprocessing and the subsequent integration step. ```R # Preprocessing obj <- UpdateSeuratObject(SeuratData::LoadData("pbmcsca")) obj[["RNA"]] <- split(obj[["RNA"]], f = obj$Method) obj <- NormalizeData(obj) obj <- FindVariableFeatures(obj) obj <- ScaleData(obj) obj <- RunPCA(obj) # After preprocessing, we integrate layers: obj <- IntegrateLayers(object = obj, method = MNNIntegration, new.reduction = 'integrated.mnn', verbose = FALSE) ``` -------------------------------- ### Example of DoIntegrate with Multiple Integration Methods Source: https://cbib.github.io/Seurat-Integrate/reference/DoIntegrate.html Demonstrates how to use DoIntegrate to apply multiple integration methods (CombatIntegration and CCAIntegration) to a Seurat object. It shows how to specify method-specific parameters, such as using all features instead of highly variable genes for CombatIntegration. ```R DoIntegrate(seu, SeuratIntegrate::CombatIntegration(features = Features(seu)), Seurat::CCAIntegration(), use.hvg = TRUE) ``` -------------------------------- ### Example: Score Density PC with Different Union Settings Source: https://cbib.github.io/Seurat-Integrate/reference/score-densityPC.html Demonstrates calculating batch mixing scores using ScoreDensityPC with and without the union of densities. Requires SeuratData package and pbmcsca dataset. ```R if (FALSE) { # \dontrun{ obj <- SeuratData::LoadData("pbmcsca") obj[["RNA"]] <- split(obj[["RNA"]], f = obj$Method) obj <- NormalizeData(obj) obj <- FindVariableFeatures(obj) obj <- ScaleData(obj) obj <- RunPCA(obj) score.union <- ScoreDensityPC(obj, "Method", "pca", dim = 1:30) score.sum <- ScoreDensityPC(obj, "Method", "pca", dim = 1:30, use.union = FALSE) score.union # ~ 0.1511 score.sum # ~ 0.0319 } # } ``` -------------------------------- ### Get Cache Path Function Source: https://cbib.github.io/Seurat-Integrate/reference/getCachePath.html Use this function to get the path to the package configuration cache. Set `include.file` to `FALSE` to retrieve the directory path instead of the file path. ```r getCachePath(include.file = TRUE) ``` -------------------------------- ### Integrate Layers with scVI Source: https://cbib.github.io/Seurat-Integrate/reference/scVIIntegration.html Performs data integration using scVI. Requires scvi-tools to be installed. Ensure necessary preprocessing steps like normalization and scaling are completed. ```R if (FALSE) { # \dontrun{ # Preprocessing obj <- SeuratData::LoadData("pbmcsca") obj[["RNA"]] <- split(obj[["RNA"]], f = obj$Method) obj <- NormalizeData(obj) obj <- FindVariableFeatures(obj) obj <- ScaleData(obj) obj <- RunPCA(obj) # After preprocessing, we integrate layers: obj <- IntegrateLayers(object = obj, method = scVIIntegration, features = Features(obj), conda_env = 'scvi-tools', layers = 'counts', groups = obj[[]], groups.name = 'Method') # To enable cell label-guided correction, save the model, add other # 'nuisance' factors and increase number of threads used: obj <- IntegrateLayers(object = obj, method = scVIIntegration, features = Features(obj), conda_env = 'scvi-tools', layers = 'counts', groups = obj[[]], groups.name = "Method", labels.name = "CellType", categorical_covariate_keys = list("Experiment"), continuous_covariate_keys = list("percent.mito"), ncores = 8, model.save.dir = '~/Documents/scVI.model') } # } ``` -------------------------------- ### Integrate Layers with bbknnIntegration Source: https://cbib.github.io/Seurat-Integrate/reference/bbknnIntegration.html Example of using bbknnIntegration within the IntegrateLayers function for data integration. Ensure the bbknn conda environment is specified. ```R if (FALSE) { # \dontrun{ # Preprocessing obj <- SeuratData::LoadData("pbmcsca") obj[["RNA"]] <- split(obj[["RNA"]], f = obj$Method) obj <- NormalizeData(obj) obj <- FindVariableFeatures(obj) obj <- ScaleData(obj) obj <- RunPCA(obj) # After preprocessing, we integrate layers: obj <- IntegrateLayers(object = obj, method = bbknnIntegration, conda_env = 'bbknn', groups = obj[[]], groups.name = 'Method') } ``` -------------------------------- ### Example: Score Batch Mixing with pbmcsca data Source: https://cbib.github.io/Seurat-Integrate/reference/score-regressPC.html Demonstrates how to use ScoreRegressPC to calculate batch mixing scores using the pbmcsca dataset. It shows calculations for both raw R2 and adjusted R2. ```r if (FALSE) { # \dontrun{ obj <- SeuratData::LoadData("pbmcsca") obj[["RNA"]] <- split(obj[["RNA"]], f = obj$Method) obj <- NormalizeData(obj) obj <- FindVariableFeatures(obj) obj <- ScaleData(obj) obj <- RunPCA(obj) score.r2 <- ScoreRegressPC(obj, "Method", "pca", dim = 1:30) score.adj.r2 <- ScoreRegressPC(obj, "Method", "pca", dim = 1:30, adj.r2 = TRUE) score.r2 # ~ 0.1147 score.adj.r2 # ~ 0.1145 } # } ``` -------------------------------- ### Integrate Seurat layers with custom mnnCorrect parameters Source: https://cbib.github.io/Seurat-Integrate/reference/MNNIntegration.html This example shows how to pass specific parameters to mnnCorrect through MNNIntegration, such as setting the number of nearest neighbors (k). ```R # We can also add parameters specific to mnnCorrect. # Here we set `k` to specify the number of nearest neighbors # to use when identifying MNNs: obj <- IntegrateLayers(object = obj, method = MNNIntegration, new.reduction = 'integrated.mnn', k = 15, verbose = FALSE) ``` -------------------------------- ### Example of CellCycleScoringPerBatch Usage Source: https://cbib.github.io/Seurat-Integrate/reference/CellCycleScoringPerBatch.html Demonstrates how to use CellCycleScoringPerBatch to score cell cycle phases per batch. Requires loading data, normalizing, finding variable features, scaling, and then applying the scoring function. ```R obj <- SeuratData::LoadData("pbmcsca") obj[["RNA"]] <- split(obj[["RNA"]], f = obj$Method) obj <- NormalizeData(obj) obj <- FindVariableFeatures(obj) obj <- ScaleData(obj) obj <- CellCycleScoringPerBatch(obj, batch.var = 'Method', s.features = cc.genes.updated.2019$s.genes, g2m.features = cc.genes.updated.2019$g2m.genes) head(obj[[]]) ``` -------------------------------- ### getCachePath Source: https://cbib.github.io/Seurat-Integrate/reference/getCachePath.html Retrieves the path to the package configuration cache. By default, it returns the path to the cache file. Set `include.file` to `FALSE` to get the directory containing the cache file. ```APIDOC ## Function: getCachePath ### Description Get path to package config cache file or directory. ### Usage ```R getCachePath(include.file = TRUE) ``` ### Arguments * `include.file` (logical) - Set to `FALSE` to retrieve the directory containing the cache file. Return the path to the file by default. ### Value A single character, the path to the cache file or directory. ``` -------------------------------- ### List Conda Packages Source: https://cbib.github.io/Seurat-Integrate/articles/setup_and_tips.html Check the installed versions of specific packages, such as jax, within a named conda environment. This is useful for identifying version conflicts between Python packages. ```Shell conda list -n [conda_env_name] jax ``` -------------------------------- ### Integrate Layers with scANVI Source: https://cbib.github.io/Seurat-Integrate/reference/scANVIIntegration.html Integrates layers of a Seurat object using the scANVI method. Requires scvi-tools to be installed and specified via conda_env. This basic example focuses on layer integration and group definition. ```R if (FALSE) { # \dontrun{ # Preprocessing obj <- SeuratData::LoadData("pbmcsca") obj[["RNA"]] <- split(obj[["RNA"]], f = obj$Method) obj <- NormalizeData(obj) obj <- FindVariableFeatures(obj) obj <- ScaleData(obj) obj <- RunPCA(obj) # After preprocessing, we integrate layers: obj <- IntegrateLayers(object = obj, method = scANVIIntegration, features = Features(obj), conda_env = 'scvi-tools', layers = 'counts', groups = obj[[]], groups.name = 'Method', labels.name = 'CellType', labels.null = 'Unassigned') } # } ``` -------------------------------- ### Organize Integration Outputs in Lists Source: https://cbib.github.io/Seurat-Integrate/articles/introduction.html Prepare lists to map integration names to their corresponding reduction and graph names. This is a preparatory step for scoring. ```r reductions <- list( unintegrated = "pca", scanorama_counts = "pca.scanorama_counts", scanorama_reduction = "integrated.scanorama", harmony = "harmony", cca = "cca.integrated", rpca = "rpca.integrated", scanvi = "integrated.scANVI", bbknn = NULL ) graphs <- list( unintegrated = "knn.unintegrated_symmetric", scanorama_counts = "knn.scanorama_counts_symmetric", scanorama_reduction = "knn.scanorama_reduction_symmetric", harmony = "knn.harmony_symmetric", cca = "knn.cca_symmetric", rpca = "knn.rpca_symmetric", scanvi = "knn.scanvi_symmetric", bbknn = "bbknn_ridge.residuals_distances_symmetric" ) integrations <- names(reductions) ``` -------------------------------- ### View Help for supportsMulticore Source: https://cbib.github.io/Seurat-Integrate/articles/setup_and_tips.html Opens the help documentation for the supportsMulticore function, providing detailed information on process forking support and its configuration. ```R help('supportsMulticore', package = 'parallelly') ``` -------------------------------- ### Scoring - General getters and setters of score table Source: https://cbib.github.io/Seurat-Integrate/reference/index.html Functions to get, set, and modify scores in the score table. ```APIDOC ## GetMiscIntegrations() ## GetMiscScores() ## IntegrationScores() ### Description Retrieve integration scores from a Seurat object. ### Method GetMiscIntegrations, GetMiscScores, IntegrationScores ### Endpoint N/A (SDK Function) ### Parameters None specified in source. ### Request Example ``` GetMiscIntegrations() GetMiscScores() IntegrationScores() ``` ### Response Returns integration scores. ``` ```APIDOC ## SetMiscScore() ### Description Set the value of a score in the score tibble. ### Method SetMiscScore ### Endpoint N/A (SDK Function) ### Parameters None specified in source. ### Request Example ``` SetMiscScore() ``` ### Response N/A ``` ```APIDOC ## AddMiscIntegrations() ## AddMiscScores() ### Description Add integration(s) or score(s) slot(s) to the score tibble. ### Method AddMiscIntegrations, AddMiscScores ### Endpoint N/A (SDK Function) ### Parameters None specified in source. ### Request Example ``` AddMiscIntegrations() AddMiscScores() ``` ### Response N/A ``` -------------------------------- ### Check Conda Binary Source: https://cbib.github.io/Seurat-Integrate/reference/checkCondaEnv.html Validates the conda binary path. Use when you need to ensure reticulate can find your conda installation. ```R checkCondaBin(x, ..., verbose = getOption("verbose")) ``` -------------------------------- ### Get Conda Cache Source: https://cbib.github.io/Seurat-Integrate/reference/getCache.html Retrieves the current cache of conda environments. Specify whether to load from the package environment or disk. ```r getCache(from = c("env", "cache")) ``` -------------------------------- ### Access supportsMulticore Help Source: https://cbib.github.io/Seurat-Integrate/articles/setup_and_tips.html A shortcut to access the help documentation for the supportsMulticore function. ```R ?supportsMulticore ``` -------------------------------- ### Get Cache of Conda Environments Source: https://cbib.github.io/Seurat-Integrate/reference/getCache.html Retrieves the current cache of conda environments. You can specify whether to load the cache from the package environment or from disk. ```APIDOC ## getCache ### Description Get current cache of conda environments from package environment or cache on disk. ### Usage ```R getCache(from = c("env", "cache")) ``` ### Arguments * `from` (character) - Either "env" or "cache". Specifies where to load the cache from. ### Value A CondaEnvManager object representing the conda environment cache. ``` -------------------------------- ### Integrate Batches using R-based Methods Source: https://cbib.github.io/Seurat-Integrate/articles/introduction.html Performs batch integration using Harmony, CCA, and RPCA methods. Set `use.future = FALSE` for R-based methods to avoid launching background sessions. ```R seu <- DoIntegrate( object = seu, SeuratIntegrate::HarmonyIntegration(orig = "pca", dims = 1:30, ncores = ncores), CCAIntegration(orig = "pca", dims = 1:30 , new.reduction = "cca.integrated", normalization.method = "SCT"), RPCAIntegration(orig = "pca", dims = 1:30, new.reduction = "rpca.integrated", normalization.method = "SCT"), use.future = FALSE # R-based ) ``` -------------------------------- ### Perform multi-method integration with Seurat Source: https://cbib.github.io/Seurat-Integrate/articles/introduction.html Use DoIntegrate to apply multiple integration methods sequentially. Set use.future = TRUE for Python-based methods and specify use.hvg for each method. ```R seu <- DoIntegrate( object = seu, bbknnIntegration(orig = "pca", layers = "data", ndims = 30), ScanoramaIntegration(orig = "pca", ncores = ncores), scANVIIntegration(groups = seu[[]], groups.name = "Method", labels.name = "CellType", layers = "counts", torch.intraop.threads = ncores, torch.interop.threads = ncores, max_epochs = 20L), use.future = TRUE, # Python-based use.hvg = c(TRUE, TRUE, FALSE) ) ``` -------------------------------- ### Run classical MNN on Seurat's Assay5 object Source: https://cbib.github.io/Seurat-Integrate/reference/MNNIntegration.html This function is a wrapper to run mnnCorrect on multi-layered Seurat V5 objects. It requires the batchelor package to be installed. ```R MNNIntegration( object, orig = NULL, groups = NULL, layers = NULL, scale.layer = NULL, features = 2000, reconstructed.assay = "mnn.reconstructed", verbose = TRUE, ... ) ``` -------------------------------- ### Advanced Integration with CombatIntegration Parameters Source: https://cbib.github.io/Seurat-Integrate/reference/CombatIntegration.html Demonstrates advanced usage of IntegrateLayers with CombatIntegration, specifying scaled data, ComBat implementation, and biological condition. ```R obj <- IntegrateLayers(object = obj, method = CombatIntegration, verbose = TRUE, features = VariableFeatures(obj), use.scaled = FALSE, combat.function = 'combat_seq', group = obj[[]]$CellType, groups = obj[[]], groups.name = "Method", layers = "counts") ``` -------------------------------- ### Construct a CondaEnv Instance Source: https://cbib.github.io/Seurat-Integrate/reference/CondaEnv.html Use this constructor to create a CondaEnv object, which holds details about a specific conda environment for a given integration method. For most use cases, prefer functions from CondaEnvManager. ```r CondaEnv( method = known.methods, conda.bin = NULL, conda.env.name = NULL, conda.env.path = NULL ) ``` -------------------------------- ### Conda Environment Management - Class Constructors Source: https://cbib.github.io/Seurat-Integrate/reference/index.html Constructors for creating CondaEnv and CondaManager instances. ```APIDOC ## CondaEnv() ### Description Handy `CondaEnv` instance constructor. ### Method CondaEnv ### Endpoint N/A (SDK Function) ### Parameters None ### Request Example ``` CondaEnv() ``` ### Response An instance of `CondaEnv`. ``` ```APIDOC ## CondaManager() ### Description Handy `CondaEnvManger` instance constructor. ### Method CondaManager ### Endpoint N/A (SDK Function) ### Parameters None ### Request Example ``` CondaManager() ``` ### Response An instance of `CondaEnvManger`. ``` -------------------------------- ### Run Harmony on Seurat Assay5 Object Source: https://cbib.github.io/Seurat-Integrate/reference/HarmonyIntegration.html Use HarmonyIntegration to run Harmony on multi-layered Seurat V5 objects. This function can be called directly or via IntegrateLayers. Ensure the harmony package is installed. ```R HarmonyIntegration( object, orig, groups = NULL, groups.name = NULL, layers = NULL, scale.layer = "scale.data", features = NULL, new.reduction = "harmony", dims = NULL, key = "harmony_", seed.use = 42L, theta = NULL, sigma = 0.1, lambda = NULL, nclust = NULL, ncores = 1L, max_iter = 10, early_stop = TRUE, plot_convergence = FALSE, .options = harmony_options(), verbose = TRUE, ... ) HarmonyIntegration.fix(...) ``` -------------------------------- ### Run scANVI on Seurat's Assay5 object Source: https://cbib.github.io/Seurat-Integrate/reference/scANVIIntegration.html Wrapper to run scANVI on multi-layered Seurat V5 objects. Requires a conda environment with scvi-tools. Recommendations: use raw counts and all features. ```R scANVIIntegration( object, groups = NULL, groups.name = NULL, labels.name = NULL, labels.null = NULL, features = NULL, layers = "counts", scale.layer = "scale.data", conda_env = NULL, new.reduction = "integrated.scANVI", reduction.key = "scANVIlatent_", torch.intraop.threads = 4L, torch.interop.threads = NULL, model.save.dir = NULL, ndims.out = 10, n_hidden = 128L, n_layers = 1L, dropout_rate = 0.1, dispersion = c("gene", "gene-batch", "gene-label", "gene-cell"), gene_likelihood = c("zinb", "nb", "poisson"), linear_classifier = FALSE, max_epochs = NULL, train_size = 0.9, batch_size = 128L, seed.use = 42L, verbose = TRUE, verbose.scvi = c("INFO", "NOTSET", "DEBUG", "WARNING", "ERROR", "CRITICAL"), ... ) ``` -------------------------------- ### Basic Harmony Integration Source: https://cbib.github.io/Seurat-Integrate/reference/HarmonyIntegration.html Integrate layers of a Seurat object using the HarmonyIntegration method. Ensure necessary packages are loaded and the object is preprocessed. ```R obj <- UpdateSeuratObject(SeuratData::LoadData("pbmcsca")) obj[["RNA"]] <- split(obj[["RNA"]], f = obj$Method) obj <- NormalizeData(obj) obj <- FindVariableFeatures(obj) obj <- ScaleData(obj) obj <- RunPCA(obj) # After preprocessing, we integrate layers based on the "Method" variable: obj <- IntegrateLayers(object = obj, method = SeuratIntegrate::HarmonyIntegration, verbose = TRUE) ``` -------------------------------- ### Perform Cell Cycle Scoring per Batch Source: https://cbib.github.io/Seurat-Integrate/articles/introduction.html Run cell cycle scoring for each batch before applying other cell cycle-related scores. Ensure the kBET, lisi, and distances packages are installed for optimal performance. ```r seu <- CellCycleScoringPerBatch(seu, batch.var = batch.var, s.features = cc.genes$s.genes, g2m.features = cc.genes$g2m.genes) ``` -------------------------------- ### Integrate Layers with trVAE Source: https://cbib.github.io/Seurat-Integrate/reference/trVAEIntegration.html Use this function after preprocessing to integrate layers of a Seurat object using the trVAE method. Ensure the scArches package is installed. The `groups` argument should be a cell metadata column for batch correction. ```R if (FALSE) { # \dontrun! { # Preprocessing obj <- SeuratData::LoadData("pbmcsca") obj[["RNA"]] <- split(obj[["RNA"]], f = obj$Method) obj <- NormalizeData(obj) obj <- FindVariableFeatures(obj) obj <- ScaleData(obj) obj <- RunPCA(obj) # After preprocessing, we integrate layers: obj <- IntegrateLayers(object = obj, method = trVAEIntegration, features = Features(obj), scale.layer = NULL, layers = 'counts', groups = obj[[]], groups.name = 'Method') # To enable surgery and full reproducibility and change the recon loss method: obj <- IntegrateLayers(object = obj, method = trVAEIntegration, features = Features(obj), scale.layer = NULL, layers = 'data', groups = obj[[]], groups.name = 'Method', surgery.name = 'Experiment', mean_var = TRUE, recon.loss = 'mse') } # } ``` -------------------------------- ### Enable Multicore Futures (with caution) Source: https://cbib.github.io/Seurat-Integrate/articles/setup_and_tips.html Force DoIntegrate to use a multicore framework for parallel processing. Note that this is unstable on RStudio and unavailable on Windows. Use with caution. ```R options(parallelly.fork.enable = FALSE) ``` -------------------------------- ### Create New Conda Environments Source: https://cbib.github.io/Seurat-Integrate/articles/setup_and_tips.html Creates new conda environments for specified SeuratIntegrate methods. Note: Tested on Linux. May take time to execute. If conda is not in PATH, specify 'conda.bin'. ```r UpdateEnvCache('bbknn') UpdateEnvCache('scvi') UpdateEnvCache('scanorama') UpdateEnvCache('trvae') ``` -------------------------------- ### Get integration scores tibble from Seurat object Source: https://cbib.github.io/Seurat-Integrate/reference/get-score.html Retrieves the tibble containing integration scores from the 'si_scores' or 'si_scaled.scores' slot of a Seurat object's Misc. By default, it returns unscaled scores. Returns NULL if the requested object does not exist. ```R IntegrationScores(object, scaled = FALSE) ``` -------------------------------- ### Get score names from Seurat object Source: https://cbib.github.io/Seurat-Integrate/reference/get-score.html Retrieves a character vector of score names stored in the 'si_scores' slot of a Seurat object's Misc. If a search term is provided, it filters for exact, case-insensitive matches. Returns NULL if no scores are found or no matches are found. ```R GetMiscScores(object, search = NULL) ``` -------------------------------- ### Run scVI on Seurat's Assay5 object Source: https://cbib.github.io/Seurat-Integrate/reference/scVIIntegration.html Wrapper function to run scVI on multi-layered Seurat V5 objects. Requires a conda environment with scvi-tools. Recommended to use raw counts and all features. ```R scVIIntegration( object, groups = NULL, groups.name = NULL, labels.name = NULL, features = NULL, layers = "counts", scale.layer = "scale.data", conda_env = NULL, new.reduction = "integrated.scVI", reduction.key = "scVIlatent_", torch.intraop.threads = 4L, torch.interop.threads = NULL, model.save.dir = NULL, ndims.out = 10, n_hidden = 128L, n_layers = 1L, dropout_rate = 0.1, dispersion = c("gene", "gene-batch", "gene-label", "gene-cell"), gene_likelihood = c("zinb", "nb", "poisson"), latent_distribution = c("normal", "ln"), max_epochs = NULL, train_size = 0.9, batch_size = 128L, seed.use = 42L, verbose = TRUE, verbose.scvi = c("INFO", "NOTSET", "DEBUG", "WARNING", "ERROR", "CRITICAL"), ... ) scVIIntegration.fix(...) ``` -------------------------------- ### Get integration names from Seurat object Source: https://cbib.github.io/Seurat-Integrate/reference/get-score.html Retrieves a character vector of integration names stored in the 'si_scores' slot of a Seurat object's Misc. If a search term is provided, it filters for exact, case-insensitive matches. Returns NULL if no scores are found or no matches are found. ```R GetMiscIntegrations(object, search = NULL) ``` -------------------------------- ### Instantiate CondaManager Source: https://cbib.github.io/Seurat-Integrate/reference/CondaManager.html Use this constructor to create a CondaEnvManager object. It's recommended to use UpdateEnvCache() for creating or updating conda environments and the package's cache. ```R CondaManager(cache) ``` -------------------------------- ### Perform Multiple Data Integrations Source: https://cbib.github.io/Seurat-Integrate/articles/SeuratIntegrate.html Applies three different integration methods (Combat, BBKNN, Harmony) to the Seurat object. It allows specifying parameters for each integration and uses HVGs. 'use.future' controls parallelization. ```R liver_small <- DoIntegrate(object = liver_small, # integrations CombatIntegration(), bbknnIntegration(orig = "pca", ndims.use = 20), SeuratIntegrate::HarmonyIntegration(orig = "pca", dims = 1:20), # additional parameters use.hvg = TRUE, use.future = c(FALSE, TRUE, FALSE) ) ``` -------------------------------- ### Display Seurat object graph, neighbor, reduction, and assay information Source: https://cbib.github.io/Seurat-Integrate/articles/introduction.html Use cat() with Seurat functions Graphs(), Neighbors(), Reductions(), and Assays() to display detailed information about the object's structure and computed components. ```R cat("Graph objects:", paste(Graphs(seu), collapse = ", "), "\n") cat("Neighbor objects:", paste(Neighbors(seu), collapse = ", "), "\n") cat("Reduction dimensions:", paste(Reductions(seu), collapse = ", "), "\n") cat("Assays:", paste(Assays(seu), collapse = ", "), "\n") ``` -------------------------------- ### Data Integration - Compatible methods from other packages Source: https://cbib.github.io/Seurat-Integrate/reference/index.html Functions for integration using methods from other packages. ```APIDOC ## RPCAIntegration() ### Description Seurat-RPCA Integration (from Seurat). ### Method RPCAIntegration ### Endpoint N/A (SDK Function) ### Parameters None specified in source. ### Request Example ``` RPCAIntegration() ``` ### Response Returns the integrated Seurat object. ``` ```APIDOC ## CCAIntegration() ### Description Seurat-CCA Integration (from Seurat). ### Method CCAIntegration ### Endpoint N/A (SDK Function) ### Parameters None specified in source. ### Request Example ``` CCAIntegration() ``` ### Response Returns the integrated Seurat object. ``` ```APIDOC ## FastMNNIntegration() ### Description Run fastMNN in Seurat 5 (from SeuratWrappers). ### Method FastMNNIntegration ### Endpoint N/A (SDK Function) ### Parameters None specified in source. ### Request Example ``` FastMNNIntegration() ``` ### Response Returns the integrated Seurat object. ``` -------------------------------- ### Standard Seurat Workflow for PCA Source: https://cbib.github.io/Seurat-Integrate/articles/introduction.html Applies the standard Seurat workflow, including SCTransform for normalization and RunPCA for principal component analysis. The `k.param` for FindNeighbors is set to 20. ```r seu <- SCTransform(seu) seu <- RunPCA(seu, verbose = F) seu <- FindNeighbors(seu, reduction = "pca", dims = 1:30, k.param = 20L) ``` -------------------------------- ### Visualize Integration Results by Batch Source: https://cbib.github.io/Seurat-Integrate/articles/introduction.html Generates DimPlots for each integration, grouped by batch variable. Requires ggplot2 and SeuratIntegrate. Plots are collected using patchwork. ```r library(ggplot2) plot_list <- sapply(integrations, function(integ) { DimPlot(seu, reduction = paste0(integ, ".umap"), group.by = batch.var) + ggtitle(integ) + theme(axis.title = element_blank()) }, simplify = FALSE) patchwork::wrap_plots(plot_list, guides = "collect") ``` -------------------------------- ### Set parallel processing to sequential Source: https://cbib.github.io/Seurat-Integrate/articles/SeuratIntegrate.html Sets the future package to use sequential processing. This can be useful for debugging or when parallel processing is not desired. ```R plan(sequential) ``` -------------------------------- ### ScanoramaIntegration Function Source: https://cbib.github.io/Seurat-Integrate/reference/ScanoramaIntegration.html A wrapper to run Scanorama on multi-layered Seurat V5 object. Requires a conda environment with scanorama and necessary dependencies. ```APIDOC ## ScanoramaIntegration ### Description A wrapper to run `Scanorama` on multi-layered Seurat V5 object. Requires a conda environment with `scanorama` and necessary dependencies. ### Usage ```R ScanoramaIntegration( object, orig, layers = NULL, features = NULL, scale.layer = "scale.data", conda_env = NULL, new.reduction = "integrated.scanorama", reduction.key = "scanorama_", reconstructed.assay = "scanorama.reconstructed", ncores = 1L, ndims.out = 100L, return_dense = TRUE, batch_size = 5000, approx = TRUE, sigma = 15L, alpha = 0.1, knn = 20L, hvg.scanorama = NULL, union.features = FALSE, sketch = FALSE, sketch_method = c("geosketch", "uniform"), sketch_max = 10000, seed.use = 42L, verbose = TRUE, ... ) ``` ### Arguments * **object** (Seurat or Assay5) - A `Seurat` object (or an `Assay5` object if not called by `IntegrateLayers`). * **orig** (DimReduc) - `DimReduc` object. Not to be set directly when called with `IntegrateLayers`, use `orig.reduction` argument instead. * **layers** (character vector, optional) - Name of the layers to use in the integration. * **features** (character vector, optional) - Vector of feature names to input to the integration method. When `features = NULL` (default), the `VariableFeatures` are used. To pass all features, use the output of `Features()`. * **scale.layer** (character) - Name of the scaled layer in `Assay`. * **conda_env** (character, optional) - Path to conda environment to run scanorama (should also contain the scipy python module). By default, uses the conda environment registered for scanorama in the conda environment manager. * **new.reduction** (character or logical, optional) - Name to store resulting dimensional reduction object. `NULL` or `FALSE` disables the dimension reduction computation. * **reduction.key** (character, optional) - Key for resulting dimensional reduction object. Ignored if `reduction.key` is `NULL` or `FALSE`. * **reconstructed.assay** (character or logical, optional) - Name for the `assay` containing the corrected expression matrix of dimension `#features` x `#cells`. `NULL` or `FALSE` disables the corrected expression matrix computation. * **ncores** (integer) - Number of parallel threads to create through blas_set_num_threads. Pointless if BLAS is not supporting multithreaded. * **ndims.out** (integer) - Number of dimensions for `new.reduction` output. Scanorama specific argument. * **return_dense** (logical) - Whether scanorama returns `numpy.ndarray` matrices instead of `scipy.sparse.csr_matrix`. Scanorama specific argument. * **batch_size** (integer) - Used in the alignment vector computation. Higher values increase memory burden. Scanorama specific argument. * **approx** (logical) - Whether scanorama approximates nearest neighbors computation. Scanorama specific argument. * **sigma** (integer) - Correction smoothing parameter on gaussian kernel. Scanorama specific argument. * **alpha** (numeric) - Minimum alignment score. Scanorama specific argument. * **knn** (integer) - Number of nearest neighbours used for matching. Scanorama specific argument. * **hvg.scanorama** (integer, optional) - A positive integer to turn scanorama's internal HVG selection on. Disabled by default. Scanorama specific argument. * **union.features** (logical) - By default, scanorama uses the intersection of features to perform integration. Set this parameter to `TRUE` to use the union. Discouraged. Scanorama specific argument. * **sketch** (logical) - Turns on sketching-based acceleration by first downsampling the datasets. See Hie et al., Cell Systems (2019). Disabled by default. Ignored when `reconstructed.assay` is enabled. * **sketch_method** (character vector) - A sketching method to apply to the data. Either 'geosketch' (default) or 'uniform'. Ignored when `reconstructed.assay` is enabled or when `sketch` is FALSE. * **sketch_max** (integer) - Downsampling cutoff. Ignored when sketching disabled. * **seed.use** (integer or NULL) - An integer to generate reproducible outputs. Set `seed.use = NULL` to disable. * **verbose** (logical) - Print messages. Set to `FALSE` to disable. * **...** - Ignored. ### Value A list containing at least one of: * a new DimReduc of name `reduction.name` (key set to `reduction.key`) with corrected embeddings matrix of `ndims.out`. * a new Assay of name `reconstructed.assay` with corrected counts for each `features` (or less if `hvg` is set to a lower integer). When called via `IntegrateLayers`, a Seurat object with the new reduction and/or assay is returned. ### Note This function requires the Scanorama package to be installed (along with scipy). ### References Hie, B., Bryson, B. & Berger, B. Efficient integration of heterogeneous single-cell transcriptomes using Scanorama. Nat Biotechnol 37, 685–691 (2019). DOI ### See also `Tool` ### Examples ```R if (FALSE) { # \dontrun{ # Example usage would go here } ``` ``` -------------------------------- ### CombatIntegration Function Signature and Arguments Source: https://cbib.github.io/Seurat-Integrate/reference/CombatIntegration.html This snippet shows the usage of the CombatIntegration function, including its parameters for specifying the input object, grouping information, layers to use, and ComBat implementation details. ```APIDOC ## CombatIntegration ### Description A wrapper to run `ComBat` or `ComBat_seq` on multi-layered Seurat V5 object. ### Usage ```R CombatIntegration( object, orig = NULL, groups = NULL, groups.name = NULL, layers = "data", scale.layer = "scale.data", features = NULL, reconstructed.assay = "combat.reconstructed", key.assay = "combat_", combat.function = c("combat", "combat_seq"), use.scaled = FALSE, verbose = TRUE, ... ) ``` ### Arguments * **object** (Seurat or Assay5) - A `Seurat` object (or an `Assay5` object if not called by `IntegrateLayers`). * **orig** (DimReduc) - `DimReduc` object. Not to be set directly when called with `IntegrateLayers`, use `orig.reduction` argument instead. * **groups** (data.frame) - A **named** data frame with grouping information. Preferably one-column when `groups.name = NULL`. * **groups.name** (character) - Column name from `groups` data frame that stores grouping information. If `groups.name = NULL`, the first column is used. * **layers** (character) - Name of the layers to use in the integration. * **scale.layer** (character) - Name of the scaled layer in `Assay`. * **features** (character vector) - Vector of feature names to input to the integration method. When `features = NULL` (default), the `VariableFeatures` are used. To pass all features, use the output of `Features()`. * **reconstructed.assay** (character) - Name for the `assay` containing the corrected expression matrix. * **key.assay** (character) - Optional key for the new combat assay. Format: "[:alnum:]*_". * **combat.function** (character) - ComBat implementation to use. One of combat, combat_seq. Note that ComBat_seq is an improved model from ComBat but requires a dense matrix. Sparse to dense matrix conversion can be memory-intensive. * **use.scaled** (logical) - By default the layer passed to the `layer` argument is used. When `use.scaled = TRUE`, the `scale.layer` is input to ComBat. * **verbose** (logical) - Print messages. Set to `FALSE` to disable. * **...** - Additional arguments passed on to ComBat or ComBat_seq. ### Value The function itself returns a list containing: * a new Assay of name `reconstructed.assay` (key set to `assay.key`) with corrected cell counts. When called via `IntegrateLayers`, a Seurat object with the new assay is returned. ### Note This function requires the sva (Surrogate Variable Analysis) package to be installed. ### References Johnson, W. E., Li, C. & Rabinovic, A. Adjusting batch effects in microarray expression data using empirical Bayes methods. Biostatistics 8, 118–127 (2006). DOI Zhang, Y., Parmigiani, G. & Johnson, W. E. ComBat-seq: batch effect adjustment for RNA-seq count data. NAR Genomics and Bioinformatics 2 (2020). DOI ```