# Seurat - subsetting by genes expressed

Originally- I was looking if in at least one of these genes were expressed:

test1 <- subset(myData,
(KLRC1 > 0) | (KIR2DL1 > 0) |
(KIR2DL3 > 0) | (KIR2DL4 > 0) |
(KIR3DL1 > 0) | (KIR3DL2 > 0) | (KIR3DL3 > 0), slot = "data")


Now- I would like to subset if expressed in at least two of these genes- is this possible with the subset function?

i) Add a new column to the data slot (only because your original subset() call does so but it can be raw counts or any other data matrix in your Seurat object). rowSums() determines how many non-zero counts you have.
df$$non_zero <- rowSums(cbind(df$$gene1 > 0, df$$gene2 > 0, df$$gene3 > 0, ...)) > 1

Change df with the your data slot, should be sth like YourSeuratObject@...$data. ii) Subset the newly modified data slot, basically treating the new column as another gene. Be careful not to use this column in preprocessing steps like normalization. YourSeuratObject <- subset(YourSeuratObject, non_zero > 1), slot = "data")  • Hi, Thanks so much for your quick response. I've tried many many combinations with my seurat object data slot -myData@assays$RNA@data\$KIR2DL1 - but I dont know how to access the information via the gene name. Thanks again!! Jun 24 '21 at 8:44
• github.com/satijalab/seurat/wiki/Seurat#slots goes over how to interact with Seurat objects. Think of a Seurat object as a container and within it there are several assays (RNA, DNA, ...) and within each of these assays there are different (data) slots, for example one for raw counts, one for normalized counts... You might need sth like: GetAssayData(object = seurat_object, slot = 'data')[1:5, 1:5]. Check the manual for GetAssayData(), you can get a specific data slot from a specific assay.