Seurat: how to delete custom additional column from seurat metadata?Help!

Created on 27 Feb 2019  路  5Comments  路  Source: satijalab/seurat

I add some columns of custom metadata by using the Seurat v3.X command(object$name <- vector),but I can't delete these columns,such as "time","hours".I try many many ways,like subset, subsetdata,and test.tc11$hours >- NULL, all them didn't work.
Can you help me?

> test.tc11$hours <- rep("E14",7303)
> tail(x = test.tc11[[]])
                      orig.ident nCount_RNA nFeature_RNA percent.mito RNA_snn_res.0.8 letter.idents time DAY hours
A_TTTGTCACATTGGTAC SeuratProject       3987         1775            0               7             H  E11 E14   E14
A_TTTGTCAGTAAGTGGC SeuratProject       4299         1992            0               7             H  E11 E14   E14
A_TTTGTCAGTAGGACAC SeuratProject       6994         2448            0               0             A  E11 E14   E14
A_TTTGTCAGTAGGCATG SeuratProject       7906         2588            0               4             E  E11 E14   E14
A_TTTGTCAGTCTCATCC SeuratProject      24778         5035            0               8             I  E11 E14   E14
A_TTTGTCAGTTCTGTTT SeuratProject       8209         2628            0               2             C  E11 E14   E14
bug enhancement

All 5 comments

I believe you could just do the following, although there may be better ways.

> [email protected] <- [email protected][, -which(colnames([email protected]) %in% 'hours')]

This was an oversight on our part, you should now (as of commit 49eae61) be able to remove metadata columns using either [[ or $

object$column.to.remove <- NULL
object[['column.to.remove']] <- NULL

Thanks for bringing this up!

@mojaveazure I still could't be able to remove metadata columns using either [[ or $.But I can delete it using this command :
[email protected] <- [email protected][, -which(colnames([email protected]) %in% 'time')].What's the matter?

> head([email protected])
                   time
A_AAACCTGAGCAGCGTA  E11
A_AAACCTGAGCGATGAC  E11
A_AAACCTGAGTACCGGA  E11
A_AAACCTGAGTGACTCT  E11
A_AAACCTGCAGTGGAGT  E11
A_AAACCTGCAGTTCCCT  E11
> test.tc11$time <- NULL
Error: Cannot find object time
> test.tc11[['time']] <- NULL
Error: Cannot find object time
> [email protected] <- [email protected][, -which(colnames([email protected]) %in% 'time')]
> head([email protected])
data frame with 0 columns and 6 rows

Please make sure you reinstall Seurat v3 from GitHub from a fresh R session

> devtools::install_github(repo = 'satijalab/seurat', ref = 'release/3.0')
> library(Seurat)
> data(pbmc_small)
> pbmc_small
An object of class Seurat 
230 features across 80 samples within 1 assay 
Active assay: RNA (230 features)
 2 dimensional reductions calculated: pca, tsne
> names(x = pbmc_small[[]])
[1] "orig.ident"      "nCount_RNA"      "nFeature_RNA"    "RNA_snn_res.0.8"
[5] "letter.idents"   "groups"          "RNA_snn_res.1"  
> pbmc_small$groups <- NULL
> names(pbmc_small[[]])
[1] "orig.ident"      "nCount_RNA"      "nFeature_RNA"    "RNA_snn_res.0.8"
[5] "letter.idents"   "RNA_snn_res.1"  
> pbmc_small[['letter.idents']] <- NULL
> names(x = pbmc_small[[]])
[1] "orig.ident"      "nCount_RNA"      "nFeature_RNA"    "RNA_snn_res.0.8"
[5] "RNA_snn_res.1"

Thank you! It works. @mojaveazure @Thessentials

Was this page helpful?
0 / 5 - 0 ratings

Related issues

igordot picture igordot  路  3Comments

kysbbubbu picture kysbbubbu  路  3Comments

RuiyangLiu94 picture RuiyangLiu94  路  3Comments

farhanma picture farhanma  路  3Comments

kysbbubbu picture kysbbubbu  路  3Comments