Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot complete assign_ligands_to_celltype #268

Closed
shawnshu1 opened this issue May 7, 2024 · 2 comments · Fixed by #275
Closed

cannot complete assign_ligands_to_celltype #268

shawnshu1 opened this issue May 7, 2024 · 2 comments · Fixed by #275
Labels
bug Something isn't working

Comments

@shawnshu1
Copy link

finished nichenet_output, and trying to run assign_ligands_to_celltype for circos plot.
error message,
Error in data.frame(ligand_type = sender, ligand = unique_ligands_sender) :
arguments imply differing number of rows: 1, 0

@shawnshu1
Copy link
Author

shawnshu1 commented May 8, 2024

fixed the issue after debugging through the source code (application_visualization.R). Also detected additional bugs!
Line 826, apply(GetAssayData(seuratObj_subset[, seuratObj_subset[[celltype_col]] == celltype], slot = slot), 1, func.agg)
for Seurat5, use:
apply(GetAssayData(seuratObj_subset[, seuratObj_subset[[celltype_col]] == celltype], layer = "counts"), 1, func.agg)

Line 831, set_rownames(ligands). This line needs to be deleted.
the data frame resulting from Line 830 already has ligand as rownames, whose order is actually DIFFERENT from the vector ligands

Line 844, data.frame(ligand_type = sender, ligand = unique_ligands_sender)
When unique_ligands_sender returns an empty character, this will create the error:
Error in data.frame(ligand_type = sender, ligand = unique_ligands_sender) :
arguments imply differing number of rows: 1, 0

A conditional flow in the following will mitigate such error
if (length(unique_ligands_sender) > 0) { return(data.frame(ligand_type = sender, ligand = unique_ligands_sender)) }

@csangara csangara added the bug Something isn't working label May 14, 2024
@csangara csangara linked a pull request May 29, 2024 that will close this issue
@csangara csangara linked a pull request May 29, 2024 that will close this issue
@csangara
Copy link
Member

Hi @shawnshu1,
Thank you for noticing the bugs and providing a solution. Apologies for taking some time to get around to this.
In the pull request, I have incorporated your condition statement and removed the set_rownames line. Additionally, I added the ... argument to allow users to provide either the 'slot' or 'layer' argument depending on their Seurat version.

I looked into the names mismatch, and it seems to be due to the different behavior of subset with v5 objects. Prior to v5, the row names of the subsetted Seurat object will follow the order of the provided vector. In v5, the Seurat object retains its original order. Example:

# Load test object
seurat_obj_test <- readRDS(url("https://zenodo.org/record/3531889/files/seuratObj_test.rds"))

# Update object, but underlying structure is still that of v3
seurat_obj_test <- UpdateSeuratObject(seurat_obj_test)

# Randomly get 20 genes from the object
random_ligands <- sample(rownames(seurat_obj_test), 20)

# This returns TRUE
all(rownames(subset(seurat_obj_test, features = random_ligands)) == random_ligands)

# Create new v5 object
seurat_obj_test_v5 <- CreateSeuratObject(counts = seurat_obj_test@assays$RNA@counts)

# This returns FALSE
all(rownames(subset(seurat_obj_test_v5, features = random_ligands)) == random_ligands)

I was not aware of this until now, and I will proceed to check other subset calls we make in our package. We really appreciate your help!

This issue will automatically be closed once I merge the PR, but feel free to reopen this should you still encounter bugs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants