美文网首页
图示杂合SNP的R脚本

图示杂合SNP的R脚本

作者: 九月_1012 | 来源:发表于2022-01-12 23:24 被阅读0次

膜拜一下小伙伴的R脚本,杂合SNP在外显子和内含子区域的图示,以下截图来自于Gendx的HLA显示,以下脚本进行一个部分的实现


image.png

具体效果如下:


image.png
options(stringsAsFactors=F)
snp = read.table('XX.snp.stat',sep="\t",header=T,comment.char="")
x <- rep(snp[,1], each=5)
y <- t(apply(snp[,2:6],1,function(x)x/sum(x)*100))
max = apply(y,1,which.max)
col = matrix(2,nc = ncol(y),nr = nrow(y))
for(i in 1:nrow(y)) col[i,max[i]] = 4
col = c(t(col))
pch = "X"
cex =matrix(0.2,nc = ncol(y),nr = nrow(y))
for(i in 1:nrow(y)){
yi =rev( sort(y[i,]))[2]
if(yi>35) cex[i,][y[i,]>35]=0.6
}
cex = c(t(cex))
y = t(y)
y <- ifelse(y==0,-2,log(y,10))
## A.bed
bed = read.table("XX.A.bed",header=F,sep="\t")
exon = bed[grep('exon',bed[,4]),]
pdf('zz.pdf',width=10)
par(mar=c(4,4,4,8),las=1)
plot(x,y,ylim=c(-3,3),xlim=c(0,max(snp[,1])),xlab="Nucleotide posion",ylab="Base variation(%)",
      main="Percentage most frequent basecall versus rest",cex=cex,pch=pch,col=col,yaxt="n",type="n")
axis(2,-2:2,10^(-2:2))
points(x,y,cex=cex,pch=pch,col=col)
rect(exon[,2],-3,exon[,3],3,col=rgb(244/255,195/255,217/255,0.5),border=rgb(244/255,195/255,217/255,0.5))
par(xpd=T)
legend(par('usr')[2],par('usr')[4]-2,pch=16,legend=c("Major base %","Rest %"),col=c(4,2),bty="n")
legend(par('usr')[2],par('usr')[3]+1,pch=c("X","x"),legend=c("Heterozygous","Homozygous"),bty="n")
dev.off()

相关文章

网友评论

      本文标题:图示杂合SNP的R脚本

      本文链接:https://www.haomeiwen.com/subject/abvgcrtx.html