1
$\begingroup$

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?

$\endgroup$
1
$\begingroup$

With a little bit of workaround:

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")
$\endgroup$
3
  • $\begingroup$ 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!! $\endgroup$ Jun 24 at 8:44
  • $\begingroup$ Hi, Does anyone know how to access the gene name via the Seurat data sctructure as descibed in the answer above. $\endgroup$ Jun 28 at 6:01
  • $\begingroup$ 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. $\endgroup$
    – haci
    Jun 28 at 13:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.