Seurat: Add sample to meta data of seurat object?

Created on 9 Sep 2019  路  1Comment  路  Source: satijalab/seurat

Hello,

I am working off of a Seurat object that consists of multiple samples merged together. How would I add sample identifiers to an already created/merged dataset in relation to the orig.ident?

For example, I have a merged object with orig.idents of sample1_lane 1, sample1_lane2, sample2_lane1, sample2_lane2. I would like to add meta data so that sample1_lane1 and sample1_lane2 cells can be identified as "Sample1", sample2_lane1 and sample2_lane2 as "Sample2" etc.

Thanks!

Analysis Question

Most helpful comment

Hi,

This is more of an R question than a Seurat question but essentially you need to make a new vector that maps your orig.idents to the new sample names and then add that to a new metadata column. One way of doing that could be:

object$sample <- plyr::mapvalues(
    x = object$orig.ident, 
    from = c("sample1_lane1", "sample1_lane2", "sample2_lane1", "sample2_lane2"), 
    to = c("Sample1", "Sample1", "Sample2", "Sample2")
)

>All comments

Hi,

This is more of an R question than a Seurat question but essentially you need to make a new vector that maps your orig.idents to the new sample names and then add that to a new metadata column. One way of doing that could be:

object$sample <- plyr::mapvalues(
    x = object$orig.ident, 
    from = c("sample1_lane1", "sample1_lane2", "sample2_lane1", "sample2_lane2"), 
    to = c("Sample1", "Sample1", "Sample2", "Sample2")
)
Was this page helpful?
0 / 5 - 0 ratings

Related issues

farhanma picture farhanma  路  3Comments

RuiyangLiu94 picture RuiyangLiu94  路  3Comments

igordot picture igordot  路  3Comments

akhst7 picture akhst7  路  3Comments

Biogitte picture Biogitte  路  3Comments