Warm tip: This article is reproduced from serverfault.com, please click

how to make a subset of cells expressing certain gene in seurat R

发布于 2020-02-12 19:47:48

I want to create a subset of a cell expressing certain genes only. Here is my coding but it always shows

'No named arguments passed'

I have no idea how to correct that.

Dbh.pos <- Idents(my.data, WhichCells(my.data, expression = Dbh > 0, slot = "data"))
Dbh.neg <- Idents(my.data, WhichCells(my.data, expression = Dbh = 0, slot = "data"))
Questioner
Elaine
Viewed
0
StupidWolf 2020-02-13 05:44:02

You can subset from the counts matrix, below I use pbmc_small dataset from the package, and I get cells that are CD14+ and CD14-:

library(Seurat)
CD14_expression = GetAssayData(object = pbmc_small, 
assay = "RNA", slot = "data")["CD14",]

This vector contains the counts for CD14 and also the names of the cells:

head(CD14_expression,30)
ATGCCAGAACGACT CATGGCCTGTGCAT GAACCTGATGAACC TGACTGGATTCTCA AGTCAGACTGCACA 
      0.000000       0.000000       0.000000       0.000000       0.000000 
TCTGATACACGTGT TGGTATCTAAACAG GCAGCTCTGTTTCT GATATAACACGCAT AATGTTGACAGTCA 
      0.000000       0.000000       0.000000       0.000000       0.000000 
AGGTCATGAGTGTC AGAGATGATCTCGC GGGTAACTCTAGTG CATGAGACACGGGA TACGCCACTCCGAA 
      0.000000       0.000000       0.000000       0.000000       0.000000 
CTAAACCTGTGCAT GTAAGCACTCATTC TTGGTACTGAATCC CATCATACGGAGCA TACATCACGCTAAC 
      0.000000       0.000000       0.000000       0.000000       0.000000 
TTACCATGAATCGC ATAGGAGAAACAGA GCGCACGACTTTAC ACTCGCACGAAAGT ATTACCTGCCTTAT 
      3.542611       3.917231       4.552789       5.159975       3.117873 
CCCAACTGCAATCG AAATTCGAATCACG CCATCCGATTCGCC TCCACTCTGAGCTT CATCAGGATGCACA 
      0.000000       3.452557       3.820847       4.432036       0.000000 

Getting the ids can be done using which :

    pos_ids = names(which(CD14_expression>0))
    neg_ids = names(which(CD14_expression==0))

Subsetting of the data can be done with:

    pos_cells = subset(pbmc_small,cells=pos_ids)
    neg_cells = subset(pbmc_small,cells=neg_ids)

A bit dumb, but I guess this is one way to check whether it works:

    FeaturePlot(pos_cells,"CD14")
    FeaturePlot(neg_cells,"CD14")