# setwd("/Users/bryanteefy/Dropbox/PIWI/CODE/5_piRNA_Analysis")
setwd("/Users/berenice/Dropbox/Manuscripts_and_Publications/2022/2022_Bryan_PIWI_manuscript/CODE/5_piRNA_Analysis")
# R version 4.1.2 (2021-11-01)
# compare DE TEs and DE TE-targeting piRNAs
# load libraries
library(Vennerable)        # Vennerable_3.1.0.9000
#set outprefix
my.outprefix <- paste(Sys.Date(),"piRNA_TE_comparison_ovary",sep="_")
# load results of LRT TE analysis (ovary)
ovary.TE.LRT  <- read.table("../4_TE_Analysis/Results/1_Ovary_TE_DGE/2022-07-13_Ovary_TE_analysis_LRT_DESeq2_LRT_TE_DGE_Table_ALL_with_DGEPatterns_Clusters_FDR1e-6.txt", header = T)
# load results of LRT piRNA analysis (ovary)
ovary.pi.LRT  <- read.table("./Results/1_Ovary_piRNA_DGE/2022-07-27_Ovary_LRT_piRNA_DESeq2_LRT_DGE_Table_ALL_piRNA_TEs_with_DGEPatterns_Clusters_FDR1e-6.txt", header = T)
# compare overlap of TEs up at mid-age [pattern b, group 1 in output] with piRNA down at mid-age [pattern a, group 1 in output]
ovary.TE.LRT.up_Mage  <- ovary.TE.LRT[which(ovary.TE.LRT$cluster == 1),]
ovary.pi.LRT.dwn_Mage <- ovary.pi.LRT[which(ovary.pi.LRT$cluster == 1),]
View(ovary.TE.LRT)
# get the consistently regulated TEs
my.consistent <- intersect(ovary.TE.LRT.up_Mage$gene, ovary.pi.LRT.dwn_Mage$gene)
my.consistent
# extract family of TEs
new_names <- gsub(".+:", "", my.consistent)
new_names
new_names
pi(new_names)
pie(new_names)
pie(table(new_names))
# make unclear merge with unknown
new_names[new_names == "unclear"] <- "Unknown"
new_names
?pie
pie(table(new_names), col = c(DNA="firebrick1", LINE="darkturquoise", LTR="cornflowerblue", SINE="blue", Unknown="gold"))
table(new_names)
pie(table(new_names), col = c("firebrick1", "darkturquoise", "cornflowerblue", "gold"))
# output pie chart of composition
pdf(paste0("./Results/9_DE_piRNA_TE_comparison_Venn/",my.outprefix,"_pie_chart_of_intersection.pdf"))
pie(table(new_names), col = c("firebrick1", "darkturquoise", "cornflowerblue", "gold"))
dev.off()
# output pie chart of composition
table(new_names)
# output pie chart of composition
table(new_names)/length(new_names)
# output pie chart of composition
table(new_names)/length(new_names)*100
# output pie chart of composition
signif(table(new_names)/length(new_names)*100,2)
# output pie chart of composition
inter.tab <- signif(table(new_names)/length(new_names)*100,2)
names(inter.tab)
paste( names(inter.tab) , inter.tab)
names(inter.tab) <- paste( names(inter.tab) , inter.tab, "%")
inter.tab
pie(inter.tab, col = c("firebrick1", "darkturquoise", "cornflowerblue", "gold"))
pdf(paste0("./Results/9_DE_piRNA_TE_comparison_Venn/",my.outprefix,"_pie_chart_of_intersection.pdf"))
pie(inter.tab, col = c("firebrick1", "darkturquoise", "cornflowerblue", "gold"))
dev.off()
