[d06c2b]: / b_DownstreamAnalysisScript / bulkATACana_1_QC.R

Download this file

111 lines (85 with data), 3.0 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
# MESSAGE -----------------------------------------------------------------
#
# author: Yulin Lyu
# email: lvyulin@pku.edu.cn
#
# require: R whatever
#
# ---
# * 1. Load packages ------------------------------------------------------
setwd("exampleData/ATAC")
# grammar
library(tidyverse)
library(magrittr)
library(glue)
library(data.table)
# analysis
library(ggplot2)
library(ggsci)
library(scales)
library(patchwork)
# * 2. TSS enrichment -----------------------------------------------------
dir.create("graphics")
usedSample <- c("F-H1", "P-H1", "XF-H1")
TSSdata <- fread("qc/TSS_value.txt", skip = 3) %>% as.matrix()
TSSdata[is.nan(TSSdata)] <- 0
TSSmean <- apply(TSSdata, 2, mean)
TSSsam <- split(TSSmean, rep(usedSample, each = 400))
enrichScore <- map_dbl(TSSsam, ~ {sum(.x[191:210]) / sum(.x[c(1:10, 391:400)])})
saveRDS(enrichScore, "enrichScore.rds")
plotData <- data.table(
pos = rep(1:400, 3),
val = TSSmean,
sample = rep(usedSample, each = 400)
)
usedLabel <- str_c(usedSample, ": ", round(enrichScore, 2))
usedColor <- ArchR::ArchRPalettes$stallion[seq_along(usedSample)]
names(usedColor) <- usedSample
ggplot(plotData, aes(x = pos, y = val)) +
geom_line(aes(color = sample)) +
scale_color_manual(values = usedColor, labels = usedLabel) +
scale_x_continuous(
breaks = c(0, 200, 400),
labels = c("-2k", "TSS", "+2k")) +
scale_y_continuous(expand = c(0, 0)) +
labs(x = "", y = "Mean signal") +
theme(
aspect.ratio = 0.9,
panel.background = element_blank(),
panel.grid = element_blank(),
axis.line = element_line(),
legend.background = element_blank(),
legend.key = element_blank(),
legend.title = element_blank(),
legend.position = c(0, 1),
legend.justification = c("left", "top")
)
ggsave("graphics/TSSenrich.png", width = 4, height = 4)
# * 3. Fragment length ----------------------------------------------------
fragFile <- list.files("qc", "-[123].txt", full.names = T)
fragSample <- str_replace_all(fragFile, ".*/|.txt", "")
fragList <- map(fragFile, ~ fread(.x, skip = 10)) %>% set_names(fragSample)
fragData <- fragList %>% imap(~ {.x[, sample := .y]}) %>% reduce(rbind)
fragData[, type := str_remove(sample, "-.$")][]
colnames(fragData)[1:2] <- c("pos", "count")
plotData <- map(usedSample, ~ {fragData[type == .x]})
usedColor <- ArchR::ArchRPalettes$stallion %>% unname()
plotList <- map(plotData, ~ {
ggplot(.x, aes(x = pos, y = count)) +
geom_line(aes(color = sample)) +
scale_color_manual(values = usedColor) +
labs(x = "", y = "") +
theme(
aspect.ratio = 1,
panel.background = element_blank(),
panel.grid = element_blank(),
axis.line = element_line(),
legend.background = element_blank(),
legend.key = element_blank(),
legend.title = element_blank(),
legend.position = c(1, 1),
legend.justification = c("right", "top")
)
})
reduce(plotList, `+`) + plot_layout(ncol = 1)
ggsave("graphics/fragLength.png", width = 4, height = 3 * length(usedSample))