Open jingonmute opened 1 year ago
Hi TJ,
I am also having this problem. Using the example dataset and default settings, it is working fine. However, the following correction is working using my datasets: First, download the PrepareBasics.R and get_pct_expr.R source code from GitHub. https://github.com/Pinlyu3/LRLoop/blob/main/R/PrepareBasics.R https://github.com/Pinlyu3/LRLoop/blob/main/R/get_pct_expr.R
Then slightly modify the get_pct_expr.R code in the following way:
get_pct_expr <- function(seuratobj, conditions) { data = seuratobj@assays$RNA@data pct_expr = matrix(0, nrow = nrow(data), ncol = length(conditions)) Idents(object = seuratobj) = seuratobj$Condition for (i in 1:length(conditions)) { subdata = data[,WhichCells(seuratobj, idents = conditions[i])] pct_expr[,i] = rowSums(subdata >0)/ncol(subdata) } rownames(pct_expr) = rownames(data) colnames(pct_expr) = conditions
return(pct_expr) }
Then put this modified get_pct_expr function inside the PrepareBasics.R code but outside the PrepareBasics function. Then load the modified PrepareBasics.R code as source code and run your data, or you can load it however you like.
I hope it will help you!
Aman
I have encountered same problem, and the suggestion from amanzju did not solve the problem.
Not sure if it is a problem caused by update in packages. Hope the developers can fix this problem. Thank you!
I have encountered same problem. After modified the 'get_pct_expr' function slightly, 'PrepareBasics' function works, though I am still unable to figure out why this error occurred. It's seems that I only correct the 'subdata = data[,WhichCells(seuratobj, idents = conditions[i])]' with 'cells_in_condition = WhichCells(seuratobj, idents = conditions[i]) subdata = data[, cells_in_condition]'
get_pct_expr <- function(seuratobj, conditions) {
data = seuratobj@assays$RNA@data
pct_expr = matrix(0, nrow = nrow(data), ncol = length(conditions))
Idents(object = seuratobj) = 'Condition'
for (i in 1:length(conditions)) {
cells_in_condition = WhichCells(seuratobj, idents = conditions[i])
subdata = data[, cells_in_condition]
if (ncol(subdata) > 0) {
pct_expr[,i] = rowSums(subdata > 0) / ncol(subdata)
} else {
warning(paste("No cells found for condition:", conditions[i]))
pct_expr[,i] = 0
}
}
rownames(pct_expr) = rownames(data)
colnames(pct_expr) = conditions
return(pct_expr)
}
Hi LRLoop Team, I followed the tutorial of [LRLoop analysis starting from Seurat objects] to learn cell-cell interaction. I use your pre-calculated default networks and two celltypes each have two conditions: ct1obj An object of class Seurat 23739 features across 24 samples within 1 assay Active assay: RNA (23739 features, 2000 variable features) 3 dimensional reductions calculated: pca, harmony, umap ct2obj An object of class Seurat 23739 features across 99 samples within 1 assay Active assay: RNA (23739 features, 2000 variable features) 3 dimensional reductions calculated: pca, harmony, umap
when I did the PrepareBasics, there was something wrong with it. Basics <- PrepareBasics(ct1obj, ct2obj, min_pct = 0.1, geneset_ct1 = DEGinfo_ct1$DEgenes, geneset_ct2 = DEGinfo_ct2$DEgenes, lr_network, ligand_target_matrix_ct1_to_ct2, receptor_target_matrix_ct1_to_ct2, ligand_target_matrix_ct2_to_ct1, receptor_target_matrix_ct2_to_ct1, discrete_error_rate = 0.1, discrete_cutoff_method = "distribution", discrete_fdr_method = "global", allow_feedback_delay = FALSE)
the error is : Error in rowSums(subdata > 0) : 'x' must be arry and has at least two dimention.
I checked the PrepareBasics function body(PrepareBasics) { conditions = as.vector(unique(ct1obj@meta.data[, "Condition"])) data_ct1 = ct1obj@assays$RNA@data data_ct2 = ct2obj@assays$RNA@data ave_expr_ct1 = log1p(AverageExpression(ct1obj, group.by = "Condition")$RNA) ave_expr_ct2 = log1p(AverageExpression(ct2obj, group.by = "Condition")$RNA) if (length(conditions) > 1) { ave_expr_ct1 = ave_expr_ct1[, conditions] ave_expr_ct2 = ave_expr_ct2[, conditions] } else { colnames(ave_expr_ct1) = conditions colnames(ave_expr_ct2) = conditions } pct_expr_ct1 = get_pct_expr(ct1obj, conditions) ####erro starts at here pct_expr_ct2 = get_pct_expr(ct2obj, conditions) ..........
then further checked the get_pct_expr( ) function body(get_pct_expr) { data = seuratobj@assays$RNA@data pct_expr = matrix(0, nrow = nrow(data), ncol = length(conditions)) Idents(object = seuratobj) = "Condition" for (i in 1:length(conditions)) { subdata = data[, WhichCells(seuratobj, idents = conditions[i])] pct_expr[, i] = rowSums(subdata > 0)/ncol(subdata) } rownames(pct_expr) = rownames(data) colnames(pct_expr) = conditions return(pct_expr) } I could get a dataframe named pct_expr: head(pct_expr) control condition2 Xkr4 0.0000000 0 Gm1992 0.0000000 0 Gm19938 0.0000000 0 Gm37381 0.0000000 0 Rp1 0.2857143 0 Sox17 0.0000000 0
then looked in to the PrepareBasics function: thresh_expr_ct1 = (pct_expr_ct1 > min_pct) 1 thresh_expr_ct2 = (pct_expr_ct2 > min_pct) 1
but we haven't got min_pct yet so erro occured
Could you please help me with that?? Really wanna know where the problem is.
Many thanks, TJ