Skip to contents

For each cell type in a network result list, this function creates a multi-panel word cloud figure where each panel represents one Leiden cluster. GO term labels are sized by their network degree (optionally weighted by absolute log2 fold-change) and semantically similar terms are merged via hierarchical clustering on Jaccard distance of constituent words. The combined figure is saved as a PNG file.

Usage

write_cluster_wordclouds_patchwork(
  net_list,
  outputDir,
  comparison = "CD206_Car_vs_Bleo",
  min_terms = 5,
  max_terms = 50,
  use_logfc_weight = FALSE,
  ncol = 3,
  merge_similarity = 0.6
)

Arguments

net_list

A named list of network result lists, one per cell type. Each element must be a list containing at least go_term_df (a data frame with columns go_term, cluster, degree, and avg_log2FC), as returned by generate_overlap_network.

outputDir

Character path to the root output directory. Word cloud PNGs are saved to <outputDir>/<comparison>/networks/.

comparison

Character string identifying the comparison (e.g., "CD206_Car_vs_Bleo"). Used to construct the output sub-directory.

min_terms

Integer. Minimum number of (post-merge) GO term phrases required to generate a word cloud for a cluster. Clusters with fewer terms are skipped. Default 5.

max_terms

Integer. Maximum number of GO term phrases to include per cluster word cloud (after sorting by weight). Default 50.

use_logfc_weight

Logical. If TRUE, term weights are scaled by 1 + abs(avg_log2FC), emphasizing terms backed by larger fold- changes. Default FALSE.

ncol

Integer. Number of columns in the patchwork grid layout. Default 3.

merge_similarity

Numeric [0, 1] or NULL. Jaccard- distance threshold for merging semantically similar GO term labels. A value of 0.6 means terms sharing >= 40\ (the most frequent label is kept and frequencies are summed). Set to NULL to disable merging. Default 0.6.

Value

Called for its side effect (writing PNG files). Returns invisible(NULL).

Output files

One PNG per cell type: <outputDir>/<comparison>/networks/<celltype>_all_clusters_wordclouds.png