Load cohort annotation file and Epithelial cells Seurat object

Figure 6-a

anno.class = anno.class.obs

############
class = "Endometrial-type Epithelium"
sel.sc = readRDS("rds/EnEpi_cells.rds")

prop.cells <- data.frame(table(sel.sc@meta.data$active.cluster))
prop.cells$Var1 <- factor(prop.cells$Var1, levels = prop.cells$Var1)
ggplot(prop.cells, aes(Var1, Freq)) +
  geom_col() +
  theme_minimal(base_size = 15) +
  geom_text(aes(label=Freq), position=position_dodge(width=0.9), vjust=-0.25) +
  theme(plot.title = element_text(hjust = 0.5),
        axis.text.x = element_text(angle = 45, hjust = 1),
        axis.title.x = element_blank()) +
  labs(y = "Number of Cells")

prop.cells <- data.frame(table(sel.sc@meta.data$Major.Class))
prop.cells$Var1 <- factor(prop.cells$Var1, levels = prop.cells$Var1)
ggplot(prop.cells, aes(Var1, Freq)) +
  geom_col() +
  theme_minimal(base_size = 15) +
  geom_text(aes(label=Freq), position=position_dodge(width=0.9), vjust=-0.25) +
  theme(plot.title = element_text(hjust = 0.5),
        axis.text.x = element_text(angle = 45, hjust = 1),
        axis.title.x = element_blank()) +
  labs(y = "Number of Cells")

.sel.sc = subset(sel.sc, subset = SampleName %in% unique(anno.class$SampleName))


prop.cells <- data.frame(table(.sel.sc@meta.data$active.cluster))
prop.cells$Var1 <- factor(prop.cells$Var1, levels = prop.cells$Var1)
ggplot(prop.cells, aes(Var1, Freq)) +
  geom_col() +
  theme_minimal(base_size = 15) +
  geom_text(aes(label=Freq), position=position_dodge(width=0.9), vjust=-0.25) +
  theme(plot.title = element_text(hjust = 0.5),
        axis.text.x = element_text(angle = 45, hjust = 1),
        axis.title.x = element_blank()) +
  labs(y = "Number of Cells")

prop.cells <- data.frame(table(.sel.sc@meta.data$Major.Class))
prop.cells$Var1 <- factor(prop.cells$Var1, levels = prop.cells$Var1)
ggplot(prop.cells, aes(Var1, Freq)) +
  geom_col() +
  theme_minimal(base_size = 15) +
  geom_text(aes(label=Freq), position=position_dodge(width=0.9), vjust=-0.25) +
  theme(plot.title = element_text(hjust = 0.5),
        axis.text.x = element_text(angle = 45, hjust = 1),
        axis.title.x = element_blank()) +
  labs(y = "Number of Cells")

.sel.sc@meta.data$Surgical = NA

for (i in 1:nrow(anno.class)) {
  sample = anno.class$SampleName[i]
  .sel.sc@meta.data$Surgical[.sel.sc@meta.data$SampleName == sample] <- anno.class$CominedSurgical[i]
}


Idents(object = .sel.sc) <- .sel.sc@meta.data$Surgical

DEG.res <- FindAllMarkers(.sel.sc, test.use = "MAST")

fc.p = 0.9
pv.p = 0.05
DEG.res$STATUS = "NOT.SIG"
DEG.res[DEG.res$avg_log2FC < -fc.p & DEG.res$p_val_adj < pv.p, ]$STATUS = "Down"
DEG.res[DEG.res$avg_log2FC > fc.p & DEG.res$p_val_adj < pv.p, ]$STATUS = "Up"

feature = "Surgical"
c = "Deep"

markers.filt = DEG.res[DEG.res$cluster == c,]
nDEG = nrow(markers.filt)
genes = markers.filt$gene[markers.filt$cluster == c & markers.filt$STATUS != "NOT.SIG"]

pv <- ggplot(markers.filt, aes(x = avg_log2FC, y = -log10(p_val_adj))) +
  geom_point(aes(color = STATUS), cex = 1.45) +
  scale_color_manual(values = c("darkgreen", "grey", "red")) +
  ylim(0, 65) +
  theme_bw(base_size = 15) + 
  theme(legend.position = "bottom",
        plot.title = element_text(hjust = 0.5)) +
  geom_text_repel(
    data          = subset(markers.filt, STATUS == "Up"),
    aes(label = markers.filt$gene[which(markers.filt$gene %in% genes  & markers.filt$STATUS %in% "Up")]),
    segment.size  = 0.4,
    direction     = "y",
    segment.color = "grey50",
    hjust         = 0
  ) +
  geom_text_repel(
    data          = subset(markers.filt, STATUS == "Down"),
    aes(label = markers.filt$gene[which(markers.filt$gene %in% genes & markers.filt$STATUS %in% "Down")]),
    segment.size  = 0.4,
    direction     = "y",
    segment.color = "grey50",
    hjust         = 1
  ) +
  geom_hline(yintercept = -log10(pv.p), linetype="dotted", color = "black", size= 0.5) +
  geom_vline(xintercept = -fc.p, linetype="dotted", color = "black", size= 0.5) +
  geom_vline(xintercept = fc.p, linetype="dotted", color = "black", size= 0.5) +
  labs(title = paste0(feature, " : ", c, " (n=", nDEG, ") FC: ", fc.p, " pval = ", pv.p))
pv

Figure 6-b

res <- compareCluster(gs.ephi, fun="enrichPathway")

