### Calculate Similarity Matrix Source: https://github.com/ssayols/rrvgo/blob/master/docs/reference/calculateSimMatrix.html This example demonstrates how to calculate a similarity matrix for GO terms using the 'Rel' method and the 'org.Hs.eg.db' database for biological process (BP) ontology. It first reads example GO IDs from a file and then calls calculateSimMatrix. ```R go_analysis <- read.delim(system.file("extdata/example.txt", package="rrvgo")) simMatrix <- calculateSimMatrix(go_analysis$ID, orgdb="org.Hs.eg.db", ont="BP", method="Rel") #> #> preparing gene to GO mapping data... #> preparing IC data... > ``` -------------------------------- ### Launch Shiny Application Source: https://context7.com/ssayols/rrvgo/llms.txt Starts an interactive web interface for the rrvgo workflow. Supports custom host and port configurations. ```r library(rrvgo) # Launch the interactive Shiny application shiny_rrvgo() # Run on a specific port shiny_rrvgo(port = 3838) # Run with specific host for network access shiny_rrvgo(host = "0.0.0.0", port = 3838) # Launch in browser automatically shiny_rrvgo(launch.browser = TRUE) ``` -------------------------------- ### Install rrvgo package Source: https://github.com/ssayols/rrvgo/blob/master/README.md Use BiocManager to install the rrvgo package from Bioconductor. ```r if (!requireNamespace("BiocManager", quietly = TRUE)) install.packages("BiocManager") BiocManager::install("rrvgo") ``` -------------------------------- ### Plot GO terms as a treemap using treemapPlot Source: https://github.com/ssayols/rrvgo/blob/master/docs/reference/treemapPlot.html Use treemapPlot to visualize reduced GO terms. Ensure the 'rrvgo' package is installed and necessary data is loaded. This example demonstrates a typical workflow from reading data to plotting. ```R if (FALSE) { # \dontrun{ go_analysis <- read.delim(system.file("extdata/example.txt", package="rrvgo")) simMatrix <- calculateSimMatrix(go_analysis$ID, orgdb="org.Hs.eg.db", ont="BP", method="Rel") scores <- setNames(-log10(go_analysis$qvalue), go_analysis$ID) reducedTerms <- reduceSimMatrix(simMatrix, scores, threshold=0.7, orgdb="org.Hs.eg.db") treemapPlot(reducedTerms) } # } ``` -------------------------------- ### Prepare Data for rrvgo Plots Source: https://context7.com/ssayols/rrvgo/llms.txt Loads GO analysis data, calculates semantic similarity matrix, computes GO term scores (e.g., -log10(qvalue)), and reduces redundant terms based on a similarity threshold. Ensure 'org.Hs.eg.db' is installed for human annotations. ```r library(rrvgo) # Prepare data go_analysis <- read.delim(system.file("extdata/example.txt", package="rrvgo")) simMatrix <- calculateSimMatrix(go_analysis$ID, orgdb="org.Hs.eg.db", ont="BP", method="Rel") scores <- setNames(-log10(go_analysis$qvalue), go_analysis$ID) reducedTerms <- reduceSimMatrix(simMatrix, scores, threshold=0.7, orgdb="org.Hs.eg.db") ``` -------------------------------- ### Get GO Term Description Source: https://github.com/ssayols/rrvgo/blob/master/docs/reference/getGoTerm.html Retrieves the description of a specified GO term. ```APIDOC ## GET /go/term/{id} ### Description Retrieves the description of a GO term using its identifier. ### Method GET ### Endpoint /go/term/{id} ### Parameters #### Path Parameters - **id** (string) - Required - The GO term identifier (e.g., GO:0008150). ### Response #### Success Response (200) - **term** (string) - The description of the GO term. #### Response Example ```json { "term": "biological_process" } ``` ``` -------------------------------- ### Generate ggplot2-style colors Source: https://github.com/ssayols/rrvgo/blob/master/docs/reference/gg_color_hue.html Use this function to create a vector of colors based on the ggplot2 hue palette. The example is wrapped in a dontrun block. ```R if (FALSE) { # \dontrun{ plot(1:10, pch=16, cex=2, col=gg_color_hue(10)) } # } ``` -------------------------------- ### Get GO Term Size Source: https://github.com/ssayols/rrvgo/blob/master/docs/reference/getGoSize.html Retrieves the number of genes associated with specified GO terms. ```APIDOC ## GET /getGoSize ### Description Retrieves the number of genes associated with GO terms. ### Method GET ### Endpoint /getGoSize ### Parameters #### Query Parameters - **terms** (GO terms) - Required - GO terms to query. - **orgdb** (string) - Required - Bioconductor org.* package name. - **keytype** (string) - Optional - Keytype for AnnotationDbi::keys. - **children** (boolean) - Optional - Whether to include genes in children terms. ### Response #### Success Response (200) - **genes_count** (integer) - The number of genes associated with each term. #### Response Example { "genes_count": 150 } ``` -------------------------------- ### Get Unique Parent Terms Source: https://context7.com/ssayols/rrvgo/llms.txt Extracts and counts unique parent terms (cluster representatives) from the reducedTerms data frame. Use this to understand the number of distinct clusters identified. ```R parent_terms <- unique(reducedTerms$parentTerm) cat("Number of clusters:", length(parent_terms), "\n") cat("Original terms:", nrow(reducedTerms), "\n") ``` -------------------------------- ### Launch the Shiny application Source: https://github.com/ssayols/rrvgo/blob/master/docs/articles/rrvgo.html Opens an interactive interface for exploring rrvgo plots and tables. ```R rrvgo::shiny_rrvgo() ``` -------------------------------- ### Initialize custom OrgDb data Source: https://github.com/ssayols/rrvgo/blob/master/docs/articles/rrvgo.html Prepares semantic similarity data for organisms not natively supported by Bioconductor. ```R my_new_fancy_orgdb_object <- 'org.Zz.eg.db' hsGO <- GOSemSim::godata(my_new_fancy_orgdb_object, ont="MF") ``` -------------------------------- ### shiny_rrvgo Source: https://github.com/ssayols/rrvgo/blob/master/docs/reference/shiny_rrvgo.html Launches an interactive web interface for rrvgo. ```APIDOC ## shiny_rrvgo ### Description Launch an interactive web interface for the rrvgo package. ### Method Function Call ### Parameters #### Arguments - **...** (dots) - Optional - Other parameters sent to shiny::runApp(). ### Response - **Value** (null) - Nothing ``` -------------------------------- ### Create Basic Heatmap with Parent Annotations Source: https://context7.com/ssayols/rrvgo/llms.txt Displays the GO term similarity matrix as a clustered heatmap with annotations indicating parent terms. This helps visualize term relationships and cluster assignments. ```r heatmapPlot( simMatrix = simMatrix, reducedTerms = reducedTerms, annotateParent = TRUE, # Show cluster annotations annotationLabel = "parentTerm" # Use term names (or "parent" for GO IDs) ) ``` -------------------------------- ### Launch Interactive Web Interface with shiny_rrvgo Source: https://github.com/ssayols/rrvgo/blob/master/docs/reference/shiny_rrvgo.html Use this function to launch an interactive web interface. It accepts additional parameters that are passed to shiny::runApp(). ```R shiny_rrvgo(...) ``` -------------------------------- ### Generate Word Cloud Plots Source: https://context7.com/ssayols/rrvgo/llms.txt Creates word clouds from GO term descriptions. Requires a reduced term set from reduceSimMatrix. ```r library(rrvgo) # Prepare data go_analysis <- read.delim(system.file("extdata/example.txt", package="rrvgo")) simMatrix <- calculateSimMatrix(go_analysis$ID, orgdb="org.Hs.eg.db", ont="BP", method="Rel") scores <- setNames(-log10(go_analysis$qvalue), go_analysis$ID) reducedTerms <- reduceSimMatrix(simMatrix, scores, threshold=0.7, orgdb="org.Hs.eg.db") # Basic word cloud using only parent terms wordcloudPlot( reducedTerms = reducedTerms, min.freq = 1, # Minimum word frequency to include colors = "black" # Single color for all words ) # Use all terms (not just parents) for word frequencies wordcloudPlot( reducedTerms = reducedTerms, onlyParents = FALSE, # Include all terms min.freq = 2 ) # Colorful word cloud with more customization wordcloudPlot( reducedTerms = reducedTerms, min.freq = 1, colors = RColorBrewer::brewer.pal(8, "Dark2"), max.words = 50, # Limit number of words random.order = FALSE, # Most frequent words in center scale = c(3, 0.5) # Font size range ) # Save to file png("go_wordcloud.png", width=600, height=600) wordcloudPlot(reducedTerms, min.freq=1, colors="black") dev.off() ``` -------------------------------- ### shiny_rrvgo Source: https://context7.com/ssayols/rrvgo/llms.txt Launches an interactive Shiny web application for the complete RRVGO workflow. ```APIDOC ## shiny_rrvgo ### Description Launches an interactive Shiny web application that provides a graphical interface for the complete RRVGO workflow. ### Parameters #### Request Body - **port** (numeric) - Optional - Port to run the application on. - **host** (character) - Optional - Host address for network access. - **launch.browser** (logical) - Optional - Whether to launch in the browser automatically. ``` -------------------------------- ### Access rrvgo documentation Source: https://github.com/ssayols/rrvgo/blob/master/README.md Open the package vignettes within the R environment. ```r browseVignettes("rrvgo") ``` -------------------------------- ### Retrieve GO Term Descriptions Source: https://context7.com/ssayols/rrvgo/llms.txt Fetches human-readable descriptions for specific GO IDs from the annotation database. ```r library(rrvgo) # Get term descriptions for GO IDs go_ids <- c("GO:0006119", "GO:0042775", "GO:0022904") terms <- getGoTerm(go_ids) print(terms) ``` -------------------------------- ### getGoTerm Source: https://context7.com/ssayols/rrvgo/llms.txt Retrieves the human-readable term description for one or more GO IDs. ```APIDOC ## getGoTerm ### Description Retrieves the human-readable term description for one or more GO IDs from the GO.db annotation database. ### Parameters #### Request Body - **go_ids** (character vector) - Required - A vector of GO IDs. ``` -------------------------------- ### Generate a word cloud plot Source: https://github.com/ssayols/rrvgo/blob/master/docs/articles/rrvgo.html Creates a word cloud visualization to emphasize frequently appearing GO terms. ```R wordcloudPlot(reducedTerms, min.freq=1, colors="black") ``` -------------------------------- ### Generate Heatmap Visualization Source: https://context7.com/ssayols/rrvgo/llms.txt Creates a heatmap of the similarity matrix, optionally annotating parent terms. Useful for visualizing the similarity structure between GO terms. Set fontsize for labels. ```R heatmapPlot(simMatrix, reducedTerms, annotateParent=TRUE, annotationLabel="parentTerm", fontsize=6) ``` -------------------------------- ### Execute Complete Workflow Source: https://context7.com/ssayols/rrvgo/llms.txt Performs the full pipeline from loading enrichment results to calculating similarity and reducing terms. ```r library(rrvgo) # Step 1: Load GO enrichment results # Expected format: tab-delimited file with at least 'ID' column (GO terms) # Optional: score column (e.g., p-value, q-value, fold enrichment) go_analysis <- read.delim(system.file("extdata/example.txt", package="rrvgo")) # Inspect the data head(go_analysis) # Step 2: Calculate similarity matrix simMatrix <- calculateSimMatrix( x = go_analysis$ID, orgdb = "org.Hs.eg.db", # Human ont = "BP", # Biological Process method = "Rel" # Relevance method ) # Step 3: Prepare scores (transform p-values: higher = better) scores <- setNames(-log10(go_analysis$qvalue), go_analysis$ID) # Step 4: Reduce similar terms reducedTerms <- reduceSimMatrix( simMatrix = simMatrix, scores = scores, threshold = 0.7, # Medium similarity threshold orgdb = "org.Hs.eg.db" ) # Step 5: Explore the results ``` -------------------------------- ### Visualize GO terms as treemap Source: https://github.com/ssayols/rrvgo/blob/master/docs/articles/rrvgo.html Creates a treemap visualization where term grouping is based on parent terms and size is proportional to scores. ```R treemapPlot(reducedTerms) ``` -------------------------------- ### Retrieve package citation Source: https://github.com/ssayols/rrvgo/blob/master/docs/articles/rrvgo.html Displays the citation information for the rrvgo package. ```R citation("rrvgo") ``` -------------------------------- ### wordcloudPlot Source: https://context7.com/ssayols/rrvgo/llms.txt Generates a word cloud from GO term descriptions to identify common themes in enrichment results. ```APIDOC ## wordcloudPlot ### Description Generates a word cloud from GO term descriptions, highlighting frequently occurring words across the reduced term set. ### Parameters #### Request Body - **reducedTerms** (object) - Required - The result object from reduceSimMatrix. - **min.freq** (numeric) - Optional - Minimum word frequency to include. - **colors** (character/vector) - Optional - Color palette for the words. - **onlyParents** (logical) - Optional - Whether to use only parent terms (default TRUE). - **max.words** (numeric) - Optional - Limit the number of words displayed. - **random.order** (logical) - Optional - If FALSE, most frequent words are in the center. - **scale** (numeric vector) - Optional - Font size range. ``` -------------------------------- ### Calculate GO term similarity matrix Source: https://github.com/ssayols/rrvgo/blob/master/docs/articles/rrvgo.html Computes the semantic similarity matrix for a list of GO terms using a specified organism database and ontology. ```R library(rrvgo) go_analysis <- read.delim(system.file("extdata/example.txt", package="rrvgo")) simMatrix <- calculateSimMatrix(go_analysis$ID, orgdb="org.Hs.eg.db", ont="BP", method="Rel") ``` -------------------------------- ### Reduce GO Terms by Similarity and Scores Source: https://github.com/ssayols/rrvgo/blob/master/docs/reference/reduceSimMatrix.html Use reduceSimMatrix to group GO terms that are similar above a specified threshold. Scores can be provided to determine the representative term for each group, otherwise 'uniqueness' or 'size' are used. Requires a pre-computed similarity matrix and an OrgDb package. ```R go_analysis <- read.delim(system.file("extdata/example.txt", package="rrvgo")) simMatrix <- calculateSimMatrix(go_analysis$ID, orgdb="org.Hs.eg.db", ont="BP", method="Rel") #> preparing gene to GO mapping data... #> preparing IC data... scores <- setNames(-log10(go_analysis$qvalue), go_analysis$ID) reducedTerms <- reduceSimMatrix(simMatrix, scores, threshold=0.7, orgdb="org.Hs.eg.db") #> 'select()' returned 1:many mapping between keys and columns ``` -------------------------------- ### Create Simple Heatmap Without Annotations Source: https://context7.com/ssayols/rrvgo/llms.txt Generates a basic heatmap of the similarity matrix without any parent term annotations. ```r heatmapPlot( simMatrix = simMatrix, annotateParent = FALSE ) ``` -------------------------------- ### Generate Word Cloud of Reduced GO Terms Source: https://github.com/ssayols/rrvgo/blob/master/docs/reference/wordcloudPlot.html Use this function to visualize reduced GO terms as a word cloud. Ensure the 'reducedTerms' argument is a data frame generated by reduceSimMatrix(). Additional parameters can be passed to customize the word cloud appearance. ```R go_analysis <- read.delim(system.file("extdata/example.txt", package="rrvgo")) simMatrix <- calculateSimMatrix(go_analysis$ID, orgdb="org.Hs.eg.db", ont="BP", method="Rel") #> preparing gene to GO mapping data... #> preparing IC data... scores <- setNames(-log10(go_analysis$qvalue), go_analysis$ID) reducedTerms <- reduceSimMatrix(simMatrix, scores, threshold=0.7, orgdb="org.Hs.eg.db") #> 'select()' returned 1:many mapping between keys and columns wordcloudPlot(reducedTerms, min.freq=1, colors="black") ``` -------------------------------- ### Generate Scatter Plot Visualization Source: https://context7.com/ssayols/rrvgo/llms.txt Creates a scatter plot to visualize term relationships using PCA. Requires the similarity matrix and reduced terms data. Adjust labelSize for readability. ```R p1 <- scatterPlot(simMatrix, reducedTerms, algorithm="pca", labelSize=3) print(p1) ``` -------------------------------- ### calculateSimMatrix Source: https://context7.com/ssayols/rrvgo/llms.txt Calculates a pairwise semantic similarity matrix for a set of GO terms using specified methods and organism databases. ```APIDOC ## calculateSimMatrix ### Description Calculates a semantic similarity matrix between GO terms using one of five established methods (Resnik, Lin, Rel, Jiang, Wang) from the GOSemSim package. ### Parameters #### Arguments - **x** (vector) - Required - Vector of GO term IDs. - **orgdb** (string) - Required - Organism annotation database (e.g., "org.Hs.eg.db"). - **ont** (string) - Required - Ontology: "BP", "MF", or "CC". - **method** (string) - Required - Semantic similarity method: "Resnik", "Lin", "Rel", "Jiang", or "Wang". - **semdata** (object) - Optional - Pre-computed semantic data object. - **include_terms_without_IC** (boolean) - Optional - Whether to include terms without Information Content. ### Response - **simMatrix** (matrix) - A square similarity matrix with values between 0 and 1, where rownames and colnames are GO term IDs. ``` -------------------------------- ### Visualize similarity matrix as heatmap Source: https://github.com/ssayols/rrvgo/blob/master/docs/articles/rrvgo.html Generates a heatmap of the similarity matrix with hierarchical clustering of terms. ```R heatmapPlot(simMatrix, reducedTerms, annotateParent=TRUE, annotationLabel="parentTerm", fontsize=6) ``` -------------------------------- ### Save Heatmap to File Source: https://context7.com/ssayols/rrvgo/llms.txt Exports a similarity heatmap to a PNG file with specified dimensions. ```r png("similarity_heatmap.png", width=1000, height=1000) heatmapPlot(simMatrix, reducedTerms, annotateParent=TRUE, fontsize=6) dev.off() ``` -------------------------------- ### Plot GO Terms with scatterPlot Source: https://github.com/ssayols/rrvgo/blob/master/docs/reference/scatterPlot.html Use scatterPlot to visualize GO terms as scattered points. This function requires a similarity matrix and reduced terms data frame. Point size can be set to 'score' or 'size'. ```R go_analysis <- read.delim(system.file("extdata/example.txt", package="rrvgo")) simMatrix <- calculateSimMatrix(go_analysis$ID, orgdb="org.Hs.eg.db", ont="BP", method="Rel") #> preparing gene to GO mapping data... #> preparing IC data... scores <- setNames(-log10(go_analysis$qvalue), go_analysis$ID) reducedTerms <- reduceSimMatrix(simMatrix, scores, threshold=0.7, orgdb="org.Hs.eg.db") #> 'select()' returned 1:many mapping between keys and columns scatterPlot(simMatrix, reducedTerms) #> Warning: ggrepel: 10 unlabeled data points (too many overlaps). Consider increasing max.overlaps ``` -------------------------------- ### Visualization Functions Source: https://github.com/ssayols/rrvgo/blob/master/docs/reference/index.html Functions for plotting GO term analysis results. ```APIDOC ## Visualization Functions ### Description Functions to visualize GO term data using various plot types. ### Methods - heatmapPlot(): Plot similarity matrix as a heatmap - scatterPlot(): Plot GO terms as scattered points - treemapPlot(): Plot GO terms as a treemap - wordcloudPlot(): Plot GO reduced terms as a wordcloud ``` -------------------------------- ### Annotate Heatmap with GO IDs Source: https://context7.com/ssayols/rrvgo/llms.txt Generates a heatmap annotated with GO IDs instead of human-readable parent term names, useful for precise identification. ```r heatmapPlot( simMatrix = simMatrix, reducedTerms = reducedTerms, annotateParent = TRUE, annotationLabel = "parent", # Show GO IDs like "GO:0006119" fontsize = 8 ) ``` -------------------------------- ### Calculate Semantic Similarity Matrix in R Source: https://context7.com/ssayols/rrvgo/llms.txt Computes pairwise similarity scores for GO terms using methods like Resnik, Lin, or Relevance. Pre-computing semdata can improve performance for repeated calculations. ```r library(rrvgo) # Load example GO enrichment results go_analysis <- read.delim(system.file("extdata/example.txt", package="rrvgo")) # Calculate similarity matrix for Biological Process ontology using Relevance method # Supported ontologies: "BP" (Biological Process), "MF" (Molecular Function), "CC" (Cellular Component) # Supported methods: "Resnik", "Lin", "Rel", "Jiang", "Wang" simMatrix <- calculateSimMatrix( x = go_analysis$ID, # Vector of GO term IDs (e.g., "GO:0006119", "GO:0042775") orgdb = "org.Hs.eg.db", # Organism annotation database (Human) ont = "BP", # Ontology: BP, MF, or CC method = "Rel" # Semantic similarity method ) # For better performance when running multiple times, pre-compute semdata semdata <- GOSemSim::godata("org.Hs.eg.db", ont = "BP", keytype = "ENTREZID") simMatrix <- calculateSimMatrix( x = go_analysis$ID, orgdb = "org.Hs.eg.db", semdata = semdata, # Reuse pre-computed semantic data ont = "BP", method = "Rel" ) # Include terms without Information Content (use with caution) simMatrix <- calculateSimMatrix( x = go_analysis$ID, orgdb = "org.Hs.eg.db", ont = "BP", method = "Rel", include_terms_without_IC = TRUE ) # Result: Square similarity matrix with values between 0 and 1 # rownames and colnames are GO term IDs print(simMatrix[1:3, 1:3]) # GO:0006119 GO:0042775 GO:0042773 # GO:0006119 1.0000000 0.9234567 0.8765432 # GO:0042775 0.9234567 1.0000000 0.8901234 # GO:0042773 0.8765432 0.8901234 1.0000000 ``` -------------------------------- ### Plot Similarity Matrix as Heatmap with heatmapPlot Source: https://github.com/ssayols/rrvgo/blob/master/docs/reference/heatmapPlot.html Use this function to visualize a similarity matrix as a heatmap. It requires a square similarity matrix and optionally accepts reduced terms for annotation. Customization of parent term annotation and font size is supported. ```R heatmapPlot( simMatrix, reducedTerms = NULL, annotateParent = TRUE, annotationLabel = "parentTerm", ... ) ``` ```R go_analysis <- read.delim(system.file("extdata/example.txt", package="rrvgo")) simMatrix <- calculateSimMatrix(go_analysis$ID, orgdb="org.Hs.eg.db", ont="BP", method="Rel") #> preparing gene to GO mapping data... #> preparing IC data... scores <- setNames(-log10(go_analysis$qvalue), go_analysis$ID) reducedTerms <- reduceSimMatrix(simMatrix, scores, threshold=0.7, orgdb="org.Hs.eg.db") #> 'select()' returned 1:many mapping between keys and columns heatmapPlot(simMatrix, reducedTerms, annotateParent=TRUE, annotationLabel="parentTerm", fontsize=6) ``` -------------------------------- ### Generate Treemap Visualization Source: https://context7.com/ssayols/rrvgo/llms.txt Generates a treemap to show hierarchical grouping of GO terms, with area proportional to significance. Requires the reduced terms data and a title for the plot. ```R treemapPlot(reducedTerms, title="GO Enrichment Summary") ``` -------------------------------- ### Reduce GO terms by similarity Source: https://github.com/ssayols/rrvgo/blob/master/docs/articles/rrvgo.html Groups GO terms based on a similarity threshold and selects a representative term for each group based on provided scores. ```R scores <- setNames(-log10(go_analysis$qvalue), go_analysis$ID) reducedTerms <- reduceSimMatrix(simMatrix, scores, threshold=0.7, orgdb="org.Hs.eg.db") ``` -------------------------------- ### loadOrgdb Function Source: https://github.com/ssayols/rrvgo/blob/master/docs/reference/loadOrgdb.html Loads an orgdb object from a specified Bioconductor org.* package. ```APIDOC ## loadOrgdb ### Description Loads an orgdb object from a Bioconductor org.* package. ### Parameters #### Arguments - **orgdb** (string) - Required - The name of one of the org.* Bioconductor packages. ### Value - **object** - The loaded orgdb object. ``` -------------------------------- ### Function: gg_color_hue Source: https://github.com/ssayols/rrvgo/blob/master/docs/reference/gg_color_hue.html Generates a vector of colors based on the number of requested hues. ```APIDOC ## gg_color_hue ### Description Emulate ggplot2 color palette by generating equally spaced hues around the color wheel. ### Parameters #### Arguments - **n** (integer) - Required - The number of colors to generate. ### Value - **vector** (alphanumeric) - A vector containing the generated color codes. ### Request Example ```r gg_color_hue(10) ``` ### Response Example ```r [1] "#F8766D" "#D39200" "#93AA00" "#00BA38" "#00C19F" "#00B9E3" "#619CFF" "#DB72FB" "#FF61C3" ``` ``` -------------------------------- ### Visualize GO terms as scatter plot Source: https://github.com/ssayols/rrvgo/blob/master/docs/articles/rrvgo.html Plots GO terms using PCoA coordinates to represent distances based on similarity. ```R scatterPlot(simMatrix, reducedTerms) ``` -------------------------------- ### reduceSimMatrix Source: https://github.com/ssayols/rrvgo/blob/master/docs/reference/index.html Reduces a set of GO terms based on their semantic similarity and scores. ```APIDOC ## reduceSimMatrix ### Description Reduce a set of GO terms based on their semantic similarity and scores. ### Method Function Call ### Endpoint reduceSimMatrix() ``` -------------------------------- ### Create Scatter Plot with UMAP Source: https://context7.com/ssayols/rrvgo/llms.txt Generates a scatter plot of GO terms using UMAP for dimensionality reduction. This is an alternative to PCA for visualizing semantic similarity. ```r scatterPlot( simMatrix = simMatrix, reducedTerms = reducedTerms, algorithm = "umap" # "pca" (default) or "umap" ) ``` -------------------------------- ### getGoSize Source: https://context7.com/ssayols/rrvgo/llms.txt Retrieves the number of genes associated with GO terms. ```APIDOC ## getGoSize ### Description Retrieves the number of genes associated with GO terms from an organism annotation database. ### Parameters #### Request Body - **terms** (character vector) - Required - GO IDs to query. - **orgdb** (object) - Required - Organism annotation database. - **keytype** (character) - Required - Key type for the database. - **children** (logical) - Optional - Whether to include genes from child terms. ``` -------------------------------- ### calculateSimMatrix Source: https://github.com/ssayols/rrvgo/blob/master/docs/reference/index.html Calculates the score similarity matrix between GO terms. ```APIDOC ## calculateSimMatrix ### Description Calculate the score similarity matrix between terms. ### Method Function Call ### Endpoint calculateSimMatrix() ``` -------------------------------- ### View Clustering Results Source: https://context7.com/ssayols/rrvgo/llms.txt Displays the first few rows of the reducedTerms data frame, showing key columns like term, parentTerm, score, and termDispensability. Useful for a quick inspection of the clustering output. ```R head(reducedTerms[, c("term", "parentTerm", "score", "termDispensability")]) ``` -------------------------------- ### scatterPlot Function Source: https://github.com/ssayols/rrvgo/blob/master/docs/reference/scatterPlot.html Visualizes GO terms as scattered points using dimensionality reduction. ```APIDOC ## scatterPlot ### Description Plots GO terms as scattered points where distances represent similarity between terms. Axes are derived from dimensionality reduction algorithms (PCA or UMAP). ### Parameters - **simMatrix** (matrix) - Required - A square similarity matrix. - **reducedTerms** (data.frame) - Required - Data frame with reduced terms from reduceSimMatrix(). - **algorithm** (string) - Optional - Algorithm for dimensionality reduction: 'pca' or 'umap'. - **onlyParents** (boolean) - Optional - If TRUE, plots only parent terms. - **size** (string) - Optional - Metric for point size: 'size' or 'score'. - **addLabel** (boolean) - Optional - Whether to add labels for the most representative term. - **labelSize** (numeric) - Optional - Text size for labels. ### Response - **ggplot2 object** - A ggplot2 object ready to be printed or manipulated. ``` -------------------------------- ### Create Treemap Plot with Custom Title Source: https://context7.com/ssayols/rrvgo/llms.txt Generates a treemap plot with a user-defined title to describe the GO enrichment results. ```r treemapPlot( reducedTerms = reducedTerms, title = "GO Biological Process Enrichment" ) ``` -------------------------------- ### reduceSimMatrix Source: https://context7.com/ssayols/rrvgo/llms.txt Reduces a set of GO terms by grouping semantically similar terms and selecting a representative parent term for each cluster. ```APIDOC ## reduceSimMatrix ### Description Reduces GO terms by performing hierarchical clustering on the similarity matrix and cutting the tree at a specified threshold. ### Parameters #### Arguments - **simMatrix** (matrix) - Required - The similarity matrix generated by calculateSimMatrix. - **scores** (vector/string) - Required - Named vector of scores (names are GO IDs) or a string ("uniqueness" or "size") to determine representative terms. - **threshold** (numeric) - Required - Similarity threshold for clustering (e.g., 0.4 to 0.9). - **orgdb** (string) - Required - Organism annotation database. ### Response - **reducedTerms** (data.frame) - A data frame containing clustering information including go, cluster, parent, score, size, term, parentTerm, and various uniqueness metrics. ``` -------------------------------- ### Reduce GO Term Redundancy in R Source: https://context7.com/ssayols/rrvgo/llms.txt Groups semantically similar GO terms using hierarchical clustering and selects representative parent terms. Scores can be provided as custom vectors or predefined metrics like 'uniqueness' or 'size'. ```r library(rrvgo) # Load data and calculate similarity matrix go_analysis <- read.delim(system.file("extdata/example.txt", package="rrvgo")) simMatrix <- calculateSimMatrix(go_analysis$ID, orgdb="org.Hs.eg.db", ont="BP", method="Rel") # Create scores vector from p-values (higher = better, so use -log10 transformation) scores <- setNames(-log10(go_analysis$qvalue), go_analysis$ID) # Reduce terms using custom scores # Threshold guidance: Large (0.9), Medium (0.7), Small (0.5), Tiny (0.4) # Higher threshold = fewer groups, lower threshold = more groups reducedTerms <- reduceSimMatrix( simMatrix = simMatrix, scores = scores, # Named vector: names are GO IDs, values are scores threshold = 0.7, # Similarity threshold for clustering orgdb = "org.Hs.eg.db" ) # Alternative: Use term uniqueness as score (default if no scores provided) reducedTerms_uniq <- reduceSimMatrix( simMatrix = simMatrix, scores = "uniqueness", # Score by how unique each term is threshold = 0.7, orgdb = "org.Hs.eg.db" ) # Alternative: Use GO term size as score (favors broader terms) reducedTerms_size <- reduceSimMatrix( simMatrix = simMatrix, scores = "size", # Score by number of genes in term threshold = 0.7, orgdb = "org.Hs.eg.db" ) # Result: data.frame with clustering information # Columns: go, cluster, parent, score, size, term, parentTerm, # termUniqueness, termUniquenessWithinCluster, termDispensability head(reducedTerms) # go cluster parent score size term # 1 GO:0006119 1 GO:0006119 4.567890 150 oxidative phosphorylation ``` -------------------------------- ### heatmapPlot Function Source: https://github.com/ssayols/rrvgo/blob/master/docs/reference/heatmapPlot.html Visualizes a similarity matrix as a heatmap, optionally including reduced terms and parent annotations. ```APIDOC ## heatmapPlot ### Description Plots a similarity matrix as a heatmap. This function is designed to visualize the similarity scores between GO terms. ### Parameters - **simMatrix** (matrix) - Required - A square similarity matrix. - **reducedTerms** (data.frame) - Optional - Data frame containing reduced terms from reduceSimMatrix(). - **annotateParent** (boolean) - Optional - Whether to add annotation of the parent term. Defaults to TRUE. - **annotationLabel** (string) - Optional - Display "parent" ids or "parentTerm" string. Defaults to "parentTerm". - **...** (dots) - Optional - Other parameters passed to pheatmap::pheatmap(). ### Value - **pheatmap object** (list) - Invisibly returns a pheatmap object. ### Request Example heatmapPlot(simMatrix, reducedTerms, annotateParent=TRUE, annotationLabel="parentTerm", fontsize=6) ``` -------------------------------- ### reduceSimMatrix Function Source: https://github.com/ssayols/rrvgo/blob/master/docs/reference/reduceSimMatrix.html Reduces a set of GO terms based on their semantic similarity and scores by clustering them and selecting a representative term for each group. ```APIDOC ## reduceSimMatrix ### Description Reduces a set of GO terms based on their semantic similarity and scores. It groups terms that are within a similarity threshold and selects a representative term based on a score. ### Parameters - **simMatrix** (matrix) - Required - A square similarity matrix. - **scores** (vector) - Optional - One of c("uniqueness", "size"), or a named vector with scores for each term. Defaults to "uniqueness". - **threshold** (numeric) - Optional - Similarity threshold (0-1). Defaults to 0.7. - **orgdb** (object/string) - Required - An org.* Bioconductor package or orgdb object. - **keytype** (string) - Optional - Keytype passed to AnnotationDbi::keys. Defaults to "ENTREZID". - **children** (boolean) - Optional - Whether to include genes in children terms when retrieving GO term size. Defaults to TRUE. ### Response - **data.frame** - A data frame identifying clusters of terms, the parent representative term, and metrics of importance (uniqueness and dispensability). ### Request Example reduceSimMatrix(simMatrix, scores = c("uniqueness"), threshold = 0.7, orgdb = "org.Hs.eg.db") ``` -------------------------------- ### Export Reduced GO Terms Source: https://context7.com/ssayols/rrvgo/llms.txt Writes the reduced GO terms data frame to a CSV file. Ensures row names are not included in the output. ```R write.csv(reducedTerms, "reduced_go_terms.csv", row.names=FALSE) ``` -------------------------------- ### Create Scatter Plot Showing Only Parents Source: https://context7.com/ssayols/rrvgo/llms.txt Generates a scatter plot displaying only parent GO terms (cluster representatives). Point size reflects the number of terms within each cluster. ```r scatterPlot( simMatrix = simMatrix, reducedTerms = reducedTerms, onlyParents = TRUE # Only show cluster representatives ) ``` -------------------------------- ### Export Parent GO Terms Source: https://context7.com/ssayols/rrvgo/llms.txt Filters and exports only the parent GO terms (cluster representatives) to a CSV file. This isolates the representative terms from the clustering results. ```R parents_only <- reducedTerms[reducedTerms$go == reducedTerms$parent, ] write.csv(parents_only, "parent_go_terms.csv", row.names=FALSE) ``` -------------------------------- ### Customize Heatmap Font Sizes Source: https://context7.com/ssayols/rrvgo/llms.txt Generates a heatmap with customized font sizes for the main plot and row/column labels, useful for heatmaps with many terms. ```r heatmapPlot( simMatrix = simMatrix, reducedTerms = reducedTerms, annotateParent = TRUE, annotationLabel = "parentTerm", fontsize = 6, # Smaller font for many terms fontsize_row = 5, fontsize_col = 5 ) ``` -------------------------------- ### Create Treemap Plot Sized by Term Size Source: https://context7.com/ssayols/rrvgo/llms.txt Generates a treemap plot where the size of the rectangles is determined by the GO term size rather than the score. ```r treemapPlot( reducedTerms = reducedTerms, size = "size" # "score" (default) or "size" ) ``` -------------------------------- ### wordcloudPlot Function Source: https://github.com/ssayols/rrvgo/blob/master/docs/reference/wordcloudPlot.html Plots Gene Ontology (GO) reduced terms as a word cloud. This function is useful for visualizing the most frequent GO terms after similarity reduction. ```APIDOC ## wordcloudPlot ### Description Plot GO reduced terms as a wordcloud. ### Method `wordcloudPlot(reducedTerms, onlyParents = TRUE, ...)` ### Parameters #### Arguments - **reducedTerms** (data.frame) - A data frame with the reduced terms from `reduceSimMatrix()`. - **onlyParents** (logical) - Use only parent terms to calculate frequencies. Defaults to TRUE. - **...** - Other parameters sent to `wordcloud::wordcloud()`. ### Value Nothing ### Examples ```R go_analysis <- read.delim(system.file("extdata/example.txt", package="rrvgo")) simMatrix <- calculateSimMatrix(go_analysis$ID, orgdb="org.Hs.eg.db", ont="BP", method="Rel") scores <- setNames(-log10(go_analysis$qvalue), go_analysis$ID) reducedTerms <- reduceSimMatrix(simMatrix, scores, threshold=0.7, orgdb="org.Hs.eg.db") wordcloudPlot(reducedTerms, min.freq=1, colors="black") ``` ``` -------------------------------- ### treemapPlot Function Source: https://github.com/ssayols/rrvgo/blob/master/docs/reference/treemapPlot.html Plots Gene Ontology (GO) terms as a treemap using the treemapPlot function. ```APIDOC ## treemapPlot ### Description Plot GO terms as a treemap. ### Method `treemapPlot(reducedTerms, size = "score", title = "", ...)` ### Parameters #### Arguments - **reducedTerms** (data.frame) - a data.frame with the reduced terms from reduceSimMatrix() - **size** (string) - what to use as point size. Can be either GO term's "size" or "score". Defaults to "score". - **title** (string) - title of the plot. Defaults to nothing. - **...** - other parameters sent to treemap::treemap() ### Value A list from the call to the `treemap()` function is silently returned. ### Examples ```R if (FALSE) { # \dontrun{ go_analysis <- read.delim(system.file("extdata/example.txt", package="rrvgo")) simMatrix <- calculateSimMatrix(go_analysis$ID, orgdb="org.Hs.eg.db", ont="BP", method="Rel") scores <- setNames(-log10(go_analysis$qvalue), go_analysis$ID) reducedTerms <- reduceSimMatrix(simMatrix, scores, threshold=0.7, orgdb="org.Hs.eg.db") treemapPlot(reducedTerms) } ``` ``` -------------------------------- ### Customize Scatter Plot with ggplot2 Source: https://context7.com/ssayols/rrvgo/llms.txt Generates a scatter plot and returns a ggplot2 object, allowing for further customization such as adding a custom title. ```r p <- scatterPlot(simMatrix, reducedTerms) p + ggplot2::ggtitle("Reduced GO Terms - Biological Process") ``` -------------------------------- ### Retrieve GO Term Gene Counts Source: https://context7.com/ssayols/rrvgo/llms.txt Calculates the number of genes associated with GO terms, with options to include or exclude child term annotations. ```r library(rrvgo) # Get GO term sizes (number of genes) go_ids <- c("GO:0006119", "GO:0042775", "GO:0022904") # Include genes from child terms (default) sizes <- getGoSize( terms = go_ids, orgdb = "org.Hs.eg.db", keytype = "ENTREZID", children = TRUE # Include genes in child terms ) print(sizes) # Count only direct annotations (no child terms) sizes_direct <- getGoSize( terms = go_ids, orgdb = "org.Hs.eg.db", keytype = "ENTREZID", children = FALSE ) ``` -------------------------------- ### Customize Treemap Labels and Fonts Source: https://context7.com/ssayols/rrvgo/llms.txt Generates a treemap plot with custom font sizes and styles for parent and child labels, allowing for better readability. ```r treemapPlot( reducedTerms = reducedTerms, title = "GO Terms", fontsize.labels = c(14, 10), # Font sizes for parent and child labels fontface.labels = c("bold", "plain") ) ``` -------------------------------- ### Save Treemap Plot to File Source: https://context7.com/ssayols/rrvgo/llms.txt Saves the generated treemap plot to a PNG file with specified dimensions and title. ```r png("go_treemap.png", width=800, height=600) treemapPlot(reducedTerms, title="Enriched GO Terms") dev.off() ``` -------------------------------- ### Create Scatter Plot Without Labels Source: https://context7.com/ssayols/rrvgo/llms.txt Generates a scatter plot without labels for parent terms, providing a cleaner visualization. ```r scatterPlot( simMatrix = simMatrix, reducedTerms = reducedTerms, addLabel = FALSE ) ``` -------------------------------- ### getTermDisp Function Source: https://github.com/ssayols/rrvgo/blob/master/docs/reference/getTermDisp.html Calculates the term dispensability score based on a similarity matrix and cluster assignments. ```APIDOC ## getTermDisp ### Description Calculate the term dispensability score, defined as the semantic similarity threshold a term was assigned to a cluster (namely, the similarity of a term to the cluster representative term). ### Parameters - **simMatrix** (matrix) - Required - A square similarity matrix. - **cluster** (vector) - Required - The cluster assignment for each term. - **clusterRep** (vector) - Required - The cluster representative term. ### Value A vector of term dispensability scores. ``` -------------------------------- ### Customize Scatter Plot Appearance Source: https://context7.com/ssayols/rrvgo/llms.txt Customizes the scatter plot by sizing points based on GO term size and adding labels for parent terms with a specified font size. ```r scatterPlot( simMatrix = simMatrix, reducedTerms = reducedTerms, size = "size", # Size points by GO term size instead of score addLabel = TRUE, # Add labels for parent terms labelSize = 4 # Font size for labels ) ``` -------------------------------- ### getTermUniq Function Source: https://github.com/ssayols/rrvgo/blob/master/docs/reference/getTermUniq.html Calculate the term uniqueness score, defined as 1 minus the average semantic similarity of a term to all other terms. ```APIDOC ## getTermUniq ### Description Calculate the term uniqueness score, defined as 1 minus the average semantic similarity of a term to all other terms. ### Parameters #### Arguments - **simMatrix** (matrix) - Required - A square similarity matrix. - **cluster** (vector) - Optional - Vector with the cluster each entry in the simMatrix belongs to. If NULL, a default behavior is applied. ### Response - **Returns** (vector) - A vector of term uniqueness scores. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.