##Figure 3 Code

library(Seurat)
library(ggplot2)
library(VennDiagram)
library(GeneOverlap)

#latest human organoid object
sub_obj2 <- readRDS(file = "~/Desktop/Purcell 2023 dataset/scRNA-seq Seurat Objects/sub_obj2.rds")
sub_obj2@meta.data$genotype <- factor(x = sub_obj2@meta.data$genotype, levels = c("Control", "3q29Del"))
sub_obj2@meta.data$timepoint <- factor(x = sub_obj2@meta.data$timepoint, levels = c("D50", "D360"), labels = c("2-month", "12-month"))

#latest mouse isocortex object
ms_obj <- readRDS(file = "~/Desktop/Purcell 2023 dataset/scRNA-seq Seurat Objects/ms_obj.rds")
ms_obj@meta.data$genotype <- factor(x = ms_obj@meta.data$genotype, levels = c("1", "2"), labels = c("WT", "3q29Del"))

#3A Blue Astrocyte UMAPs
astro_mm_umap <- DimPlot(ms_obj, reduction = "umap", label = FALSE, repel = TRUE, cols = c("grey", "royalblue", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey"))
astro_mm_umap & NoAxes() & NoLegend()

astro_hs_umap <- DimPlot(sub_obj2, reduction = "umap", label = FALSE, repel = TRUE, cols = c("grey", "grey", "grey", "grey", "royalblue", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey"))
astro_hs_umap & NoAxes() & NoLegend()

#3B Decreased and Increased DEG overlaps
#Astrocyte intersections
mm_astro <- read.csv("~/Desktop/Purcell 2023 dataset/Fig. 3/mm_hs_cell_type_overlaps/mm_astros.csv")
mm_astro_up <- subset(mm_astro, mm_astro$avg_logFC > 0)
m_astro_up <- unique(mm_astro_up$HumanGene)
mm_astro_down <- subset(mm_astro, mm_astro$avg_logFC < 0)
m_astro_down <- unique(mm_astro_down$HumanGene)

hs <- read.csv("~/Desktop/Purcell 2023 dataset/Fig. 3/mm_hs_cell_type_overlaps/human_deg_table.csv")
hs_astro_up <- subset(hs, hs$cl_number == "4" & hs$avg_logFC > 0)
h_astro_up <- unique(hs_astro_up$Gene)
hs_astro_down <- subset(hs, hs$cl_number == "4" & hs$avg_logFC < 0)
h_astro_down <- unique(hs_astro_down$Gene)

astro_down <- Reduce(intersect, list(m_astro_down, h_astro_down))
astro_up <- Reduce(intersect, list(m_astro_up, h_astro_up))

go.obj <- newGeneOverlap(m_astro_down, h_astro_down, genome.size = 8335)
go.obj                         
go.obj <- testGeneOverlap(go.obj)
go.obj

#GeneOverlap object - Astros DOWN:
#listA size=533
#listB size=217
#Intersection size=28
#Overlapping p-value=2.8e-04
#Jaccard Index=0.0

dev.off()
astro_down <- draw.pairwise.venn(area1=217, area2=533, cross.area=28,
                           main = "",
                           output=FALSE,
                           main.fontfamily = "sans",
                           main.cex = 3,
                           cat.fontfamily = "sans",
                           cat.cex = 1.8,
                           cat.default.pos = "text",
                           cat.dist = c(0.04, 0.04),
                           cat.pos = c(1, 1),
                           cat.fontface = "bold",
                           lwd = 2,
                           lty = 'blank',
                           fill = c("#774bac", "#b84774"),
                           fontfamily = "sans",
                           cex = 1.5)

go.obj <- newGeneOverlap(m_astro_up, h_astro_up, genome.size = 8335)
go.obj                         
go.obj <- testGeneOverlap(go.obj)
go.obj

#2.02-fold eniriched
#Fold enrichment calculated here:https://systems.crump.ucla.edu/hypergeometric/index.php


#GeneOverlap object - Astros UP:
#listA size=1115
#listB size=299
#Intersection size=41
#Overlapping p-value=0.46
#Jaccard Index=0.0

dev.off()
astro_up <- draw.pairwise.venn(area1=299, area2=1115, cross.area=41,
                               main = "",
                               output=FALSE,
                               main.fontfamily = "sans",
                               main.cex = 3,
                               cat.fontfamily = "sans",
                               cat.cex = 1.8,
                               cat.default.pos = "text",
                               cat.dist = c(0.04, 0.04),
                               cat.pos = c(1, 1),
                               cat.fontface = "bold",
                               lwd = 2,
                               lty = 'blank',
                               fill = c("#774bac", "#b84774"),
                               fontfamily = "sans",
                               cex = 1.5)

#NS enrichment

#3C Pathways plot
pathways <- read.csv("~/Desktop/Purcell 2023 dataset/Fig. 3/mm_hs_cell_type_overlaps/pathway_data.csv")
pathways <- subset(pathways, pathways$Rank < 16)
astros <- subset(pathways, pathways$Cell.Type == "ASTROCYTE" & pathways$source != "KEGG")
cols <- c("#745296","#58BC82")
astros[9,6] = "Respiratory electron transport, ATP synthesis by chemiosmotic coupling,\nand heat production by uncoupling proteins."
astros$source <- factor(astros$source, levels = c("GO:BP", "REAC"))
astros %>%
  mutate(term_name = reorder(term_name, negative_log10_of_adjusted_p_value)) %>%
  ggplot( aes(x=term_name, y=negative_log10_of_adjusted_p_value, source)) +
  geom_segment( aes(xend=term_name, yend=0)) +
  geom_point( size=4, aes(color=source)) +
  scale_color_manual(values = cols) +
  labs(x = "", y = "-Log10 P-value") +
  theme_bw() +
  xlab("") +
  scale_y_reverse(limits = c(5, 0)) +
  theme(legend.position = "none") +
  coord_flip()

#3D Red Neuron Clusters UMAP
neuron_mm_umap <- DimPlot(ms_obj, reduction = "umap", label = FALSE, repel = TRUE, cols = c("grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "#D62839", "grey", "#D62839", "grey", "grey", "grey", "#D62839", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey"))
neuron_mm_umap & NoAxes() & NoLegend()

neuron_hs_umap <- DimPlot(sub_obj2, reduction = "umap", label = FALSE, repel = TRUE, cols = c("grey", "grey", "grey", "#D62839", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "#D62839", "grey", "grey", "grey", "grey"))
neuron_hs_umap & NoAxes() & NoLegend()

#Neuron Intersections
mm_n <- read.csv("~/Desktop/Purcell 2023 dataset/Fig. 3/mm_hs_cell_type_overlaps/mm_neurons.csv")
mm_n_up <- subset(mm_n, mm_n$avg_logFC > 0)
m_n_up <- unique(mm_n_up$HumanGene)
mm_n_down <- subset(mm_n, mm_n$avg_logFC < 0)
m_n_down <- unique(mm_n_down$HumanGene)

hs_n_up <- subset(hs, hs$cl_number == "3" | hs$cl_number == "12" & hs$avg_logFC > 0 & hs$p_val_adj < 0.05)
h_n_up <- unique(hs_n_up$Gene)
hs_n_down <- subset(hs, hs$cl_number == "3" | hs$cl_number == "12" & hs$avg_logFC < 0 & hs$p_val_adj < 0.05)
h_n_down <- unique(hs_n_down$Gene)

n_down <- Reduce(intersect, list(m_n_down, h_n_down))
n_up <- Reduce(intersect, list(m_n_up, h_n_up))

neuron_bg <- read.csv("~/Desktop/Purcell 2023 dataset/Fig. 3/mm_hs_cell_type_overlaps/neuron_bg.csv")
bg <- unique(neuron_bg$gene)
go.obj <- newGeneOverlap(m_n_down, h_n_down, genome.size = 10647)
go.obj                         
go.obj <- testGeneOverlap(go.obj)
go.obj
#GeneOverlap object - Neuron Down:
#listA size=845
#listB size=661
#Intersection size=115
#Overlapping p-value=1.5e-16
#Jaccard Index=0.1

go.obj <- newGeneOverlap(m_n_up, h_n_up, genome.size = 10647)
go.obj                         
go.obj <- testGeneOverlap(go.obj)
go.obj
#GeneOverlap object - Neuron Up:
#listA size=907
#listB size=652
#Intersection size=112
#Overlapping p-value=1.5e-13
#Jaccard Index=0.1

#3E Venn diagrams
dev.off()
neuron_down <- draw.pairwise.venn(area1=845, area2=661, cross.area=115,
                                 main = "",
                                 output=FALSE,
                                 main.fontfamily = "sans",
                                 main.cex = 3,
                                 cat.fontfamily = "sans",
                                 cat.cex = 1.8,
                                 cat.default.pos = "text",
                                 cat.dist = c(0.04, 0.04),
                                 cat.pos = c(1, 1),
                                 cat.fontface = "bold",
                                 lwd = 2,
                                 lty = 'blank',
                                 fill = c("#b84774", "#774bac"),
                                 fontfamily = "sans",
                                 cex = 1.5)
#2.19-fold enriched

dev.off()
neuron_up <- draw.pairwise.venn(area1=907, area2=652, cross.area=112,
                               main = "",
                               output=FALSE,
                               main.fontfamily = "sans",
                               main.cex = 3,
                               cat.fontfamily = "sans",
                               cat.cex = 1.8,
                               cat.default.pos = "text",
                               cat.dist = c(0.04, 0.04),
                               cat.pos = c(1, 1),
                               cat.fontface = "bold",
                               lwd = 2,
                               lty = 'blank',
                               fill = c("#b84774", "#774bac"),
                               fontfamily = "sans",
                               cex = 1.5)
#2.02-fold enriched

#3F - Neuron down-regulated pathways
neurons <- subset(pathways, pathways$Cell.Type == "NEURON" & pathways$source != "KEGG" & pathways$Direction == "Down")
cols <- c("#745296","#58BC82")
neurons$source <- factor(neurons$source, levels = c("GO:BP", "REAC"))
neurons_top <- neurons[1:20,]
neurons_top[18,6] = "Respiratory electron transport, ATP synthesis by chemiosmotic coupling,\nand heat production by uncoupling proteins."
neurons_top %>%
  mutate(term_name = reorder(term_name, negative_log10_of_adjusted_p_value)) %>%
  ggplot( aes(x=term_name, y=negative_log10_of_adjusted_p_value, source)) +
  geom_segment( aes(xend=term_name, yend=0)) +
  geom_point( size=4, aes(color=source)) +
  scale_color_manual(values = cols) +
  labs(x = "", y = "-Log10 P-value") +
  theme_bw() +
  xlab("") +
  scale_y_reverse(limits = c(10, 0)) +
  theme(legend.position = "none") +
  coord_flip()

##############################################################
#Supplement - Comparison in additional cell types

#OPCs - mouse cluster 2 and 8, human cluster 17
opc_mm_umap <- DimPlot(ms_obj, reduction = "umap", label = FALSE, repel = TRUE, cols = c("grey", "grey", "#008080", "grey", "grey", "grey", "grey", "grey", "#008080", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey"))
opc_mm_umap & NoAxes() & NoLegend()

opc_hs_umap <- DimPlot(sub_obj2, reduction = "umap", label = FALSE, repel = TRUE, cols = c("grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "#008080"))
opc_hs_umap & NoAxes() & NoLegend()

mm_opc <- read.csv("~/OneDrive - Emory University/Single Cell Paper/Submission/Science Advances/Revision/Revision Source Data/Fig. 3/mm_hs_cell_type_overlaps/mm_opc.csv")
mm_opc_up <- subset(mm_opc, mm_opc$avg_logFC > 0)
m_opc_up <- unique(mm_opc_up$HumanGene)
mm_opc_down <- subset(mm_opc, mm_opc$avg_logFC < 0)
m_opc_down <- unique(mm_opc_down$HumanGene)

hs <- read.csv("~/OneDrive - Emory University/Single Cell Paper/Submission/Science Advances/Revision/Revision Source Data/Fig. 3/mm_hs_cell_type_overlaps/human_deg_table.csv")
hs_opc_up <- subset(hs, hs$cl_number == "17" & hs$avg_logFC > 0)
h_opc_up <- unique(hs_opc_up$Gene)
hs_opc_down <- subset(hs, hs$cl_number == "17" & hs$avg_logFC < 0)
h_opc_down <- unique(hs_opc_down$Gene)

opc_down <- Reduce(intersect, list(m_opc_down, h_opc_down))
opc_up <- Reduce(intersect, list(m_opc_up, h_opc_up))

library(GeneOverlap)
go.obj <- newGeneOverlap(m_opc_down, h_opc_down, genome.size = 8651)
go.obj                         
go.obj <- testGeneOverlap(go.obj)
go.obj
#GeneOverlap object - OPC down:
#  listA size=242
#listB size=158
#Intersection size=46
#Overlapping p-value=5.6e-35
#Jaccard Index=0.1

dev.off()
opc_down <- draw.pairwise.venn(area1=158, area2=242, cross.area=46,
                                main = "",
                                output=FALSE,
                                main.fontfamily = "sans",
                                main.cex = 3,
                                cat.fontfamily = "sans",
                                cat.cex = 1.8,
                                cat.default.pos = "text",
                                cat.dist = c(0.04, 0.04),
                                cat.pos = c(1, 1),
                                cat.fontface = "bold",
                                lwd = 2,
                                lty = 'blank',
                                fill = c("#774bac", "#b84774"),
                                fontfamily = "sans",
                                cex = 1.5)
#10.41-fold enriched

go.obj <- newGeneOverlap(m_opc_up, h_opc_up, genome.size = 8651)
go.obj                         
go.obj <- testGeneOverlap(go.obj)
go.obj
#GeneOverlap object - OPC UP:
#  listA size=332
#listB size=227
#Intersection size=18
#Overlapping p-value=2.8e-03
#Jaccard Index=0.0

dev.off()
opc_up <- draw.pairwise.venn(area1=227, area2=332, cross.area=18,
                               main = "",
                               output=FALSE,
                               main.fontfamily = "sans",
                               main.cex = 3,
                               cat.fontfamily = "sans",
                               cat.cex = 1.8,
                               cat.default.pos = "text",
                               cat.dist = c(0.04, 0.04),
                               cat.pos = c(1, 1),
                               cat.fontface = "bold",
                               lwd = 2,
                               lty = 'blank',
                               fill = c("#774bac", "#b84774"),
                               fontfamily = "sans",
                               cex = 1.5)
#2.07-fold enriched

opcs <- subset(pathways, pathways$Cell.Type == "OPC" & pathways$source != "KEGG" & pathways$Direction == "Down")
cols <- c("#745296","#58BC82")
opcs$source <- factor(opcs$source, levels = c("GO:BP", "REAC"))
opcs_top <- opcs[1:20,]
opcs_top[14,6]="Nonsense Mediated Decay (NMD) independent\nof the Exon Junction Complex (EJC)" 
opcs_top %>%
  mutate(term_name = reorder(term_name, negative_log10_of_adjusted_p_value)) %>%
  ggplot( aes(x=term_name, y=negative_log10_of_adjusted_p_value, source)) +
  geom_segment( aes(xend=term_name, yend=0)) +
  geom_point( size=4, aes(color=source)) +
  scale_color_manual(values = cols) +
  labs(x = "", y = "-Log10 P-value") +
  theme_bw() +
  xlab("") +
  scale_y_reverse(limits = c(35, 0)) +
  theme(legend.position = "none") +
  coord_flip()


#Radial glia - mouse cluster 7 and human cluster 1
rg_mm_umap <- DimPlot(ms_obj, reduction = "umap", label = FALSE, repel = TRUE, cols = c("grey", "grey", "grey", "grey", "grey", "grey", "grey", "#FF5733", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey"))
rg_mm_umap & NoAxes() & NoLegend()

rg_hs_umap <- DimPlot(sub_obj2, reduction = "umap", label = FALSE, repel = TRUE, cols = c("grey", "#FF5733", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey"))
rg_hs_umap & NoAxes() & NoLegend()

mm_rg <- read.csv("~/OneDrive - Emory University/Single Cell Paper/Submission/Science Advances/Revision/Revision Source Data/Fig. 3/mm_hs_cell_type_overlaps/mm_rg.csv")
mm_rg_up <- subset(mm_rg, mm_rg$avg_logFC > 0)
m_rg_up <- unique(mm_rg_up$HumanGene)
mm_rg_down <- subset(mm_rg, mm_rg$avg_logFC < 0)
m_rg_down <- unique(mm_rg_down$HumanGene)

hs_rg_up <- subset(hs, hs$cl_number == "1" & hs$avg_logFC > 0)
h_rg_up <- unique(hs_rg_up$Gene)
hs_rg_down <- subset(hs, hs$cl_number == "1" & hs$avg_logFC < 0)
h_rg_down <- unique(hs_rg_down$Gene)

rg_down <- Reduce(intersect, list(m_rg_down, h_rg_down))
rg_up <- Reduce(intersect, list(m_rg_up, h_rg_up))

go.obj <- newGeneOverlap(m_rg_down, h_rg_down, genome.size = 7776)
go.obj                         
go.obj <- testGeneOverlap(go.obj)
go.obj

#GeneOverlap object - RG down:
#listA size=177
#listB size=211
#Intersection size=23
#Overlapping p-value=3.2e-10
#Jaccard Index=0.1
dev.off()
rg_down <- draw.pairwise.venn(area1=177, area2=211, cross.area=23,
                             main = "",
                             output=FALSE,
                             main.fontfamily = "sans",
                             main.cex = 3,
                             cat.fontfamily = "sans",
                             cat.cex = 1.8,
                             cat.default.pos = "text",
                             cat.dist = c(0.04, 0.04),
                             cat.pos = c(1, 1),
                             cat.fontface = "bold",
                             lwd = 2,
                             lty = 'blank',
                             fill = c("#774bac", "#b84774"),
                             fontfamily = "sans",
                             cex = 1.5)

go.obj <- newGeneOverlap(m_rg_up, h_rg_up, genome.size = 7776)
go.obj                         
go.obj <- testGeneOverlap(go.obj)
go.obj
#4.79-fold enriched

#GeneOverlap object - Radial Glia Up:
#listA size=157
#listB size=323
#Intersection size=21
#Overlapping p-value=1.8e-06
#Jaccard Index=0.0
dev.off()
rg_down <- draw.pairwise.venn(area1=323, area2=157, cross.area=21,
                              main = "",
                              output=FALSE,
                              main.fontfamily = "sans",
                              main.cex = 3,
                              cat.fontfamily = "sans",
                              cat.cex = 1.8,
                              cat.default.pos = "text",
                              cat.dist = c(0.04, 0.04),
                              cat.pos = c(1, 1),
                              cat.fontface = "bold",
                              lwd = 2,
                              lty = 'blank',
                              fill = c("#774bac", "#b84774"),
                              fontfamily = "sans",
                              cex = 1.5)
#3.22-fold enriched

rgs <- subset(pathways, pathways$Cell.Type == "RG_NSC" & pathways$source != "KEGG" & pathways$Direction == "Down")
cols <- c("#745296","#58BC82")
rgs$source <- factor(rgs$source, levels = c("GO:BP", "REAC"))
rgs[2,6] = "Nonsense Mediated Decay (NMD) independent\nof the Exon Junction Complex (EJC)"
rgs[3,6] = "Nonsense Mediated Decay (NMD) enhanced by\nthe Exon Junction Complex (EJC)"

rgs %>%
  mutate(term_name = reorder(term_name, negative_log10_of_adjusted_p_value)) %>%
  ggplot( aes(x=term_name, y=negative_log10_of_adjusted_p_value, source)) +
  geom_segment( aes(xend=term_name, yend=0)) +
  geom_point( size=4, aes(color=source)) +
  scale_color_manual(values = cols) +
  labs(x = "", y = "-Log10 P-value") +
  theme_bw() +
  xlab("") +
  scale_y_reverse(limits = c(5, 0)) +
  theme(legend.position = "none") +
  coord_flip()

#Migrating Neuroblasts - human cl. 2 vs mouse cl. 6
nb_mm_umap <- DimPlot(ms_obj, reduction = "umap", label = FALSE, repel = TRUE, cols = c("grey", "grey", "grey", "grey", "grey", "grey", "#ff33db", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey"))
nb_mm_umap & NoAxes() & NoLegend()

nb_hs_umap <- DimPlot(sub_obj2, reduction = "umap", label = FALSE, repel = TRUE, cols = c("grey", "grey", "#ff33db", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey", "grey"))
nb_hs_umap & NoAxes() & NoLegend()

mm_nb <- read.csv("~/OneDrive - Emory University/Single Cell Paper/Submission/Science Advances/Revision/Revision Source Data/Fig. 3/mm_hs_cell_type_overlaps/mm_nb.csv")
mm_nb_up <- subset(mm_nb, mm_nb$avg_logFC > 0)
m_nb_up <- unique(mm_nb_up$HumanGene)
mm_nb_down <- subset(mm_nb, mm_nb$avg_logFC < 0)
m_nb_down <- unique(mm_nb_down$HumanGene)

hs_nb_up <- subset(hs, hs$cl_number == "2" & hs$avg_logFC > 0)
h_nb_up <- unique(hs_nb_up$Gene)
hs_nb_down <- subset(hs, hs$cl_number == "2" & hs$avg_logFC < 0)
h_nb_down <- unique(hs_nb_down$Gene)

nb_down <- Reduce(intersect, list(m_nb_down, h_nb_down))
nb_up <- Reduce(intersect, list(m_nb_up, h_nb_up))

go.obj <- newGeneOverlap(m_nb_down, h_nb_down, genome.size = 7226)
go.obj                         
go.obj <- testGeneOverlap(go.obj)
go.obj

#GeneOverlap object - Migrating Neuroblasts down:
#listA size=92
#listB size=220
#Intersection size=22
#Overlapping p-value=2.2e-14
#Jaccard Index=0.1
dev.off()
nb_down <- draw.pairwise.venn(area1=220, area2=92, cross.area=22,
                              main = "",
                              output=FALSE,
                              main.fontfamily = "sans",
                              main.cex = 3,
                              cat.fontfamily = "sans",
                              cat.cex = 1.8,
                              cat.default.pos = "text",
                              cat.dist = c(0.04, 0.04),
                              cat.pos = c(1, 1),
                              cat.fontface = "bold",
                              lwd = 2,
                              lty = 'blank',
                              fill = c("#774bac", "#b84774"),
                              fontfamily = "sans",
                              cex = 1.5)

#7.85-fold enriched

go.obj <- newGeneOverlap(m_nb_up, h_nb_up, genome.size = 7226)
go.obj                         
go.obj <- testGeneOverlap(go.obj)
go.obj

#GeneOverlap object - Neuroblast UP:
#listA size=94
#listB size=163
#Intersection size=15
#Overlapping p-value=2.1e-09
#Jaccard Index=0.1
dev.off()
nb_up <- draw.pairwise.venn(area1=163, area2=94, cross.area=15,
                              main = "",
                              output=FALSE,
                              main.fontfamily = "sans",
                              main.cex = 3,
                              cat.fontfamily = "sans",
                              cat.cex = 1.8,
                              cat.default.pos = "text",
                              cat.dist = c(0.04, 0.04),
                              cat.pos = c(1, 1),
                              cat.fontface = "bold",
                              lwd = 2,
                              lty = 'blank',
                              fill = c("#774bac", "#b84774"),
                              fontfamily = "sans",
                              cex = 1.5)

nb <- subset(pathways, pathways$Cell.Type == "NEUROBLAST" & pathways$source != "KEGG" & pathways$Direction == "DOWN")
cols <- c("#745296","#58BC82")
nb$source <- factor(nb$source, levels = c("GO:BP", "REAC"))
nb[2,6] = "Nonsense Mediated Decay (NMD) independent\nof the Exon Junction Complex (EJC)"
nb[5,6] = "Nonsense Mediated Decay (NMD) enhanced by\nthe Exon Junction Complex (EJC)"

nb %>%
  mutate(term_name = reorder(term_name, negative_log10_of_adjusted_p_value)) %>%
  ggplot( aes(x=term_name, y=negative_log10_of_adjusted_p_value, source)) +
  geom_segment( aes(xend=term_name, yend=0)) +
  geom_point( size=4, aes(color=source)) +
  scale_color_manual(values = cols) +
  labs(x = "", y = "-Log10 P-value") +
  theme_bw() +
  xlab("") +
  scale_y_reverse(limits = c(5, 0)) +
  theme(legend.position = "none") +
  coord_flip()




