21 Supplementary Figure 16

21.1 Summary

This is the accessory documentation of Supplementary Figure 16.

The Figure can be recreated by running the R script S16.R:

cd $WORK/3_figures/F_scripts

Rscript --vanilla S16.R
rm Rplots.pdf

21.2 Details of S16.R

In S16.R script is the F3.R script run including additional data sets. Is an executable R script that depends on the tidyverse package for data managing and plotting.

library(tidyverse)

21.2.1 Setup

First, we define the directory storing the GxP results and create an inventory of data files to load. We also create labels for the individual data sets.

dat_dir <- '../../2_output/08_popGen/06_GxP/smoothed/50kb/'
files <- c("nig-uni-gemma.lm.50k.5k.smooth.gz", "nig-uni.lmm.50k.5k.smooth.gz", 
           "pue-nig-gemma.lm.50k.5k.smooth.gz", "pue-nig.lmm.50k.5k.smooth.gz", 
           "pue-uni-gemma.lm.50k.5k.smooth.gz", "pue-uni.lmm.50k.5k.smooth.gz")

runs <- files %>% 
  str_remove(.,'-gemma') %>% 
  str_remove(.,'.50k.5k.smooth.gz') %>% 
  str_replace(.,'.lm','_lm')

We load information about hamlet reference genome and create a import function to load the data.

karyo <- read_delim('../../0_data/0_resources/F2.karyo.txt', delim = '\t') %>%
  mutate(GSTART=lag(cumsum(END),n = 1,default = 0),
         GEND=GSTART+END,GROUP=rep(letters[1:2],12)) %>%
  select(CHROM,GSTART,GEND,GROUP)

import <- function(file,run){
  read_delim(file = gzfile(file), delim = "\t") %>% 
    dplyr::left_join(karyo, by = "CHROM") %>% 
    dplyr::mutate(POS = (BIN_START + BIN_END)/2, 
                  GPOS = GSTART + POS) %>% 
    mutate(RUN = run)
}

We use the map2() function from the purrr package to load the data sets. The we define some colors an the y-axis label.

data <- purrr::map2(.x = str_c(dat_dir,'/',files),runs,import) %>% 
  bind_rows() %>% separate(RUN,into = c('COMP','TYPE'), sep = '_')
clr <- c('#fb8620','#d93327','#1b519c')
yl <- expression(-log[10](italic(p)~value))

Finally we plot the data.

S16 <- ggplot(data,aes(x=GPOS,y=avgp_wald,col=COMP))+
  geom_rect(inherit.aes = F,data=karyo,aes(xmin=GSTART,xmax=GEND,
                                           ymin=-Inf,ymax=Inf,fill=GROUP))+
  geom_point(size=.01)+
  facet_grid(COMP+TYPE~.)+
  scale_x_continuous(name = "", expand = c(0, 0), breaks = (karyo$GSTART + karyo$GEND)/2, 
                     labels = 1:24, position = "top")+
  ylab(yl)+
  scale_fill_manual(values = c(NA,"#E6E6E6"),  guide = F)+
  scale_color_manual(name='comparison',values=clr[c(3,1,2)])+
  theme_bw(base_size = 10, base_family = "Helvetica") +
  theme(plot.background = element_blank(), 
        panel.background = element_blank(), 
        panel.grid = element_blank(), 
        panel.border = element_blank(),
        axis.title.x = element_blank(), 
        axis.line = element_line(), 
        legend.position = 'none',
        strip.background = element_blank())

The Figure is then exported using ggsave():

#ggsave(plot = S16, filename = '../output/S16.pdf',width = 183,height = 60,units = 'mm',device = cairo_pdf)
ggsave(plot = S16, filename = '../output/S16.png',width = 183,height = 90,units = 'mm',dpi = 300)