Get, set, and manipulate an object's identity classes
Idents(object, ...)
Idents(object, ...) <- value
RenameIdents(object, ...)
ReorderIdent(object, var, ...)
SetIdent(object, ...)
StashIdent(object, save.name, ...)
# S3 method for Seurat
Idents(object, ...)
# S3 method for Seurat
Idents(object, cells = NULL, drop = FALSE, replace = FALSE, ...) <- value
# S3 method for Seurat
ReorderIdent(
object,
var,
reverse = FALSE,
afxn = mean,
reorder.numeric = FALSE,
...
)
# S3 method for Seurat
RenameIdents(object, ...)
# S3 method for Seurat
SetIdent(object, cells = NULL, value, ...)
# S3 method for Seurat
StashIdent(object, save.name = "orig.ident", ...)
# S3 method for Seurat
droplevels(x, ...)
# S3 method for Seurat
levels(x)
# S3 method for Seurat
levels(x) <- value
Arguments passed to other methods; for RenameIdents
: named
arguments as old.ident = new.ident
; for ReorderIdent
: arguments
passed on to FetchData
The name of the identities to pull from object metadata or the identities themselves
Feature or variable to order on
Store current identity information under this name
Set cell identities for specific cells
Drop unused levels
Replace identities for unset cells with NA
Reverse ordering
Function to evaluate each identity class based on; default is
mean
Rename all identity classes to be increasing numbers starting from 1 (default is FALSE)
An object
Idents
: The cell identities
Idents<-
: object
with the cell identities changed
RenameIdents
: An object with selected identity classes renamed
ReorderIdent
: An object with
SetIdent
: An object with new identity classes set
StashIdent
: An object with the identities stashed
# Get cell identity classes
Idents(pbmc_small)
#> ATGCCAGAACGACT CATGGCCTGTGCAT GAACCTGATGAACC TGACTGGATTCTCA AGTCAGACTGCACA
#> 0 0 0 0 0
#> TCTGATACACGTGT TGGTATCTAAACAG GCAGCTCTGTTTCT GATATAACACGCAT AATGTTGACAGTCA
#> 0 0 0 0 0
#> AGGTCATGAGTGTC AGAGATGATCTCGC GGGTAACTCTAGTG CATGAGACACGGGA TACGCCACTCCGAA
#> 2 2 2 2 2
#> CTAAACCTGTGCAT GTAAGCACTCATTC TTGGTACTGAATCC CATCATACGGAGCA TACATCACGCTAAC
#> 2 2 2 2 2
#> TTACCATGAATCGC ATAGGAGAAACAGA GCGCACGACTTTAC ACTCGCACGAAAGT ATTACCTGCCTTAT
#> 1 1 1 1 1
#> CCCAACTGCAATCG AAATTCGAATCACG CCATCCGATTCGCC TCCACTCTGAGCTT CATCAGGATGCACA
#> 1 1 1 1 1
#> CTAAACCTCTGACA GATAGAGAAGGGTG CTAACGGAACCGAT AGATATACCCGTAA TACTCTGAATCGAC
#> 0 2 0 0 0
#> GCGCATCTTGCTCC GTTGACGATATCGG ACAGGTACTGGTGT GGCATATGCTTATC CATTACACCAACTG
#> 0 0 0 0 0
#> TAGGGACTGAACTC GCTCCATGAGAAGT TACAATGATGCTAG CTTCATGACCGAAT CTGCCAACAGGAGC
#> 0 2 0 0 2
#> TTGCATTGAGCTAC AAGCAAGAGCTTAG CGGCACGAACTCAG GGTGGAGATTACTC GGCCGATGTACTCT
#> 2 0 0 0 0
#> CGTAGCCTGTATGC TGAGCTGAATGCTG CCTATAACGAGACG ATAAGTTGGTACGT AAGCGACTTTGACG
#> 1 1 2 1 1
#> ACCAGTGAATACCG ATTGCACTTGCTTT CTAGGTGATGGTTG GCACTAGACCTTTA CATGCGCTAGTCAC
#> 1 1 1 1 0
#> TTGAGGACTACGCA ATACCACTCTAAGC CATATAGACTAAGC TTTAGCTGTACTCT GACATTCTCCACCT
#> 2 1 2 1 2
#> ACGTGATGCCATGA ATTGTAGATTCCCG GATAGAGATCACGA AATGCGTGGACGGA GCGTAAACACGGTT
#> 1 1 1 1 2
#> ATTCAGCTCATTGG GGCATATGGGGAGT ATCATCTGACACCA GTCATACTTCGCCT TTACGTACGTTCAG
#> 0 0 0 0 0
#> GAGTTGTGGTAGCT GACGCTCTCTCTCG AGTCTTACTTCGGA GGAACACTTCAGAC CTTGATTGATCTTC
#> 0 0 0 0 1
#> Levels: 0 1 2
# Set cell identity classes
# Can be used to set identities for specific cells to a new level
Idents(pbmc_small, cells = 1:4) <- 'a'
head(Idents(pbmc_small))
#> ATGCCAGAACGACT CATGGCCTGTGCAT GAACCTGATGAACC TGACTGGATTCTCA AGTCAGACTGCACA
#> a a a a 0
#> TCTGATACACGTGT
#> 0
#> Levels: a 0 1 2
# Can also set idents from a value in object metadata
colnames(pbmc_small[[]])
#> [1] "orig.ident" "nCount_RNA" "nFeature_RNA" "RNA_snn_res.0.8"
#> [5] "letter.idents" "groups" "RNA_snn_res.1"
Idents(pbmc_small) <- 'RNA_snn_res.1'
levels(pbmc_small)
#> [1] "0" "1" "2"
# Rename cell identity classes
# Can provide an arbitrary amount of idents to rename
levels(pbmc_small)
#> [1] "0" "1" "2"
pbmc_small <- RenameIdents(pbmc_small, '0' = 'A', '2' = 'C')
levels(pbmc_small)
#> [1] "A" "C" "1"
if (FALSE) {
head(Idents(pbmc_small))
pbmc_small <- ReorderIdent(pbmc_small, var = 'PC_1')
head(Idents(pbmc_small))
}
# Set cell identity classes using SetIdent
cells.use <- WhichCells(pbmc_small, idents = '1')
pbmc_small <- SetIdent(pbmc_small, cells = cells.use, value = 'B')
head(pbmc_small[[]])
#> orig.ident nCount_RNA nFeature_RNA RNA_snn_res.0.8
#> ATGCCAGAACGACT SeuratProject 70 47 0
#> CATGGCCTGTGCAT SeuratProject 85 52 0
#> GAACCTGATGAACC SeuratProject 87 50 1
#> TGACTGGATTCTCA SeuratProject 127 56 0
#> AGTCAGACTGCACA SeuratProject 173 53 0
#> TCTGATACACGTGT SeuratProject 70 48 0
#> letter.idents groups RNA_snn_res.1
#> ATGCCAGAACGACT A g2 0
#> CATGGCCTGTGCAT A g1 0
#> GAACCTGATGAACC B g2 0
#> TGACTGGATTCTCA A g2 0
#> AGTCAGACTGCACA A g2 0
#> TCTGATACACGTGT A g1 0
pbmc_small <- StashIdent(pbmc_small, save.name = 'idents')
#> Warning: `StashIdent()` was deprecated in SeuratObject 3.0.0.
#> ℹ Please use pbmc_small[["idents"]] <- Idents(pbmc_small)
head(pbmc_small[[]])
#> orig.ident nCount_RNA nFeature_RNA RNA_snn_res.0.8
#> ATGCCAGAACGACT SeuratProject 70 47 0
#> CATGGCCTGTGCAT SeuratProject 85 52 0
#> GAACCTGATGAACC SeuratProject 87 50 1
#> TGACTGGATTCTCA SeuratProject 127 56 0
#> AGTCAGACTGCACA SeuratProject 173 53 0
#> TCTGATACACGTGT SeuratProject 70 48 0
#> letter.idents groups RNA_snn_res.1 idents
#> ATGCCAGAACGACT A g2 0 A
#> CATGGCCTGTGCAT A g1 0 A
#> GAACCTGATGAACC B g2 0 A
#> TGACTGGATTCTCA A g2 0 A
#> AGTCAGACTGCACA A g2 0 A
#> TCTGATACACGTGT A g1 0 A
# Get the levels of identity classes of a Seurat object
levels(x = pbmc_small)
#> [1] "B" "A" "C"
# Reorder identity classes
levels(x = pbmc_small)
#> [1] "B" "A" "C"
levels(x = pbmc_small) <- c('C', 'A', 'B')
levels(x = pbmc_small)
#> [1] "C" "A" "B"