cross-tissue 成纤维细胞比例.r

cpp 复制代码
getwd()
setwd("G:\\lung fibrosis")

##########mouse stable state--------------
mouse_ssfibro=readRDS("./Mouse_SS_Fibro.RDS")
library(Seurat)
head(mouse_ssfibro@meta.data)
DimPlot(mouse_ssfibro,label = TRUE,raster=FALSE)
table(mouse_ssfibro$Tissue)
dim(mouse_ssfibro)

Idents(mouse_ssfibro)=mouse_ssfibro$Tissue

lung_ss=subset(mouse_ssfibro,idents = "Lung")
DimPlot(lung_ss,label = TRUE)

str(lung_ss)

subset_data=lung_ss
subset_data[["percent.mt"]] <- PercentageFeatureSet(subset_data, pattern = "^mt-")
grep(pattern = "mt",x = rownames(subset_data),value = TRUE)

VlnPlot(subset_data, features = c("nFeature_RNA", "nCount_RNA", "percent.mt"), ncol = 3)

library(dplyr)
subset_data = subset_data %>%
  Seurat::NormalizeData(verbose = FALSE) %>%  
  FindVariableFeatures(selection.method = "vst", nfeatures = 2000) %>%
  ScaleData(verbose = FALSE) %>%
  RunPCA(npcs = 50, verbose = FALSE)


dims = 1:30
subset_data <- subset_data %>% 
  RunUMAP(reduction = "pca", dims = dims) %>% 
  RunTSNE(reduction = "pca", dims = dims) %>% 
  FindNeighbors(reduction = "pca", dims = dims)


#subset_data@meta.data$stim <- c(rep("Exp", length(grep("1$",colnames(subset_data)))),rep("Con", length(grep("2$",colnames(subset_data)))))
table(subset_data)
DimPlot(subset_data,label = TRUE,label.size = 7)+
  ggtitle("stable_state_mouse_lung")


DotPlot(subset_data,features = c("Inmt","Cd34","Sepp1","Ly6a",
                                 "Gpx3","Selenop"))
library(stringr)
library(ggplot2)
DotPlot(subset_data,features = str_to_title(c("GPX1","GPX3",
                                        "Dio1","Gpx4","Rps14","Selh","Selk","Selm","Selo","Sels","Selt",
                                        "Sep15","Sepp1","Sepw1","Sepx1","Txnrd1",
                                        "Txnrd2","Txnrd3")))+
  RotatedAxis()+ggtitle("stable_state_mouse_lung")
##selected stable lung--------
dim(subset_data)



################mouse ps fibro----------
mouse_ps_fibro=readRDS("./Mouse_PS_Fibro.RDS")
head(mouse_ps_fibro@meta.data)
table(mouse_ps_fibro$Tissue)
Idents(mouse_ps_fibro)=mouse_ps_fibro$Tissue

lung_fibro=subset(mouse_ps_fibro,idents = c('Lung Bleo_Fibrosis D14',
                                        "Lung Fibrosis D21",  #"Lung Nin_Fibrosis D11",
                                        "Lung Bleo_Fibrosis D11"))
DimPlot(lung_fibro,label = TRUE)

