### Install scMetabolism Package Source: https://github.com/wu-yc/scmetabolism/blob/main/README.md Installs the scMetabolism package from GitHub. Ensure you have devtools and other dependencies installed first. ```r devtools::install_github("wu-yc/scMetabolism") ``` -------------------------------- ### Install scMetabolism and Dependencies from GitHub Source: https://context7.com/wu-yc/scmetabolism/llms.txt Installs the scMetabolism package and its required dependencies, including VISION, from GitHub using the devtools package. Ensure R and devtools are installed first. ```r install.packages(c("devtools", "data.table", "wesanderson", "Seurat", "AUCell", "GSEABase", "GSVA", "ggplot2", "rsvd")) ``` ```r devtools::install_github("YosefLab/VISION@v2.1.0") ``` ```r devtools::install_github("wu-yc/scMetabolism") ``` -------------------------------- ### Full scMetabolism Analysis Pipeline in R Source: https://context7.com/wu-yc/scmetabolism/llms.txt This script demonstrates a complete workflow for analyzing single-cell RNA sequencing data with scMetabolism. It covers loading a Seurat object, quantifying metabolic pathways using the AUCell method, extracting and exploring metabolism scores, identifying highly variable pathways, visualizing results with UMAP, dot plots, and box plots, and finally saving the processed object and generated plots. Ensure Seurat, ggplot2, and rsvd libraries are installed. ```r library(scMetabolism) library(Seurat) library(ggplot2) library(rsvd) # 1. Load your Seurat object (or use demo data) load(file = "pbmc_demo.rda") # 2. Quantify metabolism (with optional imputation) countexp.Seurat <- sc.metabolism.Seurat( obj = countexp.Seurat, method = "AUCell", # Fast and accurate method imputation = FALSE, # Set TRUE if data has high dropout ncores = 4, metabolism.type = "KEGG" ) # 3. Extract and explore metabolism scores metabolism.matrix <- countexp.Seurat@assays$METABOLISM$score cat(sprintf("Scored %d pathways across %d cells\n", nrow(metabolism.matrix), ncol(metabolism.matrix))) # 4. Identify highly variable metabolic pathways pathway_variance <- apply(metabolism.matrix, 1, var) top_pathways <- names(sort(pathway_variance, decreasing = TRUE))[1:10] print(top_pathways) # 5. Visualize top pathways # UMAP for single pathway p1 <- DimPlot.metabolism( obj = countexp.Seurat, pathway = top_pathways[1], dimention.reduction.type = "umap", dimention.reduction.run = FALSE, size = 1 ) # Dot plot for multiple pathways p2 <- DotPlot.metabolism( obj = countexp.Seurat, pathway = top_pathways[1:5], phenotype = "ident", norm = "y" ) # Box plot for statistical comparison p3 <- BoxPlot.metabolism( obj = countexp.Seurat, pathway = top_pathways[1:3], phenotype = "ident", ncol = 3 ) # 6. Save results saveRDS(countexp.Seurat, "pbmc_with_metabolism.rds") ggsave("metabolism_umap.png", p1, width = 8, height = 6) ggsave("metabolism_dotplot.png", p2, width = 10, height = 6) ggsave("metabolism_boxplot.png", p3, width = 12, height = 4) ``` -------------------------------- ### Load Packages and Demo Data Source: https://github.com/wu-yc/scmetabolism/blob/main/README.md Loads necessary R packages and a demo Seurat object for testing scMetabolism functions. Ensure the demo data file is available. ```r load(file = "pbmc_demo.rda") library(scMetabolism) library(ggplot2) library(rsvd) ``` -------------------------------- ### Automatically Choose Rank k for Low Rank Approximation Source: https://context7.com/wu-yc/scmetabolism/llms.txt Determines the optimal rank 'k' for low rank approximation using singular value statistics. Requires a normalized expression matrix as input. ```R library(scMetabolism) library(rsvd) A_norm <- normalize_data(as.matrix(countexp)) k_result <- choose_k( A_norm = A_norm, K = 100, thresh = 6, noise_start = 80, q = 2, use.mkl = FALSE ) optimal_k <- k_result$k num_sds <- k_result$num_of_sds singular_values <- k_result$d catsprintf("Optimal k: %d\n", optimal_k) ``` -------------------------------- ### Visualize Metabolism with DotPlot Source: https://github.com/wu-yc/scmetabolism/blob/main/README.md Creates a dot plot to visualize metabolism scores for specified pathways across different cell phenotypes. Supports normalization options. ```r input.pathway<-c("Glycolysis / Gluconeogenesis", "Oxidative phosphorylation", "Citrate cycle (TCA cycle)") DotPlot.metabolism(obj = countexp.Seurat, pathway = input.pathway, phenotype = "ident", norm = "y") ``` -------------------------------- ### Quantify Metabolism with sc.metabolism (VISION/KEGG) Source: https://context7.com/wu-yc/scmetabolism/llms.txt Quantifies single-cell metabolism using the VISION method with KEGG pathways on a raw count matrix. Use this when not working with Seurat objects. Requires the scMetabolism library. ```r library(scMetabolism) # Prepare count expression matrix (genes as rows, cells as columns) # countexp should be a data frame with gene names as row names and cell IDs as column names # Quantify metabolism activity metabolism.matrix <- sc.metabolism( countexp = countexp, # Data frame of UMI count matrix method = "VISION", # Options: "VISION" (default), "AUCell", "ssGSEA", "GSVA" imputation = FALSE, # Whether to impute before scoring ncores = 4, # Number of parallel threads metabolism.type = "KEGG" # Options: "KEGG", "REACTOME" ) # Output: Your choice is: KEGG # Output: Start quantify the metabolism activity... # Result is a data frame with pathways as rows, cells as columns dim(metabolism.matrix) # 85 pathways x number of cells (for KEGG) ``` -------------------------------- ### Normalize and Log Transform Expression Matrix Source: https://context7.com/wu-yc/scmetabolism/llms.txt Prepares a raw count matrix for ALRA imputation by performing library size normalization, scaling to 10,000, and log transformation. ```R library(scMetabolism) A_norm <- normalize_data(as.matrix(countexp)) dim(A_norm) ``` -------------------------------- ### Create Dot Plot for Metabolic Pathways Source: https://context7.com/wu-yc/scmetabolism/llms.txt Generates a dot plot to visualize metabolic pathway activity across cell populations. Specify pathways, the grouping phenotype, and normalization method. ```R input.pathway <- c( "Glycolysis / Gluconeogenesis", "Oxidative phosphorylation", "Citrate cycle (TCA cycle)", "Fatty acid degradation", "Glutathione metabolism" ) plot_dot <- DotPlot.metabolism( obj = countexp.Seurat, pathway = input.pathway, phenotype = "ident", norm = "y" ) print(plot_dot) plot_dot + theme(axis.text.x = element_text(size = 10)) + ggtitle("Metabolic Pathway Activity by Cell Type") ``` ```R plot_dot_celltype <- DotPlot.metabolism( obj = countexp.Seurat, pathway = input.pathway, phenotype = "cell_type", norm = "x" ) ``` -------------------------------- ### Generate Box Plot for Metabolic Pathways Source: https://context7.com/wu-yc/scmetabolism/llms.txt Creates box plots to compare metabolic pathway activity distributions between cell groups. Useful for statistical comparisons. Customize layout and add annotations. ```R library(scMetabolism) library(ggplot2) input.pathway <- c( "Glycolysis / Gluconeogenesis", "Oxidative phosphorylation", "Citrate cycle (TCA cycle)" ) plot_box <- BoxPlot.metabolism( obj = countexp.Seurat, pathway = input.pathway, phenotype = "ident", ncol = 1 ) print(plot_box) plot_box_2col <- BoxPlot.metabolism( obj = countexp.Seurat, pathway = input.pathway, phenotype = "ident", ncol = 3 ) plot_box + theme(legend.position = "none") + ggtitle("Metabolic Activity Distribution") ``` -------------------------------- ### Visualize Metabolism with BoxPlot Source: https://github.com/wu-yc/scmetabolism/blob/main/README.md Generates box plots to compare metabolism scores for specified pathways across different cell phenotypes. Allows control over the number of columns per row. ```r BoxPlot.metabolism(obj = countexp.Seurat, pathway = input.pathway, phenotype = "ident", ncol = 1) ``` -------------------------------- ### Quantify Metabolism with sc.metabolism.Seurat (AUCell/KEGG) Source: https://context7.com/wu-yc/scmetabolism/llms.txt Quantifies single-cell metabolism using the AUCell method with KEGG pathways directly on a Seurat object. Results are stored in the Seurat object's METABOLISM assay. Requires Seurat, ggplot2, and rsvd libraries. ```r library(scMetabolism) library(ggplot2) library(rsvd) # Load demo PBMC data (Seurat object) load(file = "pbmc_demo.rda") # Quantify metabolism using AUCell method with KEGG pathways countexp.Seurat <- sc.metabolism.Seurat( obj = countexp.Seurat, # Seurat object with UMI count matrix method = "AUCell", # Options: "VISION" (default), "AUCell", "ssGSEA", "GSVA" imputation = FALSE, # Whether to impute data before scoring ncores = 2, # Number of parallel threads metabolism.type = "KEGG" # Options: "KEGG" (85 pathways), "REACTOME" (82 pathways) ) # Output: Your choice is: KEGG # Output: Start quantify the metabolism activity... # Extract the metabolism score matrix metabolism.matrix <- countexp.Seurat@assays$METABOLISM$score # View available pathways rownames(metabolism.matrix) # Check scores for specific cells head(metabolism.matrix[1:5, 1:5]) ``` -------------------------------- ### Quantify Single-Cell Metabolism with Seurat Source: https://github.com/wu-yc/scmetabolism/blob/main/README.md Quantifies single-cell metabolism using a Seurat object. Supports different methods (AUCell, VISION, ssgsea, gsva), imputation, and metabolism pathway databases (KEGG, REACTOME). ```r countexp.Seurat<-sc.metabolism.Seurat(obj = countexp.Seurat, method = "AUCell", imputation = F, ncores = 2, metabolism.type = "KEGG") ``` -------------------------------- ### Visualize Metabolism with DimPlot Source: https://github.com/wu-yc/scmetabolism/blob/main/README.md Generates a dimension plot (UMAP or t-SNE) colored by a specific metabolism pathway score. Allows re-running dimension reduction if needed. ```r DimPlot.metabolism(obj = countexp.Seurat, pathway = "Glycolysis / Gluconeogenesis", dimention.reduction.type = "umap", dimention.reduction.run = F, size = 1) ``` -------------------------------- ### Visualize Metabolism on UMAP Plot (Glycolysis) Source: https://context7.com/wu-yc/scmetabolism/llms.txt Generates a UMAP dimension reduction plot colored by the metabolic activity score for a specified pathway, such as 'Glycolysis / Gluconeogenesis'. Requires a Seurat object with the METABOLISM assay and ggplot2. Dimension reduction can be run or skipped. ```r library(scMetabolism) library(ggplot2) # Create UMAP plot for Glycolysis pathway plot_umap <- DimPlot.metabolism( obj = countexp.Seurat, pathway = "Glycolysis / Gluconeogenesis", # Pathway name from KEGG/REACTOME dimention.reduction.type = "umap", # Options: "umap", "tsne" dimention.reduction.run = FALSE, # Whether to re-run dimension reduction size = 1 # Point size in plot ) # Display the plot print(plot_umap) # Customize the ggplot object plot_umap + ggtitle("Glycolysis Activity in PBMC") + theme(legend.position = "bottom") # Save plot ggsave("glycolysis_umap.png", plot_umap, width = 8, height = 6) # Create t-SNE visualization plot_tsne <- DimPlot.metabolism( obj = countexp.Seurat, pathway = "Oxidative phosphorylation", dimention.reduction.type = "tsne", dimention.reduction.run = TRUE, # Run t-SNE if not already computed size = 0.8 ) ``` -------------------------------- ### Quantify Single-Cell Metabolism without Seurat Source: https://github.com/wu-yc/scmetabolism/blob/main/README.md Quantifies single-cell metabolism using a data frame of UMI counts, independent of Seurat objects. Supports various methods and pathway databases. ```r metabolism.matrix<-sc.metabolism(countexp = countexp, method = "AUCell", imputation = F, ncores = 2, metabolism.type = "KEGG") ``` -------------------------------- ### Perform ALRA Imputation for scRNA-seq Data Source: https://context7.com/wu-yc/scmetabolism/llms.txt Applies ALRA (Adaptively-thresholded Low Rank Approximation) for zero-preserving imputation of scRNA-seq data, reducing dropout effects. Requires normalized expression matrix. ```R library(scMetabolism) library(rsvd) A_norm <- normalize_data(as.matrix(countexp)) result.completed <- alra( A_norm = A_norm, k = 0, q = 10, quantile.prob = 0.001, use.mkl = FALSE ) A_norm_rank_k <- result.completed[[1]] A_norm_rank_k_cor <- result.completed[[2]] A_norm_completed <- result.completed[[3]] countexp.Seurat <- sc.metabolism.Seurat( obj = countexp.Seurat, method = "AUCell", imputation = TRUE, ncores = 2, metabolism.type = "KEGG" ) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.