subset data problem
0
1
Entering edit mode
17 months ago
Andy ▴ 120

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 • 4.2k views
ADD COMMENT
0
Entering edit mode

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.

ADD REPLY
0
Entering edit mode

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: 
ADD REPLY
0
Entering edit mode

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!

ADD REPLY
0
Entering edit mode

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"))
ADD REPLY
0
Entering edit mode

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 :)

ADD REPLY
0
Entering edit mode

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.

ADD REPLY
0
Entering edit mode

Ok. Thanks. I will add it.

ADD REPLY
0
Entering edit mode

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.

ADD REPLY

Login before adding your answer.

Traffic: 1673 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6