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

Bugfix to CellsByIdentities #80

Merged
merged 3 commits into from
Mar 3, 2023
Merged

Conversation

bbimber
Copy link
Contributor

@bbimber bbimber commented Jan 18, 2023

I think this is broken, at least in some R versions. If your object has more than one cell with NA as the ident you get an error like:

Warning message:
In cells.idents["NA"] <- names(x = which(x = is.na(x = Idents(object = object)[cells]))) :
number of items to replace is not a multiple of replacement length

You can repro this with the following:

library(Seurat)

dat <- matrix(1:100, ncol = 10, dimnames = list(LETTERS[1:10], LETTERS[11:20]))
df <- data.frame(x = LETTERS[5:14], field <- factor(c(rep('AA', 5), rep('BB', 5))), row.names = LETTERS[11:20])
so <- Seurat::CreateSeuratObject(dat, meta.data = df)

# Set NAs. These are cells N and O:
so@meta.data$field[4:5] <- NA
Idents(so) <- 'field'
Idents(so)

# This vector has two cells with NAs. If you have a single NA cell it will work:
cells <- c('M', 'N', 'O')
x <- Seurat::CellsByIdentities(
  object = so,
  idents = NULL,
  cells = cells
)

The problem is that R assignment with a single bracket fails when you're trying to assign a vector (hence why you need two or more NA cells).

I think this is broken, at least in some R versions. If your object has more than one cell with NA as the ident you get an error like:

Warning message:
  In cells.idents["NA"] <- names(x = which(x = is.na(x = Idents(object = object)[cells]))) :
  number of items to replace is not a multiple of replacement length

You can repro this with the following:
```
library(Seurat)

dat <- matrix(1:100, ncol = 10, dimnames = list(LETTERS[1:10], LETTERS[11:20]))
df <- data.frame(x = LETTERS[5:14], field <- factor(c(rep('AA', 5), rep('BB', 5))), row.names = LETTERS[11:20])
so <- Seurat::CreateSeuratObject(dat, meta.data = df)

# Set NAs. These are cells N and O:
so@meta.data$field[4:5] <- NA
Idents(so) <- 'field'
Idents(so)

# This vector has two cells with NAs. If you have a single NA cell it will work:
cells <- c('M', 'N', 'O')
x <- Seurat::CellsByIdentities(
  object = so,
  idents = NULL,
  cells = cells
)
```
@mojaveazure mojaveazure changed the base branch from master to develop March 3, 2023 19:44
@mojaveazure mojaveazure merged commit 3044f17 into satijalab:develop Mar 3, 2023
@mojaveazure
Copy link
Member

Thanks for catching and fixing this!

@bbimber bbimber deleted the patch-1 branch March 3, 2023 19:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants