2020-01-10 分析SNP位点:连锁不平衡-可视化R包LDheatmap

参考学习资料:https://cran.r-project.org/web/packages/LDheatmap/LDheatmap.pdf

  • 二代测序得到的那些SNP,有些是一起起作用的,那么怎么来判断呢,这里有个可视化的包可以帮助我们,其实呢我的理解所谓基因的连锁不平衡就是可以用相关性热图来体现的,那么R包LDheatmap就是这个作用。
  • 这个包需要一些依赖包包括:snpStatsrtracklayer, GenomicRanges, GenomInfoDb and IRanges 基本上都在 BioConductor 收录https://bioconductor.org.

源码: https://sfustatgen.github.io/LDheatmap/

内置测试数据

CEUData

  • CEUSNP: 来自60人的15个SNPs信息。
  • CEUDist: CEUSNP中15个SNPs的物理位置信息
    获取方法
rm(list = ls())
options(stringsAsFactors = F)
install.packages("LDheatmap")
library("LDheatmap")
data(CEUData)

这个数据是来自7号染色体9kb区域(国际HapMap项目第7版的基本位置126273659至126282556)的次要等位基因频率(MAF)大于5%的SNP的数据。 从30个三口之家获得了基因型。 这30个来自犹他州的多代家庭,祖先来自北欧和西欧,家庭疾病:CEPH,是从这90人中,提取了60位父母信息。

参考文献:

示例

rm(list = ls())
options(stringsAsFactors = F)
library("LDheatmap")
require(snpStats)
# Load the package's data set
data("CEUData")
# Produce an LDheatmap object
MyLDheatmap <- LDheatmap(CEUSNP, genetic.distances = CEUDist, flip = TRUE)

参数flip = TRUE设置水平显示,默认是非水平显示。

CEUdata

CHBJPTData

  • CHBJPTSNP: 来自45个中国人和45个日本人的13个SNPs
  • CHBJPTDist: CHBJPTSNP中13个SNPs的物理位置信息
    获取方法:
data(CHBJPTData)
  • CHBJPTSNP: 一个SNP genotypes的df. 每行代表一个人,每列代表一个SNP。
  • CHBJPTDist: 一个整数型向量, 表示SNP位点在染色体的基因组位置信息。

数据CHBJPTSNP包含来自45位中国人和45位日本人的7号染色体上13个SNP的基因型。 中国人是来自北京师范大学的互相无亲缘关系且至少有都有3带以上的汉族祖父母。 日本人是来自东京的所有祖父母都是东京且无亲缘关系。 数据来自国际HapMap项目的第21版(International HapMap Consortium 2005)。

参考文献:

示例:

#Now do our panel plot with LDheatmaps in the panels
library(lattice)
pop<-factor(c(rep("chinese", 45), rep("japanese", 45)))
xyplot(1:nrow(CHBJPTSNP) ~ 1:nrow(CHBJPTSNP) | pop, type="n",
       scales=list(draw=FALSE), xlab="", ylab="",
       panel=function(x, y, subscripts,...) {
         LDheatmap(CHBJPTSNP[subscripts,], CHBJPTDist, newpage=FALSE)})
CHBJPTSNP

系统不知道哪里出了问题,估计是什么依赖包没有安装好的原因,第一次尝试的结果显示数据缺失,经过一番调试,估计是多安装了一个包,才得到正确的结果。

rm(list = ls())
options(stringsAsFactors = F)
# Install the latest release version from CRAN and the
# imported/suggested BioConductor packages with
install.packages("LDheatmap")
BiocManager::install("snpStats")#需要源码安装,后面选不更新
# BiocManager::install("GenomeInfoDb")
# BiocManager::install(c("snpStats","rtracklayer","GenomicRanges","IRanges"))
# Install the latest development version from GitHub with
#devtools::install_github("SFUStatgen/LDheatmap")
library("LDheatmap")
data(CHBJPTData)
#Now do our panel plot with LDheatmaps in the panels
library(lattice)
pop<-factor(c(rep("chinese", 45), rep("japanese", 45)))
xyplot(1:nrow(CHBJPTSNP) ~ 1:nrow(CHBJPTSNP) | pop, type="n",
       scales=list(draw=FALSE), xlab="", ylab="",
       panel=function(x, y, subscripts,...) {
         LDheatmap(CHBJPTSNP[subscripts,], CHBJPTDist, newpage=FALSE)})
连锁不平衡第一例

GIMAP5

SNP基于HapMap的GIMAP5 基因的连锁不平衡分析

SNP genotypes from HapMap release 27 for SNPs in a 10KB region spanning the GIMAP5 gene. Data are on founders from each of the 11 HapMap phase III populations:
ASW African ancestry in Southwest USA
CEU Utah residents with Northern and Western European ancestry from the CEPH collection CHB Han Chinese in Beijing, China
CHD Chinese in Metropolitan Denver, Colorado GIH Gujarati Indians in Houston, Texas
JPT Japanese in Tokyo, Japan
LWK Luhya in Webuye, Kenya
MEX Mexican ancestry in Los Angeles, California MKK Maasai in Kinyawa, Kenya
TSI Toscani in Italia
YRI Yoruba in Ibadan, Nigeria

仅展示人群中MAF >5% SNPs。参考基因组位置参考NCBI build 36 (UCSC genome hg18).
参考文献:

示例

data(GIMAP5)
#Now do a lattice plot with LDheatmaps in the panels
library(lattice)
pop<-GIMAP5$subject.support$pop
n<-nrow(GIMAP5$snp.data)
xyplot(1:n ~ 1:n | pop, type="n", scales=list(draw=FALSE), xlab="", ylab="",
       panel=function(x, y, subscripts,...) {
         LDheatmap(GIMAP5$snp.data[subscripts,],GIMAP5$snp.support$Position,
                   newpage=FALSE)})
rm(pop,n)
同时展示一个基因的SNP在多个人群的比较
require(snpStats) # for the SnpMatrix data structure
data(GIMAP5.CEU)
LDheatmap(GIMAP5.CEU$snp.data,GIMAP5.CEU$snp.support$Position)
一个基因某个区段内的SNP关联

还可以通过更改相应的参数调节色块展示效果及添加标注:

rm(list = ls())
options(stringsAsFactors = F)
library("LDheatmap")
require(snpStats) # for the SnpMatrix data structure
data(GIMAP5.CEU)
MyHeatmap <-LDheatmap(GIMAP5.CEU$snp.data,GIMAP5.CEU$snp.support$Position)

old.prompt <- devAskNewPage(ask = TRUE)
# Highlight a certain LD block of interest:
LDheatmap.highlight(MyHeatmap, i = 13, j = 19, col = "black",
                    fill = "grey",flipOutline=FALSE, crissCross=FALSE)
# Plot a symbol in the center of the pixel which represents LD between
# the fourth and seventh SNPs:
LDheatmap.marks(MyHeatmap,  17.5,  14.5,  gp=grid::gpar(cex=2),  pch = "*")
#### Use an RGB pallete for the color scheme ####
rgb.palette <- colorRampPalette(rev(c("blue", "orange", "red")), space = "rgb")
LDheatmap(MyHeatmap, color=rgb.palette(18))
找出密切关联的一部分SNP

标注*的位置为连锁区域。


或者用不同的颜色来展示

或者可以用不同颜色来标注连锁区域。
每个线条也可以进行rs号的标注。先获取rs号:

> colnames(GIMAP5.CEU$snp.data)
 [1] "rs6955828"  "rs3807383"  "rs6965571"  "rs9657890"  "rs9657891" 
 [6] "rs9657879"  "rs11973400" "rs9657894"  "rs4725936"  "rs4725359" 
[11] "rs9657898"  "rs13235400" "rs10239400" "rs9657886"  "rs9657900" 
[16] "rs759011"   "rs1046355"  "rs10361"    "rs6598"     "rs2286899" 
[21] "rs2286898"  "rs9657901"  "rs11760839"

那么之前那个色块起止是第13和19位的SNP,标注出来。

require(grid)
LDheatmap(MyHeatmap, SNP.name = c("rs10239400", "rs6598"))

结果如下:


标注某些特别关注的SNP

还可以进一步修饰:

getNames()
#[1] "ldheatmap"
# Find the names of the component grobs of "ldheatmap"
childNames(grid.get("ldheatmap"))
#[1] "heatMap" "geneMap" "Key"
#Find the names of the component grobs of heatMap
childNames(grid.get("heatMap"))
#[1] "heatmap" "title"
#Find the names of the component grobs of geneMap
childNames(grid.get("geneMap"))
#[1] "diagonal" "segments" "title"    "symbols"  "SNPnames"
#Find the names of the component grobs of Key
childNames(grid.get("Key"))
#[1] "colorKey" "title"    "labels"   "ticks"    "box"
#Change the plotting symbols that identify SNPs rs10239400 and rs6598
#on the plot to bullets
grid.edit("symbols", pch = 20, gp = gpar(cex = 1))
#Change the color of the main title
grid.edit(gPath("ldheatmap", "heatMap", "title"), gp = gpar(col = "red"))
#Change size of SNP labels
grid.edit(gPath("ldheatmap", "geneMap","SNPnames"), gp = gpar(cex=1.5))
#Add a grid of white lines to the plot to separate pairwise LD measures
grid.edit(gPath("ldheatmap", "heatMap", "heatmap"), gp = gpar(col = "white",
                                                              lwd = 2))
#### Modify a heat map using 'editGrob' function ####
MyHeatmap <- LDheatmap(MyHeatmap, color = grey.colors(20))
new.grob <- editGrob(MyHeatmap$LDheatmapGrob, gPath("geneMap", "segments"),gp=gpar(col="orange"))
##Clear the old graphics object from the display before drawing the modified heat map:
grid.newpage()
grid.draw(new.grob)
# now the colour of line segments connecting the SNP
# positions to the LD heat map has been changed from black to orange.
#### Draw a resized heat map (in a 'blue-to-red' color scale ####
grid.newpage()
pushViewport(viewport(width=0.5, height=0.5))
LDheatmap(MyHeatmap, SNP.name = c("rs10239400", "rs6598"), newpage=FALSE,
          color="blueToRed")
popViewport()
组合1

组合2

这样就学会了不但知道怎么画这个图,也知道怎么理解这个图,新技能get!

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 229,732评论 6 539
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 99,214评论 3 426
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 177,781评论 0 382
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 63,588评论 1 316
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 72,315评论 6 410
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 55,699评论 1 327
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 43,698评论 3 446
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 42,882评论 0 289
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 49,441评论 1 335
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 41,189评论 3 356
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 43,388评论 1 372
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 38,933评论 5 363
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 44,613评论 3 348
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 35,023评论 0 28
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 36,310评论 1 293
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 52,112评论 3 398
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 48,334评论 2 377