Skip to content

Commit d5f95b5

Browse files
committed
Fix issue disconcordance wrapper/step-by-step
1 parent 2d2e9b0 commit d5f95b5

5 files changed

+48
-19
lines changed

.DS_Store

0 Bytes
Binary file not shown.

DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: multinichenetr
22
Type: Package
33
Title: MultiNicheNet: a flexible framework for differential cell-cell communication analysis from multi-sample multi-condition single-cell transcriptomics data
4-
Version: 2.0.0
4+
Version: 2.0.1
55
Author: person("Robin", "Browaeys", email = "robin.browaeys@ugent.be",
66
role = c("aut", "cre"))
77
Maintainer: Robin Browaeys <robin.browaeys@ugent.be>

R/pipeline.R

+43-15
Original file line numberDiff line numberDiff line change
@@ -355,11 +355,19 @@ multi_nichenet_analysis = function(sce,
355355
# do not do this -- this could give errors if only interested in one contrast but multiple groups
356356

357357
if(verbose == TRUE){
358-
print("Make diagnostic abundance plots + define expressed genes")
358+
print("Cell type & sample filtering")
359359
}
360360
## check abundance info
361361

362-
abundance_info = get_abundance_info(sce = sce, sample_id = sample_id, group_id = group_id, celltype_id = celltype_id, min_cells = min_cells, senders_oi = senders_oi, receivers_oi = receivers_oi, batches = batches)
362+
abundance_info = get_abundance_info(
363+
sce = sce,
364+
sample_id = sample_id,
365+
group_id = group_id,
366+
celltype_id = celltype_id,
367+
min_cells = min_cells,
368+
senders_oi = senders_oi,
369+
receivers_oi = receivers_oi,
370+
batches = batches)
363371

364372
## check for condition-specific cell types
365373
sample_group_celltype_df = abundance_info$abundance_data %>% filter(n > min_cells) %>% ungroup() %>% distinct(sample_id, group_id) %>% cross_join(abundance_info$abundance_data %>% ungroup() %>% distinct(celltype_id)) %>% arrange(sample_id)
@@ -377,6 +385,9 @@ multi_nichenet_analysis = function(sce,
377385
print("condition-specific celltypes:")
378386
print(condition_specific_celltypes)
379387

388+
condition_specific_celltypes_senders = condition_specific_celltypes %>% intersect(senders_oi)
389+
condition_specific_celltypes_receivers = condition_specific_celltypes %>% intersect(receivers_oi)
390+
380391
print("absent celltypes:")
381392
print(absent_celltypes)
382393

@@ -388,9 +399,28 @@ multi_nichenet_analysis = function(sce,
388399
sce = sce[, SummarizedExperiment::colData(sce)[,celltype_id] %in% retained_celltypes]
389400

390401
## define expressed genes
402+
if(verbose == TRUE){
403+
print("Gene filtering")
404+
}
391405
frq_list = get_frac_exprs(sce = sce, sample_id = sample_id, celltype_id = celltype_id, group_id = group_id, batches = batches, min_cells = min_cells, fraction_cutoff = fraction_cutoff, min_sample_prop = min_sample_prop)
392406

393-
### Perform the DE analysis ----------------------------------------------------------------
407+
## filter out non-expressed genes
408+
genes_oi = frq_list$expressed_df %>%
409+
filter(expressed == TRUE) %>% pull(gene) %>% unique()
410+
sce = sce[genes_oi, ]
411+
412+
## calculate PB expresion
413+
if(verbose == TRUE){
414+
print("Calculate normalized average and pseudobulk expression")
415+
}
416+
abundance_expression_info = process_abundance_expression_info(
417+
sce = sce, sample_id = sample_id, group_id = group_id, celltype_id = celltype_id, min_cells = min_cells,
418+
senders_oi = union(senders_oi, condition_specific_celltypes_senders),
419+
receivers_oi = union(receivers_oi, condition_specific_celltypes_receivers),
420+
lr_network = lr_network, batches = batches, frq_list = frq_list, abundance_info = abundance_info
421+
)
422+
423+
## Perform the DE analysis ----------------------------------------------------------------
394424

395425
if(verbose == TRUE){
396426
print("Calculate differential expression for all cell types")
@@ -432,9 +462,9 @@ multi_nichenet_analysis = function(sce,
432462

433463
# print(celltype_de %>% dplyr::group_by(cluster_id, contrast) %>% dplyr::filter(p_adj <= p_val_threshold & abs(logFC) >= logFC_threshold) %>% dplyr::count() %>% dplyr::arrange(-n))
434464

435-
senders_oi = celltype_de$cluster_id %>% unique()
436-
receivers_oi = celltype_de$cluster_id %>% unique()
437-
genes_oi = celltype_de$gene %>% unique()
465+
senders_oi = intersect(celltype_de$cluster_id %>% unique(), senders_oi)
466+
receivers_oi = intersect(celltype_de$cluster_id %>% unique(), receivers_oi)
467+
genes_oi = intersect(genes_oi, celltype_de$gene %>% unique())
438468

439469
retained_celltypes = c(senders_oi, receivers_oi) %>% unique()
440470
retained_celltypes = c(retained_celltypes, condition_specific_celltypes)
@@ -453,12 +483,6 @@ multi_nichenet_analysis = function(sce,
453483
))
454484
sender_receiver_tbl = sender_receiver_de %>% dplyr::distinct(sender, receiver)
455485

456-
### Receiver abundance plots + Calculate expression information
457-
if(verbose == TRUE){
458-
print("Calculate normalized average and pseudobulk expression")
459-
}
460-
abundance_expression_info = process_abundance_expression_info(sce = sce, sample_id = sample_id, group_id = group_id, celltype_id = celltype_id, min_cells = min_cells, senders_oi = union(senders_oi, condition_specific_celltypes), receivers_oi = union(receivers_oi, condition_specific_celltypes), lr_network = lr_network, batches = batches, frq_list = frq_list, abundance_info = abundance_info)
461-
462486
metadata_combined = SummarizedExperiment::colData(sce) %>% tibble::as_tibble()
463487

464488
if(!is.na(batches)){
@@ -470,10 +494,13 @@ multi_nichenet_analysis = function(sce,
470494
}
471495

472496
rm(sce)
473-
### Use the DE analysis for defining the DE genes in the receiver cell type and perform NicheNet ligand activity and ligand-target inference ----------------------------------------------------------------
497+
## Use the DE analysis for defining the DE genes in the receiver cell type and perform NicheNet ligand activity and ligand-target inference ----------------------------------------------------------------
474498
if(verbose == TRUE){
475499
print("Calculate NicheNet ligand activities and ligand-target links")
476500
}
501+
502+
n.cores = min(n.cores, celltype_de$cluster_id %>% unique() %>% length())
503+
477504
ligand_activities_targets_DEgenes = suppressMessages(suppressWarnings(get_ligand_activities_targets_DEgenes(
478505
receiver_de = celltype_de,
479506
receivers_oi = receivers_oi,
@@ -486,7 +513,8 @@ multi_nichenet_analysis = function(sce,
486513
n.cores = n.cores
487514
)))
488515

489-
### Combine the three types of information calculated above to prioritize ligand-receptor interactions ----------------------------------------------------------------
516+
517+
## Combine the three types of information calculated above to prioritize ligand-receptor interactions ----------------------------------------------------------------
490518
if(verbose == TRUE){
491519
print("Combine all the information in prioritization tables")
492520
}
@@ -505,7 +533,7 @@ multi_nichenet_analysis = function(sce,
505533
ligand_activity_down = ligand_activity_down # use only upregulatory ligand activities to prioritize
506534
))
507535

508-
# Prepare Unsupervised analysis of samples! ------------------------------------------------------------------------------------------------------------
536+
## Prepare Unsupervised analysis of samples! ------------------------------------------------------------------------------------------------------------
509537

510538
if(return_lr_prod_matrix == TRUE){
511539

vignettes/condition_specific_celltype_MISC.Rmd

+1-3
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,9 @@ In this vignette, you can learn how to perform a MultiNicheNet analysis when you
3333
As the best solution, we recommend - if possible and biologically sensible to annotate your cells at one level higher in the cell type annotation hierarchy (eg sub cell type can be seen as a different cell state). Hereby, you will not have this problem of condition-specific cell types anymore.
3434

3535
A a second solution, we propose the procedure as showcased in this vignette. This consists of 3 consecutive workflows:
36-
3736
*1) General Workflow: This is the regular MultiNicheNet approach. In the general workflow, condition-specific cell types are excluded from the analysis. This approach focuses on achieving the best prioritization for other cell types that are present across different conditions, allowing for a standard DE analysis. The exclusion of condition-specific cell types simplifies the analysis but at the expense of potentially missing out on valuable insights that these unique cell types could provide. Therefore you can go further with the next two workflows:
3837
*2) Workflow A (Sender Cell Types): This workflow adapts the analysis to include condition-specific cell types as sender cell types. It circumvents the need for DE analysis of the ligand by only focusing the ligand-prioritization on ligand cell type specificity and ligand activity.
39-
*3) Workflow B (Receiver Cell Types): Workflow B allows for the inclusion of condition-specific cell types as receiver cell types by forgoing the DE analysis of the receiver, meaning that we cannot consider receptor differential expresion and ligand activity. Instead, receptor prioritization is based solely on the receptor cell type specificity.
38+
*3) Workflow B (Receiver Cell Types): Workflow B allows for the inclusion of condition-specific cell types as receiver cell types by forgoing the DE analysis of the receiver, meaning that we cannot consider receptor differential expresion and ligand activity. Instead, receptor prioritization is based solely on the receptor cell type specificity.
4039

4140
As example expression data of interacting cells, we will here use scRNAseq data of immune cells in MIS-C patients and healthy siblings from this paper of Hoste et al.: [TIM3+ TRBV11-2 T cells and IFNγ signature in patrolling monocytes and CD16+ NK cells delineate MIS-C](https://rupress.org/jem/article/219/2/e20211381/212918/TIM3-TRBV11-2-T-cells-and-IFN-signature-in) [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.6362434.svg)](https://doi.org/10.5281/zenodo.6362434)
4241
. MIS-C (multisystem inflammatory syndrome in children) is a novel rare immunodysregulation syndrome that can arise after SARS-CoV-2 infection in children. We will use NicheNet to explore immune cell crosstalk enriched in MIS-C compared to healthy siblings and patients with adult COVID-19.
@@ -60,7 +59,6 @@ The Nichenet v2 networks and matrices for both mouse and human can be downloaded
6059
We will read these object in for human because our expression data is of human patients.
6160
Gene names are here made syntactically valid via `make.names()` to avoid the loss of genes (eg H2-M3) in downstream visualizations.
6261

63-
6462
```{r}
6563
organism = "human"
6664
```

vignettes/pairwise_analysis_MISC.Rmd

+3
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,9 @@ We will now check the top 50 interactions specific for the MIS-C group
420420

421421
```{r}
422422
group_oi = "M"
423+
424+
print(prioritized_tbl_oi_all)
425+
423426
```
424427

425428
```{r}

0 commit comments

Comments
 (0)