- 处理数据
samtools faidx genome.fasta #建索引
awk '$3=="dispersed_repeat" {print $1"\t"$4-1"\t"$5}' female_repeat.gff3 > TE.bed#TE.gff 转 BED,将注释文件中含有dispersed_repeat的行提取出来
bedtools makewindows -g genome.fasta.fai -w 100000 > windows.bed # 生成窗口(100kb,可改 50000 50kb)
bedtools coverage -a windows.bed -b TE.bed > TE_coverage.bed #统计密度
awk '{print $1"\t"$2"\t"$7}' TE_coverage.bed > TE_density.txt
#TE_density.txt 三列:chr, start, density 备注:这一步当中包含有为挂载到染色体上的部分,画图前需要去除,如果没有去除就会出现以下报错:`geom_line()`: Each group consists of only one observation.i Do you need to adjust the group aesthetic?
grep "^Chr" TE_density.txt > TE_density_chr.txt #只保留染色体的行2. 画图
library(circlize)
# 读取数据
dat <- read.table("TE_density.txt", sep = "\t", header = FALSE)
# 打开 PDF
pdf("TE_circos_clean.pdf", width = 9, height = 9)
circos.clear()
circos.par(
start.degree = 90,
gap.degree = 2,
points.overflow.warning = FALSE
)
# 初始化染色体
circos.initialize(
factors = dat$V1,
xlim = cbind(0, tapply(dat$V2, dat$V1, max))
)
# 1. 染色体框(浅灰底色)
circos.track(
ylim = c(0, 1),
track.height = 0.08,
bg.col = "#f2f2f2",
bg.border = "#666666",
panel.fun = function(x, y) {
chr <- get.cell.meta.data("sector.index")
x_mid <- get.cell.meta.data("xcenter")
# 标注染色体名字
circos.text(
x_mid, 0.5, chr,
facing = "bending", nice.facing = TRUE,
cex = 0.9, col = "black", font = 2
)
}
)
# 2. TE 密度曲线(红色)
circos.track(
ylim = c(0, 1),
track.height = 0.4,
panel.fun = function(x, y) {
chr <- get.cell.meta.data("sector.index")
sub <- dat[dat$V1 == chr, ]
# 密度折线
circos.lines(sub$V2, sub$V3, col = "#e63946", lwd = 1.5)
# 中间参考线
circos.lines(c(0, max(sub$V2)), c(0.5, 0.5), col = "gray", lty = 3, lwd = 0.8)
}
)
dev.off()
circos.clear()