# setwd( "PLOTTING" )

library( ggplot2 )
library( SuppDists )
library( MASS )
library( Haplin )

source( "../common_variables.R" )
load( "../PoO_scan/GxM_PoOxM_new_betas_mult_top-SNPs-PoO-scan_CLP.RData" )

# promoter x rs766325
gene <- "rs766325"

cur.plot.obj <- haptable.poo.prom.res.all[[ gene ]]
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/64,10 ) )

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

y.labels <- c( 1/64, 1/32, 1/16, 1/8, 1/4, 1/2, 2.5, 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_topPOO-scan-CLP_mult_betas_promoter-rs766325.png", width = 15,
        height = 12, units = "cm" )