-
Notifications
You must be signed in to change notification settings - Fork 102
Description
Issue
If the aggregateNet function is used with targets.use or sources.use, then netVisual_circle returns an error for me:
Error in i_set_vertex_attr(x, attr(value, "name"), index = value, value = attr(value, :
Length of new attribute value must be 1 or 0, the number of target vertices, not 5
Reproducible example
I can reproduce this using a basic example with the 10X PBMC data (available from link in first paragraph here: https://satijalab.org/seurat/articles/pbmc3k_tutorial)
#Testing bug
#Packages and functions
library(Seurat)
library(CellChat)
set.seed(151)
#Load in 10x pbmc data
pbmc.data <- Read10X(data.dir = "~/Downloads/filtered_gene_bc_matrices/hg19/")
pbmc <- CreateSeuratObject(counts = pbmc.data, project = "pbmc3k", min.cells = 3, min.features = 200)
#Standard seurat preprocessing (skipping some steps)
pbmc <- subset(pbmc, subset = nFeature_RNA > 200 & nFeature_RNA < 2500)
pbmc <- NormalizeData(pbmc)
pbmc <- FindVariableFeatures(pbmc, selection.method = "vst", nfeatures = 2000)
pbmc <- ScaleData(pbmc, features = rownames(pbmc))
pbmc <- RunPCA(pbmc, features = VariableFeatures(object = pbmc))
pbmc <- FindNeighbors(pbmc, dims = 1:10)
pbmc <- FindClusters(pbmc, resolution = 0.5)
pbmc <- RunUMAP(pbmc, dims = 1:10)
DimPlot(pbmc, reduction = "umap", label = TRUE)
#Label random cell names for example
pbmc[[]] <- pbmc[[]] %>% mutate(fake_celltypes = case_when(seurat_clusters %in% c(4,6) ~ 'NK Cells',
seurat_clusters %in% c(2,0) ~ 'T Cells' ,
seurat_clusters %in% c(3) ~ 'Macropahges',
seurat_clusters %in% c(1,5,7) ~ 'Endothelial',
seurat_clusters %in% c(8) ~ 'Neutrophils'))
#Create cellchat object from seurat object
cellchat <- createCellChat(object = pbmc, group.by = "fake_celltypes", assay = 'RNA')
cellchat <- setIdent(cellchat, ident.use = "fake_celltypes")
levels(cellchat@idents)
# Initialize database
CellChatDB <- CellChatDB.human
showDatabaseCategory(CellChatDB)
cellchat@DB <- CellChatDB
#Preprocess expression data
cellchat <- subsetData(cellchat) # This step is necessary even if using the whole database
future::plan("multisession", workers = 1) # doing in parellel leads to memory issues a few lines down. so 1 for now
cellchat <- identifyOverExpressedGenes(cellchat)
#Need to allow greater ram usage to run pca integration
cellchat <- identifyOverExpressedInteractions(cellchat)
#Compute the communication probability - pretty slow step, takes around 10 mins on laptop
cellchat <- computeCommunProb(cellchat, type = "triMean")
#Infer pathway level
cellchat <- computeCommunProbPathway(cellchat)
#Look at specific cell type interactions
cellchat_NK <- aggregateNet(cellchat, targets.use = "NK Cells")
groupSize <- as.numeric(table(cellchat_NK@idents))
#ERROR HERE
netVisual_circle(cellchat_NK@net$count, vertex.weight = groupSize, weight.scale = T, label.edge= F, title.name = "Number of interactions")
Possible solution
I believe the problem is in line 424 of the modeling.R script, where
a <- stringr::str_split(df.net2$source_target, "|", simplify = T) splits the source/target column into characters rather than keeping the two cell types as strings.
Could possible be fixed with something like
a <- stringr::str_split_fixed(df.net2$source_target, "\\|", n = 2) instead.
I have not explored this issue enough to actually submit a PR, but possibly an easy fix. Thanks for any help!
(relevant package versions:
Seurat_5.3.0
SeuratObject_5.1.0
CellChat_2.2.0.9001)