Chapter 19 Plot APA Heatmaps
19.1 Description
Plot heatmaps for loops APA
19.2 Load data
<- list.files('data/HiC/Pup-npfiles/', full.names = T)
file.ls <- file.ls[c(8,7,5,4,3,1)]
file.ls file.ls
## [1] "data/HiC/Pup-npfiles//WT_DM.allValidPairs.res5kb-5.0K_over_WT_DM_3k5k10kb_merged_loops_StSt_CBS_10-shifts_dist_0-inf.np.txt"
## [2] "data/HiC/Pup-npfiles//WT_DM.allValidPairs.res5kb-5.0K_over_WT_DM_3k5k10kb_merged_loops_SpeSpeANDSpeNON_CBS_10-shifts_dist_0-inf.np.txt"
## [3] "data/HiC/Pup-npfiles//WT_DM.allValidPairs.res5kb-5.0K_over_GSE98119_Vian-2018-activated_B_cells_24_hours_WT.hic_5k10kloops_onlyGSM3027985diffBDFDR01_SpeSpeANDSpeNON_CBS_10-shifts_dist_0-inf.np.txt"
## [4] "data/HiC/Pup-npfiles//GSE98119_Vian-2018-activated_B_cells_24_hours_WT.hic.5kb-5.0K_over_WT_DM_3k5k10kb_merged_loops_StSt_CBS_10-shifts_dist_0-inf.np.txt"
## [5] "data/HiC/Pup-npfiles//GSE98119_Vian-2018-activated_B_cells_24_hours_WT.hic.5kb-5.0K_over_WT_DM_3k5k10kb_merged_loops_SpeSpeANDSpeNON_CBS_10-shifts_dist_0-inf.np.txt"
## [6] "data/HiC/Pup-npfiles//GSE98119_Vian-2018-activated_B_cells_24_hours_WT.hic.5kb-5.0K_over_GSE98119_Vian-2018-activated_B_cells_24_hours_WT.hic_5k10kloops_onlyGSM3027985diffBDFDR01_SpeSpeANDSpeNON_CBS_10-shifts_dist_0-inf.np.txt"
<- lapply(file.ls, function(f){
mat.ls <- fread(f, skip = 35)
mat <- as.matrix(mat)
mat is.na(mat)] <- 0
mat[return(mat)
})
19.3 Plot Function
<- function(xdata.ls, id.ls, quant, colind){
plotSqure
## Section: make diag as na and trim max value
##################################################
<- map2(xdata.ls, quant, ~ {
xdata.ls <- .x
xdata <- .y
quant <- quantile(xdata, quant, na.rm = T)
qmax >qmax] <- qmax
xdata[xdata<- t(xdata)
xdata <- as.matrix(xdata[,ncol(xdata):1])
xdata return(xdata)
})
## Section: colour choice
##################################################
<- 1 # dot size
csize <- 64
k <- colorRampPalette(c('blue','white','red'))(k)
col.ls1 <- coolwarm(k)
col.ls2 <- tim.colors(k)
col.ls3
if(colind == 1){
= col.ls1
mycol
}
if(colind == 2){
= col.ls2
mycol
}
if(colind == 3){
= col.ls3
mycol
}
## Section: breaks
##################################################
<- min(unlist(lapply(xdata.ls, function(f){
minv quantile(unlist(f))
})))<- max(unlist(lapply(xdata.ls, function(f){
maxv quantile(unlist(f))
})))<- c(seq(minv, 1, length.out=ceiling(k/2) + 1),
myBreaks seq(maxv/k+1, maxv, length.out=floor(k/2)))
## Section: plot
##################################################
par(mfrow = c(2,3))
seq_along(xdata.ls) %>% map(~ {
<- xdata.ls[[.x]]
xdata <- id.ls[[.x]]
id
par(mar = c(1,1,1,1))
image.plot(x = 1:nrow(xdata), y = 1:nrow(xdata), z = xdata[nrow(xdata):1, nrow(xdata):1],
breaks = myBreaks, axis = F, axes = F, legend.cex = .2, main = id, col = mycol)
box()
})
}
19.4 Plot
<- c("Myocyte-Conserved", "Myocyte-MS", "Myocyte-BCellS",
sample "BCell-Conserved", "BCell-MS", "BCell-BCellS")
seq(1,3) %>% map(~ {
plotSqure(mat.ls, id.ls = sample, quant = 0.99, colind = .x)
})
## [[1]]
## [[1]][[1]]
## NULL
##
## [[1]][[2]]
## NULL
##
## [[1]][[3]]
## NULL
##
## [[1]][[4]]
## NULL
##
## [[1]][[5]]
## NULL
##
## [[1]][[6]]
## NULL
##
##
## [[2]]
## [[2]][[1]]
## NULL
##
## [[2]][[2]]
## NULL
##
## [[2]][[3]]
## NULL
##
## [[2]][[4]]
## NULL
##
## [[2]][[5]]
## NULL
##
## [[2]][[6]]
## NULL
##
##
## [[3]]
## [[3]][[1]]
## NULL
##
## [[3]][[2]]
## NULL
##
## [[3]][[3]]
## NULL
##
## [[3]][[4]]
## NULL
##
## [[3]][[5]]
## NULL
##
## [[3]][[6]]
## NULL