当前位置:网站首页>nichenet实战silicosis
nichenet实战silicosis
2022-06-30 15:48:00 【youngleeyoung】
############################################https://www.jianshu.com/p/5db596333dfb
#https://cloud.tencent.com/developer/article/1819551
.libPaths()
.libPaths("G:/R_big_packages/")
.libPaths(c("G:/R_big_packages/","D:/Win10 System/Documents/R/win-library/4.1","C:/Program Files/R/R-4.1.0/library"))
.libPaths()
installed.packages()[, c("Package", "LibPath")]
Sys.chmod(.libPaths(),'777')
#library(devtools)
#install_github("saeyslab/nichenetr")
#https://www.jianshu.com/p/c0f3c3728a8d
#如果不能正常加载包的话,就首先unloadNamespace这些包!!!!!!!!!!!!!!!!!!!!!!!!!!!!
for (packagename in c("dplyr","recipes","tidyselect",
"dbplyr","tidyr","ggpubr","ggplot2","usethis","broom")) {
unload(packagename)
}
library(nichenetr)
library(Seurat) # please update to Seurat V4
library(tidyverse)
library(ggplot2)
#BiocManager::install("glue")
#library("glue")
sessionInfo()
'''
NicheNet分析实践
数据来源
本文的分析数据和代码来自NicheNet官方分析单细胞数据的教程,
https://github.com/saeyslab/nichenetr/blob/master/vignettes/seurat_wrapper.md
演示数据集源自Medaglia et al. 2017 “Spatial Reconstruction of Immune Niches by Combining Photoactivatable Reporters and scRNA-Seq.” Science, December, eaao4277.
https://doi.org/10.1126/science.aao4277.
我们将使用Medaglia等人的小鼠NICHE-seq数据,探索淋巴细胞性脉络膜脑膜炎病毒(LCMV)感染之前
和之后72小时的腹股沟淋巴结T细胞区域的细胞间通讯。
在该数据集中,观察到稳态下的CD8 T细胞与LCMV感染后的CD8 T细胞之间存在差异表达。NicheNet可用于观察淋巴结中的几种免疫细胞群
(即单核细胞,树突状细胞,NK细胞,B细胞,CD4 T细胞)如何调节和诱导这些观察到的基因表达变化。
'''
getwd()
path="G:/silicosis/sicosis/NicheNet/6-30_silisosis"
dir.create(path)
setwd(path)
getwd()
1#读入单细胞数据
#seuratObj = readRDS(url("https://zenodo.org/record/3531889/files/seuratObj.rds"))
#save(seuratObj,file = "G:/silicosis/sicosis/NicheNet/seuratobj.rds")
load(file = "G:/silicosis/sicosis/NicheNet/seuratobj.rds")
seuratObj@meta.data %>% head() ##aggregate是处理条件,SS相当于control,LCMV相当于case。
seuratObj@assays$RNA@data[1107:1108,501:505]
2##读入nichenet先验数据
#ligand_target_matrix <- readRDS(url("https://zenodo.org/record/3260758/files/ligand_target_matrix.rds"))
#save(ligand_target_matrix,file ="G:/silicosis/sicosis/NicheNet/ligand_target_matrix.rds" )
load(file ="G:/silicosis/sicosis/NicheNet/ligand_target_matrix.rds")
head(ligand_target_matrix)[1:4,1:5] #说明是人源的数据
#lr_network = readRDS(url("https://zenodo.org/record/3260758/files/lr_network.rds"))
#save(lr_network,file = "G:/silicosis/sicosis/NicheNet/lr_network.rds")
load(file = "G:/silicosis/sicosis/NicheNet/lr_network.rds")
head(lr_network)
#weighted_networks = readRDS(url("https://zenodo.org/record/3260758/files/weighted_networks.rds"))
#save(weighted_networks,file ="G:/silicosis/sicosis/NicheNet/weighted_networks.rds" )
load(file = "G:/silicosis/sicosis/NicheNet/weighted_networks.rds")
weighted_networks_lr = weighted_networks$lr_sig %>% inner_join(lr_network %>% distinct(from,to), by = c("from","to"))
head(weighted_networks$lr_sig) # interactions and their weights in the ligand-receptor + signaling network
# weighted_networks列表包含两个数据框,lr_sig是配体-受体权重信号网络,gr是配体-靶基因权重调控网络
3 ###
'''
NicheNet分析
我们希望使用NicheNet预测哪些配体可能影响CD8 T细胞在LCMV感染后的差异表达基因。
此例中‘CD8 T cell’是receiver细胞,‘CD4 T’, ‘Treg’, ‘Mono’, ‘NK’, ‘B’ and ‘DC’是sender细胞。
NicheNet提供了一个打包函数nichenet_seuratobj_aggregate,它可以一步完成seurat对象的配体调控网络分析。
'''
scRNA=seuratObj
table(scRNA$celltype,scRNA$aggregate)
Idents(scRNA)
Idents(scRNA) <- "celltype"
nichenet_output = nichenet_seuratobj_aggregate(seurat_obj = scRNA,
top_n_ligands = 20,
receiver = "CD8 T",
sender = c("CD4 T","Treg", "Mono", "NK", "B", "DC"),
condition_colname = "aggregate",
condition_oi = "LCMV",
condition_reference = "SS",
ligand_target_matrix = ligand_target_matrix,
lr_network = lr_network,
weighted_networks = weighted_networks,
organism = "mouse")
# top_n_ligands参数指定用于后续分析的高活性配体的数量
#save(nichenet_output,file = "nichenet_output.rds")
load(file = "G:/silicosis/sicosis/NicheNet/nichenet_output.rds")
getwd()
4#NicheNet结果
## 查看配体活性分析结果
# 主要参考pearson指标,bona_fide_ligand=True代表有文献报道的配体-受体,
# bona_fide_ligand=False代表PPI预测未经实验证实的配体-受体。
head(nichenet_output)
names(nichenet_output)
x <- nichenet_output$ligand_activities
write.csv(x, "ligand_activities.csv", row.names = F)
5#
# 查看top20 ligands
nichenet_output$top_ligands
# 查看top20 ligands在各个细胞亚群中表达情况
p = DotPlot(scRNA, features = nichenet_output$top_ligands, cols = "RdYlBu") + RotatedAxis()
ggsave("top20_ligands.png", p, width = 12, height = 6)
# 按"aggregate"的分类对比配体的表达情况
p = DotPlot(scRNA, features = nichenet_output$top_ligands, split.by = "aggregate") + RotatedAxis()
ggsave("top20_ligands_compare.png", p, width = 12, height = 8)
# 用小提琴图对比配体的表达情况
p = VlnPlot(scRNA, features = nichenet_output$top_ligands,
split.by = "aggregate",split.plot = TRUE, pt.size = 0)
ggsave("VlnPlot_ligands_compare.png", p, width = 12, height = 8)
6#
## 查看配体调控靶基因
p = nichenet_output$ligand_target_heatmap
ggsave("Heatmap_ligand-target.png", p, width = 12, height = 6)
# 更改热图的风格
p = nichenet_output$ligand_target_heatmap +
scale_fill_gradient2(low = "whitesmoke", high = "royalblue", breaks = c(0,0.0045,0.009)) +
xlab("anti-LCMV response genes in CD8 T cells") +
ylab("Prioritized immmune cell ligands")
ggsave("Heatmap_ligand-target2.png", p, width = 12, height = 6)
# 查看top配体调控的靶基因及其评分
x <- nichenet_output$ligand_target_matrix
#x2 <- nichenet_output$ligand_target_df
write.csv(x, "ligand_target.csv", row.names = F)
# 查看被配体调控靶基因的表达情况
p = DotPlot(scRNA %>% subset(idents = "CD8 T"),
features = nichenet_output$top_targets,
split.by = "aggregate") + RotatedAxis()
ggsave("Targets_Expression_dotplot.png", p, width = 12, height = 6)
p = VlnPlot(scRNA %>% subset(idents = "CD8 T"), features = nichenet_output$top_targets,
split.by = "aggregate", pt.size = 0, combine = T, ncol = 8)
ggsave("Targets_Expression_vlnplot.png", p, width = 12, height = 8)
7#
## 查看受体情况
# 查看配体-受体互作
p = nichenet_output$ligand_receptor_heatmap
ggsave("Heatmap_ligand-receptor.png", p, width = 12, height = 6)
x <- nichenet_output$ligand_receptor_matrix
#x <- nichenet_output$ligand_receptor_df
write.csv(x, "ligand_receptor.csv", row.names = F)
# 查看受体表达情况
p = DotPlot(scRNA %>% subset(idents = "CD8 T"),
features = nichenet_output$top_receptors,
split.by = "aggregate") + RotatedAxis()
ggsave("Receptors_Expression_dotplot.png", p, width = 12, height = 6)
p = VlnPlot(scRNA %>% subset(idents = "CD8 T"), features = nichenet_output$top_receptors,
split.by = "aggregate", pt.size = 0, combine = T, ncol = 8)
ggsave("Receptors_Expression_vlnplot.png", p, width = 12, height = 8)
# 有文献报道的配体-受体
# Show ‘bona fide’ ligand-receptor links
#that are described in the literature and not predicted based on PPI
p = nichenet_output$ligand_receptor_heatmap_bonafide
ggsave("Heatmap_ligand-receptor_bonafide.png", p, width = 8, height = 4)
x <- nichenet_output$ligand_receptor_matrix_bonafide
#x <- nichenet_output$ligand_receptor_df_bonafide
write.csv(x, "ligand_receptor_bonafide.csv", row.names = F)
边栏推荐
- Lambda expression_ Stream stream_ File class
- 删除有序数组中的重复项 II[双指针--多情况统一]
- Additional: (not written yet, don't look at ~ ~ ~) corsfilter filter;
- Niuke.com: minimum cost of climbing stairs
- Li Zexiang, a legendary Chinese professor, is making unicorns in batches
- Rong Lianyun launched rphone based on Tongxin UOS to create a new ecology of localization contact center
- After 15 years of working on 21 types of hardware, where is Google?
- 更多龙蜥自研特性!生产可用的 Anolis OS 8.6 正式发布
- Cmakelists Basics
- 2022 Blue Bridge Cup group B - expense reimbursement - (linear dp| status DP)
猜你喜欢

Research on helmet wearing detection algorithm

八大基本排序(详解)

Tencent two sides: @bean and @component are used on the same class. What happens?

微信表情符号写入判决书,你发的OK、炸弹都可能成为“呈堂证供”

RT-Thread 堆區大小設置

备战数学建模35-时间序列预测模型

牛客网:乘积为正数的最长连续子数组

Symantec electronic sprint technology innovation board: Tan Jian, the actual controller, is an American who plans to raise 620million yuan

MC Instruction Decoder

Half year inventory of new consumption in 2022: the industry is cold, but these nine tracks still attract gold
随机推荐
Li Zexiang, a legendary Chinese professor, is making unicorns in batches
register_chrdev和cdev_init cdev_add用法区别
2022蓝桥杯国赛B组-费用报销-(线性dp|状态dp)
[wechat applet] the hosting environment of the applet
Lambda表达式_Stream流_File类
2022 Blue Bridge Cup group B - expense reimbursement - (linear dp| status DP)
The meaning of linetypes enumeration values (line_4, line_8, line_aa) in opencv
Simpleitk encountered an ITK only supports orthonormal direction cosines error while reading NII
居家办公浅谈远程协助快速提效心得 | 社区征文
register_ Chrdev and CDEV_ init cdev_ Add usage differences
Yunhe enmo won the bid for Oracle maintenance project of Tianjin Binhai rural commercial bank in 2022-2023
【微信小程序】小程序的宿主环境
Wechat emoticons are written into the judgment, and the OK and bomb you send may become "testimony in court"
RT thread heap size setting
2020 Blue Bridge Cup group B - move bricks - (greedy sorting +01 backpack)
附加:(还没写,别看~~~)WebMvcConfigurer接口;
为了使远程工作不受影响,我写了一个内部的聊天室 | 社区征文
异常类_日志框架
安全帽佩戴检测算法研究
深度学习——(2)几种常见的损失函数