monocle2 fibroblast silicosis inmt

gc()
#####安装archr包##别处复制
.libPaths(c("/home/data/t040413/R/x86_64-pc-linux-gnu-library/4.2","/home/data/t040413/R/yll/usr/local/lib/R/site-library", "/usr/local/lib/R/library","/home/data/refdir/Rlib/")).libPaths()library(Seurat)
library(ggplot2)
library(dplyr)
getwd()dir.create("~/silicosis/spatial/monocle/silicosis_fibroblasts")
setwd("~/silicosis/spatial/monocle/silicosis_fibroblasts")
print(getwd())##1 加载silicosis数据-------
#load("/home/data/t040413/silicosis/data/tabula_scRNAseq/integration_with_sc_silicosis/silicosis_fibro_AM3_mappedbacked.rds")load('/home/data/t040413/silicosis/fibroblast_myofibroblast2/subset_data_fibroblast_myofibroblast2.rds')
#subset_data=RenameIdents(subset_data,'Specialized fibroblast'='Inmt fibroblast')
#save(subset_data,file ='/home/data/t040413/silicosis/fibroblast_myofibroblast2/subset_data_fibroblast_myofibroblast2.rds' )DimPlot(subset_data,label = TRUE)
subset_data$cell.type=Idents(subset_data)
table(subset_data$cell.type)subset_data@meta.data %>%head()
subset_data$celltype=subset_data$cell.typeDimPlot(subset_data,label = T,group.by = "celltype")##############################################################33###monocle
#################################################subset_data$cell.type=Idents(subset_data)#Idents(subset_data)=subset_data$Idents.subset_data.###注意使用RNA 还是SCTDefaultAssay(subset_data)
DefaultAssay(subset_data)="RNA"
table(duplicated(rownames(subset_data)))
table(duplicated(colnames(subset_data)))
table(Idents(subset_data))
DefaultAssay(subset_data)
new.metadata <- merge(subset_data@meta.data,data.frame(Idents(subset_data)),by = "row.names",sort = FALSE)
head(new.metadata)
rownames(new.metadata)<-new.metadata[,1]#可选
head(subset_data@meta.data)
new.metadata=new.metadata[,-1]
head(subset_data@meta.data)identical(rownames(new.metadata),rownames(subset_data@meta.data))subset_data@meta.data<-new.metadata
table(subset_data$cell.type,Idents(subset_data))
head(subset_data)expression_matrix <- as(as.matrix(subset_data@assays$RNA@counts), 'sparseMatrix')
head(expression_matrix)
identical(colnames(expression_matrix),rownames(new.metadata))cell_metadata <- new('AnnotatedDataFrame',data=subset_data@meta.data)
head(subset_data@meta.data)
head(cell_metadata)gene_annotation <- new('AnnotatedDataFrame',data=data.frame(gene_short_name = row.names(subset_data),row.names = row.names(subset_data)))head(gene_annotation)
'''
head(gene_annotation)
fData(gene_annotation)
phenoData(gene_annotation)
featureData(gene_annotation)
table(subset_data$cell.type)
length(subset_data$cell.type)
table(Idents(subset_data))
length(Idents(subset_data))
'''DimPlot(subset_data,group.by = "cell.type",label = T)
DimPlot(subset_data,label = T)devtools::load_all("/home/data/t040413/ipf/diseased_lung_covid20/monocle/")monocle_cds <- monocle::newCellDataSet(expression_matrix,phenoData = cell_metadata,featureData = gene_annotation,lowerDetectionLimit = 0.5,expressionFamily = negbinomial.size())#####################################################################################归一化######
cds <- monocle_cds
cds <- estimateSizeFactors(cds)
cds <- estimateDispersions(cds)  ## Removing 110 outliers  #下面的cell.type 为subset_Data 的meta信息
library("BiocGenerics")#并行计算
devtools::load_all("/home/data/t040413/ipf/diseased_lung_covid20/monocle/")diff_test_res <- differentialGeneTest(cds,fullModelFormulaStr = "~ cell.type")### inference the pseudotrajectory########################################################
# step1: select genes for orderding setOrderingFilter() #
ordering_genes <- row.names (subset(diff_test_res, qval < 0.01))
length(ordering_genes)# 6354
cds <- setOrderingFilter(cds, ordering_genes)  
# step2: dimension reduction=> reduceDimension()  DDRTree #
cds <- reduceDimension(cds, max_components = 2,method = 'DDRTree')#package.version(pkg = "monocle")
# step3: ordering the cells=> orderCells()
#getwd()
#source("./order_cells.R")
#unloadNamespace('monocle')
#devtools::load_all("../monocle_2.26.0 (1).tar/monocle_2.26.0 (1)/monocle/")
devtools::load_all("/home/data/t040413/ipf/diseased_lung_covid20/monocle/")cds <- orderCells(cds)pdf("1.pseudutime.cell.type.pre.order.pdf")
plot_cell_trajectory(cds, color_by = "cell.type")  
dev.off()pdf("1.pseudutime.stim.pre.order.pdf")
plot_cell_trajectory(cds, color_by = "stim")  
dev.off()pdf("1.pseudutime.State.pre.order.pdf")
plot_cell_trajectory(cds, color_by = "State")  
dev.off()
###### split ########
pdf("2.split.pseudutime.Seurat.cell.type.pdf")
plot_cell_trajectory(cds, color_by = 'cell.type') + facet_wrap(~cell.type)
dev.off()pdf("2.split.pseudutime.stim.pdf")
plot_cell_trajectory(cds, color_by = "stim") + facet_wrap(~stim)
dev.off()pdf("4.split.pseudutime.Seurat.State.pdf")
plot_cell_trajectory(cds, color_by = 'cell.type') + facet_wrap(~State)
dev.off()pdf("3.split.pseudutime.Seurat.cell.type_State.pdf")
plot_cell_trajectory(cds, color_by = 'State') + facet_wrap(~cell.type)
dev.off()table(pData(cds)$State,pData(cds)$cell.type)
openxlsx::write.xlsx(table(pData(cds)$State,pData(cds)$cell.type), "State_cellType_summary.xlsx", colnames=T, rownames=T)table(pData(cds)$State,pData(cds)$stim)
openxlsx::write.xlsx(table(pData(cds)$State,pData(cds)$stim), "State_Stim_summary.xlsx", colnames=T, rownames=T)getwd()
##we set the state 2 as root ########state 2 with most cells in Endothelial cells
#这里设置谁为root??
DimPlot(subset_data,label = T)
table(Idents(subset_data))
DefaultAssay(subset_data)
#DefaultAssay(subset_data)<-"SCT"
DefaultAssay(subset_data)<-"RNA"
DimPlot(subset_data,label = T)
dev.off()table(subset_data$cell.type)
getwd()#设置root
ds <- orderCells(cds,root_state=2)getwd()# "/home/data/t040413/ipf/fibro_myofibro_recluster/+meso_monocle"pdf("4.pseudutime.Pseudotime.pdf")
p=plot_cell_trajectory(cds, color_by = "Pseudotime")  
print(p)
dev.off()save(cds,file="./cds_fibroblast_using_RNA_slot.rds")
#######################################################save(subset_data,file = "./fibroblast_formonocle.rds")getwd()
load("./cds_fibroblast_using_RNA_slot.rds")Idents(subset_data)
Markers_foreachclustercells=FindAllMarkers(subset_data,only.pos = T,logfc.threshold = 0.5)openxlsx::write.xlsx(Markers_foreachclustercells,file="./Markers_foreachclustercells.xlsx")getwd()
#############https://cloud.tencent.com/developer/article/1692225
#################################3
#Once we have a trajectory, we can use differentialGeneTest() to find genes 
#that have an expression pattern that varies according to pseudotime.#高变基因
disp_table <- dispersionTable(cds)
disp.genes <- subset(disp_table, mean_expression >= 0.5&dispersion_empirical >= 1*dispersion_fit)
disp.genes <- as.character(disp.genes$gene_id)
disp.genes
diff_test <- differentialGeneTest(cds[disp.genes,],  # cores = 4, fullModelFormulaStr = "~sm.ns(Pseudotime)")sig_gene_names <- row.names(subset(diff_test, qval < 1e-04))
p2 = plot_pseudotime_heatmap(cds[sig_gene_names,], num_clusters=5,show_rownames=T, return_heatmap=T)
ggsave("pseudotime_heatmap2.pdf", plot = p2, width = 5, height = 10)plot_pseudotime_heatmap(cds[c('Cx3cr1',"Spp1"),],# num_clusters = 5,#  cores = 4,show_rownames = T)###########################cds 里面的内容
fData(cds) %>%head()
pData(cds) %>%head()subset(fData(cds),gene_short_name %in% c("TPM1", "MYH3", "CCNB2", "GAPDH"))#############感兴趣基因的变化图
head(subset_data@meta.data)plot_genes_jitter(cds[c("TPM1", "MYH3", "CCNB2", "GAPDH"),],grouping = "cell.type", color_by = "cell.type", plot_trend = TRUE) +facet_wrap( ~ feature_label, scales= "free_y")#######拟时序热图
sig_gene_names=markers_for_eachcluster %>%group_by(cluster) %>% top_n(n = 5,wt = avg_log2FC) %>% ##加不加引号区别很大select(gene) %>% ungroup() %>%pull(gene)getwd()
p1 = plot_pseudotime_heatmap(cds[sig_gene_names,], num_clusters=3,show_rownames=T, return_heatmap=T)
ggsave("pseudotime/pseudotime_heatmap1.png", plot = p1, width = 5, height = 8)############################3
BEAM分析
devtools::load_all("/home/data/t040413/ipf/diseased_lung_covid20/monocle/")#单细胞轨迹中通常包括分支,它们的出现是因为细胞的表达模式不同。当细胞做出命运选择时,或者遗传、化学或环境扰动时,就会表现出不同的基因表达模式。BEAM(Branched expression analysis modeling)是一种统计方法,用于寻找以依赖于分支的方式调控的基因。disp_table <- dispersionTable(cds)
disp.genes <- subset(disp_table, mean_expression >= 0.5&dispersion_empirical >= 1*dispersion_fit)
disp.genes <- as.character(disp.genes$gene_id)
mycds_sub <- cds[disp.genes,]
plot_cell_trajectory(mycds_sub, color_by = "State")beam_res <- BEAM(mycds_sub, branch_point = 1,##如果大于1 后面一个参数就不需要progenitor_method = "duplicate") #, cores = 8beam_res <- beam_res[order(beam_res$qval),]
beam_res <- beam_res[,c("gene_short_name", "pval", "qval")]
mycds_sub_beam <- mycds_sub[row.names(subset(beam_res, qval < 1e-4)),]
plot_genes_branched_heatmap(mycds_sub_beam,  branch_point = 1, num_clusters = 3, show_rownames = T)methods <- c("duplicate", "expression", "cluster")results <- lapply(methods, function(method) {beam_res=BEAM(mycds_sub, branch_point = 1, progenitor_method = method)beam_res <- beam_res[order(beam_res$qval),]beam_res <- beam_res[,c("gene_short_name", "pval", "qval")]mycds_sub_beam <- mycds_sub[row.names(subset(beam_res, qval < 1e-4)),]results= plot_genes_branched_heatmap(mycds_sub_beam,  branch_point = 1, num_clusters = 3, show_rownames = T)for (each in names(results)) {pdf(paste0(each,".pdf"),height = 100,width = 10)print(each)dev.off()}  
})################################################################################
#https://davetang.org/muse/2017/10/01/getting-started-monocle/my_pseudotime_de %>% arrange(qval) %>% head()# save the top 6 genes
my_pseudotime_de %>% arrange(qval) %>% head() %>% select(id) -> my_pseudotime_gene
my_pseudotime_gene <- my_pseudotime_gene$idplot_genes_in_pseudotime(my_cds_subset[my_pseudotime_gene,])

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/338388.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Java接口的解析

在 Java 中&#xff0c;接口&#xff08;Interface&#xff09;是一种抽象类型&#xff0c;用于定义一组相关方法的契约。接口只包含方法的签名&#xff0c;而没有方法的实现。实现接口的类必须提供接口中定义的方法的具体实现。 以下是对 Java 接口的解析&#xff1a; 这只是…

构建安全可靠的系统:第二十一章到附录 A

第二十一章&#xff1a;建立安全和可靠性文化 原文&#xff1a;21. Building a Culture of Security and Reliability 译者&#xff1a;飞龙 协议&#xff1a;CC BY-NC-SA 4.0 作者&#xff1a;Heather Adkins 与 Peter Valchev&#xff0c;Felix Grbert&#xff0c;Ana Oprea…

15个等轴视图设计的电动车汽车无人机等PR剪辑素材视频制作元素

包含15个等轴视图、等距视角电动车、汽车、无人机、沙漏、飞机等PR剪辑素材视频制作元素mogrt动画模板。 特征&#xff1a; 等距设计&#xff1b; 可以更改颜色&#xff1b; 分辨率&#xff1a;全高清&#xff08;19201080&#xff09;&#xff1b; 持续时间&#xff1a;15秒&a…

SpringIOC之support模块GenericGroovyApplicationContext

博主介绍&#xff1a;✌全网粉丝5W&#xff0c;全栈开发工程师&#xff0c;从事多年软件开发&#xff0c;在大厂呆过。持有软件中级、六级等证书。可提供微服务项目搭建与毕业项目实战&#xff0c;博主也曾写过优秀论文&#xff0c;查重率极低&#xff0c;在这方面有丰富的经验…

k8s-----存储卷(数据卷)

容器内的目录和宿主机的目录进行挂载。 容器的生命状态是短站的&#xff0c;delete删除&#xff0c;k8s用控制创建的pod&#xff0c;delete相当于重启&#xff0c;容器的状态也会回复到初始状态。 一旦回到初始状态&#xff0c;所有的后天编辑的文件都会消失。 容器和节点之间创…

Camunda Event Based Gateway

一&#xff1a;bpmn 二&#xff1a;java 如果没有收到信号&#xff0c;超过等待时间&#xff0c;流程进入总经理审批&#xff0c;如果在等待时间内收到信号&#xff0c;流程进入副总经理审批。 示例1&#xff1a;发送信号事件&#xff0c;流程进入副总经理审批。 repository…

Camunda简介

一&#xff1a;简介 Camunda 团队成员是Activiti中的成员&#xff0c;Camunda是基于Activiti5的二次开发&#xff0c;同时提供Camunda7(组件方式)和Camunda8(云原生&#xff1a;部署在k8s,使用es作为数据库)两套并行发展。 官方文档 https://docs.camunda.org/manual/7.17/论…

插入排序-排序算法

前言 在玩斗地主的时候&#xff0c;你是如何理牌的&#xff1f; 当我们手中没扑克牌时&#xff0c;不管抓的是什么牌&#xff0c;都是放到手里。其他时候拿到一张牌&#xff0c;是从右向左找一个位置&#xff1a;右边是大于这张牌&#xff0c;左边是小于等于这张牌或者左边没有…

高照数量关系(三)—— 溶液问题 、植树问题、方阵问题、经济问题、基础行程、相对行程

溶液问题 溶液公式 反复操作 等量变化&#xff1a;蒸发稀释类 植树问题 两端 单端&#xff08;环形&#xff09; 楼间植树 不移动棵树 容斥原理种树问题 方阵问题 经济问题 基础经济 方程法 有具体钱数 赋值法 分段计费 函数最值 基础行程 普通行程 火车过桥 匀加速 等距…

从0到1实战微服务架构之Nacos下载安装

目录 一、前言 二、Nacos概述 三、Nacos架构 3.1 Open API 3.2 Config Service 3.3 Naming Service 3.4 Nacos Core 3.5 Consistency Protocol 四、Nacos部署实践 4.1 Nacos下载 4.2 Nacos部署 五、总结 一、前言 Nacos是一个开源的、易于使用的、功能丰富的平台&a…

我的年度总结(大一程序员的自述)

呀哈喽&#xff0c;我是结衣。 我也来参加这个年度总结的话题咯&#xff0c;喜欢的话可以点个赞哦。 作为一个大一新生&#xff0c;我从1级的编程小白到了现在的2级编程小白。在7月份之前我可以说是完全不了解编程的一位新人&#xff0c;对应电脑的了解也就只会打游戏看电视和浏…

JMeter 批量接口测试

一、背景 最近在进行某中台的接口测试准备&#xff0c;发现接口数量非常多&#xff0c;有6、70个&#xff0c;而且每个接口都有大量的参数并且需要进行各种参数验证来测试接口是否能够正确返回响应值。想了几种方案后&#xff0c;决定尝试使用JMeter的csv读取来实现批量的接口…