【视频演示】Nichenetr V2(三):nichenet分析之基于ligand-receptor的ligands排序

学术   2024-10-25 09:00   重庆  

偷偷问一下,关注了吗

内容获取


1、购买打包合集(《KS科研分享与服务》付费内容打包集合),价格感人,可以加入微信VIP群(答疑交流群,甚至有小伙伴觉得群比代码更好),可以获取建号以来所有内容,群成员专享视频教程,提前更新,其他更多福利!


2、《KS科研分享与服务》公众号有QQ群,进入门槛是20元(完全是为了防止白嫖党,请理解),请考虑清楚。群里有免费推文的注释代码和示例数据(终身拥有),没有付费内容,群成员福利是购买单个付费内容半价!


需要者详情请联系作者(非需要者勿扰,处理太费时间):


在之前的教程中(【视频教程】Nichenetr V2(一):单细胞通讯分析基础流程及可视化修饰),进行ligands活性分析之后,直接按照ligands活性进行了排序,然后分析target和receptor。作者也提供了另外的方式进行排序,根据配体和受体的细胞类型和条件特异性对配体进行优先排序(github提供了详细的教程,可仔细查看)。与之前唯一的区别在于对ligand的排序,前期的分析是一样的!我们这里还是按照分步法进行演示,如果嫌弃麻烦,可以用他提供的包装,只不过参数需要调整设置。本教程视频内容随之前教程提前发布了,微信VIP自行下载即可!

前期的分析和之前一样没有区别:
#load packages and datalibrary(nichenetr) library(Seurat)library(SeuratObject)library(tidyverse)

#load datasetwd("D:\\KS项目\\公众号文章\\nichenet单细胞通讯分析及可视化")load("D:/KS项目/公众号文章/nichenet单细胞通讯分析及可视化/scRNA_nichenet.RData")lr_network <- readRDS('./nichent-human-network/lr_network_human_21122021.rds')ligand_target_matrix <- readRDS('./nichent-human-network/ligand_target_matrix_nsga2r_final.rds')# target genes in rows, ligands in columnsweighted_networks <- readRDS('./nichent-human-network/weighted_networks_nsga2r_final.rds')lr_network <- lr_network %>% distinct(from, to)

#Perform the NicheNet analysis## 1. Define set of potential ligandsreceiver = "Tcell"expressed_genes_receiver <- get_expressed_genes(receiver, sce, pct = 0.1)
sender_celltypes <- c("Endo","Fib","Musc","Ker","APCs","Tcell","Mast","LY","Mela")list_expressed_genes_sender <- sender_celltypes %>% unique() %>% lapply(get_expressed_genes, sce, 0.1)expressed_genes_sender <- list_expressed_genes_sender %>% unlist() %>% unique()

all_ligands <- unique(lr_network$from)all_receptors <- unique(lr_network$to)
expressed_ligands <- intersect(all_ligands, expressed_genes_sender)expressed_receptors <- intersect(all_receptors, expressed_genes_receiver)
potential_ligands <- lr_network %>% filter(from %in% expressed_ligands & to %in% expressed_receptors) %>% pull(from) %>% unique()

# 2. Define the gene set of interestseurat_obj_receiver <- subset(sce, idents = receiver)DE_table_receiver <- FindMarkers(object = seurat_obj_receiver, ident.1 = "SD", ident.2 = "HC", group.by = "group", min.pct = 0.1) %>% rownames_to_column("gene")
geneset_oi <- DE_table_receiver %>% filter(p_val_adj <= 0.05 & abs(avg_log2FC) >= 0.25) %>% pull(gene)geneset_oi <- geneset_oi %>% .[. %in% rownames(ligand_target_matrix)]
# 3. Define background genesbackground_expressed_genes <- expressed_genes_receiver %>% .[. %in% rownames(ligand_target_matrix)]
# 4. Perform NicheNet ligand activity analysisligand_activities <- predict_ligand_activities(geneset = geneset_oi, background_expressed_genes = background_expressed_genes, ligand_target_matrix = ligand_target_matrix, potential_ligands = potential_ligands)ligand_activities <- ligand_activities %>% arrange(-aupr_corrected) %>% mutate(rank = rank(desc(aupr_corrected)))
然后执行差异分析:
lr_network_filtered <-  lr_network %>% filter(from %in% expressed_ligands & to %in% expressed_receptors)# 只计算实验组, with genes that are in the ligand-receptor networkDE_table <- FindAllMarkers(subset(sce, subset = group == "SD"),                           min.pct = 0, logfc.threshold = 0, return.thresh = 1,                           features = unique(unlist(lr_network_filtered))) 

# Average expression information - only for SD conditionexpression_info <- get_exprs_avg(sce, "celltype", condition_colname = "group", condition_oi = "SD", features = unique(unlist(lr_network_filtered)))
# Calculate condition specificity - only for datasets with two conditions!condition_markers <- FindMarkers(object = sce, ident.1 = "SD", ident.2 = "HC", group.by = "group", min.pct = 0, logfc.threshold = 0, features = unique(unlist(lr_network_filtered))) %>% rownames_to_column("gene")

# Combine DE of senders and receivers -> used for prioritizationprocessed_DE_table <- process_table_to_ic(DE_table, table_type = "celltype_DE", lr_network_filtered, senders_oi = sender_celltypes, receivers_oi = receiver)
processed_expr_table <- process_table_to_ic(expression_info, table_type = "expression", lr_network_filtered)
processed_condition_markers <- process_table_to_ic(condition_markers, table_type = "group_DE", lr_network_filtered)

# 不跑,一步法包装函数# info_tables <- generate_info_tables(seuratObj,# celltype_colname = "celltype",# senders_oi = sender_celltypes,# receivers_oi = receiver,# lr_network = lr_network_filtered,# condition_colname = "aggregate",# condition_oi = condition_oi,# condition_reference = condition_reference,# scenario = "case_control")
最后对结果排序:
prioritizing_weights = c("de_ligand" = 1,                         "de_receptor" = 1,                         "activity_scaled" = 1,                         "exprs_ligand" = 1,                         "exprs_receptor" = 1,                         "ligand_condition_specificity" = 1,                         "receptor_condition_specificity" = 1)
prior_table <- generate_prioritization_tables(processed_expr_table, processed_DE_table, ligand_activities, processed_condition_markers, prioritizing_weights)
#选取用去看排序的列即可prior_table <- prior_table %>% select(c('sender', 'receiver', 'ligand', 'receptor', 'scaled_p_val_adapted_ligand', 'scaled_p_val_adapted_receptor', 'scaled_avg_exprs_ligand', 'scaled_avg_exprs_receptor', 'scaled_p_val_adapted_ligand_group', 'scaled_p_val_adapted_receptor_group', 'scaled_activity'))

选择top的ligand进行分析,这种做法与之前有重叠,但是也有区别,至于选择什么方式,还是需要按照实际情况!希望我们的分享对你有用!

觉得我们分享有些用的,点个赞再走呗!

关注我们获取精彩内容:


关注不迷路:扫描下面二维码关注公众号!
B站视频号链接https://space.bilibili.com/471040659?spm_id_from=333.1007.0.0




关注 KS科研分享与服务,

认清正版优质内容和服务!

优质内容持续输出,物超所值!

合作联系:ks_account@163.com

新的板块-重要通知-双向选择

KS科研分享与服务
科研学习交流于分享,生信学习笔记,科研经历和生活!
 最新文章