current position:Home>Single cell column - how to give orig Ident, change your name

Single cell column - how to give orig Ident, change your name

2022-05-15 06:58:20Hedgehog with moustache

​ Because the upstream analysis is done by the company , But I found that I sent the wrong sample name when I told them , I want to change each one later orig.ident and groups Name , Baidu asked if there were any similar problems , As expected seurat A similar problem was found on the official website of (https://github.com/satijalab/seurat/issues/1479

).

Code sorting

## The answer given by the author who answered the question on the official website 
> # Quickly preview the metadata
> head(x = pbmc_small[[]])
                  orig.ident nCount_RNA nFeature_RNA RNA_snn_res.0.8
ATGCCAGAACGACT SeuratProject         70           47               0
CATGGCCTGTGCAT SeuratProject         85           52               0
GAACCTGATGAACC SeuratProject         87           50               1
TGACTGGATTCTCA SeuratProject        127           56               0
AGTCAGACTGCACA SeuratProject        173           53               0
TCTGATACACGTGT SeuratProject         70           48               0
               letter.idents groups RNA_snn_res.1
ATGCCAGAACGACT             A     g2             0
CATGGCCTGTGCAT             A     g1             0
GAACCTGATGAACC             B     g2             0
TGACTGGATTCTCA             A     g2             0
AGTCAGACTGCACA             A     g2             0
TCTGATACACGTGT             A     g1             0
> # Create a new metadata column called "original" with the contents of "orig.ident"
> pbmc_small$original <- pbmc_small$orig.ident
> # Remove the "orig.ident" metadata column
> pbmc_small$orig.ident <- NULL
> # Quickly preview the metadata again
> head(x = pbmc_small[[]])
               nCount_RNA nFeature_RNA RNA_snn_res.0.8 letter.idents groups
ATGCCAGAACGACT         70           47               0             A     g2
CATGGCCTGTGCAT         85           52               0             A     g1
GAACCTGATGAACC         87           50               1             B     g2
TGACTGGATTCTCA        127           56               0             A     g2
AGTCAGACTGCACA        173           53               0             A     g2
TCTGATACACGTGT         70           48               0             A     g1
               RNA_snn_res.1      original
ATGCCAGAACGACT             0 SeuratProject
CATGGCCTGTGCAT             0 SeuratProject
GAACCTGATGAACC             0 SeuratProject
TGACTGGATTCTCA             0 SeuratProject
AGTCAGACTGCACA             0 SeuratProject
TCTGATACACGTGT             0 SeuratProject
##You can add metadata columns using AddMetaData, the [[ operator, or the $ operator. For your specific case, I would create a character vector of 'ctrl' or 'patient' based on testing the value of your metadata column, then add it in like I did above.

Because we need to add addmetadata This function , So I remembered that I used this function when I did the reproduction a few days ago , So prepare for direct handling , Change the author's code .

First you need a xlsx A table of formats , Fill in the information you want , Similar to the following format .

xlsx Table example

One column needs to be the same as the information in your own matrix , Because we're going to use left_join A merger , What I choose here is orig.ident.

##load library, First load a bunch of packages that are not available , Prevent the following code from finding the function , I can't get it 
library(Seurat)
library(dplyr)
library(reticulate)
library(sctransform)
library(cowplot)
library(ggplot2)
library(viridis)
library(tidyr)
library(magrittr)
library(reshape2)
library(readxl)
library(progeny)
library(readr)
library(stringr)
## Read first xlsx A table of formats 
metatable <- read_excel("id_change.xlsx")
metadata <- FetchData(seu_obj, "orig.ident")
metadata$cell_id <- rownames(metadata)
metadata$sample_id <- metadata$orig.ident
##left_join: Left connection , Retain X All observations in , In this way, the original table data can be retained 
metadata <- left_join(x = metadata, y = metatable, by = "orig.ident")
rownames(metadata) <- metadata$cell_id
##AddMetaData: Add metadata column ;AddMetaData() The content passed to the metadata parameter in must have the same as the data @meta.data The data frame of the row name that matches the row name in 
seu_obj <- AddMetaData(seu_obj, metadata = metadata)
## Check the matrix 
head(seu_obj)
## Found more original、sample_id、cell_id、Groups Several columns , Need to put original Replace with orig.ident
## If it is cell_id And sample_id Self research is no longer needed , You can skip those two lines of code 
## delete orig.ident That's ok , Reference resources seurta Code for answering questions on the official website 
seu_obj$orig.ident <- NULL
## New generation orig.ident A list of 
seu_obj$orig.ident <- seu_obj$original
## delete original Column 
seu_ob$original <- NULL
## see seurat The situation of the object 
seu_obj
## Select the newly given group for test, See if there can be a picture , It shows that the change is reasonable 
DimPlot(seu_obj, group.by = "orig.ident",  pt.size = 0.1)

The test of umap chart

summary

At present, no problem is found by manually changing the columns of the matrix , Tomorrow, we need to discuss with the company about the feasibility of this method , But it can draw a picture , Part of the basic guarantee is still correct , There may be a need for barcode Make another modification .

copyright notice
author[Hedgehog with moustache],Please bring the original link to reprint, thank you.
https://en.chowdera.com/2022/131/202205102252441639.html

Random recommended