mouse_selected_lung_ps=lung_fibro
{
  mouse_selected_lung_ps[["percent.mt"]] <- PercentageFeatureSet(mouse_selected_lung_ps, pattern = "^mt-")
  VlnPlot(mouse_selected_lung_ps, features = c("nFeature_RNA", "nCount_RNA", "percent.mt"), ncol = 3)
  mouse_selected_lung_ps = mouse_selected_lung_ps %>%
    Seurat::NormalizeData(verbose = FALSE) %>%  
    FindVariableFeatures(selection.method = "vst", nfeatures = 2000) %>%
    ScaleData(verbose = FALSE) %>%
    RunPCA(npcs = 50, verbose = FALSE)
  table(Idents(mouse_selected_lung_ps))
  mouse_selected_lung_ps$stim=Idents(mouse_selected_lung_ps)
  #mouse_selected_lung_ps@meta.data$stim <- c(rep("Exp", length(grep("1$",colnames(mouse_selected_lung_ps)))),rep("Con", length(grep("2$",colnames(mouse_selected_lung_ps)))))
  table(mouse_selected_lung_ps$stim)
  
  ##########################run harmony
  #BiocManager::install('harmony')
  library('harmony')
  
  mouse_selected_lung_ps <- mouse_selected_lung_ps %>% RunHarmony("stim", plot_convergence = TRUE)
  harmony_embeddings <- Embeddings(mouse_selected_lung_ps, 'harmony') 
  #######################cluster
  dims = 1:30
  mouse_selected_lung_ps <- mouse_selected_lung_ps %>% 
    RunUMAP(reduction = "harmony", dims = dims) %>% 
    RunTSNE(reduction = "harmony", dims = dims) %>% 
    FindNeighbors(reduction = "harmony", dims = dims)%>% 
    FindClusters()
  
  
  DimPlot(mouse_selected_lung_ps,label = TRUE,label.size = 7)+
    ggtitle("mouse_selected_lung_ps")
  
}

DotPlot(mouse_selected_lung_ps,features = str_to_title(c("GPX1","GPX3",
                                              "Dio1","Gpx4","Rps14","Selh","Selk","Selm","Selo","Sels","Selt",
                                              "Sep15","Sepp1","Sepw1","Sepx1","Txnrd1",
                                              "Txnrd2","Txnrd3")))+
  RotatedAxis()+ggtitle("mouse_selected_lung_ps")


DotPlot(mouse_selected_lung_ps,features = c("Inmt","Cd34","Sepp1","Ly6a",
                                 "Gpx3","Selenop","Selp"))

dim(mouse_selected_lung_ps)
#######merge stable and perturbed- stable and fibrosi-------
subset_data$stim="stable"

All.merge=merge(subset_data,mouse_selected_lung_ps)

head(All.merge@meta.data)
table(All.merge$stim)
table(is.na(All.merge$stim))
All.merge$stim=case_when(is.na(All.merge$stim)~"stable",
                         .default = All.merge$stim)
table(All.merge$stim)


{
  
  All.merge[["percent.mt"]] <- PercentageFeatureSet(All.merge, pattern = "^mt-")
  VlnPlot(All.merge, features = c("nFeature_RNA", "nCount_RNA", "percent.mt"), ncol = 3)
  All.merge = All.merge %>%
    Seurat::NormalizeData(verbose = FALSE) %>%  
    FindVariableFeatures(selection.method = "vst", nfeatures = 2000) %>%
    ScaleData(verbose = FALSE) %>%
    RunPCA(npcs = 50, verbose = FALSE)
  
  #All.merge@meta.data$stim <- c(rep("Exp", length(grep("1$",colnames(All.merge)))),rep("Con", length(grep("2$",colnames(All.merge)))))
  table(All.merge$stim)
  
  library('harmony')
  
  All.merge <- All.merge %>% RunHarmony("stim", plot_convergence = TRUE)
  harmony_embeddings <- Embeddings(All.merge, 'harmony') 
  #######################cluster
  dims = 1:30
  All.merge <- All.merge %>% 
    RunUMAP(reduction = "harmony", dims = dims) %>% 
    RunTSNE(reduction = "harmony", dims = dims) %>% 
    FindNeighbors(reduction = "harmony", dims = dims)
  
  All.merge=FindClusters(All.merge)
  DimPlot(All.merge,label = TRUE,label.size = 7)
}

All.merge=All.merg
library(stringr)
DotPlot(All.merge,features = str_to_title(c("GPX1","GPX3",
                                                         "Dio1","Gpx4","Rps14","Selh","Selk","Selm","Selo","Sels","Selt",
                                                         "Sep15","Sepp1","Sepw1","Sepx1","Txnrd1",
                                                         "Txnrd2","Txnrd3")))+
  RotatedAxis()+ggtitle("allmerge_stable and fibrosis")


