2
$\begingroup$

I have a Seurat object of 8 patients. I want to add metadata to that so that I have origin of each cell. At the moment UMAP just shows a bunch of cells while I want to color clusters by sample

This is my metadata

> str(head(metadata))
'data.frame':   6 obs. of  3 variables:
 $ barcodes: chr  "AAACAGCCAAACTGCC-5" "AAACAGCCAACAGGAT-1" "AAACAGCCAAGATTCT-1" "AAACAGCCAAGGTATA-1" ...
 $ libcodes: Factor w/ 8 levels "1","2","3","4",..: 5 1 1 1 5 7
 $ samples : chr  "PN0252_0005" "PN0252_0001" "PN0252_0001" "PN0252_0001" ...
> 

> pbmc
An object of class Seurat 
36601 features across 26473 samples within 1 assay 
Active assay: RNA (36601 features, 0 variable features)
> 

> dim(metadata)
[1] 26473     3
> 
$\endgroup$
1
  • 1
    $\begingroup$ Thanks @angel much appreciated $\endgroup$
    – M__
    Sep 17, 2023 at 19:59

2 Answers 2

2
$\begingroup$

If you have single-dimension per-cell metadata, and it's arranged identically to the cell order in the Seurat object, I find it easier to use the double bracket notation to add metadata to a Seurat object. For example:

metadata$barcodes -> pbmc[["barcodes"]]
metadata$libcodes -> pbmc[["libcodes"]]
metadata$samples -> pbmc[["samples"]]
$\endgroup$
2
$\begingroup$

Answer from @user438383, converted from comment:

Did you try the AddMetaData function? This post may also be useful.

cluster_letters <- LETTERS[Idents(object = pbmc_small)]
names(cluster_letters) <- colnames(x = pbmc_small)
pbmc_small <- AddMetaData(
  object = pbmc_small,
  metadata = cluster_letters,
  col.name = 'letter.idents'
)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.