背景
用R代码画出文章PMID:25552301里的染色体分布图

使用场景
差异表达基因(RNA-seq)、开放染色质(DNase/ATAC-seq)、CTCF结合位点(ChIP-seq)、突变位点(WGS)或DNA甲基化(WGBS)在染色体上的分布,或者只是画Ideogram
输入数据
karyotype.txt,包含染色体名称、起始和终止点、着丝粒起始和终止点的文件,用于画染色体轮廓
分五列,0-based基因组坐标(以0-based开始、1-based结束),第一列染色体名,第二、三列染色体起始及终止点,第四、五列为着丝粒起始及终止点
# 染色体长度、中心粒位置
karyotype <- read.table("karyotype.txt", sep = "\t", header = T, stringsAsFactors = F, colClasses = c("character", "integer", "integer", "integer", "integer"))
head(karyotype)
karyotype前几行如下:

data_1.txt,感兴趣的区域的值,例如差异基因的log2foldchange、甲基化水平等,用来绘制染色体heatmap files
分四列,第一列染色体,第二、三列染色体上的位置,第四列对应的数值
mydata <- read.table("data_1.txt", sep = "\t", header = T, stringsAsFactors = F, colClasses = c("character", "integer", "integer", "integer"))
head(mydata)
mydata前几行如下:

data_2.txt,如果想画染色体旁边的形状标记,就要提供这个文件,例如关键基因或区域的位置标注。
分六列,第一列名称,第二列形状(只支持box正方形、triangle三角形和circle圆),第四列染色体,第五、六列染色体上的位置,第七类颜色,注意同一类的type对应的颜色一致)
mydata_interval <- read.table("data_2.txt", sep = "\t", header = T, stringsAsFactors = F, colClasses = c("character", "character", "character", "integer", "integer", "character"))
head(mydata_interval)
mydata_interval前几行如下:

写画图语句
画布大小将设置为A4纸,宽高为210mm * 297mm
页边距设置:左、右、顶、底为20mm, 20mm, 25mm, 25mm,因此最终的画图区域宽高为170mm * 247mm
1.先写染色体轮廓
图形将由n个染色体+n个注释用空隙组成
图形宽度设置成170mm, 染色体与空隙等宽,则每个染色体或空隙宽度应设置为(170/2n)mm
长度像素换算公式:1mm = 3.543307px
计算各染色体轮廓各节点坐标
mpx<-3.543307 #换算比
chr_width <- 170 / (2*nrow(karyotype)) * mpx #170mm可以根据染色体条数适当调整
karyotype$x9 <- karyotype$x1 <- karyotype$x8 <- karyotype$x4 <- karyotype$x5 <- karyotype$x12 <- apply(data.frame(1:nrow(karyotype)),1,function(x)(20*mpx+(x[1]-1)*2*chr_width))
maxchrlen<-150 #最长染色体长度设置为150mm
karyotype$y1 <- karyotype$y2 <- apply(data.frame(karyotype$End),1,function(x)((25+maxchrlen*(1-x[1]/max(karyotype$End))) * mpx + chr_width/2)) #染色体顶部圆弧高度为chr_width/2
karyotype$x10 <- karyotype$x2 <- karyotype$x3 <- karyotype$x7 <- karyotype$x6 <- karyotype$x11 <- karyotype$x1+chr_width
karyotype$y3 <- karyotype$y8 <- apply(data.frame(karyotype$End,karyotype$CE_start),1,function(x)((25+maxchrlen*(1-(x[1]-x[2])/max(karyotype$End))) * mpx))
karyotype$y4 <- karyotype$y7 <- apply(data.frame(karyotype$End,karyotype$CE_end),1,function(x)((25+maxchrlen*(1-(x[1]-x[2])/max(karyotype$End))) * mpx))
karyotype$y5 <- karyotype$y6 <- (25+maxchrlen)*mpx-chr_width/2
karyotype$y9 <- karyotype$y10 <- apply(data.frame(karyotype$End),1,function(x)((25+maxchrlen*(1-x[1]/max(karyotype$End))) * mpx))
karyotype$y11 <- karyotype$y12 <- (25+maxchrlen)*mpx
画染色体轮廓
karyotype$path = paste("<path d=\"M", karyotype$x1, ",", karyotype$y1,
" A", chr_width/2, ",", chr_width/2, " 0 1,1 ", karyotype$x2, ",", karyotype$y2, #圆弧
" L", karyotype$x3, ",", karyotype$y3,
" L", karyotype$x4, ",", karyotype$y4,
" L", karyotype$x5, ",", karyotype$y5,
" A", chr_width/2, ",", chr_width/2, " 0 0,0 ", karyotype$x6, ",", karyotype$y6,
" L", karyotype$x7, ",", karyotype$y7,
" L", karyotype$x8, ",", karyotype$y8,
" Z" ,"\" style=\"fill:none; stroke:grey; stroke-width:1\"/>", sep = "")
karyotype$hat = paste("<path d=\"M", karyotype$x1, ",", karyotype$y1,
" A", chr_width/2, ",", chr_width/2, " 0 1,1 ", karyotype$x2, ",", karyotype$y2, #圆弧
" L", karyotype$x10, ",", karyotype$y10,
" L", karyotype$x9, ",", karyotype$y9,
" Z" ,"\" style=\"fill:white; stroke:white; stroke-width:0.75\"/>", sep = "")
karyotype$shoe = paste("<path d=\"M", karyotype$x5, ",", karyotype$y5,
" A", chr_width/2, ",", chr_width/2, " 0 0,0 ", karyotype$x6, ",", karyotype$y6,
" L", karyotype$x11, ",", karyotype$y11,
" L", karyotype$x12, ",", karyotype$y12,
" Z" ,"\" style=\"fill:white; stroke:white; stroke-width:0.75\"/>", sep = "")
karyotype$bow = paste("<path d=\"M", karyotype$x8, ",", karyotype$y8,
" L", karyotype$x7, ",", karyotype$y7,
" L", karyotype$x3, ",", karyotype$y3,
" L", karyotype$x4, ",", karyotype$y4,
" Z" ,"\" style=\"fill:white; stroke:white; stroke-width:0.75\"/>", sep = "")
染色体底部加染色体名
karyotype$text = paste("<text x=\"", (karyotype$x1 + karyotype$x2)/2 - nchar(karyotype$Chr) * 2.2, "\" y=\"", (150 + 25) * mpx + 15, "\" font-size=\"9\" fill=\"black\" >", karyotype$Chr, "</text>", sep = "")