? ? ? ?有兩種方法眨补,先看比較簡單的一種:
library(CMplot)
mydata<-read.table("snp_density.csv",header=TRUE,sep=",")
head(mydata)
# snp chr pos
# snp1_1 1 2041
# snp1_2 1 2062
# snp1_3 1 2190
CMplot(mydata,plot.type="d",bin.size=1e6,col=c("darkgreen","yellow", "red"),file="jpg",memo="snp_density",dpi=300)
結(jié)果:
第二種方法就比較復(fù)雜了,需要準(zhǔn)備兩個文件:
一個是包含染色體長度的文件chr_length.txt翔始,格式如下:
chr start end
Chr1 0 43270923
Chr2 0 35937250
Chr3 0 36413819
Chr4 0 35502694
Chr5 0 29958434
Chr6 0 31248787
Chr7 0 29697621
Chr8 0 28443022
一個是包含各個基因的起始位置的文件gene_length.txt:
chr start end
Chr1 2903 2904
Chr1 11218 11219
Chr1 12648 12649
Chr1 16292 16293
Chr1 22841 22842
Chr1 27136 27137
Chr1 29818 29819
然后畫圖:
source("http://bioconductor.org/biocLite.R")
biocLite("gtrellis")
library(gtrellis)
library(RColorBrewer)
library(circlize)
library(ComplexHeatmap)
bed1<-read.table("chr_length.txt",head=T,sep='\t')
bed2<-read.table("gene_length.txt",head=F,sep='\t')
gene_density = genomicDensity(bed2,window.size = 1e6)
col_fun = colorRamp2(seq(0, max(gene_density[[4]]), length = 11),rev(brewer.pal(10, "RdYlBu")))
cm = ColorMapping(col_fun = col_fun)
lgd = color_mapping_legend(cm, plot = TRUE, title = "",color_bar="continuous")
gtrellis_layout(bed1,byrow = FALSE,ncol = 1,xpadding = c(0.1, 0),
gap = unit(2, "mm"),border = FALSE,asist_ticks=FALSE,
track_axis = FALSE,legend=lgd)
add_heatmap_track(gene_density, gene_density[[4]], fill = col_fun,track=1)
add_track(track = 1, clip = FALSE, panel_fun = function(gr) {
chr = get_cell_meta_data("name")
if(chr == "Chr12") {
grid.lines(get_cell_meta_data("xlim"),
unit(c(0, 0), "npc"),
default.units = "native") }
grid.text(chr,x =0.02, y = 0.38, just = c("left", "bottom"))
})
下面這個方法其實也可以用來畫拷貝數(shù)變異的密度圖罗心,只需要把start和end變成范圍即可。