Skip to content

Commit f2323cf

Browse files
committed
update vignettes for v5
1 parent 890b397 commit f2323cf

26 files changed

+2187
-2060
lines changed

vignettes/differential_nichenet_pEMT.Rmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ seurat_obj@meta.data$celltype_aggregate %>% table() %>% sort(decreasing = TRUE)
7070

7171
```{r}
7272
celltype_id = "celltype_aggregate" # metadata column name of the cell type of interest
73-
seurat_obj = SetIdent(seurat_obj, value = seurat_obj[[celltype_id]])
73+
seurat_obj = SetIdent(seurat_obj, value = seurat_obj[[celltype_id, drop=TRUE]])
7474
```
7575

7676
## Read in the NicheNet ligand-receptor network and ligand-target matrix

vignettes/differential_nichenet_pEMT.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ seurat_obj@meta.data$celltype_aggregate %>% table() %>% sort(decreasing = TRUE)
103103

104104
``` r
105105
celltype_id = "celltype_aggregate" # metadata column name of the cell type of interest
106-
seurat_obj = SetIdent(seurat_obj, value = seurat_obj[[celltype_id]])
106+
seurat_obj = SetIdent(seurat_obj, value = seurat_obj[[celltype_id, drop=TRUE]])
107107
```
108108

109109
## Read in the NicheNet ligand-receptor network and ligand-target matrix

vignettes/ligand_receptor_circos.svg

Lines changed: 499 additions & 858 deletions
Loading

vignettes/ligand_target_circos.svg

Lines changed: 1442 additions & 1090 deletions
Loading

vignettes/seurat_steps.Rmd

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "Perform NicheNet analysis starting from a Seurat object: step-by-step analysis"
33
author: "Robin Browaeys"
4-
date: "2019-11-12"
4+
date: "2023-10-02"
55
output: rmarkdown::html_vignette
66
vignette: >
77
%\VignetteIndexEntry{Perform NicheNet analysis starting from a Seurat object: step-by-step analysis}
@@ -45,8 +45,9 @@ The NicheNet ligand-receptor network and weighted networks are necessary to defi
4545
### Load Packages:
4646

4747
```{r}
48-
library(nichenetr)
49-
library(Seurat) # please update to Seurat V4
48+
library(nichenetr) # Please update to v2.0.4
49+
library(Seurat)
50+
library(SeuratObject)
5051
library(tidyverse)
5152
```
5253

@@ -58,7 +59,11 @@ The dataset used here is publicly available single-cell data from immune cells i
5859

5960
```{r}
6061
seuratObj = readRDS(url("https://zenodo.org/record/3531889/files/seuratObj.rds"))
62+
6163
seuratObj@meta.data %>% head()
64+
65+
# For newer Seurat versions, you may need to run the following
66+
seuratObj <- UpdateSeuratObject(seuratObj)
6267
```
6368

6469
Visualize which cell populations are present: CD4 T cells (including regulatory T cells), CD8 T cells, B cells, NK cells, dendritic cells (DCs) and inflammatory monocytes
@@ -139,7 +144,7 @@ Here, the gene set of interest are the genes differentially expressed in CD8 T c
139144

