What is the best way to process a metadata file that SEURAT can read?
1
0
Entering edit mode
20 months ago
biotrekker ▴ 100

Hello, I have been working with the Seurat pipeline. I want to know what the best way to process a metadata file is. I have been using AddMetaData() from Seurat, but I don't know how to transform my metadata file such that all the cell barcodes are represented, as required by the function. I have attached partial images of alldata and metadata objects.

alldata_m<-AddMetaData(alldata, metadata)

head(alldata)

metadata

Any help would be appreciated, Thanks

metadata scRNAseq seurat • 718 views
ADD COMMENT
0
Entering edit mode
20 months ago
fracarb8 ★ 1.6k

The metadata is saved in the meta.data slot at it is just a table, meaning that you can treat it like a normal dataframe.

# create the SampleID column by splitting the rownames 
seurat@meta.data$SampleID <- gsub("(^.+)_.*$","\\1", rownames(seurat@meta.data)
# or seurat@meta.data$SampleID <- seurat@meta.data$orig.ident

# add the other columns by matching the values from the other table
exp_meta <- the other dataframe

seurat@meta.data$patient <- sapply(seurat@meta.data$SampleID, function(ita) exp_meta[match(ita,exp_meta$SampleID),"Patient"])
seurat@meta.data$Type <- sapply(seurat@meta.data$SampleID, function(ita) exp_meta[match(ita,exp_meta$SampleID),"Type"])

Alternatively you can use merge.data.frame or any other function that join (left/right) the 2 table together.

If you want to use the AddMetaData wrapper

metadata <- seurat@meta.data
# add all the columns to `metadata`
...
seurat <- AddMetaData(seurat,metadata = metadata)
ADD COMMENT

Login before adding your answer.

Traffic: 2592 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6