当前位置:网站首页>Differential analysis between different groups nichenet for silicosis runs successfully!
Differential analysis between different groups nichenet for silicosis runs successfully!
2022-06-30 17:03:00 【youngleeyoung】

#https://github.com/thomasp85/patchwork/issues/245
#https://stackoverflow.com/questions/62599918/ggplot2-cant-add-to-a-ggplot-object
unload("patchwork")
install.packages("patchwork", repos = "https://cloud.r-project.org")
#https://github.com/howtofindme/nichenetr/blob/master/vignettes/differential_nichenet_pEMT.md
getwd()
path="G:/silicosis/sicosis/NicheNet/differential_nichenet_pEMT/FOR_Silicosis"
dir.create(path)
setwd(path)
getwd()
library(nichenetr)
library(RColorBrewer)
library(tidyverse)
library(Seurat) #
1 Get ready #Read in the expression data
#In this case study, we want to study differences in cell-cell communication patterns
#between pEMT-high and pEMT-low tumors. The meta data columns that
#indicate the pEMT status of tumors are ‘pEMT,’ and the cell type is indicated in the ‘celltype’ column.
getwd()
#seurat_obj = readRDS(url("https://zenodo.org/record/4675430/files/seurat_obj_hnscc.rds"))
#seurat_obj=UpdateSeuratObject(seurat_obj)
#save(seurat_obj,file = "G:/silicosis/sicosis/NicheNet/differential_nichenet_pEMT/seurat_obj.rds")
load(file = "G:/silicosis/sicosis/NicheNet/differential_nichenet_pEMT/seurat_obj.rds")
Assays(seurat_obj)
load("G:/silicosis/sicosis/yll/macrophage/no cluster2/0.3/pure_cluster3_in_allmerge-IM/silicosis_cluster_merge.rds")
table(All.merge$cell.type)
table(Idents(All.merge))
All.merge$celltype=Idents(All.merge)
seurat_obj=All.merge
seurat_obj$pEMT=seurat_obj$stim
DimPlot(seurat_obj, group.by = "celltype") # user adaptation required on own dataset
table(Idents(seurat_obj))
seurat_obj=subset(seurat_obj,idents = c("NS_56","SiO2_56"))
Idents(seurat_obj)=seurat_obj$stim
library("patchwork")
DimPlot(seurat_obj, group.by = "pEMT") # user adaptation required on own dataset
DimPlot(seurat_obj, group.by = "celltype") # user adaptation required on own dataset
#We will now also check the number of cells per cell type condition combination
table(seurat_obj@meta.data$celltype, seurat_obj@meta.data$pEMT) # cell types vs conditions # user adaptation required on own dataset
seurat_obj$pEMT=Idents(seurat_obj)
#For the Differential NicheNet, we need to compare at least 2 niches or conditions to each other.
#In this case, the 2 niches are the pEMT-high-niche and the pEMT-low-niche.
#We will adapt the names of the cell types based on their niche of origin.
seurat_obj@meta.data$celltype_aggregate = paste(seurat_obj@meta.data$celltype, seurat_obj@meta.data$pEMT,sep = "_") # user adaptation required on own dataset
DimPlot(seurat_obj, group.by = "celltype_aggregate")
seurat_obj@meta.data$celltype_aggregate %>% table() %>% sort(decreasing = TRUE)
celltype_id = "celltype_aggregate" # metadata column name of the cell type of interest
seurat_obj = SetIdent(seurat_obj, value = seurat_obj[[celltype_id]]) # Put the interested niche Name the default idents
table(Idents(seurat_obj))
2# Get ready #Read in the NicheNet ligand-receptor network and ligand-target matrix
#ligand_target_matrix = readRDS(url("https://zenodo.org/record/3260758/files/ligand_target_matrix.rds"))
load(file ="G:/silicosis/sicosis/NicheNet/ligand_target_matrix.rds")
ligand_target_matrix[1:5,1:5] # target genes in rows, ligands in columns
load(file = "G:/silicosis/sicosis/NicheNet/lr_network.rds")
head(lr_network)
library(dplyr)
lr_network = lr_network %>% mutate(bonafide = ! database %in% c("ppi_prediction","ppi_prediction_go"))
lr_network = lr_network %>% dplyr::rename(ligand = from, receptor = to) %>% distinct(ligand, receptor, bonafide)
head(lr_network)
#Note: if your data is of mouse origin: convert human gene symbols to their one-to-one orthologs
organism = "human" # user adaptation required on own dataset
organism="mouse"
library("tidyr")
if(organism == "mouse"){
lr_network = lr_network %>% mutate(ligand = convert_human_to_mouse_symbols(ligand), receptor = convert_human_to_mouse_symbols(receptor)) %>% drop_na()
colnames(ligand_target_matrix) = ligand_target_matrix %>% colnames() %>% convert_human_to_mouse_symbols()
rownames(ligand_target_matrix) = ligand_target_matrix %>% rownames() %>% convert_human_to_mouse_symbols()
ligand_target_matrix = ligand_target_matrix %>% .[!is.na(rownames(ligand_target_matrix)), !is.na(colnames(ligand_target_matrix))]
}
1. #Define the niches/microenvironments of interest
#Each niche should have at least one “sender/niche” cell population and one “receiver/target” cell population (present in your expression data)
niches = list(
"pEMT_High_niche" = list(
"sender" = c("myofibroblast_High", "Endothelial_High", "CAF_High", "T.cell_High", "Myeloid_High"),
"receiver" = c("Malignant_High")),
"pEMT_Low_niche" = list(
"sender" = c("myofibroblast_Low", "Endothelial_Low", "CAF_Low"),
"receiver" = c("Malignant_Low"))
) # user adaptation required on own dataset
niches = list(
"pEMT_High_niche" = list(
"sender" = c("Dendritic cell_SiO2_56", "Neutrophil_SiO2_56", "B cell_SiO2_56", "AT2 cell-3_SiO2_56", "T cell_SiO2_56",
"AM3_SiO2_56","AM1_SiO2_56","Monocyte_SiO2_56","Cycling basal cell_SiO2_56","Endothelial cell-2_SiO2_56",
"NK cell_SiO2_56","AM2_SiO2_56","Endothelial cell-1_SiO2_56","AT2 cell-1_SiO2_56"
),
"receiver" = c("Fibroblast_SiO2_56")),
"pEMT_Low_niche" = list(
"sender" = c("Monocyte_NS_56","Neutrophil_NS_56", "T cell_NS_56", "Dendritic cell_NS_56","NK cell_NS_56",
"AM1_NS_56","B cell_NS_56","Endothelial cell-1_NS_56","AT2 cell-3_NS_56"),
"receiver" = c("Fibroblast_NS_56"))
) # user adaptation required on own dataset
2.# Calculate differential expression between the niches
#In this step, we will determine DE between the different niches for both senders and receivers to define the DE of L-R pairs.
2.1#Calculate DE
Assays(seurat_obj)
assay_oi = "RNA" # other possibilities: RNA,...
DE_sender = calculate_niche_de(seurat_obj = seurat_obj %>%
subset(features = lr_network$ligand %>%
unique()), niches = niches,
type = "sender", assay_oi = assay_oi) # only ligands important for sender cell types
DE_receiver = calculate_niche_de(seurat_obj = seurat_obj %>%
subset(features = lr_network$receptor %>%
unique()), niches = niches,
type = "receiver", assay_oi = assay_oi) # only receptors now, later on: DE analysis to find targets
2.2#Process DE results:
expression_pct = 0.10
DE_sender_processed = process_niche_de(DE_table = DE_sender,
niches = niches,
expression_pct = expression_pct, type = "sender")
DE_receiver_processed = process_niche_de(DE_table = DE_receiver,
niches = niches,
expression_pct = expression_pct, type = "receiver")
2.3#Combine sender-receiver DE based on L-R pairs:
specificity_score_LR_pairs = "min_lfc"
DE_sender_receiver = combine_sender_receiver_de(DE_sender_processed, DE_receiver_processed,
lr_network, specificity_score = specificity_score_LR_pairs)
3.# Optional: Calculate differential expression between the different spatial regions
#We do this as follows, by first defining a ‘spatial info’ dataframe.
#If no spatial information in your data: set the following two parameters to FALSE, and make a mock ‘spatial_info’ data frame.
table(seurat_obj@meta.data$celltype_aggregate)
table(seurat_obj$pEMT)
# this is how this should be defined if you don't have spatial info
# mock spatial info
include_spatial_info_sender = TRUE # if not spatial info to include: put this to false # user adaptation required on own dataset
include_spatial_info_receiver = FALSE # if spatial info to include: put this to true # user adaptation required on own dataset
spatial_info = tibble(celltype_region_oi = "AM3_SiO2_56",
celltype_other_region = "B cell_SiO2_56",
niche = "pEMT_SiO2_56_niche", celltype_type = "sender") # user adaptation required on own dataset
specificity_score_spatial = "lfc"
# this is how this should be defined if you don't have spatial info
# mock spatial info
if(include_spatial_info_sender == FALSE & include_spatial_info_receiver == FALSE){
spatial_info = tibble(celltype_region_oi = NA, celltype_other_region = NA) %>% mutate(niche = niches %>% names() %>% head(1), celltype_type = "sender")
}
if(include_spatial_info_sender == TRUE){
sender_spatial_DE = calculate_spatial_DE(assay_oi = assay_oi,seurat_obj = seurat_obj %>% subset(features = lr_network$ligand %>% unique()), spatial_info = spatial_info %>% filter(celltype_type == "sender"))
sender_spatial_DE_processed = process_spatial_de(DE_table = sender_spatial_DE, type = "sender", lr_network = lr_network, expression_pct = expression_pct, specificity_score = specificity_score_spatial)
# add a neutral spatial score for sender celltypes in which the spatial is not known / not of importance
sender_spatial_DE_others = get_non_spatial_de(niches = niches, spatial_info = spatial_info, type = "sender", lr_network = lr_network)
sender_spatial_DE_processed = sender_spatial_DE_processed %>% bind_rows(sender_spatial_DE_others)
sender_spatial_DE_processed = sender_spatial_DE_processed %>% mutate(scaled_ligand_score_spatial = scale_quantile_adapted(ligand_score_spatial))
} else {
# # add a neutral spatial score for all sender celltypes (for none of them, spatial is relevant in this case)
sender_spatial_DE_processed = get_non_spatial_de(niches = niches, spatial_info = spatial_info, type = "sender", lr_network = lr_network)
sender_spatial_DE_processed = sender_spatial_DE_processed %>% mutate(scaled_ligand_score_spatial = scale_quantile_adapted(ligand_score_spatial))
}
## [1] "Calculate Spatial DE between: CAF_High and myofibroblast_High"
if(include_spatial_info_receiver == TRUE){
receiver_spatial_DE = calculate_spatial_DE(assay_oi = assay_oi,seurat_obj = seurat_obj %>% subset(features = lr_network$receptor %>% unique()), spatial_info = spatial_info %>% filter(celltype_type == "receiver"))
receiver_spatial_DE_processed = process_spatial_de(DE_table = receiver_spatial_DE, type = "receiver", lr_network = lr_network, expression_pct = expression_pct, specificity_score = specificity_score_spatial)
# add a neutral spatial score for receiver celltypes in which the spatial is not known / not of importance
receiver_spatial_DE_others = get_non_spatial_de(niches = niches, spatial_info = spatial_info, type = "receiver", lr_network = lr_network)
receiver_spatial_DE_processed = receiver_spatial_DE_processed %>% bind_rows(receiver_spatial_DE_others)
receiver_spatial_DE_processed = receiver_spatial_DE_processed %>% mutate(scaled_receptor_score_spatial = scale_quantile_adapted(receptor_score_spatial))
} else {
# # add a neutral spatial score for all receiver celltypes (for none of them, spatial is relevant in this case)
receiver_spatial_DE_processed = get_non_spatial_de(niches = niches, spatial_info = spatial_info, type = "receiver", lr_network = lr_network)
receiver_spatial_DE_processed = receiver_spatial_DE_processed %>% mutate(scaled_receptor_score_spatial = scale_quantile_adapted(receptor_score_spatial))
}
4. #Calculate ligand activities and infer active ligand-target links
#In this step, we will predict ligand activities of each ligand for each of the receiver cell types across the different niches.
#This is similar to the ligand activity analysis done in the normal NicheNet pipeline.
lfc_cutoff = 0.15 # recommended for 10x as min_lfc cutoff.
specificity_score_targets = "min_lfc"
DE_receiver_targets = calculate_niche_de_targets(seurat_obj = seurat_obj,
niches = niches, lfc_cutoff = lfc_cutoff,
expression_pct = expression_pct, assay_oi = assay_oi)
DE_receiver_processed_targets = process_receiver_target_de(DE_receiver_targets = DE_receiver_targets,
niches = niches, expression_pct = expression_pct,
specificity_score = specificity_score_targets)
background = DE_receiver_processed_targets %>% pull(target) %>% unique()
geneset_niche1 = DE_receiver_processed_targets %>% filter(receiver == niches[[1]]$receiver & target_score >= lfc_cutoff & target_significant == 1 & target_present == 1) %>% pull(target) %>% unique()
geneset_niche2 = DE_receiver_processed_targets %>% filter(receiver == niches[[2]]$receiver & target_score >= lfc_cutoff & target_significant == 1 & target_present == 1) %>% pull(target) %>% unique()
# Good idea to check which genes will be left out of the ligand activity analysis (=when not present in the rownames of the ligand-target matrix).
# If many genes are left out, this might point to some issue in the gene naming (eg gene aliases and old gene symbols, bad human-mouse mapping)
geneset_niche1 %>% setdiff(rownames(ligand_target_matrix))
geneset_niche2 %>% setdiff(rownames(ligand_target_matrix))
length(geneset_niche1)
length(geneset_niche2)
lfc_cutoff = 0.75
specificity_score_targets = "min_lfc"
DE_receiver_processed_targets = process_receiver_target_de(DE_receiver_targets = DE_receiver_targets, niches = niches, expression_pct = expression_pct, specificity_score = specificity_score_targets)
background = DE_receiver_processed_targets %>% pull(target) %>% unique()
geneset_niche1 = DE_receiver_processed_targets %>% filter(receiver == niches[[1]]$receiver & target_score >= lfc_cutoff & target_significant == 1 & target_present == 1) %>% pull(target) %>% unique()
geneset_niche2 = DE_receiver_processed_targets %>% filter(receiver == niches[[2]]$receiver & target_score >= lfc_cutoff & target_significant == 1 & target_present == 1) %>% pull(target) %>% unique()
geneset_niche1 %>% setdiff(rownames(ligand_target_matrix))
geneset_niche2 %>% setdiff(rownames(ligand_target_matrix))
length(geneset_niche1)
length(geneset_niche2)
top_n_target = 250
table(seurat_obj$pEMT)
niche_geneset_list = list(
"pEMT_SiO2_56_niche" = list(
"receiver" = niches[[1]]$receiver,
"geneset" = geneset_niche1,
"background" = background),
"pEMT_NS_56_niche" = list(
"receiver" = niches[[2]]$receiver,
"geneset" = geneset_niche2 ,
"background" = background)
)
ligand_activities_targets = get_ligand_activities_targets(niche_geneset_list = niche_geneset_list,
ligand_target_matrix = ligand_target_matrix,
top_n_target = top_n_target)
5#Calculate (scaled) expression of ligands, receptors and targets across cell types of interest
#(log expression values and expression fractions)
#In this step, we will calculate average (scaled) expression, and fraction of expression, of ligands, receptors, and target genes across all cell types of interest. Now this is here demonstrated via the DotPlot function of Seurat, but this can also be done via other ways of course.
features_oi = union(lr_network$ligand, lr_network$receptor) %>% union(ligand_activities_targets$target) %>% setdiff(NA)
dotplot = suppressWarnings(Seurat::DotPlot(seurat_obj %>% subset(idents = niches %>% unlist() %>% unique()), features = features_oi, assay = assay_oi))
exprs_tbl = dotplot$data %>% as_tibble()
exprs_tbl = exprs_tbl %>% rename(celltype = id, gene = features.plot, expression = avg.exp, expression_scaled = avg.exp.scaled, fraction = pct.exp) %>%
mutate(fraction = fraction/100) %>% as_tibble() %>% select(celltype, gene, expression, expression_scaled, fraction) %>% distinct() %>% arrange(gene) %>% mutate(gene = as.character(gene))
exprs_tbl_ligand = exprs_tbl %>% filter(gene %in% lr_network$ligand) %>% rename(sender = celltype, ligand = gene, ligand_expression = expression, ligand_expression_scaled = expression_scaled, ligand_fraction = fraction)
exprs_tbl_receptor = exprs_tbl %>% filter(gene %in% lr_network$receptor) %>% rename(receiver = celltype, receptor = gene, receptor_expression = expression, receptor_expression_scaled = expression_scaled, receptor_fraction = fraction)
exprs_tbl_target = exprs_tbl %>% filter(gene %in% ligand_activities_targets$target) %>% rename(receiver = celltype, target = gene, target_expression = expression, target_expression_scaled = expression_scaled, target_fraction = fraction)
exprs_tbl_ligand = exprs_tbl_ligand %>% mutate(scaled_ligand_expression_scaled = scale_quantile_adapted(ligand_expression_scaled)) %>% mutate(ligand_fraction_adapted = ligand_fraction) %>% mutate_cond(ligand_fraction >= expression_pct, ligand_fraction_adapted = expression_pct) %>% mutate(scaled_ligand_fraction_adapted = scale_quantile_adapted(ligand_fraction_adapted))
exprs_tbl_receptor = exprs_tbl_receptor %>% mutate(scaled_receptor_expression_scaled = scale_quantile_adapted(receptor_expression_scaled)) %>% mutate(receptor_fraction_adapted = receptor_fraction) %>% mutate_cond(receptor_fraction >= expression_pct, receptor_fraction_adapted = expression_pct) %>% mutate(scaled_receptor_fraction_adapted = scale_quantile_adapted(receptor_fraction_adapted))
6.# Expression fraction and receptor
#In this step, we will score ligand-receptor interactions based on expression strength of the receptor, in such a way that we give higher scores to the most strongly expressed receptor of a certain ligand, in a certain celltype. This will not effect the rank of individual ligands later on, but will help in prioritizing the most important receptors per ligand (next to other factors regarding the receptor - see later).
exprs_sender_receiver = lr_network %>%
inner_join(exprs_tbl_ligand, by = c("ligand")) %>%
inner_join(exprs_tbl_receptor, by = c("receptor")) %>% inner_join(DE_sender_receiver %>% distinct(niche, sender, receiver))
ligand_scaled_receptor_expression_fraction_df = exprs_sender_receiver %>% group_by(ligand, receiver) %>% mutate(rank_receptor_expression = dense_rank(receptor_expression), rank_receptor_fraction = dense_rank(receptor_fraction)) %>% mutate(ligand_scaled_receptor_expression_fraction = 0.5*( (rank_receptor_fraction / max(rank_receptor_fraction)) + ((rank_receptor_expression / max(rank_receptor_expression))) ) ) %>% distinct(ligand, receptor, receiver, ligand_scaled_receptor_expression_fraction, bonafide) %>% distinct() %>% ungroup()
7. #Prioritization of ligand-receptor and ligand-target links
prioritizing_weights = c("scaled_ligand_score" = 5,
"scaled_ligand_expression_scaled" = 1,
"ligand_fraction" = 1,
"scaled_ligand_score_spatial" = 2,
"scaled_receptor_score" = 0.5,
"scaled_receptor_expression_scaled" = 0.5,
"receptor_fraction" = 1,
"ligand_scaled_receptor_expression_fraction" = 1,
"scaled_receptor_score_spatial" = 0,
"scaled_activity" = 0,
"scaled_activity_normalized" = 1,
"bona_fide" = 1)
#Note: these settings will give substantially more weight to DE ligand-receptor pairs compared to activity. Users can change this if wanted, just like other settings can be changed if that would be better to tackle the specific biological question you want to address.
output = list(DE_sender_receiver = DE_sender_receiver,
ligand_scaled_receptor_expression_fraction_df = ligand_scaled_receptor_expression_fraction_df,
sender_spatial_DE_processed = sender_spatial_DE_processed, receiver_spatial_DE_processed = receiver_spatial_DE_processed,
ligand_activities_targets = ligand_activities_targets, DE_receiver_processed_targets = DE_receiver_processed_targets, exprs_tbl_ligand = exprs_tbl_ligand, exprs_tbl_receptor = exprs_tbl_receptor, exprs_tbl_target = exprs_tbl_target)
prioritization_tables = get_prioritization_tables(output, prioritizing_weights)
prioritization_tables$prioritization_tbl_ligand_receptor %>% filter(receiver == niches[[1]]$receiver) %>% head(10)
## # A tibble: 10 x 37
## niche receiver sender ligand_receptor ligand receptor bonafide ligand_score ligand_signific~ ligand_present ligand_expressi~
## <chr> <chr> <chr> <chr> <chr> <chr> <lgl> <dbl> <dbl> <dbl> <dbl>
## 1 pEMT_H~ Malignan~ T.cel~ PTPRC--MET PTPRC MET FALSE 3.22 1 1 9.32
## 2 pEMT_H~ Malignan~ T.cel~ PTPRC--EGFR PTPRC EGFR FALSE 3.22 1 1 9.32
## 3 pEMT_H~ Malignan~ T.cel~ PTPRC--CD44 PTPRC CD44 FALSE 3.22 1 1 9.32
## 4 pEMT_H~ Malignan~ T.cel~ PTPRC--ERBB2 PTPRC ERBB2 FALSE 3.22 1 1 9.32
## 5 pEMT_H~ Malignan~ T.cel~ PTPRC--IFNAR1 PTPRC IFNAR1 FALSE 3.22 1 1 9.32
## 6 pEMT_H~ Malignan~ T.cel~ TNF--TNFRSF21 TNF TNFRSF21 TRUE 1.74 1 1 2.34
## 7 pEMT_H~ Malignan~ Myelo~ SERPINA1--LRP1 SERPI~ LRP1 TRUE 2.52 1 1 4.83
## 8 pEMT_H~ Malignan~ Myelo~ IL1B--IL1RAP IL1B IL1RAP TRUE 1.50 1 1 1.93
## 9 pEMT_H~ Malignan~ Myelo~ IL1RN--IL1R2 IL1RN IL1R2 TRUE 1.62 1 1 2.07
## 10 pEMT_H~ Malignan~ T.cel~ PTPRC--INSR PTPRC INSR FALSE 3.22 1 1 9.32
## # ... with 26 more variables: ligand_expression_scaled <dbl>, ligand_fraction <dbl>, ligand_score_spatial <dbl>,
## # receptor_score <dbl>, receptor_significant <dbl>, receptor_present <dbl>, receptor_expression <dbl>,
## # receptor_expression_scaled <dbl>, receptor_fraction <dbl>, receptor_score_spatial <dbl>,
## # ligand_scaled_receptor_expression_fraction <dbl>, avg_score_ligand_receptor <dbl>, activity <dbl>, activity_normalized <dbl>,
## # scaled_ligand_score <dbl>, scaled_ligand_expression_scaled <dbl>, scaled_receptor_score <dbl>,
## # scaled_receptor_expression_scaled <dbl>, scaled_avg_score_ligand_receptor <dbl>, scaled_ligand_score_spatial <dbl>,
## # scaled_receptor_score_spatial <dbl>, scaled_ligand_fraction_adapted <dbl>, scaled_receptor_fraction_adapted <dbl>, ...
prioritization_tables$prioritization_tbl_ligand_target %>% filter(receiver == niches[[1]]$receiver) %>% head(10)
## # A tibble: 10 x 20
## niche receiver sender ligand_receptor ligand receptor bonafide target target_score target_signific~ target_present
## <chr> <chr> <chr> <chr> <chr> <chr> <lgl> <chr> <dbl> <dbl> <dbl>
## 1 pEMT_High_niche Malignant~ T.cell~ PTPRC--MET PTPRC MET FALSE EHF 1.04 1 1
## 2 pEMT_High_niche Malignant~ T.cell~ PTPRC--MET PTPRC MET FALSE GADD4~ 0.836 1 1
## 3 pEMT_High_niche Malignant~ T.cell~ PTPRC--MET PTPRC MET FALSE SERPI~ 0.889 1 1
## 4 pEMT_High_niche Malignant~ T.cell~ PTPRC--EGFR PTPRC EGFR FALSE EHF 1.04 1 1
## 5 pEMT_High_niche Malignant~ T.cell~ PTPRC--EGFR PTPRC EGFR FALSE GADD4~ 0.836 1 1
## 6 pEMT_High_niche Malignant~ T.cell~ PTPRC--EGFR PTPRC EGFR FALSE SERPI~ 0.889 1 1
## 7 pEMT_High_niche Malignant~ T.cell~ PTPRC--CD44 PTPRC CD44 FALSE EHF 1.04 1 1
## 8 pEMT_High_niche Malignant~ T.cell~ PTPRC--CD44 PTPRC CD44 FALSE GADD4~ 0.836 1 1
## 9 pEMT_High_niche Malignant~ T.cell~ PTPRC--CD44 PTPRC CD44 FALSE SERPI~ 0.889 1 1
## 10 pEMT_High_niche Malignant~ T.cell~ PTPRC--ERBB2 PTPRC ERBB2 FALSE EHF 1.04 1 1
## # ... with 9 more variables: target_expression <dbl>, target_expression_scaled <dbl>, target_fraction <dbl>,
## # ligand_target_weight <dbl>, activity <dbl>, activity_normalized <dbl>, scaled_activity <dbl>,
## # scaled_activity_normalized <dbl>, prioritization_score <dbl>
prioritization_tables$prioritization_tbl_ligand_receptor %>% filter(receiver == niches[[2]]$receiver) %>% head(10)
## # A tibble: 10 x 37
## niche receiver sender ligand_receptor ligand receptor bonafide ligand_score ligand_signific~ ligand_present ligand_expressi~
## <chr> <chr> <chr> <chr> <chr> <chr> <lgl> <dbl> <dbl> <dbl> <dbl>
## 1 pEMT_L~ Maligna~ Endoth~ F8--LRP1 F8 LRP1 TRUE 0.952 1 1 2.17
## 2 pEMT_L~ Maligna~ Endoth~ PLAT--LRP1 PLAT LRP1 TRUE 0.913 1 1 2.70
## 3 pEMT_L~ Maligna~ CAF_Low FGF10--FGFR2 FGF10 FGFR2 TRUE 0.385 0.8 1 1.07
## 4 pEMT_L~ Maligna~ CAF_Low NLGN2--NRXN3 NLGN2 NRXN3 TRUE 0.140 0.2 1 0.269
## 5 pEMT_L~ Maligna~ CAF_Low RSPO3--LGR6 RSPO3 LGR6 TRUE 0.557 0.8 1 1.27
## 6 pEMT_L~ Maligna~ CAF_Low COMP--SDC1 COMP SDC1 TRUE 0.290 0.8 1 1.27
## 7 pEMT_L~ Maligna~ CAF_Low SEMA3C--NRP2 SEMA3C NRP2 TRUE 0.652 1 1 1.73
## 8 pEMT_L~ Maligna~ CAF_Low SLIT2--SDC1 SLIT2 SDC1 TRUE 0.494 1 1 0.846
## 9 pEMT_L~ Maligna~ Endoth~ IL33--IL1RAP IL33 IL1RAP FALSE 1.34 1 1 2.75
## 10 pEMT_L~ Maligna~ CAF_Low C3--LRP1 C3 LRP1 TRUE 0.480 1 1 4.79
## # ... with 26 more variables: ligand_expression_scaled <dbl>, ligand_fraction <dbl>, ligand_score_spatial <dbl>,
## # receptor_score <dbl>, receptor_significant <dbl>, receptor_present <dbl>, receptor_expression <dbl>,
## # receptor_expression_scaled <dbl>, receptor_fraction <dbl>, receptor_score_spatial <dbl>,
## # ligand_scaled_receptor_expression_fraction <dbl>, avg_score_ligand_receptor <dbl>, activity <dbl>, activity_normalized <dbl>,
## # scaled_ligand_score <dbl>, scaled_ligand_expression_scaled <dbl>, scaled_receptor_score <dbl>,
## # scaled_receptor_expression_scaled <dbl>, scaled_avg_score_ligand_receptor <dbl>, scaled_ligand_score_spatial <dbl>,
## # scaled_receptor_score_spatial <dbl>, scaled_ligand_fraction_adapted <dbl>, scaled_receptor_fraction_adapted <dbl>, ...
prioritization_tables$prioritization_tbl_ligand_target %>% filter(receiver == niches[[2]]$receiver) %>% head(10)
## # A tibble: 10 x 20
## niche receiver sender ligand_receptor ligand receptor bonafide target target_score target_signific~ target_present
## <chr> <chr> <chr> <chr> <chr> <chr> <lgl> <chr> <dbl> <dbl> <dbl>
## 1 pEMT_Low_niche Malignant~ Endothe~ F8--LRP1 F8 LRP1 TRUE ETV4 0.771 1 1
## 2 pEMT_Low_niche Malignant~ Endothe~ PLAT--LRP1 PLAT LRP1 TRUE CLDN7 0.835 1 1
## 3 pEMT_Low_niche Malignant~ Endothe~ PLAT--LRP1 PLAT LRP1 TRUE ETV4 0.771 1 1
## 4 pEMT_Low_niche Malignant~ CAF_Low FGF10--FGFR2 FGF10 FGFR2 TRUE ETV4 0.771 1 1
## 5 pEMT_Low_niche Malignant~ CAF_Low FGF10--FGFR2 FGF10 FGFR2 TRUE WNT5A 1.40 1 1
## 6 pEMT_Low_niche Malignant~ CAF_Low NLGN2--NRXN3 NLGN2 NRXN3 TRUE CLDN5 0.979 1 1
## 7 pEMT_Low_niche Malignant~ CAF_Low NLGN2--NRXN3 NLGN2 NRXN3 TRUE ETV4 0.771 1 1
## 8 pEMT_Low_niche Malignant~ CAF_Low RSPO3--LGR6 RSPO3 LGR6 TRUE DDC 0.832 1 1
## 9 pEMT_Low_niche Malignant~ CAF_Low RSPO3--LGR6 RSPO3 LGR6 TRUE EGFL7 0.763 1 1
## 10 pEMT_Low_niche Malignant~ CAF_Low COMP--SDC1 COMP SDC1 TRUE CLDN7 0.835 1 1
## # ... with 9 more variables: target_expression <dbl>, target_expression_scaled <dbl>, target_fraction <dbl>,
## # ligand_target_weight <dbl>, activity <dbl>, activity_normalized <dbl>, scaled_activity <dbl>,
## # scaled_activity_normalized <dbl>, prioritization_score <dbl>
8. #Visualization of the Differential NicheNet output
top_ligand_niche_df = prioritization_tables$prioritization_tbl_ligand_receptor %>% select(niche, sender, receiver, ligand, receptor, prioritization_score) %>% group_by(ligand) %>% top_n(1, prioritization_score) %>% ungroup() %>% select(ligand, receptor, niche) %>% rename(top_niche = niche)
top_ligand_receptor_niche_df = prioritization_tables$prioritization_tbl_ligand_receptor %>% select(niche, sender, receiver, ligand, receptor, prioritization_score) %>% group_by(ligand, receptor) %>% top_n(1, prioritization_score) %>% ungroup() %>% select(ligand, receptor, niche) %>% rename(top_niche = niche)
ligand_prioritized_tbl_oi = prioritization_tables$prioritization_tbl_ligand_receptor %>% select(niche, sender, receiver, ligand, prioritization_score) %>% group_by(ligand, niche) %>% top_n(1, prioritization_score) %>% ungroup() %>% distinct() %>% inner_join(top_ligand_niche_df) %>% filter(niche == top_niche) %>% group_by(niche) %>% top_n(50, prioritization_score) %>% ungroup() # get the top50 ligands per niche
#Now we will look first at the top ligand-receptor pairs for KCs (here, we will take the top 2 scoring receptors per prioritized ligand)
table(seurat_obj$pEMT)
table(seurat_obj$celltype_aggregate)
receiver_oi = "Fibroblast_SiO2_56"
filtered_ligands = ligand_prioritized_tbl_oi %>% filter(receiver == receiver_oi) %>% pull(ligand) %>% unique()
prioritized_tbl_oi = prioritization_tables$prioritization_tbl_ligand_receptor %>% filter(ligand %in% filtered_ligands) %>% select(niche, sender, receiver, ligand, receptor, ligand_receptor, prioritization_score) %>% distinct() %>% inner_join(top_ligand_receptor_niche_df) %>% group_by(ligand) %>% filter(receiver == receiver_oi) %>% top_n(2, prioritization_score) %>% ungroup()
#Visualization: minimum LFC compared to other niches
lfc_plot = make_ligand_receptor_lfc_plot(receiver_oi, prioritized_tbl_oi, prioritization_tables$prioritization_tbl_ligand_receptor, plot_legend = FALSE, heights = NULL, widths = NULL)
lfc_plot
#Show the spatialDE as additional information
lfc_plot_spatial = make_ligand_receptor_lfc_spatial_plot(receiver_oi, prioritized_tbl_oi, prioritization_tables$prioritization_tbl_ligand_receptor, ligand_spatial = include_spatial_info_sender, receptor_spatial = include_spatial_info_receiver, plot_legend = FALSE, heights = NULL, widths = NULL)
lfc_plot_spatial
#Ligand expression, activity and target genes
exprs_activity_target_plot = make_ligand_activity_target_exprs_plot(receiver_oi, prioritized_tbl_oi, prioritization_tables$prioritization_tbl_ligand_receptor, prioritization_tables$prioritization_tbl_ligand_target, output$exprs_tbl_ligand, output$exprs_tbl_target, lfc_cutoff, ligand_target_matrix, plot_legend = FALSE, heights = NULL, widths = NULL)
exprs_activity_target_plot$combined_plot
边栏推荐
- HMS core audio editing service 3D audio technology helps create an immersive auditory feast
- Symantec electronic sprint technology innovation board: Tan Jian, the actual controller, is an American who plans to raise 620million yuan
- Wechat emoticons are written into the judgment, and the OK and bomb you send may become "testimony in court"
- Data mining knowledge points sorting (final review version)
- Dart: string replace related methods
- A scheduled task deletes data at a specified time
- Lambda表达式_Stream流_File类
- 声网自研传输层协议 AUT 的落地实践丨Dev for Dev 专栏
- Hologres共享集群助力淘宝订阅极致精细化运营
- STL教程7-set、pair对组和仿函数
猜你喜欢

