Chapter 17 SCENIC Differential Regulons
library(Seurat)
library(tidyverse)
library(magrittr)
library(viridis)
library(SCENIC)
library(network)
library(igraph)
17.1 Load Seurat Obj
<- readRDS('data/SCENIC-Demo-Seurat.rds')
combined $celltype.stim <- paste(combined$Try_Cluster2, combined$orig.ident, sep = "_")
combined$celltype.stim <- factor(combined$celltype.stim, levels = c('SC_Hyper', 'SC_AS', 'CyclingTA_Hyper', 'CyclingTA_AS',
combined'TA_Hyper', 'TA_AS', 'EC_Hyper', 'EC_AS', 'GC_Hyper', 'GC_AS', 'EEC_Hyper'))
Idents(combined) <- "celltype.stim"
17.2 Load AUC socre and binary mat
## auc socres
<- readRDS('data/SCENIC-Demo-SCENIC-AUC.rds')
scenic <- scenic$regulons
regulons <- scenic$regulonAUC
regulonAUC <- AUCell::getAUC(regulonAUC)
AUCmat rownames(AUCmat) <- gsub("[(+)]", "", rownames(AUCmat))
## binary auc scores
<- read.csv('data/SCENIC-Demo-SCENIC-AUC-Binary.mat', sep = '\t')
Binarymat rownames(Binarymat) <- Binarymat$cells
$cells <- NULL
Binarymat<- t(Binarymat)
Binarymat rownames(Binarymat) <- gsub("[...]", "", rownames(Binarymat))
'AUC']] <- CreateAssayObject(data = AUCmat)
combined[['AUCBinary']] <- CreateAssayObject(data = Binarymat) combined[[
17.3 Identify differential regulons based AUC scores
DefaultAssay(combined) <- 'AUC'
<- unique(combined$Try_Cluster2)[1:5] %>% map(~{
deg.ls <- paste0(.x, '_AS')
id1 <- paste0(.x, '_Hyper')
id2
<- FindMarkers(combined, ident.1 = id2, ident.2 = id1, logfc.threshold = 0.005)
deg <- deg[which(deg$avg_logFC > 0), ]
deg.up <- deg[which(deg$avg_logFC < 0), ]
deg.dn <- list(deg.up, deg.dn)
deg.ls names(deg.ls) <- c(id2, id1)
return(deg.ls)
})
names(deg.ls) <- unique(combined$Try_Cluster2)[1:5]
<- list(deg.ls$SC$SC_Hyper, deg.ls$SC$SC_AS,
deg.ls $CyclingTA$CyclingTA_Hyper, deg.ls$CyclingTA$CyclingTA_AS,
deg.ls$TA$TA_Hyper, deg.ls$TA$TA_AS)
deg.lsnames(deg.ls) <- c('SC-Hyper', 'SC-AS', 'CyclingTA-Hyper', 'CyclingTA-AS', 'TA-Hyper', 'TA-AS')
<- lapply(deg.ls, rownames) gene.ls
17.4 Visu check differential regulons
- AUC scores
DefaultAssay(combined) <- 'AUC'
<- ScaleData(combined, assay = 'AUC', features = rownames(AUCmat)) combined
## Centering and scaling data matrix
<- unique(Reduce('c', gene.ls[c(2)]))
mg
DoHeatmap(combined, features = mg, slot = 'scale.data', raster = F) + scale_fill_viridis()
## Scale for 'fill' is already present. Adding another scale for 'fill', which
## will replace the existing scale.
DoHeatmap(combined, features = mg, slot = 'scale.data', raster = F) + scale_fill_gradient2(
low = rev(c('#d1e5f0', '#67a9cf', '#2166ac')),
mid = "white",
high = rev(c('#b2182b', '#ef8a62', '#fddbc7')),
midpoint = 0,
guide = "colourbar",
aesthetics = "fill"
)
## Scale for 'fill' is already present. Adding another scale for 'fill', which
## will replace the existing scale.
- Binary AUC scores
DefaultAssay(combined) <- 'AUCBinary'
<- unique(Reduce('c', gene.ls[c(1,3,5)]))
mg
DoHeatmap(combined, features = mg, slot = 'data') + scale_fill_gradientn(colors = c( "white", "black"))
## Scale for 'fill' is already present. Adding another scale for 'fill', which
## will replace the existing scale.
17.5 Visu check regulons via network
<- function(regulon.name){
visuNetwork
<- regulon.name %>% map(~{
adj.ls <- adj[which(adj$TF == .x), ]
tmp <- tmp[order(tmp$importance, decreasing = T),]
tmp <- unique(c(1:50, grep('MUC2', tmp$target)))
loci <- tmp[loci,]
tmp return(tmp)
})
<- Reduce('rbind', adj.ls)
adj.sub
## generate network
<- adj.sub
edge.df colnames(edge.df) <- c('from', 'to', 'weights')
$from <- as.character(edge.df$from)
edge.df$to <- as.character(edge.df$to)
edge.df
#net1 <- network(edge.df, directed = T, loops = T)
#plot(net1)
<- unique(c(edge.df$from, edge.df$to))
vertex <- graph_from_data_frame(d = edge.df, vertices = vertex, directed = T)
net
## vertex size scaled to log2FC
#combined.tmp <- AverageExpression(combined, assays = 'RNA', features = vertex)
#fc <- combined.tmp$RNA$SC_Hyper/combined.tmp$RNA$SC_AS
#fc <- combined.tmp$RNA$SC_AS/combined.tmp$RNA$SC_Hyper
#fc[which(fc > quantile(fc, 0.9))] <- quantile(fc, 0.9)
#fc[which(fc < quantile(fc, 0.1))] <- quantile(fc, 0.1)
#vsize <- scale(fc, center = min(fc), scale = max(fc) - min(fc))
#vsize <- vsize+0.1
## vertex color: whether DEG in hyper vs as
# vcl <- ifelse(vertex %in% dn.deg, 'blue', ifelse(vertex %in% up.deg, 'red', 'grey'))
# vlabel <- rep("", length(vertex))
# vertex label
# loci <- which(vcl != 'grey' | vertex %in% edge.df$from | vertex == 'MUC2')
# vlabel[loci] = vertex[loci]
# vertex size scaled to weights
<- scale(edge.df$weights, center = min(quantile(edge.df$weights)), scale = max(quantile(edge.df$weights)) - min(quantile(edge.df$weights)))
vsize
plot(
net,# vertex.label = vlabel,
vertex.label.cex = 1,
vertex.label.dist = 1,
vertex.label.color = 'black',
vertex.size = c(1, vsize+0.1)*10,
#vertex.size = vsize*10,
vertex.frame.color = NA,
edge.arrow.size = 0.5,
# vertex.color = vcl,
main = regulon.name
)
}
<- read.csv('data/SCENIC-Demo-SCENIC-adj.csv')
adj names(regulons) <- gsub("[(+)]", "", names(regulons))
lapply(names(regulons)[grep('MUC2', regulons)][3], visuNetwork)
## [[1]]
## NULL