140145
```{r}
141146
seurat_obj_receiver= subset(seuratObj, idents = receiver)
142-
seurat_obj_receiver = SetIdent(seurat_obj_receiver, value = seurat_obj_receiver[["aggregate"]])
147+
seurat_obj_receiver = SetIdent(seurat_obj_receiver, value = seurat_obj_receiver[["aggregate", drop=TRUE]])
143148
144149
condition_oi = "LCMV"
145150
condition_reference = "SS"
@@ -298,9 +303,7 @@ p_ligand_aupr = vis_ligand_aupr %>% make_heatmap_ggplot("Prioritized ligands","L
298303

299304
```{r}
300305
# ligand expression Seurat dotplot
301-
order_ligands_adapted = order_ligands
302-
order_ligands_adapted[order_ligands_adapted == "H2.M3"] = "H2-M3" # cf required use of make.names for heatmap visualization | this is not necessary if these ligands are not in the list of prioritized ligands!
303-
order_ligands_adapted[order_ligands_adapted == "H2.T23"] = "H2-T23" # cf required use of make.names for heatmap visualization | this is not necessary if these ligands are not in the list of prioritized ligands!
306+
order_ligands_adapted <- str_replace_all(order_ligands, "\\.", "-")
304307
rotated_dotplot = DotPlot(seuratObj %>% subset(celltype %in% sender_celltypes), features = order_ligands_adapted, cols = "RdYlBu") + coord_flip() + theme(legend.text = element_text(size = 10), legend.title = element_text(size = 12)) # flip of coordinates necessary because we want to show ligands in the rows when combining all plots
305308
```
306309

@@ -332,6 +335,10 @@ combined_plot
332335

333336
Top-ranked ligands and target genes shown here differ from the predictions shown in the respective case study in the NicheNet paper because 1) a different definition of expressed genes was used, and 2) we have updated the ligand-target matrix to include more data sources.
334337

338+
```{r}
339+
sessionInfo()
340+
```
341+
335342
# References
336343

337344

vignettes/seurat_steps.md

Lines changed: 58 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Perform NicheNet analysis starting from a Seurat object: step-by-step
22
analysis
33
================
44
Robin Browaeys
5-
2019-11-12
5+
2023-10-02
66

77
<!-- github markdown built using
88
rmarkdown::render("vignettes/seurat_steps.Rmd", output_format = "github_document")
@@ -76,7 +76,8 @@ genes of these prioritized ligands.
7676

7777
``` r
7878
library(nichenetr)
79-
library(Seurat) # please update to Seurat V4
79+
library(Seurat)
80+
library(SeuratObject)
8081
library(tidyverse)
8182
```
8283

@@ -94,6 +95,7 @@ mouse/human gene symbol.
9495

9596
``` r
9697
seuratObj = readRDS(url("https://zenodo.org/record/3531889/files/seuratObj.rds"))
98+
9799
seuratObj@meta.data %>% head()
98100
## nGene nUMI orig.ident aggregate res.0.6 celltype nCount_RNA nFeature_RNA
99101
## W380370 880 1611 LN_SS SS 1 CD8 T 1607 876
@@ -102,6 +104,9 @@ seuratObj@meta.data %>% head()
102104
## W380378 847 1546 LN_SS SS 1 CD8 T 1537 838
103105
## W380379 839 1606 LN_SS SS 0 CD4 T 1603 836
104106
## W380381 517 844 LN_SS SS 0 CD4 T 840 513
107+
108+
# For newer Seurat versions, you may need to run the following
109+
seuratObj <- UpdateSeuratObject(seuratObj)
105110
```
106111

107112
Visualize which cell populations are present: CD4 T cells (including
@@ -242,7 +247,7 @@ Seurat Wilcoxon test, but this can be changed if necessary.
242247

243248
``` r
244249
seurat_obj_receiver= subset(seuratObj, idents = receiver)
245-
seurat_obj_receiver = SetIdent(seurat_obj_receiver, value = seurat_obj_receiver[["aggregate"]])
250+
seurat_obj_receiver = SetIdent(seurat_obj_receiver, value = seurat_obj_receiver[["aggregate", drop=TRUE]])
246251

