首先最重要的參考鏈接:
- [karyoploteR]
- https://bernatgel.github.io/karyoploter_tutorial/Examples/EncodeEpigenetics/EncodeEpigenetics.html
其次我就是一個(gè)搬運(yùn)工,希望給有需要的小伙伴政基,如有老哥看到侵權(quán)了拌禾,麻煩請(qǐng)私信我刪除,謝謝闽晦!
番外在和小伙伴分享的時(shí)候,小伙伴也發(fā)了一個(gè)可以完成此功能的鏈接 trackViewer Vignette
- 由于我的傻吊服務(wù)器裝不上包提岔,后面需要linux的基本就是復(fù)制粘貼看了一遍過來的仙蛉。。碱蒙。 話說服務(wù)器裝R包我是真的很無語
-
那么重要的是通過此文我們可以學(xué)會(huì)繪制出什么樣的圖呢荠瘪?見下:
if (!requireNamespace("BiocManager", quietly = TRUE))
install.packages("BiocManager")
BiocManager::install("karyoploteR", version = "3.8")
## 哇夯巷,按照上面安裝得到的是1.8.8版本的,然后會(huì)發(fā)現(xiàn)后面很多命令都沒有哀墓。趁餐。
# 從新安裝
devtools::install_github("bernatgel/karyoploteR") # karyoploteR_1.9.21版本
library(karyoploteR)
TP53.region <- toGRanges("chr17:7,564,422-7,602,719")
> TP53.region
GRanges object with 1 range and 0 metadata columns:
seqnames ranges strand
<Rle> <IRanges> <Rle>
[1] chr17 7564422-7602719 *
-------
seqinfo: 1 sequence from an unspecified genome; no seqlengths
kp <- plotKaryotype(zoom = TP53.region)
- 使用
kpPlotGenes
函數(shù)繪制上面展示區(qū)域內(nèi)的基因。
BiocManager::install("TxDb.Hsapiens.UCSC.hg19.knownGene", version = "3.8")
library(TxDb.Hsapiens.UCSC.hg19.knownGene)
> TxDb.Hsapiens.UCSC.hg19.knownGene
TxDb object:
# Db type: TxDb
# Supporting package: GenomicFeatures
# Data source: UCSC
# Genome: hg19
# Organism: Homo sapiens
# Taxonomy ID: 9606
# UCSC Table: knownGene
# Resource URL: http://genome.ucsc.edu/
# Type of Gene ID: Entrez Gene ID
# Full dataset: yes
# miRBase build ID: GRCh37
# transcript_nrow: 82960
# exon_nrow: 289969
# cds_nrow: 237533
# Db created by: GenomicFeatures package from Bioconductor
# Creation time: 2015-10-07 18:11:28 +0000 (Wed, 07 Oct 2015)
# GenomicFeatures version at creation time: 1.21.30
# RSQLite version at creation time: 1.0.0
# DBSCHEMAVERSION: 1.1
genes.data <- makeGenesDataFromTxDb(TxDb.Hsapiens.UCSC.hg19.knownGene,
karyoplot=kp,
plot.transcripts = TRUE,
plot.transcripts.structure = TRUE)
kp <- plotKaryotype(zoom = TP53.region) # 第一個(gè)圖層 染色體繪制的區(qū)間
kpPlotGenes(kp, data=genes.data) # 第二個(gè)圖層 區(qū)間內(nèi)各個(gè)基因的結(jié)構(gòu)
- 從上圖可以看到在這個(gè)區(qū)域內(nèi)的不同轉(zhuǎn)錄本的結(jié)構(gòu)圖篮绰,而不是基因的結(jié)構(gòu)圖后雷,接下來將使用
mergeTranscripts
函數(shù)將每個(gè)基因?qū)?yīng)的所有轉(zhuǎn)錄本合并成一個(gè),并且使用addGeneNames
加上基因名吠各。使用cex
函數(shù)增加染色體的名字大小臀突。
genes.data <- addGeneNames(genes.data)
genes.data <- mergeTranscripts(genes.data)
> genes.data
$`genes`
GRanges object with 2 ranges and 2 metadata columns:
seqnames ranges strand | gene_id name
<Rle> <IRanges> <Rle> | <character> <character>
55135 chr17 7589389-7606820 + | 55135 WRAP53
7157 chr17 7565097-7590868 - | 7157 TP53
-------
seqinfo: 93 sequences (1 circular) from hg19 genome
$transcripts
$transcripts$`55135`
GRanges object with 1 range and 1 metadata column:
seqnames ranges strand | tx_id
<Rle> <IRanges> <Rle> | <character>
[1] chr17 7589389-7606820 + | 55135.merged
-------
seqinfo: 93 sequences (1 circular) from hg19 genome
kp <- plotKaryotype(zoom = TP53.region, cex=2)
kpPlotGenes(kp, data=genes.data)
- 這才是對(duì)于我們展示基因結(jié)構(gòu)的比較好的方式啊。
- 接下來將使用
r0
和r1
將基因結(jié)構(gòu)圖放置在最下面贾漏,為上面其他數(shù)據(jù)元素留出空間候学。
kp <- plotKaryotype(zoom = TP53.region, cex=2)
kpPlotGenes(kp, data=genes.data, r0=0, r1=0.15, gene.name.cex = 2)
- 下一步將將基因狀態(tài)HMM結(jié)果導(dǎo)入進(jìn)來,首先使用BiocFileCache 函數(shù)下載下來纵散。然后再使用
regioneR
包的函數(shù)toGranges
導(dǎo)入R梳码。
BiocManager::install("BiocFileCache", version = "3.8")
library(BiocFileCache)
bfc <- BiocFileCache(ask=FALSE)
> bfc
class: BiocFileCache
bfccache: C:\Users\ql\AppData\Local\BiocFileCache\BiocFileCache\Cache
bfccount: 0
For more information see: bfcinfo() or bfcquery()
K562.hmm.file <- bfcrpath(bfc, "http://hgdownload.soe.ucsc.edu/goldenPath/hg19/encodeDCC/wgEncodeBroadHmm/wgEncodeBroadHmmK562HMM.bed.gz")
K562.hmm <- toGRanges(K562.hmm.file)
K562.hmm
> K562.hmm
GRanges object with 622257 ranges and 4 metadata columns:
seqnames ranges strand | name score itemRgb thick
<Rle> <IRanges> <Rle> | <character> <numeric> <character> <IRanges>
[1] chr1 10001-10600 * | 15_Repetitive/CNV 0 #F5F5F5 10001-10600
[2] chr1 10601-10937 * | 13_Heterochrom/lo 0 #F5F5F5 10601-10937
[3] chr1 10938-11937 * | 8_Insulator 0 #0ABEFE 10938-11937
[4] chr1 11938-12337 * | 5_Strong_Enhancer 0 #FACA00 11938-12337
[5] chr1 12338-13137 * | 7_Weak_Enhancer 0 #FFFC04 12338-13137
... ... ... ... . ... ... ... ...
[622253] chrX 155256807-155257806 * | 11_Weak_Txn 0 #99FF66 155256807-155257806
[622254] chrX 155257807-155259206 * | 8_Insulator 0 #0ABEFE 155257807-155259206
[622255] chrX 155259207-155259406 * | 6_Weak_Enhancer 0 #FFFC04 155259207-155259406
[622256] chrX 155259407-155259606 * | 7_Weak_Enhancer 0 #FFFC04 155259407-155259606
[622257] chrX 155259607-155260406 * | 15_Repetitive/CNV 0 #F5F5F5 155259607-155260406
-------
seqinfo: 23 sequences from an unspecified genome; no seqlengths
- 可以從上面看到在
itemRgb
列有對(duì)應(yīng)的顏色信息,當(dāng)我們使用kpPlotRegions
函數(shù)繪圖時(shí)候就可以使用這里的顏色來代表區(qū)域的顏色伍掀。
kp <- plotKaryotype(zoom = TP53.region, cex=2)
kpPlotGenes(kp, data=genes.data, r0=0, r1=0.15, gene.name.cex = 2)
kpPlotRegions(kp, K562.hmm, col=K562.hmm$itemRgb, r0=0.4, r1=0.5)
- 使用
kpAddLabels
添加HMM注釋信息边翁。
kp <- plotKaryotype(zoom = TP53.region, cex=2)
kpPlotGenes(kp, data=genes.data, r0=0, r1=0.15, gene.name.cex = 2)
kpPlotRegions(kp, K562.hmm, col=K562.hmm$itemRgb, r0=0.4, r1=0.5)
kpAddLabels(kp, labels = "Chromatin\nState (HMM)", r0=0.4, r1=0.5, cex = 1)
- 接下來我們可以添加一些表觀數(shù)據(jù)了。使用
kpPlotBigwig
函數(shù)繪制包含BigWig文件的
圖片硕盹。此函數(shù)調(diào)用的是rtracklayer’s BigWigFile函數(shù)來導(dǎo)入BigWig
文件符匾。
注意!
由于rtracklayer bigwig
管理的限制瘩例,kpPlotBigWig
在Windows
上不起作用啊胶。它僅適用于Linux
和Mac計(jì)算機(jī) - 首先我們將可視化H3K4me3信息。繪制在
0.
kp <- plotKaryotype(zoom = TP53.region, cex=2)
kpPlotGenes(kp, data=genes.data, r0=0, r1=0.15, gene.name.cex = 2)
kpPlotRegions(kp, K562.hmm, col=K562.hmm$itemRgb, r0=0.4, r1=0.5)
kpAddLabels(kp, labels = "Chromatin\nState (HMM)", r0=0.4, r1=0.5, cex = 1)
bigwig.file <- "http://hgdownload.soe.ucsc.edu/goldenPath/hg19/encodeDCC/wgEncodeBroadHistone/wgEncodeBroadHistoneK562H3k4me3StdSig.bigWig"
kpPlotBigWig(kp, data=bigwig.file, r0=0.55, r1=1)
- 可以看到上面bw文件展示出來的信息峰值太低了垛贤,因?yàn)槲覀冞x取的是默認(rèn)的
ymax
, 所以會(huì)將y
軸的最大值默認(rèn)為全局的最大值焰坪。我們可以通過ymax = "visible.region"
來設(shè)置。
kp <- plotKaryotype(zoom = TP53.region, cex=2)
kpPlotGenes(kp, data=genes.data, r0=0, r1=0.15, gene.name.cex = 2)
kpPlotRegions(kp, K562.hmm, col=K562.hmm$itemRgb, r0=0.4, r1=0.5)
kpAddLabels(kp, labels = "Chromatin\nState (HMM)", r0=0.4, r1=0.5, cex = 1)
bigwig.file <- "http://hgdownload.soe.ucsc.edu/goldenPath/hg19/encodeDCC/wgEncodeBroadHistone/wgEncodeBroadHistoneK562H3k4me3StdSig.bigWig"
kpPlotBigWig(kp, data=bigwig.file, ymax="visible.region", r0=0.55, r1=1)
- 接下來我們加入
H3K36me3
的信息
kp <- plotKaryotype(zoom = TP53.region, cex=2)
kpPlotGenes(kp, data=genes.data, r0=0, r1=0.15, gene.name.cex = 2)
kpPlotRegions(kp, K562.hmm, col=K562.hmm$itemRgb, r0=0.4, r1=0.5)
kpAddLabels(kp, labels = "Chromatin\nState (HMM)", r0=0.4, r1=0.5, cex = 1)
H3K4me3.bw <- "http://hgdownload.soe.ucsc.edu/goldenPath/hg19/encodeDCC/wgEncodeBroadHistone/wgEncodeBroadHistoneK562H3k4me3StdSig.bigWig"
kpPlotBigWig(kp, data = H3K4me3.bw, ymax="visible.region", r0=0.55, r1=1)
H3K36me3.bw <- "http://hgdownload.soe.ucsc.edu/goldenPath/hg19/encodeDCC/wgEncodeBroadHistone/wgEncodeBroadHistoneK562H3k36me3StdSig.bigWig"
kpPlotBigWig(kp, data=H3K36me3.bw, ymax="visible.region", r0 = 1, r1 = 1.3)
- 我們可以看到不同的peak profiler聘惦。但是我們還是缺少一些注釋信息某饰,比如每個(gè)bw文件對(duì)應(yīng)的修飾信息、峰的高度信息善绎。
kp <- plotKaryotype(zoom = TP53.region, cex=2)
kpPlotGenes(kp, data=genes.data, r0=0, r1=0.15, gene.name.cex = 2)
kpPlotRegions(kp, K562.hmm, col=K562.hmm$itemRgb, r0=0.4, r1=0.5)
kpAddLabels(kp, labels = "Chromatin\nState (HMM)", r0=0.4, r1=0.5, cex = 1)
H3K4me3.bw <- "http://hgdownload.soe.ucsc.edu/goldenPath/hg19/encodeDCC/wgEncodeBroadHistone/wgEncodeBroadHistoneK562H3k4me3StdSig.bigWig"
kpPlotBigWig(kp, data = H3K4me3.bw, ymax="visible.region", r0=0.55, r1=1)
computed.ymax <- kp$latest.plot$computed.values$ymax
kpAxis(kp, ymin=0, ymax=computed.ymax, r0=0.55, r1=1)
kpAddLabels(kp, labels = "H3K4me3", r0=0.55, r1=1, cex=1.6, label.margin = 0.035)
H3K36me3.bw <- "http://hgdownload.soe.ucsc.edu/goldenPath/hg19/encodeDCC/wgEncodeBroadHistone/wgEncodeBroadHistoneK562H3k36me3StdSig.bigWig"
kpPlotBigWig(kp, data=H3K36me3.bw, ymax="visible.region", r0 = 1, r1 = 1.3)
computed.ymax <- kp$latest.plot$computed.values$ymax # 獲得所繪制區(qū)域y的最大值
kpAxis(kp, ymin=0, ymax=computed.ymax, r0 = 1, r1 = 1.3) # 設(shè)置Y軸坐標(biāo)值
kpAddLabels(kp, labels = "H3K36me3", r0 = 1, r1 = 1.3, cex=1.6, label.margin = 0.035) # 設(shè)置Y軸標(biāo)簽
- 我們可以看到
H3K4me3
的修飾要高于H3K36me3
的修飾的黔漂。我們還可以看到,我們已經(jīng)開始重復(fù)代碼禀酱,并且為此使用循環(huán)會(huì)更好炬守,我們將使用autotrack
函數(shù)自動(dòng)獲取r0
和r1
值。
histone.marks <- c(H3K4me3="wgEncodeBroadHistoneK562H3k4me3StdSig.bigWig",
H3K36me3="wgEncodeBroadHistoneK562H3k36me3StdSig.bigWig")
base.url <- "http://hgdownload.soe.ucsc.edu/goldenPath/hg19/encodeDCC/wgEncodeBroadHistone/"
kp <- plotKaryotype(zoom = TP53.region, cex=2)
kpPlotGenes(kp, data=genes.data, r0=0, r1=0.15, gene.name.cex = 2)
kpPlotRegions(kp, K562.hmm, col=K562.hmm$itemRgb, r0=0.22, r1=0.3)
kpAddLabels(kp, labels = "Chromatin\nState (HMM)", r0=0.22, r1=0.3, cex=2)
for(i in seq_len(length(histone.marks))) {
bigwig.file <- paste0(base.url, histone.marks[i])
at <- autotrack(i, length(histone.marks), r0=0.35, r1=1)
kp <- kpPlotBigWig(kp, data=bigwig.file, ymax="visible.region",
r0=at$r0, r1=at$r1)
computed.ymax <- ceiling(kp$latest.plot$computed.values$ymax)
kpAxis(kp, ymin=0, ymax=computed.ymax, numticks = 2, r0=at$r0, r1=at$r1)
kpAddLabels(kp, labels = names(histone.marks)[i], r0=at$r0, r1=at$r1,
cex=1.6, label.margin = 0.035)
}
- 一旦我們有for循環(huán)和
autotrack
自動(dòng)跟蹤到位剂跟,我們可以增加組蛋白標(biāo)記的數(shù)量减途,一切都將自動(dòng)調(diào)整酣藻。
histone.marks <- c(H3K4me3="wgEncodeBroadHistoneK562H3k4me3StdSig.bigWig",
H3K36me3="wgEncodeBroadHistoneK562H3k36me3StdSig.bigWig",
H3K27ac="wgEncodeBroadHistoneK562H3k27acStdSig.bigWig",
H3K9ac="wgEncodeBroadHistoneK562H3k9acStdSig.bigWig",
H3K27me3="wgEncodeBroadHistoneK562H3k27me3StdSig.bigWig")
base.url <- "http://hgdownload.soe.ucsc.edu/goldenPath/hg19/encodeDCC/wgEncodeBroadHistone/"
kp <- plotKaryotype(zoom = TP53.region, cex=2)
kpPlotGenes(kp, data=genes.data, r0=0, r1=0.15, gene.name.cex = 2)
kpPlotRegions(kp, K562.hmm, col=K562.hmm$itemRgb, r0=0.22, r1=0.3)
kpAddLabels(kp, labels = "Chromatin\nState (HMM)", r0=0.22, r1=0.3, cex=2)
for(i in seq_len(length(histone.marks))) {
bigwig.file <- paste0(base.url, histone.marks[i])
at <- autotrack(i, length(histone.marks), r0=0.35, r1=1, margin = 0.1)
kp <- kpPlotBigWig(kp, data=bigwig.file, ymax="visible.region",
r0=at$r0, r1=at$r1)
computed.ymax <- ceiling(kp$latest.plot$computed.values$ymax)
kpAxis(kp, ymin=0, ymax=computed.ymax, numticks = 2, r0=at$r0, r1=at$r1)
kpAddLabels(kp, labels = names(histone.marks)[i], r0=at$r0, r1=at$r1,
cex=1.6, label.margin = 0.035)
}
- 我們現(xiàn)在可以調(diào)整繪圖參數(shù) plotting parameters 來減少邊距和表意文字高度并改變顏色以改善plo的整體外觀
pp <- getDefaultPlotParams(plot.type=1)
pp$leftmargin <- 0.15
pp$topmargin <- 15
pp$bottommargin <- 15
pp$ideogramheight <- 5
pp$data1inmargin <- 10
kp <- plotKaryotype(zoom = TP53.region, cex=2, plot.params = pp)
kpAddBaseNumbers(kp, tick.dist = 10000, minor.tick.dist = 2000,
add.units = TRUE, cex=1.3, digits = 6)
kpPlotGenes(kp, data=genes.data, r0=0, r1=0.1, gene.name.cex = 2)
kpPlotRegions(kp, K562.hmm, col=K562.hmm$itemRgb, r0=0.15, r1=0.18)
kpAddLabels(kp, labels = "Chromatin\nState (HMM)", r0=0.15, r1=0.18, cex=2)
for(i in seq_len(length(histone.marks))) {
bigwig.file <- paste0(base.url, histone.marks[i])
at <- autotrack(i, length(histone.marks), r0=0.23, r1=1, margin = 0.1)
kp <- kpPlotBigWig(kp, data=bigwig.file, ymax="visible.region",
r0=at$r0, r1=at$r1, col = "cadetblue2")
computed.ymax <- ceiling(kp$latest.plot$computed.values$ymax)
kpAxis(kp, ymin=0, ymax=computed.ymax, numticks = 2, r0=at$r0, r1=at$r1)
kpAddLabels(kp, labels = names(histone.marks)[i], r0=at$r0, r1=at$r1,
cex=1.6, label.margin = 0.035)
}
- 我們甚至可以添加其他實(shí)驗(yàn)峰值并使用嵌套自動(dòng)跟蹤
autotrack
來定位它們
base.url <- "http://hgdownload.soe.ucsc.edu/goldenPath/hg19/encodeDCC/wgEncodeBroadHistone/"
histone.marks <- c(H3K4me3="wgEncodeBroadHistoneK562H3k4me3StdSig.bigWig",
H3K36me3="wgEncodeBroadHistoneK562H3k36me3StdSig.bigWig",
H3K27ac="wgEncodeBroadHistoneK562H3k27acStdSig.bigWig",
H3K9ac="wgEncodeBroadHistoneK562H3k9acStdSig.bigWig",
H3K27me3="wgEncodeBroadHistoneK562H3k27me3StdSig.bigWig")
DNA.binding <- c(CTCF="wgEncodeBroadHistoneK562CtcfStdSig.bigWig",
EZH2="wgEncodeBroadHistoneK562Ezh239875StdSig.bigWig",
POL2="wgEncodeBroadHistoneK562Pol2bStdSig.bigWig",
P300="wgEncodeBroadHistoneK562P300StdSig.bigWig",
HDAC1="wgEncodeBroadHistoneK562Hdac1sc6298StdSig.bigWig",
HDAC2="wgEncodeBroadHistoneK562Hdac2a300705aStdSig.bigWig")
pp <- getDefaultPlotParams(plot.type=1)
pp$leftmargin <- 0.15
pp$topmargin <- 15
pp$bottommargin <- 15
pp$ideogramheight <- 5
pp$data1inmargin <- 10
kp <- plotKaryotype(zoom = TP53.region, cex=2, plot.params = pp)
kpAddBaseNumbers(kp, tick.dist = 10000, minor.tick.dist = 2000,
add.units = TRUE, cex=1.3, digits = 6)
kpPlotGenes(kp, data=genes.data, r0=0, r1=0.1, gene.name.cex = 2)
kpPlotRegions(kp, K562.hmm, col=K562.hmm$itemRgb, r0=0.15, r1=0.18)
kpAddLabels(kp, labels = "Chromatin\nState (HMM)", r0=0.15, r1=0.18, cex=2)
#Histone marks
total.tracks <- length(histone.marks)+length(DNA.binding)
out.at <- autotrack(1:length(histone.marks), total.tracks, margin = 0.3, r0=0.23)
for(i in seq_len(length(histone.marks))) {
bigwig.file <- paste0(base.url, histone.marks[i])
at <- autotrack(i, length(histone.marks), r0=out.at$r0, r1=out.at$r1, margin = 0.1)
kp <- kpPlotBigWig(kp, data=bigwig.file, ymax="visible.region",
r0=at$r0, r1=at$r1, col = "cadetblue2")
computed.ymax <- ceiling(kp$latest.plot$computed.values$ymax)
kpAxis(kp, ymin=0, ymax=computed.ymax, numticks = 2, r0=at$r0, r1=at$r1)
kpAddLabels(kp, labels = names(histone.marks)[i], r0=at$r0, r1=at$r1,
cex=1.6, label.margin = 0.035)
}
#DNA binding proteins
out.at <- autotrack((length(histone.marks)+1):total.tracks, total.tracks, margin = 0.3, r0=0.23)
for(i in seq_len(length(DNA.binding))) {
bigwig.file <- paste0(base.url, DNA.binding[i])
at <- autotrack(i, length(DNA.binding), r0=out.at$r0, r1=out.at$r1, margin = 0.1)
kp <- kpPlotBigWig(kp, data=bigwig.file, ymax="visible.region",
r0=at$r0, r1=at$r1, col = "darkolivegreen1")
computed.ymax <- ceiling(kp$latest.plot$computed.values$ymax)
kpAxis(kp, ymin=0, ymax=computed.ymax, numticks = 2, r0=at$r0, r1=at$r1)
kpAddLabels(kp, labels = names(DNA.binding)[i], r0=at$r0, r1=at$r1,
cex=1.6, label.margin = 0.035)
}
- 并添加一個(gè)主標(biāo)題,幾個(gè)額外的標(biāo)簽鳍置,并調(diào)整一些參數(shù)(文字大小等...)辽剧,以獲得更好的最終圖像
base.url <- "http://hgdownload.soe.ucsc.edu/goldenPath/hg19/encodeDCC/wgEncodeBroadHistone/"
histone.marks <- c(H3K4me3="wgEncodeBroadHistoneK562H3k4me3StdSig.bigWig",
H3K36me3="wgEncodeBroadHistoneK562H3k36me3StdSig.bigWig",
H3K27ac="wgEncodeBroadHistoneK562H3k27acStdSig.bigWig",
H3K9ac="wgEncodeBroadHistoneK562H3k9acStdSig.bigWig",
H3K27me3="wgEncodeBroadHistoneK562H3k27me3StdSig.bigWig")
DNA.binding <- c(CTCF="wgEncodeBroadHistoneK562CtcfStdSig.bigWig",
EZH2="wgEncodeBroadHistoneK562Ezh239875StdSig.bigWig",
POL2="wgEncodeBroadHistoneK562Pol2bStdSig.bigWig",
P300="wgEncodeBroadHistoneK562P300StdSig.bigWig",
HDAC1="wgEncodeBroadHistoneK562Hdac1sc6298StdSig.bigWig",
HDAC2="wgEncodeBroadHistoneK562Hdac2a300705aStdSig.bigWig")
pp <- getDefaultPlotParams(plot.type=1)
pp$leftmargin <- 0.15
pp$topmargin <- 15
pp$bottommargin <- 15
pp$ideogramheight <- 5
pp$data1inmargin <- 10
pp$data1outmargin <- 0
kp <- plotKaryotype(zoom = TP53.region, cex=3, plot.params = pp)
kpAddBaseNumbers(kp, tick.dist = 10000, minor.tick.dist = 2000,
add.units = TRUE, cex=2, tick.len = 3)
kpAddMainTitle(kp, "Epigenetic Regulation in K562", cex=4)
kpPlotGenes(kp, data=genes.data, r0=0, r1=0.1, gene.name.cex = 2.5)
kpPlotRegions(kp, K562.hmm, col=K562.hmm$itemRgb, r0=0.15, r1=0.18)
kpAddLabels(kp, labels = "Chromatin\nState (HMM)", r0=0.15, r1=0.18, cex=2.5)
#Histone marks
total.tracks <- length(histone.marks)+length(DNA.binding)
out.at <- autotrack(1:length(histone.marks), total.tracks, margin = 0.3, r0=0.23)
kpAddLabels(kp, labels = "Histone marks", r0 = out.at$r0, r1=out.at$r1, cex=3.5,
srt=90, pos=1, label.margin = 0.14)
for(i in seq_len(length(histone.marks))) {
bigwig.file <- paste0(base.url, histone.marks[i])
at <- autotrack(i, length(histone.marks), r0=out.at$r0, r1=out.at$r1, margin = 0.1)
kp <- kpPlotBigWig(kp, data=bigwig.file, ymax="visible.region",
r0=at$r0, r1=at$r1, col = "cadetblue2")
computed.ymax <- ceiling(kp$latest.plot$computed.values$ymax)
kpAxis(kp, ymin=0, ymax=computed.ymax, tick.pos = computed.ymax,
r0=at$r0, r1=at$r1, cex=1.6)
kpAddLabels(kp, labels = names(histone.marks)[i], r0=at$r0, r1=at$r1,
cex=2.2, label.margin = 0.035)
}
#DNA binding proteins
out.at <- autotrack((length(histone.marks)+1):total.tracks, total.tracks, margin = 0.3, r0=0.23)
kpAddLabels(kp, labels = "DNA-binding proteins", r0 = out.at$r0, r1=out.at$r1,
cex=3.5, srt=90, pos=1, label.margin = 0.14)
for(i in seq_len(length(DNA.binding))) {
bigwig.file <- paste0(base.url, DNA.binding[i])
at <- autotrack(i, length(DNA.binding), r0=out.at$r0, r1=out.at$r1, margin = 0.1)
kp <- kpPlotBigWig(kp, data=bigwig.file, ymax="visible.region",
r0=at$r0, r1=at$r1, col = "darkolivegreen1")
computed.ymax <- ceiling(kp$latest.plot$computed.values$ymax)
kpAxis(kp, ymin=0, ymax=computed.ymax, tick.pos = computed.ymax,
r0=at$r0, r1=at$r1, cex=1.6)
kpAddLabels(kp, labels = names(DNA.binding)[i], r0=at$r0, r1=at$r1,
cex=2.2, label.margin = 0.035)
}
- 與
karyoploteR
一樣,我們可以更改繪圖區(qū)域(在這種情況下放大)以繪制基因組的任何部分税产,例如怕轿,重疊區(qū)域的詳細(xì)視圖。
TP53.promoter.region <- toGRanges("chr17:7586000-7596000")
kp <- plotKaryotype(zoom = TP53.promoter.region, cex=3, plot.params = pp)
kpAddBaseNumbers(kp, tick.dist = 10000, minor.tick.dist = 2000,
add.units = TRUE, cex=2, tick.len = 3)
kpAddMainTitle(kp, "Epigenetic Regulation in K562", cex=4)
kpPlotGenes(kp, data=genes.data, r0=0, r1=0.1, gene.name.cex = 2.5)
kpPlotRegions(kp, K562.hmm, col=K562.hmm$itemRgb, r0=0.15, r1=0.18)
kpAddLabels(kp, labels = "Chromatin\nState (HMM)", r0=0.15, r1=0.18, cex=2.5)
#Histone marks
total.tracks <- length(histone.marks)+length(DNA.binding)
out.at <- autotrack(1:length(histone.marks), total.tracks, margin = 0.3, r0=0.23)
kpAddLabels(kp, labels = "Histone marks", r0 = out.at$r0, r1=out.at$r1, cex=3.5,
srt=90, pos=1, label.margin = 0.14)
for(i in seq_len(length(histone.marks))) {
bigwig.file <- paste0(base.url, histone.marks[i])
at <- autotrack(i, length(histone.marks), r0=out.at$r0, r1=out.at$r1, margin = 0.1)
kp <- kpPlotBigWig(kp, data=bigwig.file, ymax="visible.region",
r0=at$r0, r1=at$r1, col = "cadetblue2")
computed.ymax <- ceiling(kp$latest.plot$computed.values$ymax)
kpAxis(kp, ymin=0, ymax=computed.ymax, tick.pos = computed.ymax,
r0=at$r0, r1=at$r1, cex=1.6)
kpAddLabels(kp, labels = names(histone.marks)[i], r0=at$r0, r1=at$r1,
cex=2.2, label.margin = 0.035)
}
#DNA binding proteins
out.at <- autotrack((length(histone.marks)+1):total.tracks, total.tracks, margin = 0.3, r0=0.23)
kpAddLabels(kp, labels = "DNA-binding proteins", r0 = out.at$r0, r1=out.at$r1,
cex=3.5, srt=90, pos=1, label.margin = 0.14)
for(i in seq_len(length(DNA.binding))) {
bigwig.file <- paste0(base.url, DNA.binding[i])
at <- autotrack(i, length(DNA.binding), r0=out.at$r0, r1=out.at$r1, margin = 0.1)
kp <- kpPlotBigWig(kp, data=bigwig.file, ymax="visible.region",
r0=at$r0, r1=at$r1, col = "darkolivegreen1")
computed.ymax <- ceiling(kp$latest.plot$computed.values$ymax)
kpAxis(kp, ymin=0, ymax=computed.ymax, tick.pos = computed.ymax,
r0=at$r0, r1=at$r1, cex=1.6)
kpAddLabels(kp, labels = names(DNA.binding)[i], r0=at$r0, r1=at$r1,
cex=2.2, label.margin = 0.035)
}