dp + RotatedAxis()

Figure 6-c

class = "Endometrial-type Stroma"
sel.sc = readRDS("rds/EnS_cells.rds")

prop.cells <- data.frame(table(sel.sc@meta.data$active.cluster))
prop.cells$Var1 <- factor(prop.cells$Var1, levels = prop.cells$Var1)
ggplot(prop.cells, aes(Var1, Freq)) +
  geom_col() +
  theme_minimal(base_size = 15) +
  geom_text(aes(label=Freq), position=position_dodge(width=0.9), vjust=-0.25) +
  theme(plot.title = element_text(hjust = 0.5),
        axis.text.x = element_text(angle = 45, hjust = 1),
        axis.title.x = element_blank()) +
  labs(y = "Number of Cells")

prop.cells <- data.frame(table(sel.sc@meta.data$Major.Class))
prop.cells$Var1 <- factor(prop.cells$Var1, levels = prop.cells$Var1)
ggplot(prop.cells, aes(Var1, Freq)) +
  geom_col() +
  theme_minimal(base_size = 15) +
  geom_text(aes(label=Freq), position=position_dodge(width=0.9), vjust=-0.25) +
  theme(plot.title = element_text(hjust = 0.5),
        axis.text.x = element_text(angle = 45, hjust = 1),
        axis.title.x = element_blank()) +
  labs(y = "Number of Cells")

.sel.sc = subset(sel.sc, subset = SampleName %in% unique(anno.class$SampleName))

prop.cells <- data.frame(table(.sel.sc@meta.data$active.cluster))
prop.cells$Var1 <- factor(prop.cells$Var1, levels = prop.cells$Var1)
ggplot(prop.cells, aes(Var1, Freq)) +
  geom_col() +
  theme_minimal(base_size = 15) +
  geom_text(aes(label=Freq), position=position_dodge(width=0.9), vjust=-0.25) +
  theme(plot.title = element_text(hjust = 0.5),
        axis.text.x = element_text(angle = 45, hjust = 1),
        axis.title.x = element_blank()) +
  labs(y = "Number of Cells")

prop.cells <- data.frame(table(.sel.sc@meta.data$Major.Class))
prop.cells$Var1 <- factor(prop.cells$Var1, levels = prop.cells$Var1)
ggplot(prop.cells, aes(Var1, Freq)) +
  geom_col() +
  theme_minimal(base_size = 15) +
  geom_text(aes(label=Freq), position=position_dodge(width=0.9), vjust=-0.25) +
  theme(plot.title = element_text(hjust = 0.5),
        axis.text.x = element_text(angle = 45, hjust = 1),
        axis.title.x = element_blank()) +
  labs(y = "Number of Cells")

.sel.sc@meta.data$Surgical = NA

for (i in 1:nrow(anno.class)) {
  sample = anno.class$SampleName[i]
  .sel.sc@meta.data$Surgical[.sel.sc@meta.data$SampleName == sample] <- anno.class$CominedSurgical[i]
}


Idents(object = .sel.sc) <- .sel.sc@meta.data$Surgical

DEG.res <- FindAllMarkers(.sel.sc, test.use = "MAST")

fc.p = 1.1
pv.p = 0.05
DEG.res$STATUS = "NOT.SIG"
DEG.res[DEG.res$avg_log2FC < -fc.p & DEG.res$p_val_adj < pv.p, ]$STATUS = "Down"
DEG.res[DEG.res$avg_log2FC > fc.p & DEG.res$p_val_adj < pv.p, ]$STATUS = "Up"

feature = "Surgical"
c = "Deep"

markers.filt = DEG.res[DEG.res$cluster == c,]
nDEG = nrow(markers.filt)
genes = markers.filt$gene[markers.filt$cluster == c & markers.filt$STATUS != "NOT.SIG"]

pv <- ggplot(markers.filt, aes(x = avg_log2FC, y = -log10(p_val_adj))) +
  geom_point(aes(color = STATUS), cex = 1.45) +
  scale_color_manual(values = c("darkgreen", "grey", "red")) +
  ylim(0, 65) +
  theme_bw(base_size = 15) + 
  theme(legend.position = "bottom",
        plot.title = element_text(hjust = 0.5)) +
  geom_text_repel(
    data          = subset(markers.filt, STATUS == "Up"),
    aes(label = markers.filt$gene[which(markers.filt$gene %in% genes  & markers.filt$STATUS %in% "Up")]),
    segment.size  = 0.4,
    direction     = "y",
    segment.color = "grey50",
    hjust         = 0
  ) +
  geom_text_repel(
    data          = subset(markers.filt, STATUS == "Down"),
    aes(label = markers.filt$gene[which(markers.filt$gene %in% genes & markers.filt$STATUS %in% "Down")]),
    segment.size  = 0.4,
    direction     = "y",
    segment.color = "grey50",
    hjust         = 1
  ) +
  geom_hline(yintercept = -log10(pv.p), linetype="dotted", color = "black", size= 0.5) +
  geom_vline(xintercept = -fc.p, linetype="dotted", color = "black", size= 0.5) +
  geom_vline(xintercept = fc.p, linetype="dotted", color = "black", size= 0.5) +
  labs(title = paste0(feature, " : ", c, " (n=", nDEG, ") FC: ", fc.p, " pval = ", pv.p))
pv

Figure 6-d

res <- compareCluster(gs.ephi, fun="enrichPathway")
dp + RotatedAxis()