1、在linux中安装好R

2、准备好画曼哈顿图的R脚本即manhattan.r,manhattan.r内容如下:

#!/usr/bin/Rscript
#example : Rscript plot_manhatom.r XXX.assoc XXX.pdf
argv <- commandArgs()
#define the function to plot the manhatton and quantitle-quantitle plot
plot_manhatton<-function(site_file,save_file){
        read.table(site_file,header=T)->data
    data<-data[which(data[,5]=="ADD"),]
    logp=-log10(data[,9]) #value
        chr=data[,1] #chr
        position<-data[,3] #position
#       xaxis=0
        sig=numeric()
        lab=numeric()
    flogp=numeric();
        the_col=c("darkblue","gray"); #chr class
        whole_col=c()
    xlabel=numeric();
        length_add=0
        label=numeric();
        for(i in 1:22){
                position[chr==i]->chr_pos
        chr_pos<-chr_pos-chr_pos[1]+17000000
        chr_num=length(chr_pos)
                cat("For chrosome",i,",Num of SNPs:",chr_num,"\n")
                if(length(chr_pos)==0){
                        next
                }
                flogp=c(flogp,logp[chr==i])
                label=c(label,i)
                whole_col=c(whole_col,rep(the_col[i%%2+1],chr_num))
                chr_pos=length_add+chr_pos
                xlabel=c(xlabel,chr_pos)
                length_add=sort(chr_pos,decreasing=T)[1]
        lab=c(lab,(chr_pos[1]+length_add)/2)
        }
    png(save_file,height=500,width=600)
    par(mar=c(5,6,4,2))
        plot(xlabel,flogp,col=whole_col,axes=F,xlab="",ylab="",ylim=c(0,12),pch=20,cex=0.5,cex.lab=1.2,cex.axis=1.4)#ylim=c(0,6)
    significance=-log10(0.05/length(data[,1]))
    sig_pos<-xlabel[which(flogp>significance)]
    for(i in 1:length(sig_pos)){
        sig<-c(sig,which(xlabel>sig_pos[i]-60000 & xlabel<sig_pos[i]+60000))
    }
    sig<-unique(sig)
    cat("significant signal:",sig[10:20],"\n")
    points(xlabel[sig],flogp[sig],col="red",pch=20,cex=0.5)
    title(xlab="Chromosome",ylab=expression(-log[10]*(p)),cex.lab=1.4)
#   title(xlab="Chromosome",ylab="Score",cex.lab=1.8)
#       title("GWAS scan for Hair curl", cex.main=2.5)
#       yaxis=seq(0,1,by=0.1)
#       axis(2,yaxis,yaxis,las=1,cex.axis=1.5,line=-2)
        axis(2,las=2,cex.axis=1.4)
        #las can change the directory of the axis character
        #las=0 always parallel to the axis
        #las=2 always horizontal

        for(i in 1:22){
                mtext(label[i],side=1,at=lab[i],las=0,font=1,cex=0.8)
                #cex magnified relative to the to the default
        }
#    mtext("X",side=1,at=x[23],las=0,font=1,cex=1.4)
#    mtext("Y",side=1,at=x[24],las=0,font=1,cex=1.4)

#       axis(1,x,as.character(label),tick=TRUE,font=1)
        par(lty=2)
        abline(h=significance,cex=1.5,col="red")
#plot the QQ plot
#    par(fig=c(0.58,0.92,0.43,0.95),new=TRUE)
#    observed <- sort(data[,12])
#    logp=-log10(observed)
#    expected <- c(1:length(observed))
#    lexp <- -(log10(expected / (length(expected)+1)))
#    plot(x=lexp,y=logp,pch=19,cex=0.6, xlab="Expected (-logP)", ylab="Observed (-logP)",cex.lab=1.2,cex.axis=1.2)
#    abline(0,1,col="red",lwd=2,lty=1)

    dev.off()
}

site_file<-argv[6];print(site_file)
save_file<-argv[7];print(save_file)
plot_manhatton(site_file,save_file)

#round(x,digits=3) keep the length of the digit

3、准备好plink跑完后的.assoc.linear文件,比如mydata.assoc.linear

4、在linux中输入以下一个命令:

其中,mydata.png即为我们想要的曼哈顿图(manhattan plot)

Rscript manhattan.r mydata.assoc.linear mydata.png

