# Xenopus metagenome bins visualisation
# Chargement des packages

library(RColorBrewer)
library(ggplot2)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
## Folders, Themes, colors
source("prelude.R")
# Importing datafile
datafile<- paste0(data_dir_path,"Vizbin_DASTools/merged_vizbin.tbl")
vizbin<-read.table(datafile,header=TRUE,sep="\t")
vizbin<-vizbin %>% mutate(mtmg_ratio=log10(mtrpkm/mgrpkm))
#Defining colors
# Initially I used this method:
#nb.cols<-22
#mycolors<-colorRampPalette(brewer.pal(12,"Paired"))(nb.cols)
# I edited manually the lighter colors

mycolors<-c("#A6CEE3",
"#5FA0CA",
"#257CB2",
"#72B29C",
"#A5D981",
"#63B84F",
"#4F9F3B",
"#B89B74",
"#F68181",
"#E93E3F",
"#E9412F",
"#F6975B",
"#FDAC4F",
"#FE8B15",
"#ED8F47",
"#D1AAB7",
"#A585BF",
"#73489F",
"#A99099",
"#636105",
"#D9AF63",
"#B15928")

# Plot
ggplot(vizbin,aes(x=VIZBINX, y=VIZBINY))+geom_point(aes(colour=DASBIN,size=Length),alpha=0.7)+scale_colour_manual(values = mycolors)+theme_npgray()+guides(colour=FALSE)+xlab("")+ylab("")+theme(legend.position="top")

ggsave("vizbinplot.pdf",width=20,height=15,units="cm")


#plot with rpkm
ggplot(vizbin,aes(x=VIZBINX, y=VIZBINY))+geom_point(aes(colour=mtmg_ratio,size=Length),alpha=0.7)+theme_npgray()+guides(colour=FALSE)+xlab("")+ylab("")+theme(legend.position="top")

#Same plot with facetting
ggplot(vizbin,aes(x=VIZBINX, y=VIZBINY))+geom_point(aes(colour=DASBIN,size=Length))+scale_colour_manual(values = mycolors)+theme_npgray()+facet_wrap(~DASBIN)+guides(colour=FALSE)+xlab("")+ylab("")