Question: How to embed known cell information into Seurat object? AddMetaData?
0
gravatar for Pratik Mehta
12 days ago by
Pratik Mehta30
University of Connecticut
Pratik Mehta30 wrote:

How to embed known cell information into Seurat object? Using AddMetaData?

Is this possible?

I read this documentation: https://www.rdocumentation.org/packages/Seurat/versions/3.1.4/topics/AddMetaData

However I need some clarification on how to go about doing this, please?

I have cell labels that are all aligned with the expression matrix such as this:

"12wks_fetal pancreas cell_acinar"  "19wks_fetal pancreas cell_beta"    "12wks_fetal pancreas cell_ductal"  "12wks_fetal pancreas cell_beta"    "12wks_fetal pancreas cell_acinar"  "22wks_fetal pancreas cell_acinar"  "12wks_fetal pancreas cell_acinar"  "12wks_fetal pancreas cell_alpha"   "12wks_fetal pancreas cell_ductal"  "12wks_fetal pancreas cell_acinar"  "14wks_fetal pancreas cell_endocrine.progenitor..."

I used these cell labels as cell names (column names) for the expression matrix. However that's not useful for seeing which cell is from what time point 12wks, 19wks, 14 wks, etc. on the UMAP for example.

Would there be a way to label the cells using the AddMetaData function so that when I visualize the data using UMAP, they are color coded based on the time of collection (ie. 12wks, 19wks, 22wks, etc.) or would there be a way I could also filter by both time of collection and/or cell type?

Is this possible in Seurat? How would I approach this?

I would really appreciate anyone's help.

Very Respectfully, Pratik

seurat3 next-gen R scrna-seq • 142 views
ADD COMMENTlink modified 12 days ago by swbarnes28.6k • written 12 days ago by Pratik Mehta30
4
gravatar for swbarnes2
12 days ago by
swbarnes28.6k
United States
swbarnes28.6k wrote:

You didn't think to try AddMetaData?

Yes, if you have one column with barcode names an another with any kind of information, you can add a new column of metadata. You can also make a new column of metadata by concatenating two columns you already have. You can use group.by in DimPlot to color the cells by any column in the metadata, and you can subset by metadata columns after setting that column with Ident.

ADD COMMENTlink written 12 days ago by swbarnes28.6k
1

You can also just treat seurat_obj@meta.data as a standard data frame and modify it using generic functions.

ADD REPLYlink written 11 days ago by igor11k

So I tried the AddMetaData way by doing:

AddMetaData(object = scfp, metadata = celltypes_col, col.name = 'time.cell')

But that did not work!

What you suggested, igor, helped, treating the seurat_obj@meta.data as a data frame. I was able to add the meta data using this:

scfp@meta.data <-cbind(scfp@meta.data,celltypes_col)

and then changed the column name using this:

colnames(scfp@meta.data)[which(names(scfp@meta.data) == "V1")] <- "time.cell"

Thank you!

and then I followed the guidance of swbarnes2! Thank you Thank you!

ADD REPLYlink modified 10 days ago • written 11 days ago by Pratik Mehta30
1

I think you need col.name if you are adding a vector (so no obvious column name). If you are adding a data frame, there are columns with names already.

I would generally advise against cbind because you can't guarantee the same order.

ADD REPLYlink written 10 days ago by igor11k
1

Yss, cbind is very dangerous. Merge is far safer in general. But also in general, it's safer to access parts of an object by using the functions designed to interact with them, instead of writing straight to them yourself.

ADD REPLYlink written 10 days ago by swbarnes28.6k
1

I understand, I would, but it didn't work for me : (

EDIT: I think I'll report it as a bug?

ADD REPLYlink modified 1 day ago • written 1 day ago by Pratik Mehta30

I double checked the order prior to cbinding on of the Seurat object by doing > head(x = scfp@meta.data)

I would simply do AddMetaData, but it did not work for me, unfortunately. There was no error message. It just didn't show up under the Seurat object.

The method above, however, did work!

ADD REPLYlink written 1 day ago by Pratik Mehta30

Wow, this is incredibly helpful. I will keep this bookmarked, and attempt this method soon! Thank you Thank you swbarnes2!

ADD REPLYlink written 11 days ago by Pratik Mehta30
3
gravatar for Hamid Ghaedi
12 days ago by
Hamid Ghaedi230
Queens university
Hamid Ghaedi230 wrote:

Hope to get your question correctly, you can do anything to cell information via Ident function. Follow the manual to change the Idents of your cells. By this, you can replace the active.ident with what you want.

ADD COMMENTlink modified 12 days ago • written 12 days ago by Hamid Ghaedi230
1

Gosh, thank you Hamid! I am going to try this soon! I will let you know how I make out!

ADD REPLYlink written 11 days ago by Pratik Mehta30
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1134 users visited in the last hour