This vignette present the workflow performed to reconstruct a CausalCCC network using NicheNet cell-cell communication analysis on their demo dataset (see other tutorials). If you need more details about the CausalCCC helper functions presented here, we recommend you read the tutorials.

You can download their demo dataset here (Seurat object).

Setting up libraries

Make sure you can load the following packages :

### Mandatory Libraries 
library(Seurat)
library(SeuratObject)
library(ggplot2)
library(tidyverse)
library(data.table)
library(dplyr)
library(igraph)

### For CCC selection - optional if you want to use your own L-R list
library(nichenetr) # Please update to v2.0.4
library(liana)

### For network aesthetic display
library(rjson)

#How to download CausalCCC
# CausalCCC is a module part of the miic R package
# Sys.setenv(GITHUB_PAT = 'YOUR_GITHUB_API_TOKEN_HERE')
# devtools::install_github("interactMIIC/causalCCC/miic_R_package", force = T) #latest version of MIIC
library(miic)



wd_path <- "~/CausalCCC/case_studies/NicheNet"
setwd(wd_path)

Initialization

The beginning of this analysis uses NicheNet scripts to perform cell-cell communication analysis.

Load your Seurat Object:

# Set your working directory here
seuratObj <- readRDS(file.path(wd_path,"data_nichenet/seuratObj.rds"))
seuratObj <- UpdateSeuratObject(seuratObj)
seuratObj <- alias_to_symbol_seurat(seuratObj, "mouse")
DimPlot(seuratObj, reduction = "tsne")

# Precise assay of interest
assay_name <- 'RNA'

# Specify the species genes format (mouse or human)
species <- "mouse"

# Define your senders, your receivers and the metadata where they can be found
senders <-  c("CD4 T") 
receivers <-  c("CD8 T") 
interact_ident <- "celltype"

# If you want to remove ribomosomal genes exectute this chunk:
ribomosal_genes <- row.names(seuratObj)[stringr::str_detect(row.names(seuratObj), ifelse(species == "human", "RPL|RPS","Rpl|Rps") )]
counts <- GetAssayData(seuratObj, assay = "RNA")
counts <- counts[-(which(rownames(counts) %in% ribomosal_genes)),]
seuratObj <- subset(seuratObj, features = rownames(counts))
rm(counts)

MI-based genes selection

Here we use the ligands and receptors found earlier as features of interest.

#Find genes that share the most information with your biological question :
MI_senders_genes <- causalCCC.MIselection(seurat_object = seuratObj,
                                         return_full = F,
                                         assay_name = assay_name,
                                         interact_ident = interact_ident,
                                         oneinteract = senders,
                                         goi = ligands,
                                         save = T,
                                         output_dir = file.path(wd_path, "v1", "MI_tables"),
                                         plot = T)

MI_receivers_genes <- causalCCC.MIselection(seurat_object = seuratObj,
                                             assay_name = assay_name,
                                             interact_ident = interact_ident,
                                             oneinteract = receivers,
                                             goi = receptors,
                                             save = T,
                                             output_dir = file.path(wd_path, "v1", "MI_tables"),
                                             plot = T)

Create CausalCCC files

Create and save the necessary CausalCCC files to reconstruct a network :

Example of an CausalCCC input files
## Create final variables list
genes_senders <- unique(c(ligands, MI_senders_genes))
metadata_senders <- list(aggregate = c("LCMV", "SS"))

genes_receivers <- unique(c(receptors, MI_receivers_genes))
metadata_receivers <- list(aggregate = c("LCMV", "SS"))

## Create the input mosaic dataframe
causalCCC_df <- causalCCC.mosaic(seurat_object = seuratObj,
                                assay_name = assay_name,
                                interact_ident = interact_ident,
                                senders_name = senders,
                                receivers_name = receivers,
                                genes_senders= genes_senders,
                                genes_receivers = genes_receivers,
                                metadata_senders = names(metadata_senders),
                                metadata_receivers = names(metadata_receivers))

## Create the state order
causalCCC_st <- causalCCC.state_order(mosaic_data_table = causalCCC_df,
                                            genes_senders= genes_senders,
                                            genes_receivers = genes_receivers,
                                            ligands = ligands,
                                            receptors = receptors,
                                            metadata_senders = metadata_senders,
                                            metadata_receivers = metadata_receivers)


## Save files
cat(paste("Saving the causalCCC files in", file.path(wd_path,"v1/MIIC_networks")))

## Check existence of directory
dir.create(file.path(wd_path,"v1", "MIIC_networks/"))

## network layout
network_layout <- causalCCC.layout(causalCCC_st, network_height = 8)
file <- file(file.path(wd_path,"v1","MIIC_networks/causalCCC_layout.json"))
writeLines(network_layout, file)
close(file)

write.table(causalCCC_df, file = file.path(wd_path,"v1","MIIC_networks/causalCCC_df.csv"), quote = F, sep = ",", row.names = F)
write.table(causalCCC_st, file = file.path(wd_path,"v1", "MIIC_networks/causalCCC_st.tsv"), quote = F, sep = "\t", row.names = F)

#Fix ligands and receptors names when duplicated
duplicated_ligands <- intersect(ligands,genes_receivers)
duplicated_receptors <- intersect(receptors, genes_senders)
interact_edges$ligands <- ifelse(interact_edges$ligands %in% duplicated_ligands, paste0(interact_edges$ligands, "_senders"), interact_edges$ligands)
interact_edges$receptors <- ifelse(interact_edges$receptors %in% duplicated_receptors, paste0(interact_edges$receptors, "_receivers"), interact_edges$receptors)

write.table(interact_edges, file.path(wd_path,"v1","MIIC_networks/causalCCC_interactEdges.tsv"), row.names=F, quote=F, sep="\t")

Results

CausalCCC network based of NicheNet CausalCCC legend