前些天在網(wǎng)上看到的代碼穆咐,他最終的出圖如下
這份教程的鏈接地址是 https://www.royfrancis.com/beautiful-circos-plots-in-r/
但是他沒(méi)有公布完整的數(shù)據(jù)贬媒,只是提到了數(shù)據(jù)的格式快耿,我試著按照他提到的數(shù)據(jù)自己模擬了一份數(shù)據(jù)
首先是最外圈染色體的長(zhǎng)度信息
因?yàn)橹挥腥龡l染色體鳖目,數(shù)據(jù)不多,直接通過(guò)代碼輸入
circos.initialize(factors=c("genome_1","genome_2","genome_3"),
xlim=matrix(c(0,0,0,100,120,110),ncol=2))
第二圈的覆蓋度信息
第三圈的GC含量
第四圈的基因名稱
第五圈共線性的片段
教程中提到了兩套代碼锰悼,一套是不帶參數(shù)調(diào)整細(xì)節(jié)
完整代碼如下
'''
### 弦圖
### 參考鏈接
### https://www.royfrancis.com/beautiful-circos-plots-in-r/
'''
library(readxl)
cov<-read_excel("beautiful_plot/circlize/example_df.xlsx",
sheet = "Sheet1")
cov
gc<-read_excel("beautiful_plot/circlize/example_df.xlsx",
sheet = "Sheet2")
gc
ann<-read_excel("beautiful_plot/circlize/example_df.xlsx",
sheet = "Sheet3")
ann
nuc1<-read_excel("beautiful_plot/circlize/example_df.xlsx",
sheet = "Sheet4")
nuc1
nuc2<-read_excel("beautiful_plot/circlize/example_df.xlsx",
sheet = "Sheet5")
nuc2
library(circlize)
col_text <- "grey40"
#circos.par("track.height"=0.8,gap.degree=5,cell.padding=c(0,0,0,0))
circos.initialize(factors=c("genome_1","genome_2","genome_3"),
xlim=matrix(c(0,0,0,100,120,110),ncol=2))
circos.track(ylim=c(0,1),panel.fun=function(x,y) {
chr=CELL_META$sector.index
xlim=CELL_META$xlim
ylim=CELL_META$ylim
circos.text(mean(xlim),mean(ylim),chr)
})
circos.track(track.index = get.current.track.index(),
panel.fun = function(x, y) {
circos.axis(h="top")
})
circos.genomicTrack(data=cov,
panel.fun=function(region,value,...) {
circos.genomicLines(region,value)
})
# coverage y axis
circos.yaxis()
circos.track(factors=gc$chr,
x=gc$start,
y=gc$value1,
panel.fun=function(x,y) {
circos.lines(x,y)
})
# gc y axis
circos.yaxis()
circos.genomicLabels(ann,labels.column=5)
circos.genomicLink(nuc1,nuc2)
circos.clear()
出圖
還有一套代碼是帶有參數(shù)對(duì)圖進(jìn)行美化的
'''
### 弦圖
### 參考鏈接
### https://www.royfrancis.com/beautiful-circos-plots-in-r/
'''
library(readxl)
cov<-read_excel("beautiful_plot/circlize/example_df.xlsx",
sheet = "Sheet1")
cov
gc<-read_excel("beautiful_plot/circlize/example_df.xlsx",
sheet = "Sheet2")
gc
ann<-read_excel("beautiful_plot/circlize/example_df.xlsx",
sheet = "Sheet3")
ann
nuc1<-read_excel("beautiful_plot/circlize/example_df.xlsx",
sheet = "Sheet4")
nuc1
nuc2<-read_excel("beautiful_plot/circlize/example_df.xlsx",
sheet = "Sheet5")
nuc2
library(circlize)
col_text <- "grey40"
circos.par("track.height"=0.8,gap.degree=5,cell.padding=c(0,0,0,0))
circos.initialize(factors=c("genome_1","genome_2","genome_3"),
xlim=matrix(c(0,0,0,100,120,110),ncol=2))
circos.track(ylim=c(0,1),panel.fun=function(x,y) {
chr=CELL_META$sector.index
xlim=CELL_META$xlim
ylim=CELL_META$ylim
circos.text(mean(xlim),mean(ylim),chr,cex=0.5,col=col_text,
facing="bending.inside",niceFacing=TRUE)
},bg.col="grey90",bg.border=F,track.height=0.06)
brk <- c(0,20,40,60,80,100,120)
circos.track(track.index = get.current.track.index(),
panel.fun = function(x, y) {
circos.axis(h="top",
major.at=brk,
labels=brk,
labels.cex=0.4,
col=col_text,
labels.col=col_text,
lwd=0.7,
labels.facing="clockwise")
},
bg.border=F)
circos.genomicTrack(data=cov,
panel.fun=function(region,value,...) {
circos.genomicLines(region,
value,
type="l",
col="grey50",
lwd=0.6)
circos.segments(x0=0,
x1=120,
y0=100,
y1=100,
lwd=0.6,
lty="11",
col="grey90")
circos.segments(x0=0,
x1=120,
y0=150,
y1=150,
lwd=0.6,
lty="11",
col="grey90")
#circos.segments(x0=0,x1=max(ref$V2),y0=500,y1=500,lwd=0.6,lty="11",col="grey90")
},
track.height=0.08,
bg.border=F)
circos.yaxis(at=c(100,150),
labels.cex=0.25,
lwd=0,
tick.length=0,
labels.col=col_text,
col="#FFFFFF")
circos.track(factors=gc$chr,
x=gc$start,
y=gc$value1,
panel.fun=function(x,y) {
circos.lines(x,y,col="grey50",lwd=0.6)
circos.segments(x0=0,
x1=120,
y0=30,
y1=30,
lwd=0.6,
lty="11",
col="grey90")
circos.segments(x0=0,
x1=120,
y0=50,
y1=50,
lwd=0.6,
lty="11",
col="grey90")
circos.segments(x0=0,
x1=150,
y0=70,
y1=70,
lwd=0.6,
lty="11",
col="grey90")
},
ylim=c(30,70),
track.height=0.08,
bg.border=F)
# gc y axis
circos.yaxis(at=c(30,50,70),
labels.cex=0.25,
lwd=0,
tick.length=0,
labels.col=col_text,
col="#FFFFFF")
circos.genomicLabels(ann,
labels.column=5,
cex=0.25,
col=col_text,
line_lwd=0.5,
line_col="grey80",
side="inside",
connection_height=0.05,
labels_height=0.04)
rcols <- scales::alpha(ifelse(sign(nuc1$start-nuc1$end)!=sign(nuc2$start-nuc2$end),"#f46d43","#66c2a5"),alpha=0.4)
rcols
circos.genomicLink(nuc1,nuc2,col=rcols,border=NA)
circos.clear()
這個(gè)表示覆蓋度和gc含量的折線數(shù)據(jù)比較少漾月,看起來(lái)可能不太美觀,換成自己的數(shù)據(jù)多了以后就好看了
示例數(shù)據(jù)和代碼可以直接在公眾號(hào)后臺(tái)留言 20210617
獲取
歡迎大家關(guān)注我的公眾號(hào)
小明的數(shù)據(jù)分析筆記本
小明的數(shù)據(jù)分析筆記本 公眾號(hào) 主要分享:1瘦赫、R語(yǔ)言和python做數(shù)據(jù)分析和數(shù)據(jù)可視化的簡(jiǎn)單小例子辰晕;2、園藝植物相關(guān)轉(zhuǎn)錄組學(xué)确虱、基因組學(xué)含友、群體遺傳學(xué)文獻(xiàn)閱讀筆記;3校辩、生物信息學(xué)入門(mén)學(xué)習(xí)資料及自己的學(xué)習(xí)筆記窘问!