
Rename a cell type label inside a CellChat object without re-running analysis
RenameCellTypeInCC.RdPatches 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.
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.