247252
condition_oi = "LCMV"
248253
condition_reference = "SS"
@@ -291,7 +296,7 @@ ligand_activities
291296
## 8 H2-K1 0.605 0.268 0.122 0.142 8
292297
## 9 H2-Q4 0.605 0.268 0.122 0.141 10
293298
## 10 H2-Q6 0.605 0.268 0.122 0.141 10
294-
## # … with 63 more rows
299+
## # 63 more rows
295300
```
296301

297302
The different ligand activity measures (auroc, aupr, pearson correlation
@@ -456,9 +461,7 @@ p_ligand_aupr = vis_ligand_aupr %>% make_heatmap_ggplot("Prioritized ligands","L
456461

457462
``` r
458463
# ligand expression Seurat dotplot
459-
order_ligands_adapted = order_ligands
460-
order_ligands_adapted[order_ligands_adapted == "H2.M3"] = "H2-M3" # cf required use of make.names for heatmap visualization | this is not necessary if these ligands are not in the list of prioritized ligands!
461-
order_ligands_adapted[order_ligands_adapted == "H2.T23"] = "H2-T23" # cf required use of make.names for heatmap visualization | this is not necessary if these ligands are not in the list of prioritized ligands!
464+
order_ligands_adapted <- str_replace_all(order_ligands, "\\.", "-")
462465
rotated_dotplot = DotPlot(seuratObj %>% subset(celltype %in% sender_celltypes), features = order_ligands_adapted, cols = "RdYlBu") + coord_flip() + theme(legend.text = element_text(size = 10), legend.title = element_text(size = 12)) # flip of coordinates necessary because we want to show ligands in the rows when combining all plots
463466
```
464467

@@ -494,6 +497,54 @@ predictions shown in the respective case study in the NicheNet paper
494497
because 1) a different definition of expressed genes was used, and 2) we
495498
have updated the ligand-target matrix to include more data sources.
496499

500+
``` r
501+
sessionInfo()
502+
## R version 4.3.1 (2023-06-16)
503+
## Platform: x86_64-redhat-linux-gnu (64-bit)
504+
## Running under: CentOS Stream 8
505+
##
506+
## Matrix products: default
507+
## BLAS/LAPACK: /usr/lib64/libopenblaso-r0.3.15.so; LAPACK version 3.9.0
508+
##
509+
## locale:
510+
## [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 LC_PAPER=en_US.UTF-8 LC_NAME=C
511+
## [9] LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
512+
##
513+
## time zone: Europe/Brussels
514+
## tzcode source: system (glibc)
515+
##
516+
## attached base packages:
517+
## [1] stats graphics grDevices utils datasets methods base
518+
##
519+
## other attached packages:
520+
## [1] forcats_0.5.1 stringr_1.5.0 dplyr_1.1.2 purrr_1.0.2 readr_2.1.2 tidyr_1.3.0 tibble_3.2.1 ggplot2_3.4.3 tidyverse_1.3.1 Seurat_4.4.0 nichenetr_2.0.3 testthat_3.1.2
521+
## [13] SeuratObject_4.1.4 sp_2.0-0
522+
##
523+
## loaded via a namespace (and not attached):
524+
## [1] fs_1.5.2 matrixStats_1.0.0 spatstat.sparse_3.0-2 bitops_1.0-7 devtools_2.4.3 lubridate_1.8.0 httr_1.4.2 RColorBrewer_1.1-2 doParallel_1.0.17
525+
## [10] tools_4.3.1 sctransform_0.4.0 backports_1.4.1 utf8_1.2.2 R6_2.5.1 lazyeval_0.2.2 uwot_0.1.16 GetoptLong_1.0.5 withr_2.5.0
526+
## [19] prettyunits_1.1.1 gridExtra_2.3 fdrtool_1.2.17 progressr_0.14.0 cli_3.6.1 DiceKriging_1.6.0 spatstat.explore_3.2-1 labeling_0.4.2 spatstat.data_3.0-1
527+
## [28] randomForest_4.7-1.1 proxy_0.4-27 ggridges_0.5.3 pbapply_1.5-0 foreign_0.8-84 smoof_1.6.0.3 parallelly_1.30.0 sessioninfo_1.2.2 limma_3.56.2
528+
## [37] readxl_1.3.1 rstudioapi_0.13 visNetwork_2.1.2 generics_0.1.2 shape_1.4.6 ica_1.0-2 spatstat.random_3.1-5 car_3.1-2 Matrix_1.6-1
529+
## [46] S4Vectors_0.38.1 fansi_1.0.2 abind_1.4-5 lifecycle_1.0.3 yaml_2.2.2 carData_3.0-5 recipes_1.0.7 Rtsne_0.15 grid_4.3.1
530+
## [55] promises_1.2.0.1 crayon_1.5.0 miniUI_0.1.1.1 lattice_0.21-8 haven_2.4.3 cowplot_1.1.1 mlr_2.19.1 pillar_1.9.0 knitr_1.37
531+
## [64] ComplexHeatmap_2.16.0 rjson_0.2.21 future.apply_1.8.1 codetools_0.2-19 fastmatch_1.1-3 leiden_0.3.9 glue_1.6.2 ParamHelpers_1.14.1 data.table_1.14.2
532+
## [73] remotes_2.4.2 vctrs_0.6.3 png_0.1-7 cellranger_1.1.0 gtable_0.3.0 assertthat_0.2.1 cachem_1.0.6 gower_1.0.1 xfun_0.40
533+
## [82] mime_0.12 prodlim_2023.03.31 survival_3.5-5 timeDate_4022.108 iterators_1.0.14 hardhat_1.3.0 lava_1.7.2.1 DiagrammeR_1.0.10 ellipsis_0.3.2
534+
## [91] fitdistrplus_1.1-6 ROCR_1.0-11 ipred_0.9-14 nlme_3.1-162 usethis_2.2.2 RcppAnnoy_0.0.19 rprojroot_2.0.2 irlba_2.3.5 KernSmooth_2.23-21
535+
## [100] rpart_4.1.19 DBI_1.1.2 BiocGenerics_0.46.0 colorspace_2.0-2 Hmisc_5.1-0 nnet_7.3-19 tidyselect_1.2.0 processx_3.5.2 compiler_4.3.1
536+
## [109] parallelMap_1.5.1 rvest_1.0.2 htmlTable_2.4.1 xml2_1.3.3 desc_1.4.2 plotly_4.10.0 shadowtext_0.1.2 checkmate_2.2.0 scales_1.2.1
537+
## [118] caTools_1.18.2 lmtest_0.9-39 callr_3.7.0 digest_0.6.29 goftest_1.2-3 spatstat.utils_3.0-3 rmarkdown_2.11 htmltools_0.5.6 pkgconfig_2.0.3
538+
## [127] base64enc_0.1-3 lhs_1.1.6 highr_0.9 dbplyr_2.1.1 fastmap_1.1.0 rlang_1.1.1 GlobalOptions_0.1.2 htmlwidgets_1.6.2 shiny_1.7.1
539+
## [136] BBmisc_1.13 farver_2.1.0 zoo_1.8-9 jsonlite_1.7.3 mlrMBO_1.1.5.1 ModelMetrics_1.2.2.2 magrittr_2.0.2 Formula_1.2-5 patchwork_1.1.1
540+
## [145] munsell_0.5.0 Rcpp_1.0.11 ggnewscale_0.4.9 reticulate_1.24 stringi_1.7.6 pROC_1.18.4 brio_1.1.3 MASS_7.3-60 plyr_1.8.6
541+
## [154] pkgbuild_1.3.1 parallel_4.3.1 listenv_0.8.0 ggrepel_0.9.3 deldir_1.0-6 splines_4.3.1 tensor_1.5 hms_1.1.1 circlize_0.4.15
542+
## [163] ps_1.6.0 igraph_1.5.1 ggpubr_0.6.0 spatstat.geom_3.2-4 ggsignif_0.6.4 reshape2_1.4.4 stats4_4.3.1 pkgload_1.2.4 reprex_2.0.1
543+
## [172] evaluate_0.14 modelr_0.1.8 tweenr_2.0.2 tzdb_0.4.0 foreach_1.5.2 httpuv_1.6.5 RANN_2.6.1 polyclip_1.10-0 clue_0.3-64
544+
## [181] future_1.23.0 scattermore_1.2 ggforce_0.4.1 broom_0.7.12 xtable_1.8-4 emoa_0.5-0.2 e1071_1.7-13 rstatix_0.7.2 later_1.3.0
545+
## [190] viridisLite_0.4.0 class_7.3-22 IRanges_2.34.1 memoise_2.0.1 cluster_2.1.4 globals_0.14.0 caret_6.0-94
546+
```
547+
497548
# References
498549

499550
<div id="refs" class="references csl-bib-body hanging-indent">
8.99 KB
Loading

vignettes/seurat_steps_prioritization.Rmd

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "Perform NicheNet analysis with prioritization"
33
author: "Robin Browaeys & Chananchida Sang-aram"
4-
date: "2023-07-20"
4+
date: "2023-10-02"
55
output: rmarkdown::html_vignette
66
vignette: >
77
%\VignetteIndexEntry{Perform NicheNet analysis starting from a Seurat object: step-by-step analysis with prioritization}
@@ -25,13 +25,16 @@ knitr::opts_chunk$set(
2525

2626
```{r}
2727
### Load Packages
28-
library(nichenetr)
29-
library(Seurat) # please update to Seurat V4
28+
library(nichenetr) # Please update to v2.0.4
29+
library(Seurat)
30+
library(SeuratObject)
3031
library(tidyverse)
3132
3233
### Read in Seurat object
3334
seuratObj = readRDS(url("https://zenodo.org/record/3531889/files/seuratObj.rds"))
3435
36+
# For newer Seurat versions, you may need to run the following
37+
seuratObj <- UpdateSeuratObject(seuratObj)
3538
```
3639

3740
In this vignette, we will extend the basic NicheNet analysis analysis from [Perform NicheNet analysis starting from a Seurat object: step-by-step analysis](seurat_steps.md) by incorporating gene expression as part of the prioritization This is a generalization of the [Differential NicheNet](differential_nichenet.md) and [MultiNicheNet](https://github.com/saeyslab/multinichenetr) approach. While the original NicheNet only ranks ligands based on the ligand activity analysis, it is now also possible to prioritize ligands based on upregulation of the ligand/receptor, and the cell-type and condition specificity of hte ligand and receptor.
@@ -52,6 +55,7 @@ The NicheNet ligand-receptor network and weighted networks are necessary to defi
5255
lr_network = readRDS(url("https://zenodo.org/record/7074291/files/lr_network_mouse_21122021.rds"))
5356
ligand_target_matrix = readRDS(url("https://zenodo.org/record/7074291/files/ligand_target_matrix_nsga2r_final_mouse.rds"))
5457
weighted_networks = readRDS(url("https://zenodo.org/record/7074291/files/weighted_networks_nsga2r_final_mouse.rds"))
58+
5559
lr_network = lr_network %>% distinct(from, to)
5660
head(lr_network)
5761
ligand_target_matrix[1:5,1:5] # target genes in rows, ligands in columns
@@ -89,7 +93,7 @@ expressed_genes_sender = list_expressed_genes_sender %>% unlist() %>% unique()
8993
# 2. Define a gene set of interest: these are the genes in the “receiver/target” cell population that are potentially affected by ligands expressed by interacting cells (e.g. genes differentially expressed upon cell-cell interaction)
9094
9195
seurat_obj_receiver= subset(seuratObj, idents = receiver)
92-
seurat_obj_receiver = SetIdent(seurat_obj_receiver, value = seurat_obj_receiver[["aggregate"]])
96+
seurat_obj_receiver = SetIdent(seurat_obj_receiver, value = seurat_obj_receiver[["aggregate", drop=TRUE]])
9397
9498
condition_oi = "LCMV"
9599
condition_reference = "SS"
@@ -278,4 +282,8 @@ make_mushroom_plot(prior_table, top_n = 30, show_rankings = TRUE, show_all_datap
278282
make_mushroom_plot(prior_table, top_n = 30, true_color_range = TRUE)
279283
```
280284

285+
```{r}
286+
sessionInfo()
287+
```
288+
281289
### References

0 commit comments

Comments
 (0)