R语言画全基因组关联分析中的曼哈顿图(manhattan plot)的更多相关文章

  1. 全基因组关联分析(Genome-Wide Association Study,GWAS)流程

    全基因组关联分析流程: 一.准备plink文件 1.准备PED文件 PED文件有六列,六列内容如下: Family ID Individual ID Paternal ID Maternal ID S ...

  2. 全基因组关联分析(GWAS)的计算原理

    前言 关于全基因组关联分析(GWAS)原理的资料,网上有很多. 这也是我写了这么多GWAS的软件教程,却从来没有写过GWAS计算原理的原因. 恰巧之前微博上某位小可爱提问能否写一下GWAS的计算原理. ...

  3. GWAS 全基因组关联分析 | summary statistic 概括统计 | meta-analysis 综合分析

    有很多概念需要明确区分: 人有23对染色体,其中22对常染色体autosome,另外一对为性染色体sex chromosome,XX为女,XY为男. 染色体区带命名:在标示一特定的带时需要包括4项:① ...

  4. 【GWAS文献解读】疟原虫青蒿素抗药性的全基因组关联分析

    英文名:Genetic architecture of artemisinin-resistant Plasmodium falciparum 中文名:疟原虫青蒿素抗药性的全基因组关联分析 期刊:Na ...

  5. GWAS | 全基因组关联分析 | Linkage disequilibrium (LD)连锁不平衡 | 曼哈顿图 Manhattan_plot | QQ_plot | haplotype phasing

    现在GWAS已经属于比较古老的技术了,主要是碰到严重的瓶颈了,单纯的snp与表现的关联已经不够,需要具体的生物学解释,这些snp是如何具体导致疾病的发生的. 而且,大多数病找到的都不是个别显著的snp ...

  6. 全基因组关联分析(GWAS):为何我的QQ图那么飘

    前段时间有位小可爱问我,为什么她的QQ图特别飘,如果你不理解怎样算飘,请看下图: 理想的QQ图应该是这样的: 我当时的第一反应是:1)群体分层造成的:2)表型分布有问题.因此让她检查一下数据的群体分层 ...

  7. 一行命令学会全基因组关联分析(GWAS)的meta分析

    为什么需要做meta分析 群体分层是GWAS研究中一个比较常见的假阳性来源. 也就是说,如果数据存在群体分层,却不加以控制,那么很容易得到一堆假阳性位点. 当群体出现分层时,常规手段就是将分层的群体独 ...

  8. 全基因组关联分析(GWAS)扫不出信号怎么办(文献解读)

    假如你的GWAS结果出现如下图的时候,怎么办呢?GWAS没有如预期般的扫出完美的显著信号,也就没法继续发挥后续研究的套路了. 最近,nature发表了一篇文献“Common genetic varia ...

  9. 全基因组关联分析学习资料(GWAS tutorial)

    前言 很多人问我有没有关于全基因组关联分析(GWAS)原理的书籍或者文章推荐. 其实我个人觉得,做这个分析,先从跑流程开始,再去看原理. 为什么这么说呢,因为对于初学者来说,跑流程就像一个大黑洞,学习 ...

随机推荐

  1. 查询oracle连接数 对应的 应用程序

     select  b.MACHINE, b.PROGRAM , count(*) from v$process a, v$session b where a.ADDR = b.PADDR and  b ...

  2. 1不等于1?numeric、decimal、float 和 real 数据类型的区别

    大家有没有在SQL中遇见1不等于1(1<>1)的情形!?下面会有一个例子演示这个情形. 先简单介绍一下标题中的四种数值数据类型. 在T-SQL中,numeric和decimal是精确数值数 ...

  3. 扩展easyui.datagrid,添加数据loading遮罩效果代码 --来自网摘收集

    //jquery.datagrid 扩展 (function (){ $.extend($.fn.datagrid.methods, { //显示遮罩 loading: function(jq){ r ...

  4. 二叉树遍历(Binary Tree Traversal)

    二叉树的递归遍历比较简单,这里说一下非递归遍历,以中序遍历为例子. 非递归遍历主要用到栈来协助进行.对于一个二叉树,首先根节点入栈,如果有左儿子,则继续入栈,重复直到最左边的儿子,这时候此节点值为要遍 ...

  5. C#笔试(程序设计)

    1.如何把一个Array复制到ArrayList里,如何把ArrayList复制到Array里? foreach( object o in array )arrayList.Add(o); Array ...

  6. over partition by与group by 的区别

    (本文摘自scottpei的博客) over partition by与group by 的区别 今天看到一个老兄的问题, 大概如下: 查询出部门的最低工资的userid 号 表结构: D号      ...

  7. OpenGL 矩阵变换

    Overview 几何数据--顶点位置,和标准向量(normal vectors),在OpenGL 管道raterization 处理过程之前可通过顶点操作(Vertex Operation)和基本组 ...

  8. python基础知识8——模块1——自定义模块和第三方开源模块

    模块的认识 模块,用一砣代码实现了某个功能的代码集合. 类似于函数式编程和面向过程编程,函数式编程则完成一个功能,其他代码用来调用即可,提供了代码的重用性和代码间的耦合.而对于一个复杂的功能来,可能需 ...

  9. eclipse debug maven项目时出现缺少库的问题

    调试maven web项目时出现缺少库的情况导致项目无法启动  可是打包到tomcat发布却一切正常 后来在stackoverlow上找到了解决方案 项目右键属性->Deployment Ass ...

  10. HMC破解控制台密码

    一般我们装完HMC以后默认的登录控制台的账户是:admin 密码:abc123当我们可以自创建登录账户后,忘记密码了怎么办? 这里有两种方法: 1 由于HMC是suse系统,基于linux内核的,所以 ...