seurat
seurat copied to clipboard
Change orig.ident column in seurat meta.data to match cell barcode sample prefixes
Hi Seurat Team,
Do you know how I can change the orig.ident column of the seurat meta.data so that it can differentiate between the 4_D_MI2_S2 and the 4_MI1_S5 sample? Right now it's labeling both samples as 4
Sample name (orig.ident column in seurat object meta.data) 1_MI1_S3 (1) 2_MI1_S4 (2) 3_C_MI2_S1 (3) 4_D_MI2_S2 (4) 4_MI1_S5 (4) *seurat is labeling these different samples as 4 5_MI1_S6 (5) 7_MI1_S7 (7)
I made a UMAP grouped by orig.ident and it's supposed to be colored by 7 samples, not 6. Basically I would like the UMAP legend and the orig.ident column to have something like the following to match the cell barcode sample prefixes. 1 2 3C 4D 4 5 7
How can I do this? Or is this necessary as the cell barcode prefixes are already labeled by sample?
DimPlot(seurat.obj_combined_filtered, reduction = "umap", group.by = "orig.ident", label = TRUE)
Hi - you can rename/add new metadata columns to your Seurat object very easily by creating a column of labels based on the sample name assuming you want to use the , and when plotting, calling group.by
on that metadata column.
# Create a new metadata column
seurat.obj_combined_filtered$sample_label <- NA
# Replace the values based on the original labels
seurat.obj_combined_filtered$sample_label[grepl("1_", seurat.obj_combined_filtered$orig.ident)] <- "1"
seurat.obj_combined_filtered$sample_label[grepl("2_", seurat.obj_combined_filtered$orig.ident)] <- "2"
seurat.obj_combined_filtered$sample_label[grepl("3_C_", seurat.obj_combined_filtered$orig.ident)] <- "3C"
seurat.obj_combined_filtered$sample_label[grepl("4_D_",seurat.obj_combined_filtered$orig.ident)] <- "4D"
seurat.obj_combined_filtered$sample_label[grepl("4 ", seurat.obj_combined_filtered$orig.ident)] <- "4"
seurat.obj_combined_filtered$sample_label[grepl("5_", seurat.obj_combined_filtered$orig.ident)] <- "5"
seurat.obj_combined_filtered$sample_label[grepl("7_", seurat.obj_combined_filtered$orig.ident)] <- "7"
Hi - you can rename/add new metadata columns to your Seurat object very easily by creating a column of labels based on the sample name assuming you want to use the , and when plotting, calling
group.by
on that metadata column.# Create a new metadata column seurat.obj_combined_filtered$sample_label <- NA # Replace the values based on the original labels seurat.obj_combined_filtered$sample_label[grepl("1_", seurat.obj_combined_filtered$orig.ident)] <- "1" seurat.obj_combined_filtered$sample_label[grepl("2_", seurat.obj_combined_filtered$orig.ident)] <- "2" seurat.obj_combined_filtered$sample_label[grepl("3_C_", seurat.obj_combined_filtered$orig.ident)] <- "3C" seurat.obj_combined_filtered$sample_label[grepl("4_D_",seurat.obj_combined_filtered$orig.ident)] <- "4D" seurat.obj_combined_filtered$sample_label[grepl("4 ", seurat.obj_combined_filtered$orig.ident)] <- "4" seurat.obj_combined_filtered$sample_label[grepl("5_", seurat.obj_combined_filtered$orig.ident)] <- "5" seurat.obj_combined_filtered$sample_label[grepl("7_", seurat.obj_combined_filtered$orig.ident)] <- "7"
Hi @zskylarli thank you!