Question: Adding UMAP coordinates to metadata
0
gravatar for roberts
5 days ago by
roberts0
roberts0 wrote:

Hello, I want to store my umap coordinates in my seurat objects meta.data. The umap coordinates are saved in my Object under reductions in cell.embeddings. How would I add this to the meta.data? I tried running

AD007[["coordinates"]]<--AD007@reductions$umap@cell.embeddings

I keep getting the error-- Error: Cannot add more or fewer cell meta.data information without values being named with cell names. Any suggestions? Thanks!

seurat R • 86 views
ADD COMMENTlink modified 5 days ago by fracarb850 • written 5 days ago by roberts0
4
gravatar for fracarb8
5 days ago by
fracarb850
fracarb850 wrote:

In Seurat 3, you can export the coordinates to a dataframe using Embeddings().

umapCoord <- as.data.frame(Embeddings(object = AD007[["umap"]]))

You can then add the PC columns to the meta.data as you please (cbind, sapply, paste(..,collapse=),...)

For example, if you only need to add the PCs components, without modifying them or doing other processing, you can do a simple merge

metadata_table <- AD007@meta.data
metadata_table$UMI_id <- rownames(metadata_table)
umapCoord$UMI_id <- rownames(umapCoord)
metadata_table <- merge.data.frame(metadata_table,umapCoord,by = "UMI_id")
metadata_table$UMI_id <- NULL
AD007@meta.data <- metadata_table

or if you want to be "seurat compliant"

AddMetaData(AD007, metadata=metadata_table)`

Always double check that the order of the cells between the metadata and the umap match.

ADD COMMENTlink modified 3 days ago • written 5 days ago by fracarb850

Thank you for your help. Just a follow up question how do I add PC to the meta.data (sorry I am new to coding). Thank you!

ADD REPLYlink written 4 days ago by roberts0

Check the edited answer

ADD REPLYlink written 3 days ago by fracarb850
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: 1783 users visited in the last hour