Figure 2I

Code
# Inma Hernandez Lopez
# inmaculada.hernandez-lopez@ukr.de
# LIT -  Leibniz-Institute für Immunotherapie

# Enrique Blanco Carmona
# e.blancocarmona@kitz-heidelberg.de
# PhD Student – Clinical Bioinformatics
# Division of Pediatric Neurooncology (B062)
# DKFZ-KiTZ | Germany


sample.atac <- readRDS("/omics/odcf/analysis/OE0145_projects/idh_gliomas/Figures_Science/revision/IDH_gliomas_book/datasets/primary_ATAC_AS.rds")
markers <- readRDS("/omics/odcf/analysis/OE0145_projects/idh_gliomas/Figures_Science/revision/IDH_gliomas_book/datasets/motif_markers_atac_AS.rds")
markers$cluster <- as.character(markers$cluster)
markers$cluster[markers$cluster == "RA"] <- "RE"
sample.atac <- sample.atac[, sample.atac$relabelling %in% c("OPC-like", "RA", "Cycling", "Astro-like")]
Seurat::DefaultAssay(sample.atac) <- "chromvar"

sample.atac$relabelling[sample.atac$relabelling == "RA"] <- "RE"
Seurat::Idents(sample.atac) <- sample.atac$relabelling

genes.use <- unique(markers$gene_short)

markers <- markers %>% 
           dplyr::filter(.data$gene_short %in% genes.use) %>% 
           dplyr::mutate(cluster = factor(.data$cluster, levels = c("Astro-like", "Cycling", "OPC-like", "RE"))) %>% 
           dplyr::group_by(.data$cluster) %>% 
           dplyr::arrange(.data$p_val_adj, dplyr::desc(.data$avg_log2FC)) %>% 
           dplyr::slice_head(n = 50)

markers <- markers[!duplicated(markers$gene_short), ]

markers <- markers %>% 
           dplyr::slice_head(n = 15)
sample.atac <- Seurat::ScaleData(sample.atac, features = markers$gene_long)
Code
p <- SCpubr::do_ExpressionHeatmap(sample.atac, 
                                  features = markers$gene_long, 
                                  assay = "chromvar", 
                                  flip = FALSE, 
                                  cluster = TRUE, 
                                  slot = "scale.data", 
                                  enforce_symmetry = TRUE, 
                                  features.order = markers$gene_long,
                                  groups.order = list("Groups" = rev(c("Astro-like", "Cycling", "OPC-like", "RE"))),
                                  legend.title = "Motif Score",
                                  max.cutoff = 0.8,
                                  min.cutoff = -0.4,
                                  font.size = 20,
                                  legend.length = 15,
                                  legend.width = 0.5,
                                  legend.framecolor = "grey50",
                                  legend.tickcolor = "white",
                                  legend.framewidth = 0.2,
                                  legend.tickwidth = 0.2,
                                  axis.text.face = "plain") +
      ggplot2::labs(x = "Motif",
                    y = "Cell type") + 
      ggplot2::theme(axis.title.y.left = ggplot2::element_text(hjust = 0.5))
p$data$gene <-  unname(vapply(p$data$gene, function(x){stringr::str_split(x, "-")[[1]][3]}, FUN.VALUE = character(1)))
p$data$gene <- factor(p$data$gene, levels = c(markers$gene_short))