用TrackViewer包画棒棒糖图
trackViewer包用于可视化
参考1 mp.weixin.qq.com/s/wuPklQ6KhhPqn2JjRWAMTA https://bioconductor.org/packages/release/bioc/vignettes/trackViewer/inst/doc/trackViewer.html#Variant_Call_Format_(VCF)_data
#BiocManager::install("trackViewer")
setwd("e:/Rcode/trackviewer")
library(trackViewer) #主要画图包
library(RColorBrewer) #引入颜色包
SNP <- c(10,12,23,250,300,303,400,500,510,535,650,680,700,1005,1200,1350,1402) # 指定SNP 坐标位置
sample.gr <- GRanges("chr1", IRanges(SNP, width=1, names=paste0("snp", SNP))) # 设置棒棒图位置
features <- GRanges("chr1", IRanges(c(1, 401, 1001), # 设置block起使位置
width=c(400, 600, 505), # 设置block 的长度
names=c("UTR5","CDS","UTR3"))) # 设置名字
features$fill <- brewer.pal(3,"Set2") #块的颜色
sample.gr$color <- sample.int(length(SNP), length(SNP)) #棒子上面的球的颜色
sample.gr$border <- sample(c("grey60", "grey50"), length(SNP), replace=TRUE) #棒子的颜色
sample.gr$alpha <- sample(100:200, length(SNP), replace = TRUE)/200 #设置透明度0-1之间,sample是生成100-200之间的随机数
sample.gr$label <- as.character(1:length(sample.gr)) #球内的字符
sample.gr$label.col <- "black" #球内的标签的颜色
# features$height <- c(0.02, 0.05, 0.04) #块的高度
sample.gr$score <- sample.int(4, length(sample.gr), replace = TRUE) #设置球的数量
lolliplot(sample.gr, features,yaxis = F) #yaxis设置不显示y轴
xaxis <- c(1, 200, 400, 701, 1000, 1200, 1400) ## 重新定义x轴
names(xaxis) <- xaxis
names(xaxis)[4] <- "center"
sample2.gr <- sample.gr
# 饼图
sample2.gr$score <- NULL
sample2.gr$label <- NULL
# 清空所有其他无关数值
sample2.gr$color <- rep(list(c("#16A05D", '#FFCD43')), length(SNP)) # 这里需要使用列表,对应饼图各部分颜色
sample2.gr$border <- "gray30"
sample2.gr$value1 <- sample.int(5, length(sample2.gr), replace = TRUE) # 饼图数值1 所占比重
sample2.gr$value2 <- 10 - sample2.gr$value1 # 数值2 所占比重
features2 <- features
features2$fill <- brewer.pal(3,"Set1")
lolliplot(sample2.gr, features2,yaxis = F)
lolliplot(list(A=sample.gr,B=sample2.gr),list(features,features2), type=c("circle","pie"), xaxis=xaxis)
library(VariantAnnotation)
#BiocManager::install("TxDb.Hsapiens.UCSC.hg38.knownGene")
#BiocManager::install("org.Hs.eg.db")
#以上两个包下载比较慢,可以下载到本地,使用devtools安装。
#devtools::install_local("org.Hs.eg.db_3.12.0.tar.gz")
#devtools::install_local("TxDb.Hsapiens.UCSC.hg38.knownGene_3.10.0.tar.gz")
library(TxDb.Hsapiens.UCSC.hg38.knownGene)
library(org.Hs.eg.db)
library(trackViewer)
my_gr <- GRanges("chr1", IRanges(69200, 70000, names="OR4F5"))