### Installing `BiocManager` R Package Source: https://github.com/corceslab/choir/blob/main/docs/index.html This R code checks if the `BiocManager` package is already installed. If not, it installs it from CRAN. `BiocManager` is required for managing and installing packages from the Bioconductor project, which CHOIR depends on. ```R if (!requireNamespace("BiocManager", quietly = TRUE)) install.packages("BiocManager") ``` -------------------------------- ### Installing R `BiocManager` Package Source: https://github.com/corceslab/choir/blob/main/README.md This R command verifies if the `BiocManager` package is installed. If absent, it installs it. `BiocManager` is crucial for managing and installing packages from Bioconductor, which provides several dependencies for the CHOIR algorithm. ```R if (!requireNamespace("BiocManager", quietly = TRUE)) install.packages("BiocManager") ``` -------------------------------- ### Installing CHOIR R Package (Development Branch) Source: https://github.com/corceslab/choir/blob/main/docs/index.html This R command installs the CHOIR package from the `dev` (development) branch of the `corceslab/CHOIR` GitHub repository. This branch contains the latest updates and features. Similar to the main branch installation, it uses `BiocManager::repositories()` for dependency resolution and `upgrade = "never"`. ```R remotes::install_github("corceslab/CHOIR", ref="dev", repos = BiocManager::repositories(), upgrade = "never") ``` -------------------------------- ### Installing CHOIR R Package from GitHub (Development Branch) Source: https://github.com/corceslab/choir/blob/main/docs/articles/CHOIR.html This R command installs the CHOIR package from the `dev` (development) branch of the `corceslab/CHOIR` GitHub repository. This branch contains the latest updates and features. Similar to the main branch installation, it uses `BiocManager::repositories()` for dependency management and avoids unnecessary package upgrades. ```R remotes::install_github("corceslab/CHOIR", ref="dev", repos = BiocManager::repositories(), upgrade = "never") ``` -------------------------------- ### Installing `remotes` Package in R Source: https://github.com/corceslab/choir/blob/main/docs/articles/CHOIR.html This R code checks if the `remotes` package is already installed. If not, it proceeds to install it from CRAN. The `remotes` package is essential for installing R packages directly from GitHub repositories. ```R if (!requireNamespace("remotes", quietly = TRUE)) install.packages("remotes") ``` -------------------------------- ### Installing CHOIR R Package from GitHub (Main Branch) Source: https://github.com/corceslab/choir/blob/main/docs/articles/CHOIR.html This R command installs the CHOIR package from the `main` branch of the `corceslab/CHOIR` GitHub repository. It uses `remotes::install_github` and specifies `BiocManager::repositories()` to ensure proper dependency resolution, preventing package upgrades during installation. ```R remotes::install_github("corceslab/CHOIR", ref="main", repos = BiocManager::repositories(), upgrade = "never") ``` -------------------------------- ### Installing `remotes` R Package Source: https://github.com/corceslab/choir/blob/main/docs/index.html This R code checks if the `remotes` package is already installed. If not, it proceeds to install it from CRAN. The `remotes` package is essential for installing R packages directly from GitHub repositories. ```R if (!requireNamespace("remotes", quietly = TRUE)) install.packages("remotes") ``` -------------------------------- ### Installing CHOIR R Package from Main Branch Source: https://github.com/corceslab/choir/blob/main/README.md This R command installs the CHOIR package directly from the `main` branch of the `corceslab/CHOIR` GitHub repository. It leverages `remotes` for GitHub installation and `BiocManager::repositories()` to resolve Bioconductor dependencies, with `upgrade = "never"` to prevent unintended package upgrades. ```R remotes::install_github("corceslab/CHOIR", ref="main", repos = BiocManager::repositories(), upgrade = "never") ``` -------------------------------- ### Installing CHOIR R Package (Main Branch) Source: https://github.com/corceslab/choir/blob/main/docs/index.html This R command installs the CHOIR package from the `main` branch of the `corceslab/CHOIR` GitHub repository. It uses `remotes::install_github` and specifies `BiocManager::repositories()` to ensure all Bioconductor dependencies are resolved, with `upgrade = "never"` to prevent unintended package upgrades. ```R remotes::install_github("corceslab/CHOIR", ref="main", repos = BiocManager::repositories(), upgrade = "never") ``` -------------------------------- ### Loading Essential R Packages for CHOIR Tutorial Source: https://github.com/corceslab/choir/blob/main/docs/articles/CHOIR.html This R code block ensures that the `scRNAseq` package is installed via BiocManager if not already present, then loads `scRNAseq`, `Seurat`, and `CHOIR` libraries. These packages are prerequisites for running the CHOIR tutorial and processing single-cell RNA-seq data. ```R if (!requireNamespace("scRNAseq", quietly = TRUE)) BiocManager::install("scRNAseq") library(scRNAseq) library(Seurat) library(CHOIR) ``` -------------------------------- ### Installing CHOIR R Package from Development Branch Source: https://github.com/corceslab/choir/blob/main/README.md This R command installs the CHOIR package from the `dev` branch of the `corceslab/CHOIR` GitHub repository. The `dev` branch typically contains the latest features and updates. Similar to the main branch installation, it uses `remotes` and `BiocManager::repositories()` for dependency management, ensuring no existing packages are upgraded. ```R remotes::install_github("corceslab/CHOIR", ref="dev", repos = BiocManager::repositories(), upgrade = "never") ``` -------------------------------- ### Installing R `remotes` Package Source: https://github.com/corceslab/choir/blob/main/README.md This R command checks if the `remotes` package is already installed. If it's not found, it proceeds to install it from CRAN. The `remotes` package is a prerequisite for installing R packages directly from GitHub repositories, which is necessary for CHOIR. ```R if (!requireNamespace("remotes", quietly = TRUE)) install.packages("remotes") ``` -------------------------------- ### Loading Example Single-Cell RNA-seq Data in R Source: https://github.com/corceslab/choir/blob/main/docs/articles/CHOIR.html This R code loads an example single-cell RNA-seq dataset, specifically mouse dopaminergic neurons from La Manno et al. (2016), using the `LaMannoBrainData` function from the `scRNAseq` package. It extracts the raw count matrix and assigns sequential column names for further processing. ```R data_matrix <- LaMannoBrainData('mouse-adult')@assays@data$counts colnames(data_matrix) <- seq(1:ncol(data_matrix)) ``` -------------------------------- ### Installing `BiocManager` Package in R Source: https://github.com/corceslab/choir/blob/main/docs/articles/CHOIR.html This R code checks for the presence of the `BiocManager` package, which is necessary for installing Bioconductor packages. If `BiocManager` is not found, it is installed from CRAN, enabling access to a wide range of bioinformatics tools. ```R if (!requireNamespace("BiocManager", quietly = TRUE)) install.packages("BiocManager") ``` -------------------------------- ### Visualizing Specific Subtree UMAP with CHOIR in R Source: https://github.com/corceslab/choir/blob/main/docs/articles/atlas_scale_data.html This example demonstrates visualizing a specific subset of clusters. It runs UMAP on the `object` using a different reduction key (`P24_reduction`) and then plots the results, specifying the UMAP reduction for more granular visualization of specific cell types. ```R # Run UMAP object <- runCHOIRumap(object, reduction = "P24_reduction") # Plot plotCHOIR(object, reduction = "P24_reduction_UMAP") ``` -------------------------------- ### Subsetting a Specific Parent Cluster in Seurat Source: https://github.com/corceslab/choir/blob/main/docs/articles/atlas_scale_data.html This example demonstrates how to subset a Seurat object to isolate cells belonging to a specific parent cluster, identified by 'CHOIR_parent_clusters == "P1"'. This prepares smaller, manageable chunks of data for parallel processing in the subsequent steps. ```R subtree_s <- subset(obj, subset = CHOIR_parent_clusters == "P1") ``` -------------------------------- ### Run CHOIR Clustering (R) Source: https://github.com/corceslab/choir/blob/main/docs/reference/index.html This function initiates and performs the CHOIR clustering algorithm on input data, serving as the primary entry point for the clustering process. ```R CHOIR() ``` -------------------------------- ### Creating Seurat Object with Initial Filtering (R) Source: https://github.com/corceslab/choir/blob/main/docs/articles/CHOIR.html This snippet demonstrates how to initialize a Seurat object from a data matrix. It applies basic quality control by filtering out cells with fewer than 100 features and genes present in less than 5 cells, which are common initial steps in single-cell RNA-seq analysis. The `data_matrix` is the required input. ```R object <- CreateSeuratObject(data_matrix, min.features = 100, min.cells = 5) ``` -------------------------------- ### Loading Required R Packages for CHOIR Source: https://github.com/corceslab/choir/blob/main/docs/articles/atlas_scale_data.html This snippet loads the necessary R packages, 'CHOIR' and 'Seurat', which are fundamental for single-cell data analysis and utilizing the CHOIR framework. These packages provide the core functionalities for data manipulation and clustering. ```R library(CHOIR) library(Seurat) ``` -------------------------------- ### Running Standard CHOIR Method in R Source: https://github.com/corceslab/choir/blob/main/docs/articles/atlas_scale_data.html This snippet runs the standard CHOIR method on a `subtree_s` object, retaining specific `downsampling_rate` parameters from the parent tree building process. It uses a `key` to identify the subtree, which is crucial for subsequent operations. ```R subtree_s <- CHOIR(subtree_s, key = "CHOIR_subtree", downsampling_rate = object@misc$CHOIR$parameters$buildParentTree_parameters$downsampling_rate) ``` -------------------------------- ### Running CHOIR with Count-Split Matrices in R Source: https://github.com/corceslab/choir/blob/main/docs/articles/CHOIR.html This snippet shows how to run the `CHOIR` function using the count-split matrices generated previously. It specifies `use_slot = "counts_log"` to utilize the normalized split matrices for analysis and sets `countsplit = TRUE` to inform CHOIR that count-split input is being used. The `n_cores` parameter allows for parallel processing to speed up computation. ```R object <- CHOIR(object, use_slot = "counts_log", countsplit = TRUE, n_cores = 2) ``` -------------------------------- ### Function Signature for runCHOIRumap in R Source: https://github.com/corceslab/choir/blob/main/docs/reference/runCHOIRumap.html This code snippet presents the function signature for `runCHOIRumap`, outlining the parameters required to invoke it. It takes an `object` (Seurat, SingleCellExperiment, or ArchRProject), an optional `key` for CHOIR data, an optional `reduction` to specify which dimensionality reduction to use, and a `verbose` flag for output control. ```R runCHOIRumap(object, key = "CHOIR", reduction = NULL, verbose = TRUE) ``` -------------------------------- ### Building Hierarchical Clustering Tree with CHOIR in R Source: https://github.com/corceslab/choir/blob/main/docs/reference/buildTree.html This R function, `buildTree`, initiates the hierarchical clustering process within the CHOIR algorithm. It takes an object (Seurat, SingleCellExperiment, or ArchRProject) and numerous parameters to control the clustering, statistical testing, feature selection, and computational aspects, ultimately generating a tree where branches are subdivided until all cells are overclustered. ```R buildTree( object, key = "CHOIR", alpha = 0.05, p_adjust = "bonferroni", feature_set = "var", exclude_features = NULL, n_iterations = 100, n_trees = 50, use_variance = TRUE, min_accuracy = 0.5, min_connections = 1, max_repeat_errors = 20, distance_approx = TRUE, sample_max = Inf, downsampling_rate = "auto", min_reads = NULL, max_clusters = "auto", min_cluster_depth = 2000, normalization_method = "none", subtree_reductions = TRUE, reduction_method = NULL, reduction_params = list(), n_var_features = NULL, batch_correction_method = "none", batch_correction_params = list(), batch_labels = NULL, neighbor_params = list(), cluster_params = list(algorithm = 1, group.singletons = TRUE), use_assay = NULL, use_slot = NULL, ArchR_matrix = NULL, ArchR_depthcol = NULL, countsplit = FALSE, countsplit_suffix = NULL, reduction = NULL, var_features = NULL, atac = FALSE, n_cores = NULL, random_seed = 1, verbose = TRUE ) ``` -------------------------------- ### Building Parent Clustering Tree with CHOIR in R Source: https://github.com/corceslab/choir/blob/main/docs/reference/buildParentTree.html This R code snippet illustrates the usage of the `buildParentTree` function, which is central to the CHOIR package for constructing a hierarchical clustering tree. It takes an `object` (Seurat, SingleCellExperiment, or ArchRProject) and numerous parameters to customize the clustering process, including distance approximation, downsampling, normalization, and dimensionality reduction methods. This function serves as the initial step for generating subtrees for further analysis. ```R buildParentTree( object, key = "CHOIR", distance_approx = TRUE, downsampling_rate = "auto", normalization_method = "none", reduction_method = NULL, reduction_params = list(), n_var_features = NULL, batch_correction_method = "none", batch_correction_params = list(), batch_labels = NULL, neighbor_params = list(), cluster_params = list(algorithm = 1, group.singletons = TRUE), use_assay = NULL, use_slot = NULL, ArchR_matrix = NULL, ArchR_depthcol = NULL, countsplit = FALSE, countsplit_suffix = NULL, reduction = NULL, var_features = NULL, atac = FALSE, n_cores = NULL, random_seed = 1, verbose = TRUE ) ``` -------------------------------- ### Running CHOIR Algorithm with Parallelization (R) Source: https://github.com/corceslab/choir/blob/main/docs/articles/CHOIR.html This snippet executes the main CHOIR algorithm, which performs hierarchical clustering and tree pruning. It utilizes parallel processing by setting `n_cores` to 2, which improves efficiency. The function takes a Seurat object as input and can be configured with parameters like `alpha` for significance level, `batch_correction_method`, and `countsplit` for advanced use cases. ```R object <- CHOIR(object, n_cores = 2) ``` -------------------------------- ### Run UMAP on CHOIR Reductions (R) Source: https://github.com/corceslab/choir/blob/main/docs/reference/index.html This function executes the UMAP (Uniform Manifold Approximation and Projection) algorithm on dimensionality reductions previously generated by CHOIR, for further visualization. ```R runCHOIRumap() ``` -------------------------------- ### Building Hierarchical Clustering Tree with CHOIR in R Source: https://github.com/corceslab/choir/blob/main/docs/articles/CHOIR.html This R code snippet demonstrates how to build a hierarchical clustering tree using the `buildTree` function from the CHOIR package. It takes an existing `object` (likely a Seurat object) and specifies `n_cores = 2` for parallel processing. The function performs dimensionality reduction, nearest neighbor graph generation, and multi-resolution clustering to construct the tree, with detailed progress output. ```R object <- buildTree(object, n_cores = 2) ``` -------------------------------- ### Inspecting CHOIR Cluster Labels in Seurat (R) Source: https://github.com/corceslab/choir/blob/main/docs/articles/CHOIR.html This snippet demonstrates how to view the first few rows of the `meta.data` slot of a Seurat object, where CHOIR stores the final cluster labels. It helps in verifying the integration of CHOIR's output into the Seurat object. ```R head(object@meta.data) ``` -------------------------------- ### Generating Parent Clustering Tree with CHOIR Source: https://github.com/corceslab/choir/blob/main/docs/articles/atlas_scale_data.html This code runs the 'buildParentTree' function from the CHOIR package on the full dataset. This initial step performs dimensionality reduction, optional batch correction, and constructs a hierarchical clustering tree to define the 'parent' clusters, which serve as the basis for subsequent parallel processing. ```R object <- buildParentTree(object) ``` -------------------------------- ### Citing the CHOIR R Package (BibTeX) Source: https://github.com/corceslab/choir/blob/main/docs/authors.html This BibTeX entry provides the standard citation format for the CHOIR R package, version 0.3.0. It includes details such as the title, author, and year, suitable for inclusion in academic papers and reference managers. ```BibTeX @Manual{, title = {CHOIR: CHOIR - Cluster Hierachy Optimization by Iterative Random forests}, author = {Cathrine Sant}, year = {2025}, note = {R package version 0.3.0}, } ``` -------------------------------- ### Generating and Plotting UMAP for CHOIR Clusters in R Source: https://github.com/corceslab/choir/blob/main/docs/articles/atlas_scale_data.html This code first generates a UMAP dimensionality reduction for the `object` using `runCHOIRumap`, specifying a reduction key. Then, it visualizes the resulting clusters using the `plotCHOIR` function, providing a global overview of the clustering. ```R # Run UMAP object <- runCHOIRumap(object, reduction = "P0_reduction") # Plot plotCHOIR(object) ``` -------------------------------- ### Combine Pruned Clustering Trees (R) Source: https://github.com/corceslab/choir/blob/main/docs/reference/index.html This function compiles multiple separately pruned clustering trees and standardizes their thresholds, enabling consistent analysis across different tree subsets. ```R combineTrees() ``` -------------------------------- ### Build Full Hierarchical Clustering Tree (R) Source: https://github.com/corceslab/choir/blob/main/docs/reference/index.html This function generates the complete hierarchical clustering tree from the input data, providing the full structure of the clusters. ```R buildTree() ``` -------------------------------- ### Retrieve CHOIR Metadata (R) Source: https://github.com/corceslab/choir/blob/main/docs/reference/index.html This function fetches and returns all associated metadata records from the CHOIR package, providing contextual information about the data or analysis. ```R getRecords() ``` -------------------------------- ### Defining Cluster Comparison Parameters in CHOIR R Source: https://github.com/corceslab/choir/blob/main/docs/reference/compareClusters.html This snippet defines the `compareClusters` function signature, outlining all available parameters for comparing two cell clusters using CHOIR's random forest permutation testing. It allows specifying input objects, cluster identifiers, statistical thresholds, feature sets, and computational parameters to assess distinguishability. ```R compareClusters( object = NULL, key = "CHOIR", cluster1_cells = NULL, cluster2_cells = NULL, ident1 = NULL, ident2 = NULL, group_by = NULL, alpha = 0.05, feature_set = "var", exclude_features = NULL, n_iterations = 100, n_trees = 50, use_variance = TRUE, min_accuracy = 0.5, min_connections = 1, max_repeat_errors = 20, collect_all_metrics = FALSE, sample_max = Inf, downsampling_rate = "auto", min_reads = NULL, normalization_method = "none", batch_labels = NULL, use_assay = NULL, use_slot = NULL, ArchR_matrix = NULL, atac = FALSE, input_matrix = NULL, nn_matrix = NULL, var_features = NULL, n_cores = NULL, random_seed = 1, verbose = TRUE ) ``` -------------------------------- ### Generating Color Palette with CHOIRpalette (R) Source: https://github.com/corceslab/choir/blob/main/docs/reference/CHOIRpalette.html This R function, `CHOIRpalette`, generates a vector of hex color values. For up to 100 colors, standard hex values are used; for larger numbers, `Polychrome::createPalette()` is utilized. The function takes a single argument, `n`, which specifies the desired number of colors. It returns a vector of `n` hex color strings. ```R CHOIRpalette(n) ``` -------------------------------- ### Generating UMAP and Plotting CHOIR Clusters (R) Source: https://github.com/corceslab/choir/blob/main/docs/articles/CHOIR.html This code block first runs UMAP dimensionality reduction on the Seurat object using `runCHOIRumap`, specifying a reduction to use. Subsequently, `plotCHOIR` is called to visualize the identified clusters on the generated UMAP embedding. This provides a visual representation of the clustering results. ```R object <- runCHOIRumap(object, reduction = "P0_reduction") ``` ```R plotCHOIR(object) ``` -------------------------------- ### Combining Pruned Clustering Trees with combineTrees in R Source: https://github.com/corceslab/choir/blob/main/docs/reference/combineTrees.html This R function, `combineTrees`, is central to CHOIR's atlas-scale data processing. It integrates clustering results from `buildParentTree` and individual subtree analyses, then standardizes thresholds across the combined tree. Key parameters include `object` for input data, `subtree_list` for subtree records, `alpha` for significance level, and `p_adjust` for multiple comparison correction, among many others for fine-tuning the clustering process. ```R combineTrees( object, subtree_list, key = "CHOIR", alpha = NULL, p_adjust = NULL, feature_set = NULL, exclude_features = NULL, n_iterations = NULL, n_trees = NULL, use_variance = NULL, min_accuracy = NULL, min_connections = NULL, max_repeat_errors = NULL, distance_approx = NULL, distance_awareness = NULL, collect_all_metrics = NULL, sample_max = NULL, downsampling_rate = NULL, min_reads = NULL, normalization_method = NULL, batch_correction_method = NULL, batch_labels = NULL, use_assay = NULL, use_slot = NULL, ArchR_matrix = NULL, countsplit = NULL, countsplit_suffix = NULL, input_matrix = NULL, nn_matrix = NULL, dist_matrix = NULL, reduction = NULL, n_cores = NULL, random_seed = NULL, verbose = TRUE ) ``` -------------------------------- ### Inferring Clustering Tree with CHOIR in R Source: https://github.com/corceslab/choir/blob/main/docs/reference/inferTree.html This R function, `inferTree`, generates a clustering tree from pre-generated cluster labels. It requires a named vector of `cluster_labels` and can optionally take a `dist_matrix` or `reduction` matrix for distance calculations. The `verbose` parameter controls output verbosity. ```R inferTree(cluster_labels, dist_matrix = NULL, reduction = NULL, verbose = TRUE) ``` -------------------------------- ### Applying Harmony Batch Correction with CHOIR (R) Source: https://github.com/corceslab/choir/blob/main/docs/articles/CHOIR.html This R code demonstrates how to apply Harmony batch correction using the CHOIR function. It sets the batch_correction_method to "Harmony" and specifies the batch_labels parameter with the name of the cell metadata column containing batch information. This ensures batch-aware random forest classifier comparisons and generates corrected dimensionality reductions. ```R object <- CHOIR(object, batch_correction_method = "Harmony", batch_labels = "Batch") # Change 'Batch' to corresponding cell metadata column for your data ``` -------------------------------- ### Retrieving CHOIR Metadata with getRecords (R) Source: https://github.com/corceslab/choir/blob/main/docs/reference/getRecords.html This R function `getRecords` is used to retrieve all CHOIR-related data from an object. It accepts an `object` of class `Seurat`, `SingleCellExperiment`, or `ArchRProject` that has undergone CHOIR clustering, and an optional `key` (defaulting to 'CHOIR') specifying where the data is stored. The function returns the data associated with the provided key. ```R getRecords(object, key = "CHOIR") ``` -------------------------------- ### Build Parent Clustering Tree (R) Source: https://github.com/corceslab/choir/blob/main/docs/reference/index.html This function constructs the parent clustering tree, which likely represents a higher level of hierarchical organization or a summary of the full tree. ```R buildParentTree() ``` -------------------------------- ### Running CHOIR with ATAC-seq Data (R) Source: https://github.com/corceslab/choir/blob/main/docs/articles/CHOIR.html This R code snippet demonstrates how to run the CHOIR function with ATAC-seq data. It passes an ArchR_object to the CHOIR function and sets the 'atac' parameter to TRUE to ensure CHOIR uses appropriate defaults for ATAC-seq analysis, such as 25000 variable features. ```R ArchR_object <- CHOIR(ArchR_object, atac = TRUE) ``` -------------------------------- ### Running CHOIR with Multi-modal RNA-seq and ATAC-seq Data (R) Source: https://github.com/corceslab/choir/blob/main/docs/articles/CHOIR.html This R code snippet illustrates how to execute the CHOIR function for multi-modal data, specifically joint RNA-seq and ATAC-seq. It provides vectors for 'ArchR_matrix' and 'ArchR_depthcol' to specify matrices and depth columns for each modality, and a vector for 'atac' to indicate the data type for each. This configuration enables CHOIR to process and integrate multiple data types from the same cells. ```R ArchR_object <- CHOIR(ArchR_object, ArchR_matrix = c("GeneScoreMatrix", "GeneExpressionMatrix"), ArchR_depthcol = c("nFrags", "Gex_nUMI"), atac = c(TRUE, FALSE)) ``` -------------------------------- ### Running CHOIR Clustering Function in R Source: https://github.com/corceslab/choir/blob/main/docs/reference/CHOIR.html This R function, `CHOIR`, performs clustering to identify statistically distinct cell populations. It takes an object (Seurat, SingleCellExperiment, or ArchRProject) and numerous parameters to control the clustering process, including significance levels, feature selection, iteration counts, and batch correction methods. The function aims to distinguish clusters based on feature-based classification accuracy. ```R CHOIR( object, key = "CHOIR", alpha = 0.05, p_adjust = "bonferroni", feature_set = "var", exclude_features = NULL, n_iterations = 100, n_trees = 50, use_variance = TRUE, min_accuracy = 0.5, min_connections = 1, max_repeat_errors = 20, distance_approx = TRUE, distance_awareness = 2, collect_all_metrics = FALSE, sample_max = Inf, downsampling_rate = "auto", min_reads = NULL, max_clusters = "auto", min_cluster_depth = 2000, normalization_method = "none", subtree_reductions = TRUE, reduction_method = NULL, reduction_params = list(), n_var_features = NULL, batch_correction_method = "none", batch_correction_params = list(), batch_labels = NULL, neighbor_params = list(), cluster_params = list(algorithm = 1, group.singletons = TRUE), use_assay = NULL, use_slot = NULL, ArchR_matrix = NULL, ArchR_depthcol = NULL, countsplit = FALSE, countsplit_suffix = NULL, reduction = NULL, var_features = NULL, atac = FALSE, n_cores = NULL, random_seed = 1, verbose = TRUE ) ``` -------------------------------- ### Combining Subtrees and Standardizing Thresholds in R Source: https://github.com/corceslab/choir/blob/main/docs/articles/atlas_scale_data.html This snippet uses the `combineTrees` CHOIR function to merge the records from all subtrees. It standardizes the significance threshold across all clustering trees, yielding a final, unified set of clusters for downstream analysis. ```R object <- combineTrees(object, subtree_list = subtree_records_list) ``` -------------------------------- ### Compare Clusters with Random Forest (R) Source: https://github.com/corceslab/choir/blob/main/docs/reference/index.html This function compares any two given clusters utilizing CHOIR's random forest classifier and permutation testing methodology to assess their similarity or differences. ```R compareClusters() ``` -------------------------------- ### Performing Log Normalization on Seurat Object (R) Source: https://github.com/corceslab/choir/blob/main/docs/articles/CHOIR.html This code performs log normalization on the Seurat object. Normalization is a crucial step in single-cell data analysis to account for differences in sequencing depth between cells, making gene expression comparable across the dataset. The `object` is the required input, which is a Seurat object. ```R object <- NormalizeData(object) ``` -------------------------------- ### Using the Pipe Operator in R Source: https://github.com/corceslab/choir/blob/main/docs/reference/pipe.html This snippet illustrates the basic syntax of the pipe operator (`%>%`) in R. It takes a left-hand side (LHS) value and pipes it as the first argument to a right-hand side (RHS) function call, simplifying chained operations. It is a re-export or documentation of `magrittr::%>%`. ```R lhs %>% rhs ``` -------------------------------- ### Generate CHOIR Color Palette (R) Source: https://github.com/corceslab/choir/blob/main/docs/reference/index.html This function creates a specific color palette designed for consistent and visually appealing use with CHOIR visualizations and plots. ```R CHOIRpalette() ``` -------------------------------- ### Handling Unsubclusterable Parent Clusters in R Source: https://github.com/corceslab/choir/blob/main/docs/articles/atlas_scale_data.html This code is executed when a parent cluster cannot be subclustered further. It manually adds cluster labels for a single cluster and copies parameter records from the original `subtree_s` object to `subtree_x` to ensure consistency and proper integration into the overall CHOIR structure. ```R # Add cluster labels for a single cluster subtree_x@misc$CHOIR_subtree$clusters$CHOIR_clusters_0.05 <- data.frame(CellID = colnames(subtree_x), CHOIR_clusters_0.05 = 1, Record_cluster_label = "P0_L0_1") # Add parameter records matching remaining subtrees subtree_x@misc$CHOIR_subtree$parameters <- subtree_s@misc$CHOIR$parameters ``` -------------------------------- ### Extracting CHOIR Records from Subtrees in R Source: https://github.com/corceslab/choir/blob/main/docs/articles/atlas_scale_data.html This loop iterates through a list of subtree objects, extracting the resulting clusters, clustering trees, and comparison records using the `getRecords` CHOIR function. The extracted records are stored in `subtree_records_list`, preparing them for combination. ```R subtree_records_list <- vector(mode = "list", length = n_subtrees) for (s in 1:n_subtrees) { subtree_records_list[[s]] <- getRecords(subtree_objects_list[[s]], key = "CHOIR_subtree") } ``` -------------------------------- ### Using runCountSplit Function in R Source: https://github.com/corceslab/choir/blob/main/docs/reference/runCountSplit.html This snippet illustrates the basic usage and parameters of the `runCountSplit` function. It takes an object (Seurat, SingleCellExperiment, or ArchRProject) and various optional parameters to control count matrix selection, count splitting, and post-splitting normalization. ```R runCountSplit( object, key = "CHOIR", use_assay = NULL, use_slot = NULL, ArchR_matrix = NULL, countsplit_suffix = c("_1", "_2"), countsplit_params = list(), normalization_method = "log", verbose = TRUE ) ``` -------------------------------- ### Infer Clustering Tree from Clusters (R) Source: https://github.com/corceslab/choir/blob/main/docs/reference/index.html This function infers a clustering tree structure based on a set of pre-generated clusters, useful for reconstructing hierarchies from existing cluster assignments. ```R inferTree() ``` -------------------------------- ### Pruning Hierarchical Clustering Tree in CHOIR (R) Source: https://github.com/corceslab/choir/blob/main/docs/articles/CHOIR.html This R code snippet demonstrates how to prune a hierarchical clustering tree using the `pruneTree` function from the CHOIR package. The function iteratively evaluates child clusters using a permutation test and a random forest classifier to determine if they should merge or remain separate, based on a p-value and the `alpha` significance threshold. The `n_cores` parameter allows specifying the number of CPU cores for parallel execution, accelerating the pruning process. ```R object <- pruneTree(object, n_cores = 2) ``` -------------------------------- ### Run Count Splitting (R) Source: https://github.com/corceslab/choir/blob/main/docs/reference/index.html This function performs the countsplitting operation, likely for data processing or normalization, to adjust or distribute count data. ```R runCountSplit() ``` -------------------------------- ### Performing Count Splitting on Seurat Object in R Source: https://github.com/corceslab/choir/blob/main/docs/articles/CHOIR.html This snippet demonstrates how to apply the `runCountSplit` function to a Seurat object. It extracts the existing count matrix, performs count splitting, and stores the two resulting matrices (e.g., 'counts_1', 'counts_2') back into the object. The `normalization_method` parameter can be used to apply normalization and store normalized count split matrices (e.g., 'counts_log_1', 'counts_log_2'). ```R object <- runCountSplit(object) ``` -------------------------------- ### Prune Clustering Tree with Random Forest (R) Source: https://github.com/corceslab/choir/blob/main/docs/reference/index.html This function prunes the hierarchical clustering tree by applying random forest classifiers, optimizing its structure and removing less significant branches. ```R pruneTree() ``` -------------------------------- ### Pruning Clustering Tree with Random Forest Classifiers in R Source: https://github.com/corceslab/choir/blob/main/docs/reference/pruneTree.html This R function, `pruneTree`, is used to refine hierarchical clustering by iteratively pruning a tree. It employs random forest classifiers and permutation tests to identify a final set of clusters. The function accepts numerous parameters to control statistical significance, feature selection, computational intensity, and input data types, allowing for highly customizable cluster refinement. ```R pruneTree( object, key = "CHOIR", alpha = NULL, p_adjust = NULL, feature_set = NULL, exclude_features = NULL, n_iterations = NULL, n_trees = NULL, use_variance = NULL, min_accuracy = NULL, min_connections = NULL, max_repeat_errors = NULL, distance_approx = NULL, distance_awareness = 2, collect_all_metrics = FALSE, sample_max = NULL, downsampling_rate = NULL, min_reads = NULL, normalization_method = NULL, batch_correction_method = NULL, batch_labels = NULL, cluster_params = NULL, use_assay = NULL, countsplit = NULL, countsplit_suffix = NULL, cluster_tree = NULL, input_matrix = NULL, nn_matrix = NULL, snn_matrix = NULL, dist_matrix = NULL, reduction = NULL, n_cores = NULL, random_seed = NULL, verbose = TRUE ) ``` -------------------------------- ### Subdividing Large Parent Clusters for Parallel Processing Source: https://github.com/corceslab/choir/blob/main/docs/articles/atlas_scale_data.html This conditional block handles parent clusters exceeding 450,000 cells. It performs additional dimensionality reduction and clustering to further subdivide these large clusters into manageable sizes, ensuring all resulting subclusters are under the specified cell limit before running CHOIR in parallel. ```R if (ncol(subtree_s) > 450000) { # Get nearest neighbors subtree_s <- subtree_s %>% FindVariableFeatures() %>% ScaleData() %>% RunPCA() %>% FindNeighbors() # Find starting resolution starting_resolution <- CHOIR:::.getStartingResolution(subtree_s@graphs$RNA_snn, cluster_params = list(algorithm = 1, group.singletons = TRUE), random_seed = 1, verbose = TRUE) # Get clusters at starting resolution subtree_s <- FindClusters(subtree_s, resolution = starting_resolution[["starting_resolution"]]) # Further subset each resulting cluster subtree_s_0 <- subset(subtree_s, subset = seurat_clusters == 0) subtree_s_1 <- subset(subtree_s, subset = seurat_clusters == 1) # Etc.. } ``` -------------------------------- ### Usage of plotCHOIR for Dimensionality Reduction Plots in R Source: https://github.com/corceslab/choir/blob/main/docs/reference/plotCHOIR.html This R function signature demonstrates how to call `plotCHOIR` to visualize CHOIR clusters on a dimensionality reduction embedding. It takes a `Seurat`, `SingleCellExperiment`, or `ArchRProject` object and allows customization of the reduction, grouping, cell selection, labeling, legend, and the optional overlay of cluster accuracy scores. ```R plotCHOIR( object, key = "CHOIR", reduction = NULL, group_by = NULL, cells = NULL, highlight_cells = NULL, label = TRUE, legend = TRUE, accuracy_scores = FALSE, plot_nearest = TRUE, ... ) ``` -------------------------------- ### Plot CHOIR Dimensional Reduction (R) Source: https://github.com/corceslab/choir/blob/main/docs/reference/index.html This function generates a dimensional reduction plot, with the clusters identified by CHOIR clearly labeled for visual interpretation of the clustering results. ```R plotCHOIR() ``` -------------------------------- ### Plotting CHOIR Clusters with Accuracy Scores (R) Source: https://github.com/corceslab/choir/blob/main/docs/articles/CHOIR.html This snippet extends the basic `plotCHOIR` functionality by setting `accuracy_scores = TRUE` to overlay prediction accuracy scores between neighboring clusters on the UMAP plot. `plot_nearest` is set to `FALSE` to prevent plotting nearest neighbors, focusing solely on cluster accuracy. ```R plotCHOIR(object, accuracy_scores = TRUE, plot_nearest = FALSE) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.