Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

Add seed to netEmbedding function #679

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ycl6
Copy link

@ycl6 ycl6 commented Sep 1, 2023

The PR adds a seed paramter to the netEmbedding function to allow generating reproducible UMAPs, as requested in #155, #196 and #435. This works on both umap-learn and uwot methods. The default setting is seed = 42. One can use seed = NULL to reset and produce a different set of embeddings.

Below is an example running using the uwot method.

library(CellChat)

####################
# load data
####################
load("data_humanSkin_CellChat.rda")
data.input = data_humanSkin$data
meta = data_humanSkin$meta
cell.use = rownames(meta)[meta$condition == "LS"]
data.input = data.input[, cell.use]
meta = meta[cell.use, ]

####################
# Create a CellChat object
####################
cellchat <- createCellChat(object = data.input, meta = meta, group.by = "labels")
#> [1] "Create a CellChat object from a data matrix"
#> Set cell identities for the new CellChat object 
#> The cell groups used for CellChat analysis are  APOE+ FIB FBN1+ FIB COL11A1+ FIB Inflam. FIB cDC1 cDC2 LC Inflam. DC TC Inflam. TC CD40LG+ TC NKT
cellchat <- addMeta(cellchat, meta = meta)
cellchat <- setIdent(cellchat, ident.use = "labels")

####################
# Set the ligand-receptor interaction database
####################
CellChatDB <- CellChatDB.human
CellChatDB.use <- subsetDB(CellChatDB, search = "Secreted Signaling")
cellchat@DB <- CellChatDB.use

####################
# Preprocessing the expression data
####################
cellchat <- subsetData(cellchat)
cellchat <- identifyOverExpressedGenes(cellchat)
cellchat <- identifyOverExpressedInteractions(cellchat)

####################
# Inference of cell-cell communication network
####################
cellchat <- computeCommunProb(cellchat)
#> triMean is used for calculating the average gene expression per cell group. 
#> [1] ">>> Run CellChat on sc/snRNA-seq data <<< [2023-09-01 17:16:25]"
#> [1] ">>> CellChat inference is done. Parameter values are stored in `object@options$parameter` <<< [2023-09-01 17:17:47]"
cellchat <- computeCommunProbPathway(cellchat)
cellchat <- aggregateNet(cellchat)

####################
# Visulaise manifold of signaling networks
####################

# seed = 1
cellchat <- computeNetSimilarity(cellchat, type = "functional")
cellchat <- netEmbedding(cellchat, type = "functional", umap.method = "uwot", seed = 1)
#> Manifold learning of the signaling networks for a single dataset
cellchat <- netClustering(cellchat, type = "functional", do.parallel = FALSE)
#> Classification learning of the signaling networks for a single dataset
netVisual_embedding(cellchat, type = "functional", label.size = 3.5)

# re-run seed = 1
cellchat <- computeNetSimilarity(cellchat, type = "functional")
cellchat <- netEmbedding(cellchat, type = "functional", umap.method = "uwot", seed = 1)
#> Manifold learning of the signaling networks for a single dataset
cellchat <- netClustering(cellchat, type = "functional", do.parallel = FALSE)
#> Classification learning of the signaling networks for a single dataset
netVisual_embedding(cellchat, type = "functional", label.size = 3.5)

# seed = NULL
cellchat <- computeNetSimilarity(cellchat, type = "functional")
cellchat <- netEmbedding(cellchat, type = "functional", umap.method = "uwot", seed = NULL)
#> Manifold learning of the signaling networks for a single dataset
cellchat <- netClustering(cellchat, type = "functional", do.parallel = FALSE)
#> Classification learning of the signaling networks for a single dataset
netVisual_embedding(cellchat, type = "functional", label.size = 3.5)

# re-run seed = NULL
cellchat <- computeNetSimilarity(cellchat, type = "functional")
cellchat <- netEmbedding(cellchat, type = "functional", umap.method = "uwot", seed = NULL)
#> Manifold learning of the signaling networks for a single dataset
cellchat <- netClustering(cellchat, type = "functional", do.parallel = FALSE)
#> Classification learning of the signaling networks for a single dataset
netVisual_embedding(cellchat, type = "functional", label.size = 3.5)

Created on 2023-09-01 with reprex v2.0.2

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant