This is a test version of Biostars. For the public version, visit https://www.biostars.org.
subset data problem

Good afternoon,

I am trying to subset my data, but I meet following error:

subset(data1, idents=cell_values, invert=FALSE)
Error in .subscript.2ary(x, i, j, drop = drop) : subscript out of bounds

I am wondering how to solve the error.

Thanks
Andy

r seurat

I tried all of the likely ways to get this error that I could think of (passing in logical or numeric vectors for the idents arguments with length that doesn't match nrow(dataframe)) and couldn't figure out how you got this error. Can we get a reproducible example? Or at least some info about what data1 and cell_values look like? Otherwise best I can do is direct you towards this general and in-depth solution.

Hi, thanks for help.

>idents <- data@meta.data$disease

>cell_values<-'normal'

I tried several different ways to solve the problem. I set meta.data as active.ident, but still failed.

>table(data@active.ident)

>breast cancer        normal 

   >    144285            570046 

>normal_subset <- subset(data, idents == "normal")

>Error in FetchData.Seurat(object = object, vars = unique(x = expr.char[vars.use]),  : 
  None of the requested variables were found: 

Hello,

I am having the same error when I try to subset my Seurat object, both when I try with "cells" or with "idents".

> Idents(feat_c)=feat_c$seurat_clusters

> chondrocytes=WhichCells(feat_c, idents = c("1", "3"))

> feat_chondrocytes = subset(x=feat_c, cells = chondrocytes)

Error in .subscript.2ary(x, i, j, drop = drop) : subscript out of bounds

These are the length/dimensions of my vector and data

> length(chondrocytes)

[1] 3757

> dim(feat_c)

[1] 16830  6171

I hope this information can give more insight into solving the error. Thanks for the help!

Ahh I guess you are talking about Seurat's subset function...I'm not great with Seurat but what if you simply tried:

> Idents(feat_c)=feat_c$seurat_clusters

> feat_chondrocytes = subset(x=feat_c, idents = c("1", "3"))

It would be nice to know how you got cell_values, but you can check if the cells are in that subset first:

table( cell_values  %in% Cells(data1) )

In the case not all of them are in there (but maybe a lot of them are?), you could do the following

subset(data1, idents=Cells(data1)[Cells(data1) %in% cell_values], invert=FALSE)

Let me know if it helped :)

You should have really mentioned Seurat in your post - without it, the questions looks a lot like a generic R question with little to do with bioinformatics. I've added a seurat tag to the post now.

Ok. Thanks. I will add it.

UPDATE: I have come to realize that my problem arose when I downloaded an RDS file online. In the "count" line, the data represented gene IDs instead of gene names. While attempting to translate the gene IDs to names, I must have made an error, and this is likely the reason for the subset issue.

0 answers

No answers yet.

Log in to answer this question.