Skip to contents

Patches every slot that carries cell-type names (idents, meta, net arrays, netP arrays, centrality scores, pattern tables, LR significant pairs) so that downstream visualization functions and CompareCellChat / RankCellChatPathways see the new name.

Usage

RenameCellTypeInCC(cc, old_name, new_name)

Arguments

cc

A CellChat object.

old_name

Character. The cell type label to replace.

new_name

Character. The replacement label.

Value

The modified CellChat object (the original is not changed in place - assign the result back).

Details

The communication probability matrices are not recomputed - only labels change. This is safe because the underlying values are invariant to what the cell type is called.

Typical workflow after renaming:

# 1. Patch and re-save all RDS files
rds_files <- list.files("CellChatObjects/", "CellChat\\.rds$", full.names = TRUE)
for (f in rds_files) {
  cc <- RenameCellTypeInCC(readRDS(f), "Immune_contam", "NK_TCells")
  saveRDS(cc, f)
}

# 2. Re-run comparison figures (fast - pure plotting)
cclist <- setNames(lapply(rds_files, readRDS),
                   sub("CellChat\\.rds$", "", basename(rds_files)))
CompareCellChat(cclist, output_dir = ...)
RankCellChatPathways(cclist, output_dir = ...)

# 3. Per-group RunCellChat PDFs: delete old PDFs and re-run RunCellChat with
#    resume = TRUE - the pipeline checkpoint means only plots are regenerated.