install.packages("Seurat")
library(Seurat)
gene.list <- c("MS4A1", "CD79B", "CD79A", "TCL1A")
pbmc_small <- pbmc_small
There is a function is package Seurat called 'subset' which will subset a group from the dataset based on the expression level of a specific gene. You can directly use the gene name in the function like this which works fine:
Sample <- subset(pbmc_small, CD79A > 0, slot = "data")
However, I wish to call an element from the list I made (gene.list) in place of the gene name. It doesn't work and Im not sure why. I tried the following 3 methods:
Sample <- subset(pbmc_small, gene.list[3] > 0, slot = "data")
Sample <- subset(pbmc_small, `gene.list[3]` > 0, slot = "data")
Sample <- subset(pbmc_small, "gene.list[3]" > 0, slot = "data")
All 3 methods fail and return the same error which indicates the data can not find that gene:
Error in FetchData(object = object, vars = expr.char[vars.use], cells = cells, :
None of the requested variables were found:
I can't think of any other way to call the gene name from the list. Is there another way that I am missing? If its not possible for some reason is there another way to subset this group based on calling the list? The expression data that is uses to subset is located at:
pbmc_small@assays[["RNA"]]@data
Thanks so much for any tips you can provide