HMS Core音频编辑服务3D音频技术,助力打造沉浸式听觉盛宴

Etcd tutorial - Chapter 8 compact, watch, and lease APIs for etcd

Niuke.com: minimum cost of climbing stairs

How to connect the Internet Reading Notes - Summary

基于51单片机的计件器设计

Etcd tutorial - Chapter 9 etcd implementation of distributed locks
![[Verilog quick start of Niuke online question series] ~ bit splitting and operation](/img/17/4b8f5607c4cba1596435233a6cf30a.png)
[Verilog quick start of Niuke online question series] ~ bit splitting and operation

Mathematical modeling for war preparation 36 time series model 2

Raft介绍

【机器学习】K-means聚类分析
随机推荐
Research on helmet wearing detection algorithm
nichenet实战silicosis
Halcon knowledge: matrix topic [02]
Pref usage record
【机器学习】K-means聚类分析
【微信小程序】常用组件基本使用(view/scroll-view/swiper、text/rich-text、button/image)
differential analysis between different groups nichenet for silicosis成功运行!
编译丨迅为STM32P157开发板编译U-Boot源码
[bjdctf2020]the mystery of ip|[ciscn2019 southeast China division]web11|ssti injection
Mathematical modeling for war preparation 34-bp neural network prediction 2
基于51单片机的计件器设计
利用PIL进行不失真的resize
Deep learning - (2) several common loss functions
Bc1.2 PD protocol
Delete duplicates in an ordered array ii[double pointers -- unified in multiple cases]
数据安全合规之后,给风控团队带来了新的问题
Mathematical modeling for war preparation 36 time series model 2
Data mining knowledge points sorting (final review version)
[JVM] class loading related interview questions - class loading process and parental delegation model
Restartprocessifvisible process