DotPlot(All.merge,features = c("Inmt","Cd34","Sepp1","Ly6a",
                                            "Gpx3","Selenop","Selp"))

DimPlot(All.merge,label = TRUE,
        split.by = "stim")
table(All.merge$stim)
All.merge$group =ifelse(All.merge$stim=="stable","Stable","Fibrosis")

FeaturePlot(All.merge,features = c("Inmt","Cd34","Sepp1","Ly6a",
                               "Gpx3","Selenop"),split.by = "group")


grep(pattern = "sele|sep|sel|inmt|selen",rownames(All.merge),ignore.case = TRUE,
     value = TRUE)

All.merg=RenameIdents(All.merge,"2"="universal fib",
                     "5"="universal fib",
                     "13"="universal fib",
                     "0"="specialized fib",
                     "3"="specialized fib")
ggplot(All.merg@meta.data, 
       aes(x=Idents(All.merg),fill=Idents(All.merg))) + geom_bar(position = "fill")  
 #+scale_fill_manual(values = c("royalblue", "red"))#scale_fill_gradientn(colors = colorRampPalette(c("royalblue", "firebrick3"))(12))#colorRampPalette(c("royalblue","firebrick3"))(2)

ggplot(All.merg@meta.data, 
       aes(x=Idents(All.merg), fill=group)) + geom_bar(position = "fill")+
  RotatedAxis()

  table(All.merg$group,Idents(All.merg))  #%>%summarise()
table(All.merg$group)

getwd()
save(All.merg,file = "All.merg.rds")


dir.create("G:/lung fibrosis/silicosis_cross_tissue_fibroblasts")
setwd("G:/lung fibrosis/silicosis_cross_tissue_fibroblasts")
load("G:/lung fibrosis/All.merg.rds")
library(ggplot2)
library(Seurat)
head(All.merg@meta.data)
table(All.merg$stim)
table(All.merg$group)
Idents(All.merg)=All.merg$group

degs_cross_tissue_mice_fibrosis_vs_stable=FindMarkers(All.merg,
                                                      ident.1 = "Fibrosis",
                                                        ident.2 = "Stable")
degs_cross_tissue_mice_fibrosis_vs_stable$gene=rownames(degs_cross_tissue_mice_fibrosis_vs_stable)

DT::datatable(degs_cross_tissue_mice_fibrosis_vs_stable)
openxlsx::write.xlsx(degs_cross_tissue_mice_fibrosis_vs_stable,
                     file ="degs_cross_tissue_mice_fibrosis_vs_stable.xlsx" )
相关推荐
bin915311 分钟前
当AI优化搜索引擎算法:Go初级开发者的创意突围实战指南
人工智能·算法·搜索引擎·工具·ai工具
人工智能培训1 小时前
深度学习—卷积神经网络(1)
人工智能·深度学习·神经网络·机器学习·cnn·知识图谱·dnn
云天徽上1 小时前
【机器学习】Kaggle案例之Rossmann连锁药店销售额预测:时间序列与机器学习完美融合的实战指南
机器学习·数据挖掘·kaggle
曹牧2 小时前
Java:Math.abs()‌
java·开发语言·算法
啊巴矲2 小时前
小白从零开始勇闯人工智能:机器学习初级篇(贝叶斯算法与SVM算法)
人工智能·机器学习·支持向量机
CoovallyAIHub2 小时前
纯视觉的终结?顶会趋势:不会联觉(多模态)的CV不是好AI
深度学习·算法·计算机视觉
CoovallyAIHub2 小时前
一文读懂大语言模型家族:LLM、MLLM、LMM、VLM核心概念全解析
深度学习·算法·计算机视觉
范纹杉想快点毕业3 小时前
嵌入式C语言实战开发详解
linux·运维·算法
闲看云起3 小时前
LeetCode day3-最长连续序列
算法·leetcode
智算菩萨3 小时前
【Python机器学习】交叉验证与超参数调优:自动化寻优之旅
人工智能·深度学习·机器学习