From 17ae657fdfc35865bc080102e4b4e8d44e66b739 Mon Sep 17 00:00:00 2001 From: Ivo Kwee Date: Fri, 21 Nov 2025 18:13:31 +0100 Subject: [PATCH] Add fc_threshold parameter to cnetplot for filtering genes by fold change MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add new fc_threshold parameter that filters genes to only include those with absolute fold change greater than the threshold. This allows users to plot only genes with |foldChange| > fc_threshold (e.g., fc_threshold = 1). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- R/cnetplot.R | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/R/cnetplot.R b/R/cnetplot.R index 3df71ea..22192ea 100644 --- a/R/cnetplot.R +++ b/R/cnetplot.R @@ -13,6 +13,7 @@ #' @param size_edge relative size of edge #' @param node_label one of 'all', 'none', 'category', 'item', 'exclusive' or 'share' #' @param foldChange numeric values to color the item (e.g, foldChange of gene expression values) +#' @param fc_threshold threshold for filtering genes by absolute fold change (e.g., fc_threshold = 1 keeps only genes with |foldChange| > 1) #' @param hilight selected category to be highlighted #' @param hilight_alpha transparent value for not selected to be highlight #' @param ... additional parameters @@ -33,6 +34,7 @@ cnetplot.enrichResult <- function( size_edge = .5, node_label = "all", foldChange = NULL, + fc_threshold = NULL, hilight = "none", hilight_alpha = .3, ... @@ -40,6 +42,17 @@ cnetplot.enrichResult <- function( geneSets <- extract_geneSets(x, showCategory) foldChange <- fc_readable(x, foldChange) + # Filter genes by absolute fold change threshold + if (!is.null(fc_threshold) && !is.null(foldChange)) { + keep_genes <- names(foldChange)[abs(foldChange) > fc_threshold] + foldChange <- foldChange[keep_genes] + geneSets <- lapply(geneSets, function(gs) { + intersect(gs, keep_genes) + }) + # Remove empty gene sets + geneSets <- geneSets[sapply(geneSets, length) > 0] + } + p <- cnetplot( geneSets, layout = layout,