绘制 SNP 密度图

一般使用 CMplot 绘制SNP密度图:
包链接:https://github.com/YinLiLin/R-CMplot

要绘制 SNP 密度图,仅仅需要三列即可:
a. 第一列是 SNP 名称
b. 第二列是染色体
c. 第三列是 SNP 的位置
d. 第四列开始为不同性状的P值

1. 示例数据:

          SNP Chromosome Position    trait1     trait2     trait3
1 ALGA0000009          1    52297 0.7738187 0.51194318 0.51194318
2 ALGA0000014          1    79763 0.7738187 0.51194318 0.51194318
3 ALGA0000021          1   209568 0.7583016 0.98405289 0.98405289
4 ALGA0000022          1   292758 0.7200305 0.48887140 0.48887140
5 ALGA0000046          1   747831 0.9736840 0.22096836 0.22096836
6 ALGA0000047          1   761957 0.9174565 0.05753712 0.05753712

2. 安装 CMplot 包

install.packages("CMplot")
library("CMplot")

3. 作图代码

首先读取数据
pig60k <- read.table("data.txt",header=T)

3.1 示例1 -- 密度条形图

# users can personally set the windowsize and the max of legend by:
# bin.size=1e6
# bin.max=N
# memo: add a character to the output file name.

data(pig60K)
CMplot(
        pig60K, plot.type="d",  bin.size=1e6, col=c("darkgreen", "yellow", "red"),
        file="jpg", memo="Fig1", dpi=300, file.output=TRUE, verbose=TRUE
)
Fig1

3.2 示例2 -- 环状图

CMplot(
        pig60K, plot.type="c", chr.labels=paste("Chr",c(1:18,"X"), sep=""), r=0.4, cir.legend=TRUE,
        outward=FALSE, cir.legend.col="black", cir.chr.h=1.3, chr.den.col="black", file="jpg",
        memo="Fig2", dpi=300, file.output=TRUE, verbose=TRUE
)
Fig2

3.3 示例3 -- 多层圈图

CMplot(pig60K,plot.type="c",r=0.4,col=c("grey30","grey60"),chr.labels=paste("Chr",c(1:18,"X"),sep=""),
      threshold=c(1e-6,1e-4),cir.chr.h=1.5,amplify=TRUE,threshold.lty=c(1,2),threshold.col=c("red",
      "blue"),signal.line=1,signal.col=c("red","green"),chr.den.col=c("darkgreen","yellow","red"),
      bin.size=1e6,outward=FALSE,file="jpg",memo="",dpi=300,file.output=TRUE,verbose=TRUE)

## Note:
# 1. if signal.line=NULL, the lines that crosse circles won't be added.
# 2. if the length of parameter 'chr.den.col' is not equal to 1, SNP density that counts the number of SNP within given size('bin.size') will be plotted around the circle.
Fig3

3.4 示例4 -- 曼哈顿图

CMplot(
        pig60K, plot.type="m", col=c("grey30","grey60"), LOG10=TRUE, ylim=c(2,12), threshold=c(1e-6,1e-4),
        threshold.lty=c(1,2), threshold.lwd=c(1,1), threshold.col=c("black","grey"), amplify=TRUE,
        chr.den.col=NULL, signal.col=c("red","green"), signal.cex=c(1,1),signal.pch=c(19,19),
        file="jpg",memo="",dpi=300,file.output=TRUE,verbose=TRUE
)

## Note:
## if the ylim is setted, then CMplot will only plot the ponits which among this interval.
Fig4

3.5 示例5 -- 曼哈顿 + 条形图

CMplot(
        pig60K, plot.type="m", LOG10=TRUE, ylim=NULL, threshold=c(1e-6,1e-4),threshold.lty=c(1,2),
        threshold.lwd=c(1,1), threshold.col=c("black","grey"), amplify=TRUE,bin.size=1e6,
        chr.den.col=c("darkgreen", "yellow", "red"),signal.col=c("red","green"),signal.cex=c(1,1),
        signal.pch=c(19,19),file="jpg",memo="",dpi=300,file.output=TRUE,verbose=TRUE
)  
## Note:
## if the length of parameter 'chr.den.col' is bigger than 1, SNP density that counts the number of SNP within given size('bin.size') will be plotted.
Fig5

3.6 示例6 -- 分染色体曼哈顿图

CMplot(
        pig60K, plot.type="m", multracks=TRUE, threshold=c(1e-6,1e-4),threshold.lty=c(1,2), 
        threshold.lwd=c(1,1), threshold.col=c("black","grey"), amplify=TRUE,bin.size=1e6,
        chr.den.col=c("darkgreen", "yellow", "red"), signal.col=c("red","green"),signal.cex=c(1,1),
        file="jpg",memo="",dpi=300,file.output=TRUE,verbose=TRUE
)
Fig6

3.7 示例7 -- 单性状 QQ 图

CMplot(
      pig60K,plot.type="q",conf.int.col=NULL,box=TRUE,file="jpg",memo="",dpi=300,
      file.output=TRUE,verbose=TRUE
)
Fig7

3.8 示例8 -- 多性状 QQ 图

CMplot(
        pig60K,plot.type="q",col=c("dodgerblue1", "olivedrab3", "darkgoldenrod1"),threshold=1e6,
        signal.pch=19,signal.cex=1.5,signal.col="red",conf.int.col="grey",box=FALSE,multracks=
        TRUE,file="jpg",memo="",dpi=300,file.output=TRUE,verbose=TRUE
)
Fig8

