From 82ca6e3c5b2653960f66ffb6da4fbff439a5f617 Mon Sep 17 00:00:00 2001
From: ahugues <alice.hugues@ens-lyon.fr>
Date: Mon, 20 Feb 2023 10:07:57 +0100
Subject: [PATCH] maj base scripts

---
 src/00_base_functions.R | 19 +++++++++++++++----
 src/00_root.R           | 10 ++++++++++
 src/00_utils.R          |  2 ++
 3 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/src/00_base_functions.R b/src/00_base_functions.R
index 2664f47..ac81b96 100644
--- a/src/00_base_functions.R
+++ b/src/00_base_functions.R
@@ -7,13 +7,24 @@ labeller <- function(l, l_names = NULL, features){
   }
   
   if ( length(l) == 3 ){
-    label <- as.factor(ifelse(features %in% l[[1]], 'K4-only', 
-                              ifelse(features %in% l[[2]], 'Bivalent', 
-                                     ifelse(features %in% l[[3]], 'K27-only', 'Unclass.'))))
+    label <- as.factor(ifelse(features %in% l[[1]], l_names[1], 
+                              ifelse(features %in% l[[2]], l_names[2],
+                                     ifelse(features %in% l[[3]], l_names[3], 'Unclass.'))))
   } else if ( length(l) == 1 ) {
-    label <- factor(ifelse(features %in% l[[1]], 'K27', 'Unmarked'))
+    label <- factor(ifelse(features %in% l[[1]], l_names, 'Unmarked'))
   }
   
   names(label) <- features
   return(label)
 }
+
+make_pal <- function(factor, pal = 'Set1'){
+  if ( length(unique(factor)) < 3 ){
+    cols <- brewer.pal(3, pal)[c(1,3)]
+  } else {
+    cols <- brewer.pal(length(unique(factor)), pal)
+  }
+  
+  names(cols) <- unique(factor)
+  return(cols)
+}
\ No newline at end of file
diff --git a/src/00_root.R b/src/00_root.R
index 95cb410..766660f 100644
--- a/src/00_root.R
+++ b/src/00_root.R
@@ -50,3 +50,13 @@ root_tfs <- names(which(table(df$gene) == 3))
 write.table(root_tfs, 
             file = sprintf('%s/root_tfs.txt', output.dir), 
             quote = FALSE, col.names = F, row.names = F)
+
+
+# Pcg
+all <- union(glist, root_genes)
+df <- rbind(data.frame('gene' = K27_wr, 'set' = 'K27me3 (whole root)'),
+            data.frame('gene' = root_genes, 'set' = 'Root genes'),
+            data.frame('gene' = FIE, 'set' = 'FIE'),
+            data.frame('gene' = c(K27_genes, K27K4_genes), 'set' = 'K27me3 (WOX5)'))
+v <- venneuler(df)
+plot(v)
\ No newline at end of file
diff --git a/src/00_utils.R b/src/00_utils.R
index a25415a..c06f278 100644
--- a/src/00_utils.R
+++ b/src/00_utils.R
@@ -12,6 +12,8 @@ library(tibble)
 library(RColorBrewer)
 library(venneuler)
 
+source('src/00_base_functions.R')
+
 # from calculus
 working.dir <- "/projects/epichromdev/ahugues/scarabi_pcg_identity"
 rds.path <- "data/list_seuObj.rds"
-- 
GitLab