❝详情请联系作者: ❞ 之前的玩转单细胞系列,还是受到很多人的喜欢的,这里的都是一些小问题,但是遇到的话一时半会觉得无从下手,因为都是写细枝末节的问题,学习了也是锦上添花。同样的,今天的问题也是一直以来没有想过的,只不过是在做项目的时候需要,查询了相关的解决办法,这里分享验证一下。问题:我们在构建seurat对象的时候,使用表达矩阵,基因名一般是gene symbol,如果是ID的话,网上的教程也是建议转为symbol再构建,因为构建好seurat后无法修改,确实是,因为seurat没有专门的函数进行修改。另外就是进行同源转化的时候,只有seurat对象,那就很难受。 解决办法:在阅读一篇文章的时候作者写过一个函数,github上也有:RenameGenesSeurat <- function(obj = ls.Seurat[[i]], newnames = tmp) { # Replace gene names in different slots of a Seurat object. Run this before integration. Run this before integration. It only changes obj@assays$RNA@counts, @data and @scale.data. print("Run this before integration. It only changes obj@assays$RNA@counts and @data ") RNA <- obj@assays$RNA
if (nrow(RNA) == length(newnames)) { if (length(RNA@counts)) RNA@counts@Dimnames[[1]] <- newnames if (length(RNA@data)) RNA@data@Dimnames[[1]] <- newnames # if (length(RNA@scale.data)) RNA@scale.data@Dimnames[[1]] <- newnames } else {"Unequal gene sets: nrow(RNA) != nrow(newnames)"} obj@assays$RNA <- RNA return(obj) } 但是后来在一个帖子上发现,作者说github的函数不是通用形的,且不能全局修改,作者提供了一种改写函数。为了尊重劳动成果,这里就不直接贴出来函数了,附上作者函数的帖子,自行查看:https://www.jianshu.com/p/6495706bac53这里我们进行演示,看看效果,我们用小鼠的seurat对象进行人同源转化:这里也提一种同源转化R包homologene。
library(Seurat) library(nichenetr) library(dplyr) install.packages('homologene') library(homologene)#基因同源转化R包 # homologene::taxData # tax_id name_txt # 1 10090 Mus musculus # 2 10116 Rattus norvegicus # 3 28985 Kluyveromyces lactis # 4 318829 Magnaporthe oryzae # 5 33169 Eremothecium gossypii # 6 3702 Arabidopsis thaliana # 7 4530 Oryza sativa # 8 4896 Schizosaccharomyces pombe # 9 4932 Saccharomyces cerevisiae # 10 5141 Neurospora crassa # 11 6239 Caenorhabditis elegans # 12 7165 Anopheles gambiae # 13 7227 Drosophila melanogaster # 14 7955 Danio rerio # 15 8364 Xenopus (Silurana) tropicalis # 16 9031 Gallus gallus # 17 9544 Macaca mulatta # 18 9598 Pan troglodytes # 19 9606 Homo sapiens # 20 9615 Canis lupus familiaris # 21 9913 Bos taurus # A <- homologene(rownames(mouse_data), inTax = 10090, outTax = 9606) # inTax输入物种、outTax输出物种 #将鼠的基因名转化为人的 mouse_data <- readRDS("D:/mouse_data.rds") gene_trans = rownames(mouse_data) %>% convert_mouse_to_human_symbols() gene_trans <- as.data.frame(gene_trans) gene_mouse <- as.data.frame(rownames(mouse_data)) gene_use <- cbind(gene_trans, gene_mouse) gene_use <- na.omit(gene_use) mouse_data_trans <- subset(mouse_data,features=gene_use$`rownames(mouse_data)`)
#转化 mouse_data_trans <- RenameGenesSeurat(mouse_data_trans, newnames = gene_use$gene_trans, gene.use = gene_use$`rownames(mouse_data)`, de.assay = 'RNA')
![](http://image109.360doc.com/DownloadImg/2023/04/1909/264611589_2_2023041909093065_wm.png)
![](http://image109.360doc.com/DownloadImg/2023/04/1909/264611589_3_20230419090930487_wm.png) 可以看到,转化后不论是哪个assay,都变成了人的基因。接下来我们做一下差异基因的分析,看看会不会出错。发现没有任何问题。而且作图也是一样的,说明转化的成功。#测试一下,差异基因 DEGs <- FindMarkers(mouse_data_trans, min.pct = 0.25, logfc.threshold = 0.25, group.by = "orig.ident", ident.1 ="10X_ntph_F", ident.2="10X_ntph_M")
DEGs1 <- FindMarkers(mouse_data, min.pct = 0.25, logfc.threshold = 0.25, group.by = "orig.ident", ident.1 ="10X_ntph_F", ident.2="10X_ntph_M")
p1 <- FeaturePlot(mouse_data_trans, features = 'LTF') p2 <- FeaturePlot(mouse_data, features = 'Ltf') p1|p2
![](http://image109.360doc.com/DownloadImg/2023/04/1909/264611589_4_20230419090930753_wm.png) 最后,我们对这个数据进行重聚类,发现这个过程没有任何问题!#重聚类 mouse_trans_human <- ScaleData(mouse_data_trans, vars.to.regress = c("nCount_RNA"), verbose = FALSE) mouse_trans_human <- FindVariableFeatures(mouse_trans_human, nfeatures = 4000) mouse_trans_human <- RunPCA(mouse_trans_human, npcs = 50, verbose = FALSE) mouse_trans_human <- FindNeighbors(mouse_trans_human, reduction = "pca", dims = 1:50) mouse_trans_human <- FindClusters(mouse_trans_human, resolution=0.8) mouse_trans_human <- RunUMAP(mouse_trans_human, reduction = "pca", dims = 1:50) DimPlot(mouse_trans_human, label = T,pt.size = 1)
![](http://image109.360doc.com/DownloadImg/2023/04/1909/264611589_5_20230419090931112_wm.png) 最后,再次感谢这个提供函数的作者,这个函数特别有用,不仅在需要同源转化的分析中,在跨物种的分析中也同样适用。觉得分享有用的点个赞、分享下再走呗。
|