Closed dbswls0322 closed 1 year ago
Thanks. Is this linked to https://github.com/sqjin/CellChat/issues/547?
We believe that the code in the CellChat package has a subtle problem that is uncovered with recent changes in igraph 1.4.1. This issue should be fixed in the CellChat package.
To help, we need a fully reproducible example. What code do I need to run, on my machine, to see the problem you are seeing with the CellChat package and igraph 1.4.1? See https://reprex.tidyverse.org/articles/reprex-dos-and-donts.html and https://reprex.tidyverse.org/ for advice on creating a good reproducible example.
Thank you for reply.
Here is my code.
mat <- Cellchat@net$weight par(mfrow = c(2,4), xpd=TRUE) for (i in 1:nrow(mat)) { mat2 <- matrix(0, nrow = nrow(mat), ncol = ncol(mat), dimnames = dimnames(mat)) mat2[i, ] <- mat[i, ] netVisual_circle(mat2, vertex.weight = groupSize, weight.scale = T, edge.weight.max = max(mat), title.name = rownames(mat)[i]) }
and this is my error
Error in i_set_edge_attr(x, attr(value, "name"), index = value, value = attr(value, : Length of new attribute value must be 1 or 4, the number of target edges, not 2
Actually I just followed the tutorial served by cellchat's github. So every process is same with cellchat's tutorial. And It was available about 6months ago.
Also I can run this code. par(mfrow = c(1,2), xpd=TRUE) netVisual_circle(Cellchat@net$count, vertex.weight = groupSize, weight.scale = T, label.edge= F, title.name = "Number of interactions") netVisual_circle(Cellchat@net$weight, vertex.weight = groupSize, weight.scale = T, label.edge= F, title.name = "Interaction weights/strength")
But except for this code, nothing can be ran.
I hope it'll be helpful for you guys. If you need more information, please let me know.
Regardless.
Thanks. When I run your code on my machine, I get:
mat <- Cellchat@net$weight
#> Error in eval(expr, envir, enclos): object 'Cellchat' not found
par(mfrow = c(2, 4), xpd = TRUE)
for (i in 1:nrow(mat)) {
mat2 <- matrix(0, nrow = nrow(mat), ncol = ncol(mat), dimnames = dimnames(mat))
mat2[i, ] <- mat[i, ]
netVisual_circle(mat2, vertex.weight = groupSize, weight.scale = T, edge.weight.max = max(mat), title.name = rownames(mat)[i])
}
#> Error in nrow(mat): object 'mat' not found
Created on 2023-03-02 with reprex v2.0.2
What packages and what datasets do I need? Please take a look at https://reprex.tidyverse.org/articles/reprex-dos-and-donts.html.
Oh, I'll send you the code how to make cellchat object.
If you follow this direction, you can run that code.
library(CellChat) library(patchwork) options(stringsAsFactors = FALSE)
load(url("https://ndownloader.figshare.com/files/25950872")) load("/"your directory"/data_humanSkin_CellChat.rda")
data.input = data_humanSkin$data # normalized data matrix meta = data_humanSkin$meta # a dataframe with rownames containing cell mata data cell.use = rownames(meta)[meta$condition == "LS"] # extract the cell names from disease data
data.input = data.input[, cell.use] meta = meta[cell.use, ]
unique(meta$labels) # check the cell labels
cellchat <- createCellChat(object = data.input, meta = meta, group.by = "labels")
cellchat <- addMeta(cellchat, meta = meta) cellchat <- setIdent(cellchat, ident.use = "labels") # set "labels" as default cell identity levels(cellchat@idents) # show factor levels of the cell labels groupSize <- as.numeric(table(cellchat@idents)) # number of cells in each cell group
CellChatDB <- CellChatDB.human cellchat@DB <- CellChatDB cellchat <- subsetData(cellchat) future::plan("multisession", workers = 4)
cellchat <- identifyOverExpressedGenes(cellchat) cellchat <- identifyOverExpressedInteractions(cellchat) cellchat <- projectData(cellchat, PPI.human) cellchat <- computeCommunProb(cellchat) cellchat <- filterCommunication(cellchat, min.cells = 10) cellchat <- computeCommunProbPathway(cellchat) cellchat <- aggregateNet(cellchat)
groupSize <- as.numeric(table(cellchat@idents)) par(mfrow = c(1,2), xpd=TRUE) netVisual_circle(cellchat@net$count, vertex.weight = groupSize, weight.scale = T, label.edge= F, title.name = "Number of interactions") netVisual_circle(cellchat@net$weight, vertex.weight = groupSize, weight.scale = T, label.edge= F, title.name = "Interaction weights/strength")
mat <- cellchat@net$weight par(mfrow = c(3,4), xpd=TRUE) for (i in 1:nrow(mat)) { mat2 <- matrix(0, nrow = nrow(mat), ncol = ncol(mat), dimnames = dimnames(mat)) mat2[i, ] <- mat[i, ] netVisual_circle(mat2, vertex.weight = groupSize, weight.scale = T, edge.weight.max = max(mat), title.name = rownames(mat)[i]) }
It's exact my code.
If there is any problem, you can tell me anytime:)
Thanks. What is "your directory" or data_humanSkin_CellChat.rda in the code? It's unlikely that I have it.
I managed to download the file from figshare and can use it. Running your code now, it takes a bit.
Oh, that code is for loading data to your R session
If you run code below load(url("https://ndownloader.figshare.com/files/25950872"))
You'll get data_humanSkin_CellChat.rda file. Then you can load that file to your R environment.
If it's not working, just double click that file at your finder or download folder
That's good!
The script takes minutes to run, and it succeeded on my machine the first time I ran it. Is there a random component?
The "multisession" part doesn't exactly help with reproducibility, either.
Can you please attach your cellchat
object to this issue, saved with saveRDS()
?
I ran a second time, without failure.
Can you please try updating the CellChat package on your machine, if needed?
Thanks god.
You're genius.
Now it's going on.
You're my saver.
I'll share this solution with the other users.
Have a nice day!!
For reference, this is what I'm seeing on my machine, with your .rds
file.
I like it how easy it is for me, with the reprex package, to create a code that you can also double-check.
suppressMessages(library(CellChat, warn.conflicts = FALSE))
library(patchwork, warn.conflicts = FALSE)
options(stringsAsFactors = FALSE)
# set.seed(20230302)
#
# path <- tempfile(fileext = ".rda")
# curl::curl_download("https://ndownloader.figshare.com/files/25950872", path)
# load(path)
#
# data.input = data_humanSkin$data # normalized data matrix
# meta = data_humanSkin$meta # a dataframe with rownames containing cell mata data
# cell.use = rownames(meta)[meta$condition == "LS"] # extract the cell names from disease data
#
# data.input = data.input[, cell.use]
# meta = meta[cell.use, ]
#
# unique(meta$labels) # check the cell labels
# #> [1] Inflam. FIB FBN1+ FIB APOE+ FIB COL11A1+ FIB cDC2
# #> [6] LC Inflam. DC cDC1 CD40LG+ TC Inflam. TC
# #> [11] TC NKT
# #> 12 Levels: APOE+ FIB FBN1+ FIB COL11A1+ FIB Inflam. FIB cDC1 cDC2 ... NKT
#
# cellchat <- createCellChat(object = data.input, meta = meta, group.by = "labels")
#
# cellchat <- addMeta(cellchat, meta = meta)
# cellchat <- setIdent(cellchat, ident.use = "labels") # set "labels" as default cell identity
# levels(cellchat@idents) # show factor levels of the cell labels
# groupSize <- as.numeric(table(cellchat@idents)) # number of cells in each cell group
#
# CellChatDB <- CellChatDB.human
# cellchat@DB <- CellChatDB
# cellchat <- subsetData(cellchat)
# future::plan("multisession", workers = 4)
#
# cellchat <- identifyOverExpressedGenes(cellchat)
# cellchat <- identifyOverExpressedInteractions(cellchat)
# cellchat <- projectData(cellchat, PPI.human)
# cellchat <- computeCommunProb(cellchat)
# cellchat <- filterCommunication(cellchat, min.cells = 10)
# cellchat <- computeCommunProbPathway(cellchat)
# cellchat <- aggregateNet(cellchat)
cellchat <- readRDS("~/Downloads/Cellchat.rds")
groupSize <- as.numeric(table(cellchat@idents))
par(mfrow = c(1, 2), xpd = TRUE)
netVisual_circle(cellchat@net$count, vertex.weight = groupSize, weight.scale = T, label.edge = F, title.name = "Number of interactions")
netVisual_circle(cellchat@net$weight, vertex.weight = groupSize, weight.scale = T, label.edge = F, title.name = "Interaction weights/strength")
mat <- cellchat@net$weight
par(mfrow = c(3, 4), xpd = TRUE)
for (i in 1:nrow(mat)) {
mat2 <- matrix(0, nrow = nrow(mat), ncol = ncol(mat), dimnames = dimnames(mat))
mat2[i, ] <- mat[i, ]
netVisual_circle(mat2, vertex.weight = groupSize, weight.scale = T, edge.weight.max = max(mat), title.name = rownames(mat)[i])
}
Created on 2023-03-02 with reprex v2.0.2
Thank you for helping me a lot.
I really appreciated your help and kindness.
God bless you.
Hello, I'm an user of "igraph"
I wanna ask you guys one thing.
I need to run "Cellchat" package. In this process, "igraph" ver1.3.5 is necessary.
But in many cases, there are someone who can't install "igraph" ver1.3.5 in R. https://github.com/sqjin/CellChat/issues/547#issue-1581351747
As i said, without this package we can't do anything.
In conclusion, There are 2 options. First, I want you to solve the installing issue in ver 1.3.5 Second, If you can't solve above problem, then please make ver 1.4.1 be available in Cellchat package
So I beg you, please solve this problem asap.
########################################################################
This is my code when installing package.
devtools::install_version("igraph", version = "1.3.5")
Error: package or namespace load failed for ‘igraph’ in dyn.load(file, DLLpath = DLLpath, ...): unable to load shared object '/Library/Frameworks/R.framework/Versions/4.2/Resources/library/00LOCK-igraph/00new/igraph/libs/igraph.so': dlopen(/Library/Frameworks/R.framework/Versions/4.2/Resources/library/00LOCK-igraph/00new/igraph/libs/igraph.so, 6): Library not loaded: @rpath/libxml2.2.dylib Referenced from: /Library/Frameworks/R.framework/Versions/4.2/Resources/library/00LOCK-igraph/00new/igraph/libs/igraph.so Reason: image not found Error: loading failed Execution halted ERROR: loading failed
removing ‘/Library/Frameworks/R.framework/Versions/4.2/Resources/library/igraph’
And this is result of that code.
Also I'll attach my error from cellchat when i use "igraph" ver 1.4.1
Whenever I run code below, netVisual_aggregate(Cellchat, signaling = pathway.show, layout = "chord")
then i got this error message Error in i_set_edge_attr(x, attr(value, "name"), index = value, value = attr(value, : Length of new attribute value must be 1 or 8, the number of target edges, not 6
https://github.com/sqjin/CellChat/issues/547#issue-1581351747 If you check this link, you can see that many people suffer due to this problem.
########################################################################
R version 4.2.1 (2022-06-23) Platform: x86_64-apple-darwin17.0 (64-bit) Running under: macOS Big Sur 11.5.2
Matrix products: default LAPACK: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRlapack.dylib
locale: [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages: character(0)
other attached packages: [1] CellChat_1.5.0