# setwd( "PLOTTING" )

library( ggplot2 )
## Registered S3 methods overwritten by 'ggplot2':
##   method         from 
##   [.quosures     rlang
##   c.quosures     rlang
##   print.quosures rlang
library( SuppDists )
library( MASS )
library( Haplin )
## Registered S3 methods overwritten by 'ffbase':
##   method   from
##   [.ff     ff  
##   [.ffdf   ff  
##   [<-.ff   ff  
##   [<-.ffdf ff
source( "../common_variables.R" )

# promoter x NOG1
gene <- "NOG1"
load( "../PoOxM_new_betas_mult_onlyNOG1-ch-17-52148184R_CLO.RData" )

cur.plot.obj <- haptable.poo.prom.res.NOG1
cur.plot.obj.list <- lapply( unique( cur.plot.obj$stratum ), function(x){
  return( dplyr::filter( cur.plot.obj, stratum == x ) )
} )
names( cur.plot.obj.list ) <- c( "all", "1", "2", "3" )

cur.signif.plot <- plot.haplinSlide( cur.plot.obj.list, title = "", y.lim = c( 1/32,10 ) )

intercept.hline <- ( as.numeric( cur.signif.plot$data$haplos[ 3 ] ) -
    as.numeric( cur.signif.plot$data$haplos[ 2 ] ) ) / 2

y.labels <- c( 1/32, 1/16, 1/8, 1/4, 1/2, 5, 10 )

cur.signif.plot +
  geom_vline( xintercept = 1.5, linetype = 2 ) +
    scale_y_continuous( breaks = y.labels, labels = as.character( y.labels ) ) +
  xlab( "stratum" ) +
    theme( axis.text.x = element_text( angle = 0, size = 12 ),
            axis.text.y = element_text( size = 12 ),
            axis.line.y = element_line( color = "black" ),
            axis.title = element_text( size = 14 ),
            panel.background = element_rect( fill = "white", colour = "grey50" ),
            panel.grid.major.y = element_line( colour = "grey70", linetype = 2 ) )

ggsave( "PoOxM_CLO_mult_betas_promoter-NOG1-only-ch-17-52148184R.png",
        width = 15, height = 12, units = "cm" )
load( "../PoOxM_new_betas_mult_onlyNOG1-ch-17-52148184R_CLorP.RData" )

cur.plot.obj <- haptable.poo.prom.res.NOG1
cur.plot.obj.list <- lapply( unique( cur.plot.obj$stratum ), function(x){
  return( dplyr::filter( cur.plot.obj, stratum == x ) )
} )
names( cur.plot.obj.list ) <- c( "all", "1", "2", "3" )

cur.signif.plot <- plot.haplinSlide( cur.plot.obj.list, title = "", y.lim = c( 1/4,15 ) )

intercept.hline <- ( as.numeric( cur.signif.plot$data$haplos[ 3 ] ) -
    as.numeric( cur.signif.plot$data$haplos[ 2 ] ) ) / 2

y.labels <- c( 1/4, 1/2, 5, 10, 15 )

cur.signif.plot +
  geom_vline( xintercept = 1.5, linetype = 2 ) +
    scale_y_continuous( breaks = y.labels, labels = as.character( y.labels ) ) +
  xlab( "stratum" ) +
    theme( axis.text.x = element_text( angle = 0, size = 12 ),
            axis.text.y = element_text( size = 12 ),
            axis.line.y = element_line( color = "black" ),
            axis.title = element_text( size = 14 ),
            panel.background = element_rect( fill = "white", colour = "grey50" ),
            panel.grid.major.y = element_line( colour = "grey70", linetype = 2 ) )

ggsave( "PoOxM_CLorP_mult_betas_promoter-NOG1-only-ch-17-52148184R.png",
        width = 15, height = 12, units = "cm" )
load( "../PoOxM_new_betas_mult_onlyNOG1-ch-17-52148184R_CLP.RData" )

cur.plot.obj <- haptable.poo.prom.res.NOG1
cur.plot.obj.list <- lapply( unique( cur.plot.obj$stratum ), function(x){
  return( dplyr::filter( cur.plot.obj, stratum == x ) )
} )
names( cur.plot.obj.list ) <- c( "all", "1", "2", "3" )

cur.signif.plot <- plot.haplinSlide( cur.plot.obj.list, title = "", y.lim = c( 1/8,15 ) )

intercept.hline <- ( as.numeric( cur.signif.plot$data$haplos[ 3 ] ) -
    as.numeric( cur.signif.plot$data$haplos[ 2 ] ) ) / 2

y.labels <- c( 1/8, 1/4, 1/2, 5, 10, 15 )

cur.signif.plot +
  geom_vline( xintercept = 1.5, linetype = 2 ) +
    scale_y_continuous( breaks = y.labels, labels = as.character( y.labels ) ) +
  xlab( "stratum" ) +
    theme( axis.text.x = element_text( angle = 0, size = 12 ),
            axis.text.y = element_text( size = 12 ),
            axis.line.y = element_line( color = "black" ),
            axis.title = element_text( size = 14 ),
            panel.background = element_rect( fill = "white", colour = "grey50" ),
            panel.grid.major.y = element_line( colour = "grey70", linetype = 2 ) )

ggsave( "PoOxM_CLP_mult_betas_promoter-NOG1-only-ch-17-52148184R.png",
        width = 15, height = 12, units = "cm" )