### Install ReporterScore R Package Source: https://github.com/asa12138/reporterscore/blob/main/README_zh_CN.md Provides instructions to install the ReporterScore package from CRAN and the development version from GitHub. It also includes installation for a dependency package 'pcutils'. ```r install.packages("ReporterScore") # install.packages("devtools") devtools::install_github("Asa12138/pcutils") devtools::install_github("Asa12138/ReporterScore") ``` -------------------------------- ### Install ReporterScore Development Version from GitHub (R) Source: https://github.com/asa12138/reporterscore/blob/main/README.md Installs the development version of the ReporterScore R package and its dependency 'pcutils' directly from GitHub. This allows access to the latest features and bug fixes, but may be less stable than the CRAN version. ```r # install.packages("devtools") devtools::install_github("Asa12138/pcutils") devtools::install_github("Asa12138/ReporterScore") ``` -------------------------------- ### Install ReporterScore from CRAN (R) Source: https://github.com/asa12138/reporterscore/blob/main/README.md Installs the released version of the ReporterScore R package from the Comprehensive R Archive Network (CRAN). This is the standard method for installing stable package versions. ```r install.packages("ReporterScore") ``` -------------------------------- ### Example KO Abundance Table Source: https://github.com/asa12138/reporterscore/blob/main/README_zh_CN.md Displays the head of a sample KO abundance table (`KO_abundance_test`) available within the ReporterScore package. This table serves as an example input for the GRSA method. ```r data("KO_abundance_test") head(KO_abundance[, 1:6]) ``` -------------------------------- ### Example Metadata Table Source: https://github.com/asa12138/reporterscore/blob/main/README_zh_CN.md Shows the first few rows of a sample metadata table (`metadata`) used to define experimental groups or time points. This table is crucial for running analyses in ReporterScore. ```r head(metadata) ``` -------------------------------- ### Load and Inspect CAZy Database Information (R) Source: https://github.com/asa12138/reporterscore/blob/main/README.md This snippet loads the CAZy database using the `load_CAZy_info()` function. It then displays the head of the `fam_subfam_ec` table, which links CAZyme sub-families to their accession numbers and EC (Enzyme Commission) numbers. This function requires the 'reporterScore' package to be installed. ```r CAZy_info <- load_CAZy_info() #> =================================load CAZy_info================================= #> ==================CAZy_info download time: 2025-03-14 01:10:20================== #> If you want to update CAZy_info, use `update_CAZy_info()` head(CAZy_info$fam_subfam_ec) #> Sub_family Accession EC #> 1 AA1_1 AAA33103.1 1.10.3.2 #> 2 AA1_1 AAA33104.1 1.10.3.2 #> 3 AA1_1 AAA86659.1 1.10.3.2 #> 4 AA1_1 AAC41686.1 1.10.3.2 #> 5 AA1_1 AAC41687.1 1.10.3.2 #> 6 AA1_1 AAC49828.1 1.10.3.2 ``` -------------------------------- ### Load and Inspect CARD Database Information (R) Source: https://github.com/asa12138/reporterscore/blob/main/README.md This snippet loads the CARD database using the `load_CARDinfo()` function. It then displays the head of the ARO_index table, which contains detailed information about antibiotic resistance genes, including accession numbers, sequence IDs, gene families, and drug classes. This function requires the 'reporterScore' package to be installed. ```r CARDinfo <- load_CARDinfo() #> =================================load CARDinfo================================== #> ==================CARDinfo download time: 2024-01-12 01:12:11=================== #> If you want to update CARDinfo, use `update_GOlist()` head(CARDinfo$ARO_index) #> ARO Accession CVTERM ID Model Sequence ID Model ID #> 3005099 ARO:3005099 43314 6143 3831 #> 3002523 ARO:3002523 38923 8144 1781 #> 3002524 ARO:3002524 38924 85 746 #> 3002525 ARO:3002525 38925 4719 1246 #> 3002526 ARO:3002526 38926 228 1415 #> 3002527 ARO:3002527 38927 5510 2832 #> Model Name #> 3005099 23S rRNA (adenine(2058)-N(6))-methyltransferase Erm(A) #> 3002523 AAC(2')-Ia #> 3002524 AAC(2')-Ib #> 3002525 AAC(2')-Ic #> 3002526 AAC(2')-Id #> 3002527 AAC(2')-Ie #> ARO Name #> 3005099 23S rRNA (adenine(2058)-N(6))-methyltransferase Erm(A) #> 3002523 AAC(2')-Ia #> 3002524 AAC(2')-Ib #> 3002525 AAC(2')-Ic #> 3002526 AAC(2')-Id #> 3002527 AAC(2')-Ie #> Protein Accession DNA Accession AMR Gene Family #> 3005099 AAB60941.1 AF002716.1 Erm 23S ribosomal RNA methyltransferase #> 3002523 AAA03550.1 L06156.2 AAC(2') #> 3002524 AAC44793.1 U41471.1 AAC(2') #> 3002525 CCP42991.1 AL123456.3 AAC(2') #> 3002526 AAB41701.1 U72743.1 AAC(2') #> 3002527 CAC32082.1 AL583926.1 AAC(2') #> Drug Class #> 3005099 lincosamide antibiotic;macrolide antibiotic;streptogramin antibiotic #> 3002523 aminoglycoside antibiotic #> 3002524 aminoglycoside antibiotic #> 3002525 aminoglycoside antibiotic #> 3002526 aminoglycoside antibiotic #> 3002527 aminoglycoside antibiotic #> Resistance Mechanism CARD Short Name #> 3005099 antibiotic target alteration Spyo_ErmA_MLSb #> 3002523 antibiotic inactivation AAC(2')-Ia #> 3002524 antibiotic inactivation AAC(2')-Ib #> 3002525 antibiotic inactivation AAC(2')-Ic #> 3002526 antibiotic inactivation AAC(2')-Id #> 3002527 antibiotic inactivation AAC(2')-Ie ``` -------------------------------- ### Calculate Reporter Score for Gene Data (Setting Feature and Type) in R Source: https://github.com/asa12138/reporterscore/blob/main/README.md This example shows how to calculate reporter scores using gene expression data. It highlights the importance of setting the `feature` and `type` parameters correctly (e.g., `feature = 'gene'`, `type = 'hsa'`) when working with species-specific gene data. The `genedf` and `metadata` are assumed to be pre-loaded. ```r data("genedf") # Method 1: Set the `feature` and `type`! reporter_res_gene <- GRSA(genedf, "Group", metadata, mode = "directed", method = "wilcox.test", perm = 999, type = "hsa", feature = "gene" ) ``` -------------------------------- ### Get Reporter Score with get_reporter_score Source: https://github.com/asa12138/reporterscore/blob/main/README.md This code snippet shows how to calculate the reporter score using the `get_reporter_score` function. It requires the previously computed Z-scores (`ko_stat`) and allows for specifying the number of permutations (`perm`). This function is central to the reporter score analysis. ```r reporter_s1 <- get_reporter_score(ko_stat, perm = 499) ``` -------------------------------- ### Plot Genes/KOs in a Specific Pathway (Boxes and Lines) Source: https://github.com/asa12138/reporterscore/blob/main/README.md Plots the distribution of genes or KOs within a specified KEGG pathway ('map00780' in this example) using boxes and lines to represent their abundance or activity. This function helps in understanding the contribution of individual components to the overall pathway score. ```r plot_KOs_in_pathway(reporter_res, map_id = "map00780") ``` -------------------------------- ### Load and Inspect KEGG Compound Pathway Database Source: https://github.com/asa12138/reporterscore/blob/main/README_zh_CN.md Illustrates loading the built-in KEGG pathway-compound and module-compound databases from ReporterScore. It displays the initial entries of the pathway list. ```r CPDlist <- load_CPDlist() head(CPDlist$pathway) ``` -------------------------------- ### Load GO-Gene Database Source: https://github.com/asa12138/reporterscore/blob/main/README_zh_CN.md Demonstrates loading the built-in GO-gene database within the ReporterScore package. It shows how to view the first few entries of the GO list for biological processes (BP). ```r GOlist <- load_GOlist() head(GOlist$BP) ``` -------------------------------- ### Load and Inspect KEGG KO Pathway Database Source: https://github.com/asa12138/reporterscore/blob/main/README_zh_CN.md Demonstrates how to load the built-in KEGG pathway-KO and module-KO databases included with the ReporterScore package. It shows how to view the first few entries of the pathway list. ```r KOlist <- load_KOlist() head(KOlist$pathway) ``` -------------------------------- ### Load and Update Pathway Databases Source: https://context7.com/asa12138/reporterscore/llms.txt This section illustrates how to load various pathway and gene ontology (GO) databases from KEGG and GO, and how to update them. It includes functions for loading KO lists, compound databases, GO lists, custom pathways, and updating organism-specific pathways. Dependencies include access to KEGG API for updates. ```r # Load built-in KEGG pathway-KO database KOlist <- load_KOlist() head(KOlist$pathway) # Load KEGG module-KO database head(KOlist$module) # Load compound databases CPDlist <- load_CPDlist() head(CPDlist$pathway) # Load GO database for genes GOlist <- load_GOlist() head(GOlist$BP) # Biological Process head(GOlist$CC) # Cellular Component head(GOlist$MF) # Molecular Function # Load organism-specific pathways hsa_pathway <- custom_modulelist_from_org( org = "hsa", # organism code feature = "gene", # 'ko', 'gene', or 'compound' gene = "symbol" # 'symbol' or 'id' ) # Update databases from KEGG API update_KO_file() # Update KO-pathway mappings update_org_pathway("hsa") # Update organism pathways update_GOlist() # Update GO database # Create custom pathway database custom_db <- custom_modulelist( path2ko = data.frame(pathway = c("custom01", "custom01", "custom02"), ko = c("K00001", "K00002", "K00003")), pathway_name = data.frame(id = c("custom01", "custom02"), pathway = c("Custom pathway 1", "Custom pathway 2")) ) # Load hierarchical tables for KO classification KO_htable <- load_KO_htable() head(KO_htable) # Upgrade KO abundance to higher levels KO_level1 <- up_level_KO( kodf = KO_abundance, level = "level1", # 'pathway', 'module', 'level1', 'level2', 'level3' show_name = TRUE ) ``` -------------------------------- ### Load Human Pathway-Gene Database Source: https://github.com/asa12138/reporterscore/blob/main/README_zh_CN.md Shows how to load the human (hsa) pathway-gene database using the `custom_modulelist_from_org` function in ReporterScore. It displays the first few entries of the resulting list. ```r hsa_pathway_gene <- custom_modulelist_from_org( org = "hsa", feature = c("ko", "gene", "compound")[2] ) head(hsa_pathway_gene) ``` -------------------------------- ### Load and Analyze KEGG Enzyme htable (R) Source: https://github.com/asa12138/reporterscore/blob/main/README.md Loads the KEGG enzyme htable and then uses 'pctax' library functions to create and visualize an annotated tree. It highlights 'Enzyme1_name' and does not add tip labels or abundance information. ```r load_Enzyme_htable() -> Enzyme_htable library(pctax) ann_tree(distinct(Enzyme_htable[, 1:3])) -> Enzyme_tr easy_tree(Enzyme_tr, highlight = "Enzyme1_name", add_abundance = F, add_tiplab = F) ``` -------------------------------- ### Load and Visualize KO Hierarchy Table (R) Source: https://github.com/asa12138/reporterscore/blob/main/README.md This code block shows how to load the KEGG Orthology (KO) hierarchy table using load_KO_htable and then visualize its structure with plot_htable. It includes messages indicating the download time and suggests how to update the table. The visualization helps in understanding the hierarchical organization of KO terms. ```r KO_htable <- load_KO_htable() head(KO_htable) plot_htable(type = "ko") ``` -------------------------------- ### Load Built-in KEGG Pathway-Compound Database (R) Source: https://github.com/asa12138/reporterscore/blob/main/README.md Loads the built-in KEGG pathway-compound database (version 2023-08) for compound abundance tables. It allows users to view the structure of the loaded compound pathway data. ```r # 2. KEGG pathway-compound and module-compound databases CPDlist <- load_CPDlist() head(CPDlist$pathway) ``` -------------------------------- ### Compare with Alternative Enrichment Methods Source: https://context7.com/asa12138/reporterscore/llms.txt This code snippet demonstrates how to perform enrichment analysis using alternative methods to GRSA, including Fisher's exact test (ORA), clusterProfiler, GSEA, GSA, PADOG, and GSVA. Each method uses specific functions like KO_fisher, KO_enrich, KO_gsea, KO_gsa, KO_padog, and KO_gsva, often taking reporter score results or abundance data as input. ```r # Fisher's exact test (ORA method) fisher_res <- KO_fisher( reporter_res = reporter_res, padj_threshold = 0.05, logFC_threshold = NULL ) # clusterProfiler enricher method enrich_res <- KO_enrich( ko_stat = reporter_res, # Note: This might be an error and should likely be ko_stat variable from the first snippet padj_threshold = 0.05, p.adjust.method = "BH" ) # GSEA method gsea_res <- KO_gsea( reporter_res = reporter_res, weight = "Z_score", # weight by Z_score or logFC pvalueCutoff = 0.05 ) # GSA method gsa_res <- KO_gsa( reporter_res = reporter_res, method = "maxmean" ) # PADOG method padog_res <- KO_padog( reporter_res = reporter_res ) # GSVA method gsva_res <- KO_gsva( kodf = KO_abundance, modulelist = reporter_res$modulelist ) ``` -------------------------------- ### Check Metadata and Abundance Table Compatibility Source: https://github.com/asa12138/reporterscore/blob/main/README_zh_CN.md Verifies if the row names of the metadata table are present as column names in the KO abundance table, ensuring proper sample matching for analysis in ReporterScore. ```r all(rownames(metadata) %in% colnames(KO_abundance)) intersect(rownames(metadata), colnames(KO_abundance)) > 0 ``` -------------------------------- ### Calculate Reporter Scores and Combine Results Source: https://context7.com/asa12138/reporterscore/llms.txt This snippet demonstrates the core ReporterScore analysis pipeline, involving p-value to Z-score conversion, reporter score calculation, and combining results with KO abundance data and metadata. It uses functions like pvalue2zs, get_reporter_score, and combine_rs_res. ```r ko_stat <- pvalue2zs( ko_pvalue = ko_pvalue, mode = "directed", # 'directed' or 'mixed' p.adjust.method1 = "none" ) reporter_s <- get_reporter_score( ko_stat = ko_stat, type = "pathway", feature = "ko", perm = 4999, min_exist_KO = 3, max_exist_KO = 600, p.adjust.method2 = "BH" ) reporter_res <- combine_rs_res( kodf = KO_abundance, group = "Group", metadata = metadata, ko_stat = ko_stat, reporter_s = reporter_s ) ``` -------------------------------- ### Load Built-in KEGG Pathway-KO Database (R) Source: https://github.com/asa12138/reporterscore/blob/main/README.md Loads the built-in KEGG pathway-KO database (version 2023-08) provided by the ReporterScore package. This function is used for KO abundance tables and allows inspection of the loaded pathway data. ```r # 1. KEGG pathway-KO and module-KO databases KOlist <- load_KOlist() head(KOlist$pathway) ``` -------------------------------- ### Aggregate KO Abundance to Level 1 in R Source: https://github.com/asa12138/reporterscore/blob/main/README_zh_CN.md Aggregates KEGG Orthology (KO) abundance data to the 'level1' hierarchical category using the `up_level_KO` function. The `show_name = TRUE` argument ensures that the names of the level 1 categories are displayed. The resulting data is then plotted using `pcutils::stackplot` and styled with `ggsci::scale_fill_d3`, with x-axis labels rotated for readability. This requires `KO_abundance` data, `up_level_KO`, `pcutils::stackplot`, and `ggsci` packages. ```r KO_level1 <- up_level_KO(KO_abundance, level = "level1", show_name = TRUE) #> =================================load KO_htable================================= #> ==================KO_htable download time: 2024-01-12 00:49:03================== #> If you want to update KO_htable, use `update_htable(type='ko')` pcutils::stackplot(KO_level1[-which(rownames(KO_level1) == "Unknown"), ]) + ggsci::scale_fill_d3() + theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5)) ``` -------------------------------- ### Compare Analysis Results using Venn Diagrams (R) Source: https://context7.com/asa12138/reporterscore/llms.txt Compares results from different analysis methods (ReporterScore, Fisher's exact test, GSEA) by identifying significant IDs (p.adjust < 0.05) and visualizing overlaps using Venn diagrams. This helps in assessing the concordance between methods. Dependencies include 'dplyr' for data manipulation and 'pcutils' for Venn diagram plotting. ```r library(dplyr) RS <- filter(reporter_res$reporter_s, abs(ReporterScore) > 1.64, p.adjust < 0.05) %>% pull(ID) Fisher <- filter(fisher_res, p.adjust < 0.05) %>% pull(ID) GSEA <- filter(data.frame(gsea_res), p.adjust < 0.05) %>% pull(ID) venn_res <- list(GRSA = RS, Fisher = Fisher, GSEA = GSEA) library(pcutils) venn(venn_res, "network") ``` -------------------------------- ### Load and Inspect KO Hierarchy Table in R Source: https://github.com/asa12138/reporterscore/blob/main/README_zh_CN.md Loads the KEGG Orthology (KO) hierarchy table using `load_KO_htable`. It then displays the head of the table, showing columns like level names, IDs, and KO names. This function is essential for understanding the structure of KO data. No specific dependencies are mentioned beyond the assumed availability of the `load_KO_htable` function. ```r KO_htable <- load_KO_htable() #> =================================load KO_htable================================= #> ==================KO_htable download time: 2024-01-12 00:49:03================== #> If you want to update KO_htable, use `update_htable(type='ko')` head(KO_htable) #> level1_name level2_name level3_id level3_name #> 1 Metabolism Carbohydrate metabolism map00010 Glycolysis / Gluconeogenesis #> 2 Metabolism Carbohydrate metabolism map00010 Glycolysis / Gluconeogenesis #> 3 Metabolism Carbohydrate metabolism map00010 Glycolysis / Gluconeogenesis #> 4 Metabolism Carbohydrate metabolism map00010 Glycolysis / Gluconeogenesis #> 5 Metabolism Carbohydrate metabolism map00010 Glycolysis / Gluconeogenesis #> 6 Metabolism Carbohydrate metabolism map00010 Glycolysis / Gluconeogenesis #> KO_id KO_name #> 1 K00844 HK; hexokinase [EC:2.7.1.1] #> 2 K12407 GCK; glucokinase [EC:2.7.1.2] #> 3 K00845 glk; glucokinase [EC:2.7.1.2] #> 4 K25026 glk; glucokinase [EC:2.7.1.2] #> 5 K01810 GPI, pgi; glucose-6-phosphate isomerase [EC:5.3.1.9] #> 6 K06859 pgi1; glucose-6-phosphate isomerase, archaeal [EC:5.3.1.9] ``` -------------------------------- ### R: Integrating Limma for p-value Calculation Source: https://github.com/asa12138/reporterscore/blob/main/README.md Shows how to integrate external differential analysis tools like Limma into the reporter score calculation workflow. It involves calculating p-values using Limma and then replacing the default p-values in the 'ko_pvalue' object before proceeding to Z-score transformation. ```r # 1-1. Calculate p-value by Limma ko_pvalue <- ko.test(KO_abundance, "Group", metadata, method = "none") ko_Limma_p <- pctax::diff_da(KO_abundance, group_df = metadata["Group"], method = "limma") # 1-2. Replace the p-value in ko_pvalue, remember to match the KO_ids ko_pvalue$`p.value` <- ko_Limma_p[match(ko_pvalue$KO_id, ko_Limma_p$tax), "pvalue"] ``` -------------------------------- ### Load Enzyme Information (R) Source: https://github.com/asa12138/reporterscore/blob/main/README.md Loads the Enzyme information database. It shows how to display the head of the 'enzclass_df' dataframe, which contains enzyme classification and descriptions. This function relies on the internal R package functions. ```r Enzyme_info <- load_Enzyme_info() #> ================================load Enzyme_info================================ #> =================Enzyme_info download time: 2025-03-24 14:51:45================= #> If you want to update Enzyme_info, use `update_Enzyme_info()` head(Enzyme_info$enzclass_df) ``` -------------------------------- ### Load Built-in GO-Gene Database (R) Source: https://github.com/asa12138/reporterscore/blob/main/README.md Loads the built-in Gene Ontology (GO) database specifically for gene annotations. This function enables the use of GO terms for enrichment analysis on gene expression data. ```r # 4. GO-gene database GOlist <- load_GOlist() head(GOlist$BP) ``` -------------------------------- ### R: Step-by-step Reporter Score Calculation Source: https://github.com/asa12138/reporterscore/blob/main/README.md Demonstrates the three-step process for calculating reporter scores: calculating p-values using ko.test, transforming p-values to Z-scores with pvalue2zs, and obtaining the final reporter scores using get_reporter_score. This allows for modular analysis and integration with external differential analysis tools. ```r data("KO_abundance_test") ko_pvalue <- ko.test(KO_abundance, "Group", metadata, method = "wilcox.test") ko_stat <- pvalue2zs(ko_pvalue, mode = "directed") reporter_s1 <- get_reporter_score(ko_stat, perm = 499) ``` -------------------------------- ### Step-by-step Reporter Score Calculation in R Source: https://context7.com/asa12138/reporterscore/llms.txt Enables granular control over the GRSA process by allowing step-by-step calculation. The `ko.test` function calculates initial p-values for features, which can be replaced by custom differential analysis results (e.g., from DESeq2 or Limma). ```r # Step 1: Calculate p-values for each feature ko_pvalue <- ko.test( kodf = KO_abundance, group = "Group", metadata = metadata, method = "wilcox.test", p.adjust.method1 = "none", threads = 1 ) # Or use custom method (e.g., DESeq2, Limma) ko_pvalue <- ko.test(KO_abundance, "Group", metadata, method = "none") # ... perform custom differential analysis ... # ko_pvalue$p.value <- custom_results$pvalue # replace with custom p-values ``` -------------------------------- ### Plot KEGG Pathway Map Source: https://github.com/asa12138/reporterscore/blob/main/README_zh_CN.md Renders a KEGG pathway map, coloring the pathway elements based on a specified variable, such as Z-score. This provides a visual representation of pathway activity. It requires reporter results, a pathway ID, and the variable to color by. ```r plot_KEGG_map(reporter_res, map_id = "map00780", color_var = "Z_score") ``` -------------------------------- ### Display Head of Metadata Table (R) Source: https://github.com/asa12138/reporterscore/blob/main/README.md Shows the first few rows of the metadata table, which includes sample names as rownames and group information as columns. This is crucial for understanding sample classification for analysis. ```r head(metadata) #> Group Group2 #> WT1 WT G3 #> WT2 WT G3 #> WT3 WT G3 #> WT4 WT G3 #> WT5 WT G3 #> WT6 WT G1 ``` -------------------------------- ### Load Gene Pathway Data (R) Source: https://github.com/asa12138/reporterscore/blob/main/README_zh_CN.md Loads gene pathway data using the 'genedf' dataset in R. This is often a precursor to performing gene-pathway analysis, where specific parameters like 'feature' and 'type' need to be set for accurate results, especially when dealing with specific species like humans. ```r data("genedf") ``` -------------------------------- ### Calculate KO-pathway Reporter Scores (R) Source: https://github.com/asa12138/reporterscore/blob/main/README_zh_CN.md Calculates Reporter Scores for KO-pathway analysis using the GRSA function. It requires KO abundance data, metadata, and specifies parameters such as mode, method, type, and feature. The output includes detailed processing steps and summary statistics. ```r cat("Comparison: ", levels(factor(metadata$Group)), "\n") # for microbiome!!! reporter_res <- GRSA(KO_abundance, "Group", metadata, mode = "directed", method = "wilcox.test", perm = 999, type = "pathway", feature = "ko" ) ``` -------------------------------- ### C-means Clustering for Pattern Discovery (R) Source: https://context7.com/asa12138/reporterscore/llms.txt Performs reporter score analysis using C-means clustering to discover potential patterns in the data. It involves running the RSA_by_cm function with specified parameters, visualizing cluster patterns with plot_c_means, plotting enriched pathways by cluster using plot_report_bar, and accessing individual cluster results. Dependencies include the ReporterScore package itself. ```r # Perform reporter score analysis with C-means clustering rsa_cm_res <- RSA_by_cm( kodf = KO_abundance, group = "Group2", metadata = metadata, method = "pearson", k_num = 3, # number of clusters perm = 999 ) # Visualize cluster patterns plot_c_means( rsa_cm_res, filter_membership = 0.7 # filter by membership threshold ) # Plot enriched pathways by cluster plot_report_bar( reporter_res = rsa_cm_res, rs_threshold = 2.5, y_text_size = 10 ) # Access individual cluster results rsa_cm_res$Cluster1$reporter_s rsa_cm_res$Cluster2$ko_stat ``` -------------------------------- ### Load Human KEGG Pathway-Gene Database (R) Source: https://github.com/asa12138/reporterscore/blob/main/README.md Loads custom KEGG pathway databases for human ('hsa') focusing on gene features. This function allows specifying the organism and feature type (e.g., 'ko', 'gene', 'compound') for pathway analysis. ```r # 3. human (hsa) pathway-ko/gene/compound databases hsa_pathway_gene <- custom_modulelist_from_org( org = "hsa", feature = c("ko", "gene", "compound")[2] ) head(hsa_pathway_gene) ``` -------------------------------- ### View Reporter Score Dataframe in RStudio Source: https://github.com/asa12138/reporterscore/blob/main/README.md Opens the `reporter_s` dataframe, which contains the reporter scores for each pathway, in the RStudio viewer. This allows for interactive inspection of the primary results. ```r View(reporter_res$reporter_s) ``` -------------------------------- ### Plot KOs Heatmap Source: https://github.com/asa12138/reporterscore/blob/main/README_zh_CN.md Creates a heatmap to visualize the abundance of KOs within a pathway, allowing for the identification of patterns and clusters. It supports filtering for significant KOs and customizing heatmap parameters like row clustering. Requires reporter results, a pathway ID, and heatmap parameters. ```r plot_KOs_heatmap(reporter_res, map_id = "map00780", only_sig = TRUE, heatmap_param = list(cutree_rows = 2) ) ``` -------------------------------- ### Plot KO Abundance Hierarchy in R Source: https://github.com/asa12138/reporterscore/blob/main/README_zh_CN.md Generates a plot visualizing the abundance of KEGG Orthology (KO) categories. It first ensures the KO_htable is loaded and then uses the `plot_htable` function with the type set to 'ko'. This function aids in the visual exploration of KO data distribution. It depends on the `plot_htable` function and likely graphical packages. ```r plot_htable(type = "ko") #> =================================load KO_htable================================= #> ==================KO_htable download time: 2024-01-12 00:49:03================== #> If you want to update KO_htable, use `update_htable(type='ko')` #> Warning: Vectorized input to `element_text()` is not officially supported. #> ℹ Results may be unexpected or may change in future versions of ggplot2. ``` -------------------------------- ### One-step Reporter Score Analysis in R Source: https://context7.com/asa12138/reporterscore/llms.txt Performs a complete GRSA workflow from abundance table to reporter scores. Supports multi-group and longitudinal designs using various statistical tests and modes ('mixed', 'directed'). Dependencies include the ReporterScore package. Outputs reporter score results and feature statistics. ```r library(ReporterScore) # Load example KO abundance data and metadata data("KO_abundance_test") head(KO_abundance[, 1:6]) #> WT1 WT2 WT3 WT4 WT5 WT6 #> K03169 0.002653545 0.005096380 0.002033923 0.000722349 0.003468322 0.001483028 #> K07133 0.000308237 0.000280458 0.000596527 0.000859854 0.000308719 0.000878098 head(metadata) #> Group Group2 #> WT1 WT G3 #> WT2 WT G3 #> WT3 WT G3 # Two-group differential analysis (directed mode) reporter_res <- reporter_score( kodf = KO_abundance, group = "Group", metadata = metadata, mode = "directed", # 'directed' for up/down regulation, 'mixed' for overall method = "wilcox.test", # statistical test method feature = "ko", # feature type: 'ko', 'gene', or 'compound' type = "pathway", # database: 'pathway', 'module', or organism code perm = 999, # permutation times for background distribution p.adjust.method1 = "none", # p-value adjustment for features p.adjust.method2 = "BH" # p-value adjustment for pathways ) # View reporter score results head(reporter_res$reporter_s) #> Columns: ID, Description, K_num, Exist_K_num, Significant_K_num, #> Z_score, BG_Mean, BG_Sd, ReporterScore, p.value, p.adjust # Access ko statistics head(reporter_res$ko_stat) #> Contains: KO_id, p.value, p.adjust, Z_score, Significantly, type # Multi-group correlation analysis reporter_res2 <- reporter_score( kodf = KO_abundance, group = "Group2", metadata = metadata, mode = "directed", method = "spearman", # correlation method for multi-group perm = 999 ) # Pattern-specific analysis (find pathways with specific trend) reporter_res3 <- reporter_score( kodf = KO_abundance, group = "Group2", metadata = metadata, mode = "directed", method = "pearson", pattern = c("G1" = 1, "G2" = 5, "G3" = 1) # down-up-down pattern ) ``` -------------------------------- ### Perform Enrichment Analysis using ReporterScore R Package Source: https://github.com/asa12138/reporterscore/blob/main/README_zh_CN.md This snippet demonstrates how to perform various enrichment analyses using the ReporterScore R package, including Fisher's exact test, clusterProfiler's enricher, GSEA, and others. It shows how to filter results and visualize overlaps using a Venn diagram. Dependencies include the ReporterScore package and pcutils for visualization. ```r library(ReporterScore) library(dplyr) library(pcutils) # Assuming reporter_res is loaded and contains the necessary data # Extract IDs from ReporterScore results filter(reporter_res$reporter_s, abs(ReporterScore) > 1.64, p.adjust < 0.05) %>% pull(ID) -> RS # Perform Fisher's exact test fisher_res <- KO_fisher(reporter_res) filter(fisher_res, p.adjust < 0.05) %>% pull(ID) -> Fisher # Perform clusterProfiler enrichment enrich_res <- KO_enrich(reporter_res) filter(enrich_res, p.adjust < 0.05) %>% pull(ID) -> clusterProfiler # Perform GSEA analysis set.seed(1234) gsea_res <- KO_gsea(reporter_res, weight = "Z_score") filter(data.frame(gsea_res), p.adjust < 0.05) %>% pull(ID) -> GSEA # Combine results for Venn diagram venn_res <- list(GRSA = RS, Fisher = Fisher, CP = clusterProfiler, GSEA = GSEA) # Generate Venn diagram venn(venn_res, "network") ``` -------------------------------- ### Plot Significantly Enriched Pathways (Circle Packing) Source: https://github.com/asa12138/reporterscore/blob/main/README.md Visualizes significantly enriched pathways using a circle packing layout. The `plot_report_circle_packing` function takes the reporter results and an `rs_threshold` for filtering. It also loads pathway annotation data and handles potential scaling conflicts. ```r plot_report_circle_packing(reporter_res, rs_threshold = c(-2.5, 2.5)) #> ==============================load Pathway_htable=============================== #> ===============Pathway_htable download time: 2024-01-12 00:52:39================ #> If you want to update Pathway_htable, use `update_htable(type='pathway')` #> Non-leaf weights ignored #> Scale for fill is already present. #> Adding another scale for fill, which will replace the existing scale. ``` -------------------------------- ### Plot KOs Distribution Source: https://github.com/asa12138/reporterscore/blob/main/README_zh_CN.md Generates a distribution plot for KOs within a specified pathway, visualizing their Z-score distribution. This helps in understanding the variability and significance of KOs in the pathway context. It requires reporter results and a pathway ID. ```r plot_KOs_distribution(reporter_res, map_id = "map00780") ``` -------------------------------- ### Customize Pathway Database (R) Source: https://github.com/asa12138/reporterscore/blob/main/README.md Provides a placeholder for customizing pathway databases. The `custom_modulelist()` function allows users to define their own gene sets of interest for enrichment analysis, offering flexibility beyond built-in databases. ```r # 5. customize your own pathway databases ?custom_modulelist() ``` -------------------------------- ### Display Group Comparisons (R) Source: https://github.com/asa12138/reporterscore/blob/main/README.md Prints the current factor levels of the 'Group' column in the metadata table. This is useful for understanding the default control group and planning comparisons for differential analysis. ```r cat("Comparison: ", levels(factor(metadata$Group)), "\n") #> Comparison: WT OE ``` -------------------------------- ### Plot Reporter Score Circle Packing Source: https://github.com/asa12138/reporterscore/blob/main/README_zh_CN.md Visualizes reporter scores using a circle packing plot, where the size and color of circles represent the significance and direction of enrichment. It requires reporter results and a significance threshold. ```r plot_report_circle_packing(reporter_res, rs_threshold = c(-2.5, 2.5)) ``` -------------------------------- ### Load Specialized Functional Annotation Databases (R) Source: https://context7.com/asa12138/reporterscore/llms.txt Loads information from specialized functional annotation databases including CARD (antibiotic resistance genes), CAZy (carbohydrate-active enzymes), and Enzyme (enzyme classification and hierarchical data). These functions are part of the ReporterScore package or related libraries. The output typically includes data frames with relevant annotations. ```r # CARD database for antibiotic resistance genes CARDinfo <- load_CARDinfo() head(CARDinfo$ARO_index) # CAZy database for carbohydrate-active enzymes CAZy_info <- load_CAZy_info() head(CAZy_info$fam_subfam_ec) # Enzyme classification database Enzyme_info <- load_Enzyme_info() head(Enzyme_info$enzclass_df) # Enzyme hierarchical table Enzyme_htable <- load_Enzyme_htable() ``` -------------------------------- ### R: C-means Clustering for Pattern Discovery with RSA_by_cm Source: https://github.com/asa12138/reporterscore/blob/main/README.md Utilizes C-means clustering to explore potential patterns within the data and calculates reporter scores. The RSA_by_cm function groups pathways based on abundance trends. Dependencies include the 'reporter_score' package and 'metadata'. ```r rsa_cm_res <- RSA_by_cm(KO_abundance, "Group2", metadata, method = "pearson", k_num = 3, perm = 999 ) # show the patterns plot_c_means(rsa_cm_res, filter_membership = 0.7) plot_report_bar(rsa_cm_res, rs_threshold = 2.5, y_text_size = 10) ``` -------------------------------- ### Visualize Enrichment Results Source: https://context7.com/asa12138/reporterscore/llms.txt This section provides R code for various visualization functions to interpret reporter scores and feature abundance. It includes generating bar plots, circle packing plots, feature distribution plots, network plots, boxplots, heatmaps, and KEGG pathway maps. These functions typically take the reporter_res object as input. ```r # Bar plot of significantly enriched pathways plot_report_bar( reporter_res = reporter_res, rs_threshold = c(-2.5, 2.5), # filter by reporter score y_text_size = 10, str_width = 40, show_ID = FALSE, facet_level = TRUE # facet by pathway hierarchy ) # Circle packing plot plot_report_circle_packing( reporter_res = reporter_res, rs_threshold = c(-2.5, 2.5) ) # Feature abundance in a specific pathway plot_KOs_in_pathway( reporter_res = reporter_res, map_id = "map00780" # pathway ID ) # Z-score distribution for pathway features plot_KOs_distribution( reporter_res = reporter_res, map_id = "map00780" ) # Network plot of multiple pathways plot_KOs_network( reporter_res = reporter_res, map_id = c("map00780", "map00785", "map00900"), mark_module = TRUE ) # Boxplot of feature abundance plot_KOs_box( reporter_res = reporter_res, map_id = "map00780", only_sig = TRUE # show only significant features ) # Heatmap of feature abundance plot_KOs_heatmap( reporter_res = reporter_res, map_id = "map00780", only_sig = TRUE, heatmap_param = list(cutree_rows = 2) ) # KEGG pathway map with overlaid colors plot_KEGG_map( reporter_res = reporter_res, map_id = "map00780", color_var = "Z_score" # color by Z_score or other variables ) # Export results to CSV files export_report_table( reporter_res = reporter_res, dir_name = "~/Downloads/results", overwrite = FALSE ) ``` -------------------------------- ### Plot KOs Network Source: https://github.com/asa12138/reporterscore/blob/main/README_zh_CN.md Visualizes the network of KOs within specified pathways, highlighting relationships and modules. This function is useful for exploring pathway structures and interactions. It takes reporter results, pathway IDs, and optional parameters for main title and module marking. ```r plot_KOs_network(reporter_res, map_id = c("map00780", "map00785", "map00900"), main = "", mark_module = TRUE ) ``` -------------------------------- ### Perform Fisher's Exact Test for Enrichment Source: https://github.com/asa12138/reporterscore/blob/main/README.md This code demonstrates how to perform Fisher's exact test for enrichment analysis using the `KO_fisher` function. It takes reporter score results as input and returns enrichment results, which can then be filtered by adjusted p-value to identify significant IDs. ```r # fisher fisher_res <- KO_fisher(reporter_res) filter(fisher_res, p.adjust < 0.05) %>% pull(ID) -> Fisher ``` -------------------------------- ### Check Metadata and Feature Abundance Table Matching (R) Source: https://github.com/asa12138/reporterscore/blob/main/README.md Verifies if the rownames of the metadata table are present in the colnames of the feature abundance table. This ensures correct sample matching for analysis. It checks for complete overlap and any common elements. ```r all(rownames(metadata) %in% colnames(KO_abundance)) ## TRUE intersect(rownames(metadata), colnames(KO_abundance)) > 0 ## TRUE ``` -------------------------------- ### Combine Reporter Score Results Source: https://github.com/asa12138/reporterscore/blob/main/README.md This snippet illustrates how to combine the calculated reporter scores with other data. The `combine_rs_res` function takes abundance data, a group identifier, metadata, Z-scores, and reporter scores as input to generate a comprehensive result object. This combined result is then suitable for visualization and further analysis. ```r reporter_res1 <- combine_rs_res(KO_abundance, "Group", metadata, ko_stat, reporter_s1) ``` -------------------------------- ### Update and Plot KO Hierarchy to Specific Level (R) Source: https://github.com/asa12138/reporterscore/blob/main/README.md This R code demonstrates updating the KO hierarchy to a specific level (e.g., 'level1') using the up_level_KO function. It then uses the pcutils::stackplot function to create a stacked plot of the updated KO abundance, applying a D3 color scale and adjusting x-axis text for better readability. Unknown entries are removed before plotting. ```r KO_level1 <- up_level_KO(KO_abundance, level = "level1", show_name = TRUE) pcutils::stackplot(KO_level1[-which(rownames(KO_level1) == "Unknown"), ]) + ggsci::scale_fill_d3() + theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5)) ``` -------------------------------- ### Calculate Z-score with pvalue2zs Source: https://github.com/asa12138/reporterscore/blob/main/README.md This snippet demonstrates how to convert p-values to Z-scores using the `pvalue2zs` function from the ReporterScore package. It takes a p-value input and returns a Z-score, with a 'directed' mode option available. This is a preliminary step for reporter score calculation. ```r ko_stat <- pvalue2zs(ko_pvalue, mode = "directed") ``` -------------------------------- ### Perform GSEA and Generate Venn Diagram (R) Source: https://github.com/asa12138/reporterscore/blob/main/README.md This snippet demonstrates how to perform Gene Set Enrichment Analysis (GSEA) using the KO_gsea function and then visualize the results along with other analysis outputs (RS, Fisher, CP) using a Venn diagram. It highlights filtering GSEA results and customizes the Venn plot appearance. ```r set.seed(1234) gsea_res <- KO_gsea(reporter_res, weight = "Z_score") filter(data.frame(gsea_res), p.adjust < 0.05) %>% pull(ID) -> GSEA venn_res <- list(GRSA = RS, Fisher = Fisher, CP = clusterProfiler, GSEA = GSEA) library(pcutils) venn(venn_res, "network") ``` -------------------------------- ### Plot KOs in Pathway Boxplot Source: https://github.com/asa12138/reporterscore/blob/main/README_zh_CN.md Displays the abundance of Key Operational Taxonomic Units (KOs) within a specific pathway using a boxplot. This function is useful for examining the distribution of KOs in relation to reporter scores. It requires reporter results, a pathway ID, and an option to show only significant KOs. ```r plot_KOs_in_pathway(reporter_res, map_id = "map00780") ``` ```r plot_KOs_in_pathway(reporter_res2, map_id = "map02060") + scale_y_log10() ``` ```r plot_KOs_in_pathway(reporter_res, map_id = "map00780", only_sig = TRUE) #> `geom_smooth()` using formula = 'y ~ x' ``` -------------------------------- ### Plot Reporter Score Bar Chart Source: https://github.com/asa12138/reporterscore/blob/main/README_zh_CN.md Generates a bar plot of reporter scores, allowing for visualization of enrichment across different categories. It takes reporter results and a threshold for significance as input. Faceting can be enabled for detailed comparisons. ```r plot_report_bar(reporter_res, rs_threshold = c(-2.5, 2.5), facet_level = TRUE) ``` -------------------------------- ### Perform Enrichment Analysis with clusterProfiler Source: https://github.com/asa12138/reporterscore/blob/main/README.md This snippet shows how to perform enrichment analysis using the `KO_enrich` function, likely a wrapper around clusterProfiler's `enricher` function. It takes reporter score results and generates enrichment data that can be filtered for significance based on adjusted p-values. ```r # enricher enrich_res <- KO_enrich(reporter_res) filter(enrich_res, p.adjust < 0.05) %>% pull(ID) -> clusterProfiler ```