.libPaths("/Users/eli/Documents/Tosches_Lab/Seurat5/Seurat5/renv/")

setwd("~/Documents/Tosches_Lab/Tosches_R/")

library(ggplot2)

library(Seurat)



###  GSI correleation 
mouse.0<-readRDS("FB_Neuron_mouse_develop_clean_4000-_1CLR_022026_annotate_V3_fix_022026")

pleuro.0<-readRDS("clean_annotate_v2_sal.dev_mat_neur_FORE_TP73_iso_061625_v3.rds")




mouse.0@meta.data$tr_anno<-factor(mouse.0@meta.data$tr_anno, levels = c("Mouse Cajal-Retzius","Mouse Glutamatergic Telencephalon", 
                                                                        "Mouse GABAergic Telencephalon",
                                                                        "Mouse Glutamatergic Diencephalon","Mouse GABAergic Diencephalon"))

Idents(pleuro.0)<-"tr_anno"

pleuro.0<-subset(pleuro.0, idents =c("Pleuro Other Telencephalon","Pleuro Other Diencephalon" ), invert=T )



pleuro.0@meta.data$tr_anno<-factor(pleuro.0@meta.data$tr_anno, levels = c("PW_TP73_Neuron","Pleuro Glutamatergic Telencephalon", 
                                                                          "Pleuro GABAergic Telencephalon",
                                                                          "Pleuro Glutamatergic Diencephalon","Pleuro GABAergic Diencephalon"))

Idents(mouse.0)<-"tr_anno"


mouse.de <- FindAllMarkers(mouse.0, max.cells.per.ident = 600, logfc.threshold = .75)
mouse.de <- mouse.de[mouse.de$p_val_adj<0.01,]
mouse.de.genes <- unique(mouse.de$gene)





DefaultAssay(mouse.0)<-"RNA"

mouse.0<- NormalizeData(
  mouse.0,
  assay = "RNA",
  normalization.method = "LogNormalize",
  scale.factor = 10000,
  margin = 1,
  verbose = TRUE)


ExpressionTableMouse<-AverageExpression(mouse.0, group.by = "tr_anno", assays = "RNA")

rownames(ExpressionTableMouse$RNA)

colnames(ExpressionTableMouse$RNA)


pleuro.de <- FindAllMarkers(pleuro.0, max.cells.per.ident = 600, logfc.threshold = .75)
pleuro.de <- pleuro.de[pleuro.de$p_val_adj<0.01,]


pleuro.de.genes <- unique(pleuro.de$gene)


DefaultAssay(pleuro.0)<-"RNA"

pleuro.0<- NormalizeData(
  pleuro.0,
  assay = "RNA",
  normalization.method = "LogNormalize",
  scale.factor = 10000,
  margin = 1,
  verbose = TRUE)



ExpressionTablePleuro<-AverageExpression(pleuro.0, group.by = "tr_anno", assays = "RNA")




data.frame(ExpressionTableMouse$RNA)





library(Seurat)

library(corrplot)

#install.packages("tidyverse")

library(tidyverse)


CorrComparePlot(ExpressionTableSpecies1 = data.frame(ExpressionTableMouse$RNA),   DEgenesSpecies1 = mouse.de.genes,
                ExpressionTableSpecies2 = data.frame(ExpressionTablePleuro$RNA) ,
                DEgenesSpecies2 = pleuro.de.genes,
                Species1 = "mouse", Species2 = "pleurodeles",
                filename = "Lamanno_int_FB_tr_TF_v7_022026", Height=12, Width=12)                             


DimPlot(mouse.0, group.by = "tr_anno")