4. CMplot 的参数及解释:

Pmap: 
  a dataframe, at least four columns. The first column is the name of SNP, the second column is the chromosome of SNP, the third column is the position of SNP, and the remaining columns are the P-value of each trait(Note:each trait a column).
col:
  a vector or a matrix, if "col" equals to a vector, each circle use the same colors, it means that the same chromosome is drewed in the same color, the colors are not fixed, one, two, three or more colors can be used, if the length of the "col" is shorter than the length the chromosome, then colors will be applied circularly. 
  if "col" equals to a matrix, the row is the number of circles(traits), the columns are the colors that users want to use for different circles, so each circle can be plotted in different number of colors, the missing value can be replaced by NA. For example: 
  col=matrix(c("grey30","grey60",NA,"red","blue","green","orange",NA,NA),3,3,byrow=T).
bin.size: 
  the size of bin for SNP_density plot.
bin.max: 
  the max value of legend of SNP_density plot, the bin whose SNP number is bigger than 'bin.max' will be use the same color.
pch: 
  a number, the type for the points, is the same with "pch" in <plot>.
band:   
  a number, the space between chromosomes, the default is 1(if the band equals to 0, then there would be no space between chromosome).
cir.band: 
  a number, the space between circles, the default is 1.
H:   
  a number, the height for each circle, each circle represents a trait, the default is 1.
ylim: 
  a vector, the range of Y-axis when plotting the two type of Manhattans, is the same with "ylim" in <plot>.
cex.axis: 
  a number, controls the size of numbers of X-axis and the size of labels of circle plot.
plot.type: 
  a character or vector, only "d", "c", "m", "q" or "b" can be used. if plot.type="d", SNP density will be plotted; if plot.type="c", only circle-Manhattan plot will be plotted; if plot.type="m",only Manhattan plot will be plotted; if plot.type="q",only Q-Q plot will be plotted;if plot.type="b", both circle-Manhattan, Manhattan and Q-Q plots will be plotted; if plot.type=c("m","q"), Both Manhattan and Q-Q plots will be plotted.
multracks: 
  a logical,if multracks=FALSE, plotting multiple traits on multiple tracks, if it is TRUE, all Manhattan plots will be plotted in only one track.
cex:
  a number or a vector, the size for the points, is the same with "size" in <plot>, and if it is a vector, the first number controls the size of points in circle plot(the default is 0.5), the second number controls the size of points in Manhattan plot(the default is 1), the third number controls the size of points in Q-Q plot(the default is 1)
r: 
  a number, the radius for the circle(the inside radius), the default is 1.
xlab: 
  a character, the labels for x axis.
ylab: 
  a character, the labels for y axis.
xaxs: 
  a character, The style of axis interval calculation to be used for the x-axis. Possible values are "r", "i", "e", "s", "d". The styles are generally controlled by the range of data or xlim, if given.
yaxs: 
  a character, The style of axis interval calculation to be used for the y-axis. See xaxs above..
outward: 
  logical, if outward=TRUE,then all points will be plotted from inside to outside.
threshold: 
  a number or vector, the significant threshold. For example, Bonfferoni adjustment method: threshold=0.01/nrow(Pmap). More than one significant line can be added on the plots, if threshold=0 or NULL, then the threshold line will not be added.
threshold.col: 
  a character or vector, the colour for the line of threshold levels.
threshold.lwd: 
  a number or vector, the width for the line of threshold levels.
threshold.lty: 
  a number or vector, the type for the line of threshold levels.
amplify: 
  logical, CMplot can amplify the significant points, if amplify=T, then the points greater than the minimal significant level will be highlighted, the default: amplify=TRUE.
chr.labels: 
  a vector, the labels for the chromosomes of circle-Manhattan plot.
signal.cex: 
  a number, if amplify=TRUE, users can set the size of significant points.
signal.pch: 
  a number, if amplify=TRUE, users can set the shape of significant points.
signal.col: 
  a character, if amplify=TRUE, users can set the colour of significant points, if signal.col=NULL, then the colors of significant points will not be changed.
signal.line: 
  a number, the width of the lines cross the circle
cir.chr: 
  logical, a boundary represents chromosome, the default is TRUE.
cir.chr.h: 
  a number, the width for the boundary, if cir.chr=FALSE, then this parameter will be useless.
chr.den.col: 
  a character or vector or NULL, the colour for the SNP density. If the length of parameter 'chr.den.col' is bigger than 1, SNP density that counts 
   the number of SNP within given size('bin.size') will be plotted around the circle. If chr.den.col=NULL, then the default colours are the same with the parameter "col" for circle.
cir.legend: 
  logical, whether to add the legend of each circle.
cir.legend.cex: 
  a number, the size of the number of legend.
cir.legend.col: 
  a character, the color of the axis of legend.
LOG10: 
  logical, whether to change the p-value into log10(p-value).
box: 
  logical, this function draws a box around the current Manhattan plot.
conf.int.col: 
  a character, the color of the confidence interval on QQ-plot.
file.output: 
  a logical, users can choose whether to output the plot results.
file: 
  a character, users can choose the different output formats of plot, so for, "jpg", "pdf", "tiff" can be selected by users.
dpi: 
  a number, the picture element for .jpg and .tiff files. The default is 300.
memo: 
  add a character to the output file name.
verbose: 
  whether print the reminder.

感觉作者好棒!

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

推荐阅读更多精彩内容