### Install and Load ClusterGVis Source: https://junjunlab.github.io/ClusterGvis-manual/index.html This snippet demonstrates how to install the ClusterGVis package from GitHub using either devtools or remotes, followed by loading the library into the R environment. ```R # install.packages("devtools") devtools::install_github("junjunlab/ClusterGVis") # or remotes::install_github("junjunlab/ClusterGVis") library(ClusterGVis) ``` -------------------------------- ### Load and Inspect Example Expression Data in R Source: https://junjunlab.github.io/ClusterGvis-manual/basic-usage.html Loads a sample gene expression dataset named 'exps' using the ClusterGVis library and displays the first few rows to inspect its structure. This is a prerequisite for clustering analysis. ```R library(ClusterGVis) # load data data(exps) # check head(exps,3) ``` -------------------------------- ### Visualize Cluster Enrichment with Annotations Source: https://junjunlab.github.io/ClusterGvis-manual/enrichment-anaysis.html Demonstrates how to use the visCluster function to plot cluster data with enrichment annotations. Includes examples for specific cluster subsetting, adding enrichment barplots, and adjusting label positions. ```R pdf('subc.pdf',height = 10,width = 12,onefile = F) visCluster(object = cm, plotType = "both", column_names_rot = 45, show_row_dend = F, markGenes = markGenes, markGenesSide = "left", genesGp = c('italic',fontsize = 12,col = "black"), annoTermData = enrich, lineSide = "left", goCol = rep(ggsci::pal_d3()(8),each = 5), goSize = "pval", subgroupAnno = c("C4","C6","C8")) dev.off() ``` -------------------------------- ### Visualize Enrichment Annotations with visCluster Source: https://junjunlab.github.io/ClusterGvis-manual/enrichment-anaysis.html Shows how to integrate enrichment data frames into cluster visualizations. Includes examples for adjusting annotation side, removing dendrograms, and scaling pathway labels by p-value. ```R pdf('testHTterm.pdf',height = 10,width = 10) visCluster(object = ck, plotType = "both", column_names_rot = 45, annoTermData = termanno) dev.off() pdf('termlfts.pdf',height = 10,width = 12,onefile = F) visCluster(object = ck, plotType = "both", column_names_rot = 45, markGenes = markGenes, markGenesSide = "left", genesGp = c('italic',fontsize = 12,col = "black"), annoTermData = termanno2, lineSide = "left", goCol = rep(ggsci::pal_d3()(8),each = 3), goSize = "pval") dev.off() ``` -------------------------------- ### Basic Cluster Visualization with GO and KEGG Annotations (R) Source: https://junjunlab.github.io/ClusterGvis-manual/enrichment-anaysis.html Generates a cluster visualization plot with GO and KEGG annotations. It saves the plot to a PDF file. Dependencies include the 'jjAnno' package for color palettes. Inputs are the cluster object 'cm', enrichment data 'enrich.go' and 'enrich.kegg', and gene markers 'markGenes'. Outputs a PDF file. ```r pdf('gokegg.pdf',height = 10,width = 16,onefile = F) visCluster(object = cm, plotType = "both", column_names_rot = 45, show_row_dend = F, markGenes = markGenes, markGenesSide = "left", annoTermData = enrich.go, goCol = rep(jjAnno::useMyCol("calm",n = 6),each = 5), annoKeggData = enrich.kegg, keggCol = rep(jjAnno::useMyCol("stallion",n = 6),each = 5), lineSide = "left", sampleGroup = rep(c("sample1","sample2","sample3"),each = 2)) dev.off() ``` -------------------------------- ### Combined GO and KEGG Cluster Visualization with Barplots (R) Source: https://junjunlab.github.io/ClusterGvis-manual/enrichment-anaysis.html Combines GO and KEGG enrichment results into a single annotation data frame for plotting. It then generates a cluster visualization with distinct colors for GO and KEGG terms and includes bar plots. Dependencies include 'dplyr' for data manipulation and 'jjAnno' for colors. Outputs a PDF file. ```r library(dplyr) all <- rbind(enrich.go %>% group_by(group) %>% slice_head(n = 2) %>% mutate(Description = paste("BP: ",Description,sep = "")), enrich.kegg %>% group_by(group) %>% slice_head(n = 2) %>% mutate(Description = paste("KEGG: ",Description,sep = ""))) %>% arrange(group) # plot pdf('gokeggcomb.pdf',height = 10,width = 16,onefile = F) visCluster(object = cm, plotType = "both", column_names_rot = 45, show_row_dend = F, markGenes = markGenes, markGenesSide = "left", annoTermData = all, goCol = c(rep(jjAnno::useMyCol("calm",n = 6),each = 2), rep(jjAnno::useMyCol("circus",n = 6),each = 2)), lineSide = "left", wordWrap = F,addNewLine = F, byGo = "anno_block", addBar = T, sampleGroup = rep(c("sample1","sample2","sample3"),each = 2)) dev.off() ``` -------------------------------- ### Cluster Visualization with Formatted Annotation Panels (R) Source: https://junjunlab.github.io/ClusterGvis-manual/enrichment-anaysis.html Customizes the annotation panel style in the cluster visualization plot by setting 'byGo' and 'byKegg' to 'anno_block'. This allows for a different visual representation of GO and KEGG terms. Dependencies include 'jjAnno'. Outputs a PDF file. ```r pdf('gokeggsq.pdf',height = 12,width = 18,onefile = F) visCluster(object = cm, plotType = "both", column_names_rot = 45, show_row_dend = F, markGenes = markGenes, markGenesSide = "left", annoTermData = enrich.go, goCol = rep(jjAnno::useMyCol("calm",n = 6),each = 5), byGo = "anno_block", annoKeggData = enrich.kegg, keggCol = rep(jjAnno::useMyCol("stallion",n = 6),each = 5), byKegg = "anno_block", wordWrap = F,addNewLine = F, lineSide = "left", sampleGroup = rep(c("sample1","sample2","sample3"),each = 2)) dev.off() ``` -------------------------------- ### Sample Grouping and Ordering in Heatmaps with visCluster Source: https://junjunlab.github.io/ClusterGvis-manual/basic-usage.html Enables adding sample groups and changing sample orders in heatmap visualizations. Uses parameters like `sampleGroup` and `sampleOrder`. ```R # assign groups pdf('htcolg.pdf',height = 10,width = 6,onefile = F) visCluster(object = cm, plotType = "heatmap", column_names_rot = 45, markGenes = markGenes, show_row_dend = F, sampleGroup = rep(c("group1","group2","group3"),each = 2)) dev.off() ``` ```R # change sample order pdf('htsr.pdf',height = 10,width = 6,onefile = F) visCluster(object = cm, plotType = "heatmap", column_names_rot = 45, markGenes = markGenes, show_row_dend = F, sampleOrder = rev(colnames(exps))) dev.off() ``` -------------------------------- ### Perform Gene Clustering using mfuzz, TCseq, and kmeans in R Source: https://junjunlab.github.io/ClusterGvis-manual/basic-usage.html Demonstrates how to perform gene clustering on expression data (exps) using three different methods: 'mfuzz', 'TCseq', and 'kmeans'. Each method is applied with a specified number of clusters (clusterNum = 8). 'mfuzz' and 'TCseq' are particularly suited for time-course data. ```R # using mfuzz for clustering cm <- clusterData(obj = exps, clusterMethod = "mfuzz", clusterNum = 8) # using TCseq for clustering ct <- clusterData(obj = exps, clusterMethod = "TCseq", clusterNum = 8) # using kemans for clustering ck <- clusterData(obj = exps, clusterMethod = "kmeans", clusterNum = 8) ``` -------------------------------- ### Batch Enrichment Analysis and Visualization Workflow Source: https://junjunlab.github.io/ClusterGvis-manual/enrichment-anaysis.html A complete workflow for performing batch enrichment analysis using clusterProfiler and visualizing the results with custom formatting. ```R library(org.Mm.eg.db) enrich <- enrichCluster(object = ck, OrgDb = org.Mm.eg.db, type = "BP", pvalueCutoff = 0.05, topn = 5) pdf('termenrich.pdf',height = 10,width = 11,onefile = F) visCluster(object = ck, plotType = "both", column_names_rot = 45, show_row_dend = F, markGenes = markGenes, markGenesSide = "left", genesGp = c('italic',fontsize = 12,col = "black"), annoTermData = enrich, lineSide = "left", goCol = rep(ggsci::pal_d3()(8),each = 5), goSize = "pval") dev.off() ``` -------------------------------- ### Cluster Visualization with GO and KEGG Barplots (R) Source: https://junjunlab.github.io/ClusterGvis-manual/enrichment-anaysis.html Adds bar plots to the GO and KEGG annotation sections of the cluster visualization. This provides a quantitative view alongside the annotations. Dependencies include 'jjAnno'. Outputs a PDF file. ```r pdf('gokeggbarNew.pdf',height = 10,width = 20,onefile = F) visCluster(object = cm, plotType = "both", column_names_rot = 45, show_row_dend = F, markGenes = markGenes, markGenesSide = "left", annoTermData = enrich.go, goCol = rep(jjAnno::useMyCol("calm",n = 6),each = 5), addBar = T, byGo = "anno_block", annoKeggData = enrich.kegg, keggCol = rep(jjAnno::useMyCol("stallion",n = 6),each = 5), addKeggBar = T, byKegg = "anno_block", wordWrap = F,addNewLine = F, lineSide = "left", sampleGroup = rep(c("sample1","sample2","sample3"),each = 2)) dev.off() ``` -------------------------------- ### Loading and Inspecting WGCNA Output Object Source: https://junjunlab.github.io/ClusterGvis-manual/parse-wgcna-output.html This R code snippet shows how to load a pre-computed WGCNA network object (named 'net') and inspect its structure. It uses the `data()` function to load the object and `str()` to display its hierarchical list structure, including module colors, module eigengenes (MEs), and gene/sample quality metrics. ```R data("net") str(net) ``` -------------------------------- ### Perform K-means Clustering and Visualization Source: https://junjunlab.github.io/ClusterGvis-manual/parse-preudotime-data.html Applies k-means clustering to the expression matrix and generates a visualization of the clusters using ClusterGVis. ```R ck <- clusterData(obj = mat, clusterMethod = "kmeans", clusterNum = 5) pdf('monocle3.pdf',height = 10,width = 8,onefile = F) visCluster(object = ck, plotType = "both", addSampleAnno = F, markGenes = sample(rownames(mat),30,replace = F)) dev.off() ``` -------------------------------- ### Perform Combined GO and KEGG Enrichment Analysis Source: https://junjunlab.github.io/ClusterGvis-manual/enrichment-anaysis.html Provides a workflow for clustering data using mfuzz and performing both Gene Ontology (GO) and KEGG pathway enrichment analysis on the resulting clusters. ```R cm <- clusterData(obj = exps, clusterMethod = "mfuzz", clusterNum = 6) enrich.go <- enrichCluster(object = cm, OrgDb = org.Mm.eg.db, type = "BP", pvalueCutoff = 0.05, topn = 5) enrich.kegg <- enrichCluster(object = cm, OrgDb = org.Mm.eg.db, type = "KEGG", organism = "mmu", pvalueCutoff = 0.05, topn = 5) ``` -------------------------------- ### Visualize Cluster with Line Annotation Source: https://junjunlab.github.io/ClusterGvis-manual/parse-preudotime-data.html Creates a visualization of clustered data with line annotations, suitable for showing branching patterns. This function saves the output to a PDF file. ```r pdf(file = "two-branch.pdf",height = 6,width = 7) visCluster(object = df, plotType = "both") dev.off() ``` -------------------------------- ### Visualize Cluster with Advanced Options Source: https://junjunlab.github.io/ClusterGvis-manual/parse-preudotime-data.html Generates a 'both' plot type visualization for clustered data, incorporating custom color palettes and pseudotime color mappings. The output is saved to a PDF file. ```r library(RColorBrewer) pdf(file = "multiple-branch.pdf",height = 6,width = 8) visCluster(object = df, plotType = "both", htColList = list(col_range = seq(-2,2,length.out = 100), col_color = colorRampPalette(brewer.pal(9,"PRGn"))(100)), pseudotime_col = ggsci::pal_d3()(4)) dev.off() ``` -------------------------------- ### Prepare Data with Duplicate Gene Handling Source: https://junjunlab.github.io/ClusterGvis-manual/parse-single-cell-data.html Prepares single-cell data for visualization, allowing the retention of duplicate differentially expressed genes across clusters by setting keepUniqGene to FALSE. ```R st.data <- prepareDataFromscRNA(object = pbmc, diffData = pbmc.markers, showAverage = TRUE, keepUniqGene = FALSE, sep = "_") df <- st.data$wide.res ``` -------------------------------- ### Multiple Sample Annotations in Heatmaps with visCluster Source: https://junjunlab.github.io/ClusterGvis-manual/basic-usage.html Adds multiple group annotations to heatmap samples using ComplexHeatmap grammars. Supports defining annotation colors and splitting columns based on groups. ```R # group info mg1 = rep(c("D1","D2"), each = 3) names(mg1) <- c("zygote","t2.cell","t4.cell","t8.cell","tmorula","blastocyst") mg2 = rep(c("E1", "E2", "E3"), each = 2) names(mg2) <- c("zygote","t2.cell","t4.cell","t8.cell","tmorula","blastocyst") # TOP annotations HeatmapAnnotation <- ComplexHeatmap::HeatmapAnnotation(mg1 = mg1, mg2 = mg2, col = list(mg1 = c("D1" = "#C147E9","D2" = "#FF7000"), mg2 = c("E1" = "#54B435","E2" = "#31C6D4","E3" = "#D9CB50")), gp = grid::gpar(col = "white")) pdf('htcolmg.pdf',height = 10,width = 6,onefile = F) visCluster(object = cm, plotType = "heatmap", column_names_rot = 45, markGenes = markGenes, show_row_dend = F, htColList = list(col_range = c(-2, 0, 2),col_color = c("#A555EC","#EEEEEE","#FF597B")), heatmapAnnotation = HeatmapAnnotation) dev.off() ``` ```R pdf('htcolmgs1.pdf',height = 10,width = 6,onefile = F) visCluster(object = cm, plotType = "heatmap", column_names_rot = 45, markGenes = markGenes, show_row_dend = F, htColList = list(col_range = c(-2, 0, 2),col_color = c("#A555EC","#EEEEEE","#FF597B")), heatmapAnnotation = HeatmapAnnotation, columnSplit = rep(c(1,2,3),each = 2)) dev.off() ``` -------------------------------- ### Perform Batch Enrichment Analysis with enrichCluster Source: https://junjunlab.github.io/ClusterGvis-manual/enrichment-anaysis.html Demonstrates how to use enrichCluster to perform batch enrichment analysis for clusters. It covers both standard OrgDb-based analysis and custom TERM2GENE/TERM2NAME mapping. ```R enrich <- enrichCluster(object = cm, OrgDb = org.myorg.eg.db, type = "BP", idTrans = F, toType = "GID", readable = F, pvalueCutoff = 0.5, topn = 5) enrich <- enrichCluster(object = cm, type = "ownSet", idTrans = F, TERM2GENE = ko2gene, TERM2NAME = ko2name, pvalueCutoff = 0.5, topn = 5) ``` -------------------------------- ### WGCNA Module Detection using blockwiseModules Source: https://junjunlab.github.io/ClusterGvis-manual/parse-wgcna-output.html This R code snippet demonstrates how to perform one-step network construction and module detection using the WGCNA package. It takes gene expression data (datExpr) and identifies co-expression modules. Key parameters include the soft threshold power, TOM type, and minimum module size. The output includes various network and module properties, and can save TOM files. ```R net = blockwiseModules(datExpr, power = 6, TOMType = "unsigned", minModuleSize = 30, reassignThreshold = 0, mergeCutHeight = 0.25, numericLabels = TRUE, pamRespectsDendro = FALSE, saveTOMs = TRUE, saveTOMFileBase = "femaleMouseTOM", verbose = 3) ``` -------------------------------- ### Prepare Marker Genes and Generate Plots (R) Source: https://junjunlab.github.io/ClusterGvis-manual/add-custom-annotation.html This R code snippet identifies marker genes for each cluster in a Seurat object, prepares the data, and generates plots for each cluster using Seurat's FeaturePlot. These plots are then stored in a list for later use. ```R pbmc.markers.all <- Seurat::FindAllMarkers(pbmc, only.pos = TRUE, min.pct = 0.25, logfc.threshold = 0.25) pbmc.markers <- pbmc.markers.all %>% dplyr::group_by(cluster) %>% dplyr::top_n(n = 4, wt = avg_log2FC) st.data <- prepareDataFromscRNA(object = pbmc, diffData = pbmc.markers, showAverage = TRUE) lapply(unique(pbmc.markers$cluster), function(x){ tmp <- pbmc.markers |> dplyr::filter(cluster == x) p <- Seurat::FeaturePlot(object = pbmc, features = tmp$gene, ncol = 4) return(p) }) -> gglist names(gglist) <- paste("C",1:9,sep = "") ``` -------------------------------- ### Generate Heatmap Visualization Source: https://junjunlab.github.io/ClusterGvis-manual/parse-wgcna-output.html Creates a PDF file containing a heatmap of gene expression clusters. The function uses the previously defined markGenes to annotate specific genes within the heatmap. ```R pdf('netht.pdf',height = 10,width = 6,onefile = F) visCluster(object = cw, plotType = "heatmap", markGenes = markGenes) dev.off() ``` -------------------------------- ### Data Preparation and Sample Clustering for WGCNA Source: https://junjunlab.github.io/ClusterGvis-manual/parse-wgcna-output.html This R code prepares gene expression data for WGCNA analysis by transposing and cleaning the expression matrix. It then performs sample clustering using hierarchical clustering to identify and remove outliers. The code includes steps for quality control, plotting the sample dendrogram, and cutting the tree to select samples for downstream analysis. ```R datExpr0 = as.data.frame(t(femData[, -c(1:8)])); names(datExpr0) = femData$substanceBXH; rownames(datExpr0) = names(femData)[-c(1:8)]; gsg = goodSamplesGenes(datExpr0, verbose = 3); gsg$allOK if (!gsg$allOK) { # Optionally, print the gene and sample names that were removed: if (sum(!gsg$goodGenes)>0) printFlush(paste("Removing genes:", paste(names(datExpr0)[!gsg$goodGenes], collapse = ", ")))); if (sum(!gsg$goodSamples)>0) printFlush(paste("Removing samples:", paste(rownames(datExpr0)[!gsg$goodSamples], collapse = ", ")))); # Remove the offending genes and samples from the data: datExpr0 = datExpr0[gsg$goodSamples, gsg$goodGenes] } sampleTree = hclust(dist(datExpr0), method = "average"); # Plot the sample tree: Open a graphic output window of size 12 by 9 inches # The user should change the dimensions if the window is too large or too small. sizeGrWindow(12,9) #pdf(file = "Plots/sampleClustering.pdf", width = 12, height = 9); par(cex = 0.6); par(mar = c(0,4,2,0)) plot(sampleTree, main = "Sample clustering to detect outliers", sub="", xlab="", cex.lab = 1.5, cex.axis = 1.5, cex.main = 2) # Plot a line to show the cut abline(h = 15, col = "red"); # Determine cluster under the line clust = cutreeStatic(sampleTree, cutHeight = 15, minSize = 10) table(clust) # clust 1 contains the samples we want to keep. keepSamples = (clust==1) datExpr = datExpr0[keepSamples, ] ``` -------------------------------- ### POST /visCluster/heatmap Source: https://junjunlab.github.io/ClusterGvis-manual/basic-usage.html Configures and generates a heatmap visualization with custom row annotations using ComplexHeatmap objects. ```APIDOC ## POST /visCluster/heatmap ### Description Generates a heatmap visualization for clustered gene expression data, allowing for the integration of row annotations like barplots or text labels. ### Method POST ### Endpoint /visCluster/heatmap ### Parameters #### Request Body - **object** (object) - Required - The clustered data object (e.g., ck or ct). - **plotType** (string) - Required - Set to "heatmap" or "both". - **rowAnnotationObj** (object) - Optional - A ComplexHeatmap::rowAnnotation object for adding metadata. - **column_names_rot** (integer) - Optional - Rotation angle for column labels. ### Request Example { "object": "ct", "plotType": "heatmap", "column_names_rot": 45 } ### Response #### Success Response (200) - **plot** (file) - Returns a rendered heatmap visualization. ``` -------------------------------- ### Generate Line Plot Visualization Source: https://junjunlab.github.io/ClusterGvis-manual/parse-single-cell-data.html Creates a line plot visualization for clustered data, useful for observing expression trends across clusters. ```R visCluster(object = st.data, plotType = "line") ``` -------------------------------- ### Parsing WGCNA Output with ClusterGvis Source: https://junjunlab.github.io/ClusterGvis-manual/parse-wgcna-output.html This R code demonstrates how to use the `clusterData` function from ClusterGvis to parse WGCNA output. It first transposes the expression data ('exps') and then passes it along with the WGCNA network object ('net') to `clusterData` specifying 'wgcna' as the clustering method. The function returns a list containing processed data suitable for visualization. ```R expt <- t(exps) # get data cw <- clusterData(obj = expt, clusterMethod = "wgcna", object = net) str(cw) ``` -------------------------------- ### Multiple Group Line Plot in Heatmap using visCluster Source: https://junjunlab.github.io/ClusterGvis-manual/basic-usage.html Demonstrates how to create line annotations across multiple groups within a heatmap using the 'mulGroup' parameter in visCluster. This is useful for comparing expression tendencies across different conditions. ```R # multiple groups pdf('termlftsmp.pdf',height = 10,width = 11,onefile = F) visCluster(object = ck, plotType = "both", column_names_rot = 45, show_row_dend = F, markGenes = markGenes, markGenesSide = "left", genesGp = c('italic',fontsize = 12,col = "black"), annoTermData = termanno2, lineSide = "left", goCol = rep(ggsci::pal_d3()(8),each = 3), goSize = "pval", mulGroup = c(2,2,2), mlineCol = c(ggsci::pal_lancet()(3))) dev.off() ``` -------------------------------- ### Add Boxplot and Points to Heatmap using visCluster Source: https://junjunlab.github.io/ClusterGvis-manual/basic-usage.html Shows how to incorporate boxplots and points into the heatmap visualization using visCluster. Includes options to customize boxplot colors and to disable line plots. ```R # add boxplot pdf('testbx.pdf',height = 10,width = 6) visCluster(object = ck, plotType = "both", column_names_rot = 45, addBox = T) dev.off() ``` ```R # remove line and change box fill color pdf('testbxcol.pdf',height = 10,width = 6) visCluster(object = ck, plotType = "both", column_names_rot = 45, addBox = T, addLine = F, boxCol = ggsci::pal_npg()(8)) dev.off() ``` ```R # add point pdf('testbxcolP.pdf',height = 10,width = 6) visCluster(object = ck, plotType = "both", column_names_rot = 45, addBox = T, addLine = F, boxCol = ggsci::pal_npg()(8), addPoint = T) dev.off() ``` -------------------------------- ### Add Line Annotation to Heatmap using visCluster Source: https://junjunlab.github.io/ClusterGvis-manual/basic-usage.html Illustrates how to add line annotations to a heatmap, typically used for visualizing expression tendencies across sub-clusters. It emphasizes saving the plot as a PDF for accurate viewing of annotations. ```R pdf('addgene.pdf',height = 6,width = 6,onefile = F) visCluster(object = ct, plotType = "both", column_names_rot = 45, rowAnnotationObj = left_annotation) dev.off() ``` ```R pdf('addgene2.pdf',height = 6,width = 6,onefile = F) visCluster(object = ct, plotType = "both", column_names_rot = 45, rowAnnotationObj = row_annotation_obj, lineSide = "left") dev.off() ``` ```R # add line annotation pdf('testHT.pdf',height = 10,width = 6) visCluster(object = ck, plotType = "both", column_names_rot = 45) dev.off() ``` -------------------------------- ### Visualize Pseudotime Heatmap with ClusterGVis (Monocle2) Source: https://junjunlab.github.io/ClusterGvis-manual/parse-preudotime-data.html Generates a heatmap visualization of pseudotime data using the modified plot_pseudotime_heatmap2 function. It can return either the heatmap plot directly or a list object containing clustered data for further analysis with visCluster. ```R # return plot plot_pseudotime_heatmap2(HSMM, num_clusters = 4, cores = 1, show_rownames = T, return_heatmap = T) ``` ```R # test code df <- plot_pseudotime_heatmap2(HSMM, num_clusters = 4, cores = 1) # check data str(df) # List of 6 # $ wide.res :'data.frame': 100 obs. of 102 variables: # ..$ gene : chr [1:100] "TSPAN6" "C1orf112" "CYP51A1" "AK2" ... # ..$ 1 : num [1:100] -1.573 2.783 -1.646 -0.566 2.264 ... # ..$ 2 : num [1:100] -1.55 2.65 -1.62 -0.57 2.19 ... # ..$ 3 : num [1:100] -1.524 2.517 -1.587 -0.575 2.118 ... # ... # ..$ 96 : num [1:100] 0.48 -1.421 0.363 2.647 -1.753 ... # ..$ 97 : num [1:100] 0.34 -1.46 0.21 2.86 -1.94 ... # ..$ 98 : num [1:100] 0.1988 -1.4958 0.0542 3 -2.1274 ... # .. [list output truncated] # $ long.res :'data.frame': 10000 obs. of 5 variables: # ..$ cluster : Factor w/ 4 levels "1","2","3","4": 1 1 1 1 1 1 1 1 1 1 ... # ..$ gene : chr [1:10000] "TSPAN6" "CYP51A1" "AASS" "MGST1" ... # ..$ cell_type : num [1:10000] 1 1 1 1 1 1 1 1 1 1 ... # ..$ norm_value : num [1:10000] -1.573 -1.646 -1.86 -0.457 -2.024 ... # ..$ cluster_name: Factor w/ 4 levels "cluster 1 (14)",..: 1 1 1 1 1 1 1 1 1 1 ... # $ type : chr "monocle" # $ geneMode : chr "all" # $ geneType : chr "non-branched" # $ pseudotime: num [1:100] 0 0.236 0.471 0.707 0.942 ... ``` -------------------------------- ### Visualize Gene Clusters with Line Plots Source: https://junjunlab.github.io/ClusterGvis-manual/parse-wgcna-output.html Generates a line plot visualization for gene expression clusters. It selects a random subset of genes to label and uses the visCluster function to render the plot. ```R markGenes = rownames(exps)[sample(1:nrow(exps),30,replace = F)] visCluster(object = cw, plotType = "line", ncol = 3) ``` -------------------------------- ### Line Plot Visualization with visCluster Source: https://junjunlab.github.io/ClusterGvis-manual/basic-usage.html Generates a line plot from cluster data. Supports customization of line colors and the addition or removal of a median line. Accepts results from clusterData. ```R # plot line only visCluster(object = cm, plotType = "line") ``` ```R # change color visCluster(object = cm, plotType = "line", msCol = c("green","orange","red")) ``` ```R # remove meadian line visCluster(object = cm, plotType = "line", msCol = c("green","orange","red"), addMline = FALSE) ``` ```R # plot line only with kmeans method visCluster(object = ck, plotType = "line") ``` -------------------------------- ### POST /visCluster/trend-analysis Source: https://junjunlab.github.io/ClusterGvis-manual/basic-usage.html Generates visualizations including trend lines, boxplots, and multi-group comparisons for gene expression clusters. ```APIDOC ## POST /visCluster/trend-analysis ### Description Adds statistical annotations such as boxplots, trend lines, and multi-group comparison lines to the cluster visualization. ### Method POST ### Endpoint /visCluster/trend-analysis ### Parameters #### Request Body - **addBox** (boolean) - Optional - Whether to display boxplots. - **addLine** (boolean) - Optional - Whether to display trend lines. - **addPoint** (boolean) - Optional - Whether to display individual data points. - **mulGroup** (vector) - Optional - Defines grouping for multi-group line plots. - **boxCol** (vector) - Optional - Color palette for boxplot fills. ### Request Example { "object": "ck", "plotType": "both", "addBox": true, "addLine": false, "addPoint": true } ### Response #### Success Response (200) - **plot** (file) - Returns a rendered visualization with trend annotations. ``` -------------------------------- ### POST /visCluster Source: https://junjunlab.github.io/ClusterGvis-manual/parse-preudotime-data.html Visualizes gene expression clusters using heatmaps and line annotations. ```APIDOC ## POST /visCluster ### Description Generates a heatmap and/or line plot to visualize gene expression patterns across clusters. ### Method POST ### Endpoint /visCluster ### Parameters #### Request Body - **object** (data.frame) - Required - The data object containing cluster results. - **plotType** (string) - Required - Type of plot: 'heatmap' or 'both'. - **htColList** (list) - Optional - Custom color configuration for the heatmap. - **pseudotime_col** (vector) - Optional - Color palette for pseudotime annotation. ### Request Example { "object": "df", "plotType": "both" } ### Response #### Success Response (200) - **plot** (image/pdf) - The generated visualization. ``` -------------------------------- ### Visualize Pseudotime Data with visCluster Source: https://junjunlab.github.io/ClusterGvis-manual/parse-preudotime-data.html Visualizes the clustered pseudotime data obtained from ClusterGVis functions. Supports different plot types like 'line' and 'heatmap', and allows for marking specific genes. ```R # plot visCluster(object = df,plotType = "line") ``` ```R visCluster(object = df,plotType = "heatmap") ``` ```R gene = sample(df$wide.res$gene,20,replace = F) pdf(file = "one-branch.pdf",height = 6,width = 7) visCluster(object = df, plotType = "both", markGenes = gene) dev.off() ``` -------------------------------- ### Row Annotation in Heatmaps with visCluster Source: https://junjunlab.github.io/ClusterGvis-manual/basic-usage.html Demonstrates adding row annotations to heatmaps using the `row_annotation_obj` parameter. Requires gene order to match the clustered order when using ComplexHeatmap::rowAnnotation. ```R library(ClusterGVis) library(ComplexHeatmap) # load data data(exps) # using TCseq for clustering ct <- clusterData(obj = exps[1:20,], clusterMethod = "TCseq", clusterNum = 2) visCluster(object = ct, plotType = "heatmap", column_names_rot = 45) ``` ```R df <- ct$wide.res %>% dplyr::arrange(cluster) l_ano <- rep(LETTERS[1:3],c(6,4,10)) names(l_ano) <- df$gene l_ano ``` -------------------------------- ### Prepare Data Without Averaging Cells Source: https://junjunlab.github.io/ClusterGvis-manual/parse-single-cell-data.html Prepares data for visualization without averaging expression across cells, allowing for high-resolution analysis of specific top-ranked genes. ```R pbmc.markers1 <- pbmc.markers.all %>% dplyr::group_by(cluster) %>% dplyr::top_n(n = 6, wt = avg_log2FC) st.data <- prepareDataFromscRNA(object = pbmc, diffData = pbmc.markers1, showAverage = FALSE) str(st.data) ``` -------------------------------- ### Inspect Cluster Data Structure in R Source: https://junjunlab.github.io/ClusterGvis-manual/basic-usage.html Shows the detailed structure of the clustering results obtained from the clusterData function, specifically for the 'mfuzz' and 'kmeans' methods. It illustrates the 'wide.res' (gene-wise expression and cluster assignment) and 'long.res' (long format with normalized values) data frames, along with method-specific attributes. ```R str(cm) # List of 5 # $ wide.res:'data.frame': 3767 obs. of 9 variables: # ..$ gene : chr [1:3767] "0610037L13Rik" "1110020G09Rik" "1110065P20Rik" "2010106G01Rik" ... # ..$ zygote : num [1:3767] 0.255 -1.193 0.477 0.537 -1.395 ... # ..$ t2.cell : num [1:3767] 0.608 0.347 0.121 0.15 0.387 ... # ..$ t4.cell : num [1:3767] 0.708 0.113 -0.114 0.588 0.516 ... # ..$ t8.cell : num [1:3767] 0.589 1.418 1.272 0.888 1.383 ... # ..$ tmorula : num [1:3767] -0.2467 0.4319 0.0123 -0.3015 -0.8505 ... # ..$ blastocyst: num [1:3767] -1.9124 -1.1167 -1.7682 -1.8611 -0.0408 ... # ..$ cluster : num [1:3767] 1 1 1 1 1 1 1 1 1 1 ... # ..$ membership: num [1:3767] 0.765 0.437 0.581 0.66 0.206 ... # $ long.res:'data.frame': 22602 obs. of 6 variables: # ..$ cluster : num [1:22602] 1 1 1 1 1 1 1 1 1 1 ... # ..$ gene : chr [1:22602] "0610037L13Rik" "1110020G09Rik" "1110065P20Rik" "2010106G01Rik" ... # ..$ membership : num [1:22602] 0.765 0.437 0.581 0.66 0.206 ... # ..$ cell_type : Factor w/ 6 levels "zygote","t2.cell",..: 1 1 1 1 1 1 1 1 1 1 ... # ..$ norm_value : num [1:22602] 0.255 -1.193 0.477 0.537 -1.395 ... # ..$ cluster_name: Factor w/ 8 levels "cluster 1 (381)",..: 1 1 1 1 1 1 1 1 1 1 ... # $ type : chr "mfuzz" # $ geneMode: chr "none" # $ geneType: chr "none" str(ck) # List of 5 # $ wide.res:'data.frame': 3767 obs. of 8 variables: # ..$ zygote : num [1:3767] -1.189 -0.993 -1.095 -0.772 -0.683 ... # ..$ t2.cell : num [1:3767] 1.177 0.936 1.027 1.075 1.11 ... # ..$ t4.cell : num [1:3767] 0.126 0.561 0.484 0.397 0.337 ... # ..$ t8.cell : num [1:3767] 0.1831 0.2203 0.0516 -0.1314 -0.0698 ... # ..$ tmorula : num [1:3767] -1.17 -1.48 -1.33 -1.49 -1.56 ... # ..$ blastocyst: num [1:3767] 0.878 0.758 0.861 0.923 0.865 ... # ..$ gene : chr [1:3767] "Pdlim1" "Zp3" "Crk" "Ndufaf4" ... # ..$ cluster : num [1:3767] 1 1 1 1 1 1 1 1 1 1 ... # $ long.res:'data.frame': 22602 obs. of 5 variables: # ..$ cluster : num [1:22602] 1 1 1 1 1 1 1 1 1 1 ... # ..$ gene : chr [1:22602] "Pdlim1" "Zp3" "Crk" "Ndufaf4" ... # ..$ cell_type : Factor w/ 6 levels "zygote","t2.cell",..: 1 1 1 1 1 1 1 1 1 1 ... # ..$ norm_value : num [1:22602] -1.189 -0.993 -1.095 -0.772 -0.683 ... # ..$ cluster_name: Factor w/ 8 levels "cluster 1 (134)",..: 1 1 1 1 1 1 1 1 1 1 ... # $ type : chr "kmeans" # $ geneMode: chr "none" # $ geneType: chr "none" ``` -------------------------------- ### Add Enrichment Barplots to Cluster Visualization Source: https://junjunlab.github.io/ClusterGvis-manual/enrichment-anaysis.html Shows how to integrate barplots into the cluster visualization, including options to change the side of the annotation and adjust the position of text labels within the bars. ```R pdf('bar.pdf',height = 10,width = 12,onefile = F) visCluster(object = cm, plotType = "both", column_names_rot = 45, show_row_dend = F, markGenes = markGenes, markGenesSide = "left", genesGp = c('italic',fontsize = 12,col = "black"), annoTermData = enrich, lineSide = "left", goCol = rep(ggsci::pal_d3()(8),each = 5), goSize = "pval", addBar = T) dev.off() ``` -------------------------------- ### POST /plot_multiple_branches_heatmap2 Source: https://junjunlab.github.io/ClusterGvis-manual/parse-preudotime-data.html Extracts and visualizes gene expression data across multiple branches of a trajectory. ```APIDOC ## POST /plot_multiple_branches_heatmap2 ### Description Processes Monocle trajectory data to extract branched gene expression patterns and optionally returns a heatmap. ### Method POST ### Endpoint /plot_multiple_branches_heatmap2 ### Parameters #### Request Body - **HSMM** (object) - Required - The Monocle object. - **branches** (vector) - Required - List of branch IDs to include. - **num_clusters** (integer) - Required - Number of clusters to identify. - **return_heatmap** (boolean) - Optional - Whether to return the plot object directly. ### Request Example { "branches": [1, 3, 4, 5], "num_clusters": 4, "return_heatmap": true } ### Response #### Success Response (200) - **data** (list) - Contains wide and long format expression data, cluster assignments, and pseudotime info. ``` -------------------------------- ### plot_pseudotime_heatmap2 Source: https://junjunlab.github.io/ClusterGvis-manual/parse-preudotime-data.html Visualizes pseudotime data from Monocle2 objects and returns either a heatmap or a structured list object for further visualization with visCluster. ```APIDOC ## plot_pseudotime_heatmap2 ### Description Generates a heatmap for pseudotime data or returns a list object containing clustered data for downstream analysis. ### Parameters #### Arguments - **HSMM** (object) - Required - The Monocle2 object. - **num_clusters** (integer) - Required - Number of clusters to identify. - **cores** (integer) - Optional - Number of CPU cores to use. - **return_heatmap** (boolean) - Optional - If TRUE, returns the plot object; otherwise returns a data list. ### Request Example plot_pseudotime_heatmap2(HSMM, num_clusters = 4, cores = 1, return_heatmap = T) ### Response #### Success Response (200) - **wide.res** (data.frame) - Wide format expression data. - **long.res** (data.frame) - Long format expression data for plotting. - **type** (string) - Data type identifier ('monocle'). ``` -------------------------------- ### Initialize Monocle3 Dataset and Identify Modulated Genes Source: https://junjunlab.github.io/ClusterGvis-manual/parse-preudotime-data.html Loads cell metadata, gene metadata, and expression matrices to create a cell_data_set object. It performs preprocessing, dimension reduction, clustering, and trajectory inference to identify genes with significant expression changes. ```R library(monocle3) library(dplyr) cell_metadata <- readRDS(system.file('extdata', 'worm_embryo/worm_embryo_coldata.rds', package='monocle3')) gene_metadata <- readRDS(system.file('extdata', 'worm_embryo/worm_embryo_rowdata.rds', package='monocle3')) expression_matrix <- readRDS(system.file('extdata', 'worm_embryo/worm_embryo_expression_matrix.rds', package='monocle3')) cds <- new_cell_data_set(expression_data=expression_matrix, cell_metadata=cell_metadata, gene_metadata=gene_metadata) cds <- preprocess_cds(cds) cds <- align_cds(cds, alignment_group = "batch", residual_model_formula_str = "~ bg.300.loading + bg.400.loading + bg.500.1.loading + bg.500.2.loading + bg.r17.loading + bg.b01.loading + bg.b02.loading") cds <- reduce_dimension(cds) cds <- cluster_cells(cds) cds <- learn_graph(cds) cds <- order_cells(cds, root_pr_nodes='Y_21') modulated_genes <- graph_test(cds, neighbor_graph = "principal_graph", cores = 4) genes <- row.names(subset(modulated_genes, q_value == 0 & morans_I > 0.25)) ```