玩轉(zhuǎn)單細(xì)胞(2):Seurat批量做圖修飾玩轉(zhuǎn)單細(xì)胞(3):堆疊柱狀圖添加比例
玩轉(zhuǎn)單細(xì)胞(4):單細(xì)胞相關(guān)性
玩轉(zhuǎn)單細(xì)胞(5):單細(xì)胞UMAP圖只標(biāo)記特定細(xì)胞群寻馏、圈定細(xì)胞群及坐標(biāo)軸修改
玩轉(zhuǎn)單細(xì)胞(6):單細(xì)胞差異基因展示之對角散點圖
之前的玩轉(zhuǎn)單細(xì)胞系列,還是受到很多人的喜歡的,這里的都是一些小問題擒贸,但是遇到的話一時半會覺得無從下手矢门,因為都是寫細(xì)枝末節(jié)的問題誉结,學(xué)習(xí)了也是錦上添花董虱。同樣的店煞,今天的問題也是一直以來沒有想過的苞慢,只不過是在做項目的時候需要诵原,查詢了相關(guān)的解決辦法,這里分享驗證一下挽放。問題:我們在構(gòu)建seurat對象的時候绍赛,使用表達(dá)矩陣,基因名一般是gene symbol辑畦,如果是ID的話吗蚌,網(wǎng)上的教程也是建議轉(zhuǎn)為symbol再構(gòu)建,因為構(gòu)建好seurat后無法修改纯出,確實是蚯妇,因為seurat沒有專門的函數(shù)進(jìn)行修改。另外就是進(jìn)行同源轉(zhuǎn)化的時候潦刃,只有seurat對象侮措,那就很難受。 解決辦法:在閱讀一篇文章的時候作者寫過一個函數(shù)乖杠,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)
}
但是后來在一個帖子上發(fā)現(xiàn)分扎,作者說github的函數(shù)不是通用形的,且不能全局修改胧洒,作者提供了一種改寫函數(shù)畏吓。為了尊重勞動成果墨状,這里就不直接貼出來函數(shù)了,附上作者函數(shù)的帖子菲饼,自行查看:http://www.reibang.com/p/6495706bac53這里我們進(jìn)行演示肾砂,看看效果,我們用小鼠的seurat對象進(jìn)行人同源轉(zhuǎn)化:這里也提一種同源轉(zhuǎn)化R包homologene宏悦。
library(Seurat)
library(nichenetr)
library(dplyr)
install.packages('homologene')
library(homologene)#基因同源轉(zhuǎn)化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輸出物種
#將鼠的基因名轉(zhuǎn)化為人的
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)`)
#轉(zhuǎn)化
mouse_data_trans <- RenameGenesSeurat(mouse_data_trans,
newnames = gene_use$gene_trans,
gene.use = gene_use$`rownames(mouse_data)`,
de.assay = 'RNA')
轉(zhuǎn)化前:
轉(zhuǎn)化后:
可以看到,轉(zhuǎn)化后不論是哪個assay饼煞,都變成了人的基因源葫。接下來我們做一下差異基因的分析,看看會不會出錯砖瞧。發(fā)現(xiàn)沒有任何問題息堂。而且作圖也是一樣的,說明轉(zhuǎn)化的成功块促。
#測試一下荣堰,差異基因
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
最后,我們對這個數(shù)據(jù)進(jìn)行重聚類竭翠,發(fā)現(xiàn)這個過程沒有任何問題振坚!
#重聚類
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)
最后,再次感謝這個提供函數(shù)的作者逃片,這個函數(shù)特別有用屡拨,不僅在需要同源轉(zhuǎn)化的分析中,在跨物種的分析中也同樣適用褥实。覺得分享有用的點個贊、分享下再走唄裂允。