Density SNP map on chromosome

       There are two ways to look at a relatively simple one:

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) 

result:


7559841-ca012f5075681eb1.jpg
SNP_Density.Index_snp_density.jpg

The second method is more complicated, you need two files:
a file that contains chr_length.txt chromosome length, format is as follows:

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 is a file containing the start position of each gene:

chr start   end
Chr1    2903    2904
Chr1    11218   11219
Chr1    12648   12649
Chr1    16292   16293
Chr1    22841   22842
Chr1    27136   27137
Chr1    29818   29819

Then drawing:

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"))
                                    })
7559841-ecbcd822d21bef63.PNG
Capture .PNG

In fact, the following method may be used to draw FIG density copy number variation, becomes just need to start and end range.

Guess you like

Origin blog.csdn.net/weixin_34405557/article/details/91028981