Chapter 4 diffBD enhancer containing ratio piechart
4.1 Description
- Calculate the TE/SE-containing percentage for lineage-stable/specific CBS
- SEs are called by
rose
using H3K27ac and TF ChIP-seq profiles
4.2 Loda data
<- list.files('data/DiffBD/', full.names = T)
cbs.ls <- list.files("data/peakfiles/Enhancer-groupby-CBS/AllEnh-table/", full.names = T)
enh.ls cbs.ls
## [1] "data/DiffBD//human-BcellVSAllotherWithoutNeutrophilANDmonocyteE-CTCF.diffBD.minOverlap1.log2FC1FDR005.upinBcell.D210112-Alltissues.bed"
## [2] "data/DiffBD//human-LiverVSAllother-CTCF.diffBD.minOverlap1.log2FC1FDR0001.upinLiver.D210112-Alltissues.bed"
## [3] "data/DiffBD//human-MTVSAllotherWithouMB-CTCF.diffBD.minOverlap1.log2FC1FDR001.upinMT.D210112-Alltissues.bed"
## [4] "data/DiffBD//liver.npc.mt.macrophage.mb.lungfibroblast.spleen.netrophil"
## [5] "data/DiffBD//liver.npc.mt.macrophage.mb.lungfibroblast.spleen.netrophil.center200bp.bed"
## [6] "data/DiffBD//liver.npc.mt.macrophage.mb.lungfibroblast.spleen.netrophil.center400bp.bed"
enh.ls
## [1] "data/peakfiles/Enhancer-groupby-CBS/AllEnh-table//ENCSR000AUP-human-Bcell-H3K27ac_AllEnhancers.table.txt"
## [2] "data/peakfiles/Enhancer-groupby-CBS/AllEnh-table//ENCSR601OGE-human-liver-HNF4A-treat_AllEnhancers.table.txt"
## [3] "data/peakfiles/Enhancer-groupby-CBS/AllEnh-table//ENCSR981UJA-human-rightlobeLiver-tissue-H3K27ac_AllEnhancers.table.txt"
## [4] "data/peakfiles/Enhancer-groupby-CBS/AllEnh-table//GSE50413-MYOD-human-MT-treat-Rep2_1_AllEnhancers.table.txt"
## [5] "data/peakfiles/Enhancer-groupby-CBS/AllEnh-table//GSM3686918_PU1_human_primaryBcell-treat_AllEnhancers.table.txt"
## [6] "data/peakfiles/Enhancer-groupby-CBS/AllEnh-table//GSM733666-H3K27ac-human-MB-treat_AllEnhancers.table.txt"
## [7] "data/peakfiles/Enhancer-groupby-CBS/AllEnh-table//GSM733666-H3K27ac-human-MT-treat_AllEnhancers.table.txt"
4.3 Define function: calculate overlap
<- function(stable.f, specific.f, enh.f, cell){
getVP
<- fread(enh.f, header = T)
enh
## Section: get the CTCF and SE regions in GR format
##################################################
<- function(f){
getGR <- fread(f, header = F)
mat <- mat[,1:3]
mat colnames(mat) <- c('chr', 'start', 'end')
<- makeGRangesFromDataFrame(mat)
bed return(bed)
}
<- getGR(stable.f)
stable.gr <- getGR(specific.f)
specific.gr <- enh[which(enh$isSuper == 1), c(2:4,1)]
se.gr <- makeGRangesFromDataFrame(se.gr, keep.extra.columns = T)
se.gr <- enh[which(enh$isSuper == 0), c(2:4,1)]
te.gr <- makeGRangesFromDataFrame(te.gr, keep.extra.columns = T)
te.gr
## Section: group the CBS based on enhancer type
##################################################
<- function(gr){
getEnh <- findOverlaps(gr, se.gr)
comm1 <- findOverlaps(gr, te.gr)
comm2 <- length(unique(queryHits(comm1)))
n1 <- length(unique(queryHits(comm2)))
n2 <- length(gr) - n1 -n2
n return(c(n,n2,n1))
}
<- getEnh(stable.gr)
stable.freq <- getEnh(specific.gr)
specific.freq
<- data.frame(cbind(region = rep(c('stable', 'specific'), each = 3),
df type = rep(c('no','TE','SE'),2),
value = c(stable.freq, specific.freq)))
$region <- factor(df$region, levels = c('stable', 'specific'))
df$type <- factor(df$type, levels = c('no','TE', 'SE'))
df$value <- as.numeric(as.character(df$value))
df
## Section: pie chart plots
##################################################
<- list()
gp.ls for (i in 1:2) {
<- df[which(df$region == unique(df$region)[i]),]
df1 # Compute the position of labels
<- df1 %>%
data arrange(desc(type)) %>%
mutate(prop = round(value / sum(df1$value) ,2)) %>%
mutate(ypos = cumsum(prop)- 0.5*prop )
<- ggplot(data, aes(x = "", y = prop, fill = type)) +
g geom_bar(stat="identity", width=1)+
coord_polar("y", start=0) +
theme_void()+
geom_text(aes(y = ypos, label = prop), size=6) +
scale_fill_brewer(palette = "Dark2")+
# scale_fill_manual(values = c('with' = 'darkgoldenrod2', 'without' = 'azure3')) +
ggtitle(str_c(unique(df$region)[i], " ",cell))
<- g
gp.ls[[i]]
}
return(gp.ls)
}
4.4 Plot
<- list(stable = rep(cbs.ls[6], 6),
para.ls specific = rep(c(cbs.ls[2], cbs.ls[3], cbs.ls[1]), 2),
enh = c(enh.ls[3], enh.ls[7], enh.ls[1], enh.ls[2], enh.ls[4], enh.ls[5]),
cell = c("hep-k27ac", "myo-k27ac", "bcell-k27ac", "hep-hnf4a", "myo-myod", "bcell-pu1" ))
<- pmap(para.ls, getVP)
gp.ls
%>% map(~ {
gp.ls grid.arrange(.x[[1]], .x[[2]], ncol = 2)
})
## [[1]]
## TableGrob (1 x 2) "arrange": 2 grobs
## z cells name grob
## 1 1 (1-1,1-1) arrange gtable[layout]
## 2 2 (1-1,2-2) arrange gtable[layout]
##
## [[2]]
## TableGrob (1 x 2) "arrange": 2 grobs
## z cells name grob
## 1 1 (1-1,1-1) arrange gtable[layout]
## 2 2 (1-1,2-2) arrange gtable[layout]
##
## [[3]]
## TableGrob (1 x 2) "arrange": 2 grobs
## z cells name grob
## 1 1 (1-1,1-1) arrange gtable[layout]
## 2 2 (1-1,2-2) arrange gtable[layout]
##
## [[4]]
## TableGrob (1 x 2) "arrange": 2 grobs
## z cells name grob
## 1 1 (1-1,1-1) arrange gtable[layout]
## 2 2 (1-1,2-2) arrange gtable[layout]
##
## [[5]]
## TableGrob (1 x 2) "arrange": 2 grobs
## z cells name grob
## 1 1 (1-1,1-1) arrange gtable[layout]
## 2 2 (1-1,2-2) arrange gtable[layout]
##
## [[6]]
## TableGrob (1 x 2) "arrange": 2 grobs
## z cells name grob
## 1 1 (1-1,1-1) arrange gtable[layout]
## 2 2 (1-1,2-2) arrange gtable[layout]
pdf('results/Features/N4-Hep.Myo.Bcell-specificANDstable-CTCF_EnhancerContainingRatio_pichartplot.pdf', width = 6, height = 3)
%>% map(~ {
gp.ls grid.arrange(.x[[1]], .x[[2]], ncol = 2)
})dev.off()