Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add Metadata to Seurat Object

I am working with a R package called "Seurat" for single cell RNA-Seq analysis. I am trying to add metadata information about individual cell samples to the Seurat Object. But the downstream plotting commands are not working. I am wondering if anyone knows how I could check the modified Seurat object to confirm that the metadata was added in the correct slot and column.

To add the metadata i used the following commands.

First I extracted the cell names from the Seurat object

> Cells <- WhichCells(seurat_object)

Then I created a list of the morphologically determined cell types using numbers 1-3 this NOTE: the list is much longer but abbreviated as the first 3 here

> MorphCellTypes = c(1,2,3)

Then I merged cells and MorphCellTypes together as a data.frame

> MorphCellTypesDF = data.frame(Cells, MorphCellTypes)

Then I tried to add this MorphCellTypesDF metadata to the seurat object using the following command which ran successfully

> AddMetaData(Sleuth_object, MorphCellTypesDF, col.name = MorphCellTypes

Then I tried to visualize it with TSNEPlot using the following command

> TSNEPlot(pbmc, do.label = TRUE, pt.size = 3, group.by = MorphCellTypes

This returned the following Error:

“Error in DimPlot(object, reduction.use = "tsne", cells.use = cells.use,  :
  object 'MorphCellTypes' not found”

So I think that I am either adding the meta data to the wrong location in my seurat object or i am somehow messing up the col.name. Either way it appears that I am using the AddMetaData or TSNEPlot() functions incorrectly. If by any chance you spot the error or could point me to an example of how to use AddMetaData it would be very much appreciated.

like image 651
Paul Avatar asked Feb 16 '17 16:02

Paul


Video Answer


1 Answers

After much trial and error I found a way to successfully add columns of experimental meta data. The trick was to maintain the correct formatting from the Seurat Object while adding your data. I did this by copying the [email protected] table and then modifying it by adding a column to it. Then by importing the modified table back into Seurat. The following code adds a column of random numbers called Gene_ID's to the Seurat object in the [email protected] slot. Then it tests the addition of this data with a visualization.

CellsMeta = [email protected]
head(CellsMeta)

randomnumbers <- runif(2700, 0.0, 1.1)

CellsMeta["Gene_IDs"] <- randomnumbers
head(CellsMeta)

CellsMetaTrim <- subset(CellsMeta, select = c("Gene_IDs"))
head(CellsMetaTrim)

pbmc <- AddMetaData(pbmc, CellsMetaTrim)

head([email protected])

VlnPlot(pbmc, c("nGene", "nUMI", "Gene_IDs"), nCol = 3)
like image 191
Paul Avatar answered Sep 28 '22 22:09

Paul