GWAS Sumstats Harmonization GWAS数据的协调统一

背景介绍

在进行meta分析之前,我们首先要对gwas的sumstats进行预处理,这一步看似简单,但却是高质量meta分析中必不可少的一步,本文将简单介绍预处理过程中需要注意的事项,并简单介绍一款实用的预处理软件。

不同GWAS sumstats通常格式千差万别,单单统一格式就已经让人烦恼,而更令人万念俱灰的是,不同sumstats的参考的基因组版本并不相同,allele的正负链也不统一,SNPID有的用rsID(rsID的版本又是个问题~_~),有的又用chrpos…

针对以上种种的不统一,我们都要逐一进行处理,要注意事项主要包括:

  1. 参考基因组的版本:hg19还是hg38 或其他
  2. 表示变异等位的正负链是否统一
  3. 如果是a1,a2这种表示形式,则需要明确effect allele与non-efffect allele
  4. 对于palindromic SNP (A/T, 或是G/C如何处理?)
  5. 表示效应量的是beta还是OR

Pipeline

预处理简要的pipeline:

  1. 确定参考所用的VCF文件, 最好包含相应群体的allele frequency(AF)数据
  2. 对于基因组版本不一致的sumstats首先liftover转换成参考vcf的基因组版本
  3. 对sumstats进行整理并统一beta与OR的使用,
    1. 数量表型用beta与SE
    2. 二分类表型用OR与OR_95L,OR_95U
  4. 对不同群体的sumstats,使用相应的AF,利用harmoniser工具分别进行harmonise
    1. 设定依据AF判断正负链的阈值
  5. 对于处理后的gwas sumstats进行统一的质控 QC
    1. INFO
    2. MAF等

Genetics-Sumstats-Harmoniser工具使用教程

下载与安装

harmonise可以使用的工具

该工具由opentargets项目组成员开发

github链接:https://github.com/opentargets/genetics-sumstat-harmoniser

# Download 从github下载
git clone <https://github.com/opentargets/sumstat_harmoniser.git>
cd sumstat_harmoniser

# Install dependencies into isolated environment 创建环境
conda env create -n sumstat_harmoniser --file environment.yaml

# Activate environment 激活环境
source activate sumstat_harmoniser

# Run tests 检验是否安装成功
cd tests
./run_tests.py

环境要求 Requirements

参考数据 Reference data

可以使用的参考数据:

以global biobank meta-analysis initiative为例,其参考数据使用了gnomAD的数据:

https://gnomad.broadinstitute.org/downloads

示例:

INFO字段中包含了不同族裔中的allele frequency的信息:

#CHROM	POS	ID	REF	ALT	QUAL	FILTER	INFO
1	10108	rs62651026	CAACCCT	C	46514.3	RF	AF_eas=0;AF_nfe=0;AF_fin=0.0227273
1	10109	rs376007522	AACCCT	A	89837.3	RF	AF_eas=0;AF_nfe=0.0512821;AF_fin=0.0588235

使用方法

输入选项

需要两个文件:一是gwas的sumstats,二是参考的vcf文件

Input files:
  --sumstats <file>     GWAS summary statistics file
  --vcf <file>          Reference VCF file. Use # as chromosome wildcard.

其中gwas sumstats还需要指定对应的列名:

Input column names:
  --chrom_col <str>     Chromosome column 染色体
  --pos_col <str>       Position column 碱基位置
  --effAl_col <str>     Effect allele column 效应等位
  --otherAl_col <str>   Other allele column 非效应等位
  --beta_col <str>      beta column
  --or_col <str>        Odds ratio column 
  --or_col_lower <str>  Odds ratio lower CI column
  --or_col_upper <str>  Odds ratio upper CI column
  --eaf_col <str>       Effect allele frequency column
  --rsid_col <str>      rsID column in the summary stat file

输出选项

输出3个文件,Harmonise后的文件,Harmonise过程中的统计文件,以及forward/reverse/palindromic variants的数量的文件,通过以下选项指定:

Output files:
  --hm_sumstats <file>  Harmonised sumstat output file (use 'gz' extension to
                        gzip)
  --hm_statfile <file>  Statistics from harmonisation process output file.
                        Should only be used in conjunction with --hm_sumstats.
  --strand_counts <file>
                        Output file showing number of variants that are
                        forward/reverse/palindromic

其他选项

Other args:
  --only_chrom <str>    Only process this chromosome
  --in_sep <str>        Input file column separator (default: tab)
  --out_sep <str>       Output file column separator (default: tab)
  --na_rep_in <str>     How NA are represented in the input file (default: "")
  --na_rep_out <str>    How to represent NA values in output (default: "")
  --chrom_map <str> [<str> ...]
                        Map summary stat chromosome names, e.g. `--chrom_map
                        23=X 24=Y`

Harmonisation mode 模式选择:

可以选择以下四种模式:[infer|forward|reverse|drop]

对于 palindromic variants 的处理方式为:

(a) infer strand from effect-allele freq, 根据AF推测

(b) assume forward strand, 假设全部都为正链

(c) assume reverse strand, 假设全部为负链

(d) drop palindromic variants 舍弃所有palindromic variants

AF字段名与阈值

如果选择通过AF推测正负链(–palin_mode infer),那么还需要制定vcf文件中af的字段名与推测的阈值 –af_vcf_field <str> VCF info field containing alt allele freq (default:AF_NFE)

指定VCF文件中INFO里包含AF信息的字段

–infer_maf_threshold <float>Max MAF that will be used to infer palindrome strand (default: 0.42)

推测palindrome strand的最大MAF的阈值

使用例

如果输入的sumstats为以下格式:

CHROMOSOME      POSITION        MARKERNAME      NEA     EA      EAF     INFO    N       BETA    SE      P       OR      OR_95L  OR_95U

那么harmonise时,可以使用如下的代码:

sumstat_harmoniser \
 --sumstats ${sumstats} \
 --vcf gnomad.vcf.gz \    #以gnomad为参考
 --eaf_col EAF \
 --af_vcf_field AF_eas \
 --chrom_col CHROMOSOME \
 --pos_col POSITION \
 --effAl_col EA \
 --otherAl_col NEA \
 --beta_col BETA \
 --or_col OR \
 --or_col_lower OR_95L \
 --or_col_upper OR_95U \
 --palin_mode infer \
 --hm_sumstats ${out}.hm \
 --hm_statfile ${out}.stats

harmonise后的结果为原文件前加上以下harmonise后的列

hm_varid hm_rsid hm_chrom hm_pos hm_other_allele hm_effect_allele hm_beta hm_OR hm_OR_lowerCI hm_OR_upperCI hm_eaf hm_code

参考

https://gnomad.broadinstitute.org/downloads

MAGMA 基因及通路分析

目录

1 背景
2 算法简介
3 使用教程
 3.1 magma软件与参考数据下载
 3.2 注释
 3.3 基因关联分析
 3.4 通路分析
4 参考

背景

通过以有生物学意义的方式整合复杂疾病的信息的基因以及通路分析,是单变异GWAS的有效补充。

本文将介绍MAGMA,一个基于多变量回归模型的基因以及通路分析工具。

算法简介

Gene-based分析

magma的gene-based分析模型采用了多元线性主成分回归(multiple linear principal components regression)

α0g为截距,Xg* 为PC矩阵,W与βg为协变量变量的效应(可选),αg为遗传效应,εg为残差

计算时:

首先根据染色体位置提取某个基因SNP矩阵,计算PC

去除掉特征值过小的PC

对剩下的主成分进行回归

最后通过F检验获得p值 (H0: αg =0 )

Gene set /Pathway 基因集 通路分析

进行通路分析时,magma首先将上一步所得到的每个基因的p值通过probit方程转化为z值,

这里的zg整体上近似服从正态分布,zg反映了该基因关联的强度。

Self-contained gene-set analysis检验一个通路上的基因的整体上是否与表型相关联。使用通路里基因的z值,可以构建一个只有截距项的回归,然后检验β是否大于0:

Competitive gene-set analysis检验在一个通路里的基因,是否比这个通路里其他基因的相关性更高。

因为通路分析中的回归模型为标准线性回归,假设残差项独立正态分布,即

但实际上,由于LD,相邻的基因可能会互相关联,而打破上述假设。所以magma采用了广义最小二乘法,并假设

R为基因-基因的关联矩阵。

概括性数据分析

在没有原始基因型数据的情况下,magma也提供分析概括性数据SNP的p值的方法,即逐个分析某个基因中的SNP,然后将SNP的p值合并成该基因的检验统计量,但是该方法需要提供一个相近群体的LD参考面板。

使用教程

magma软件与参考数据下载

https://ctg.cncr.nl/software/magma

1.软件下载,下载对应系统的版本即可

2.基因注释参考,magma提供了多种版本,下载对因自己数据的版本

3.LD参考面板,来自1000 genome,下载相应人群的文件即可

magma三步骤:

  1. 注释:将自己的SNP根据染色体位置注释到基因上
  2. Gene-based 分析
  3. 基因集/通路分析

SNP注释 Annotation

第一步需要对gwas中所包含的SNP进行注释,在这里就是将SNP根据染色体上的位置对应到相应基因上。

示例代码如下:

magma \
	--annotate \
	--snp-loc [SNPLOC_FILE] \
	--gene-loc [GENELOC_FILE] \
	--out [ANNOT_PREFIX]

snp-loc 文件应当包含三列,SNPID,CHR以及POS,这里也可以直接使用plink的bim文件

rs540836310	1 861725
rs139858754	1 861728

gene-loc 可以直接使用magma提供的基因注释参考文件 (注意版本)

注释完成后会得到 .genes.annot文件,内容为第一例为geneID 之后为在这个基因内的SNP

816	rs540836310	rs139858754	rs188152259	rs13302982	rs76842830	rs13303101	rs74442310	rs6680268

基因关联分析 Gene-based analysis

第二部,进行基于基因的关联分析,

示例代码如下所示:

magma \
	--bfile [REFDATA] \
	--pval [PVAL_FILE] \
	N=[N] \
	--gene-annot [ANNOT_PREFIX].genes.annot \
	--out [GENE_PREFIX]

bfile为原始数据或是参考LD面板,如果数据量不大可以直接使用自己的plink的bed格式原始数据,在原始数据无法获得的时候可以使用magma提供的1000 genome参考数据,biobank级别的数据的情况下,可以随机抽取某个族裔无亲缘关系的一定人数(例如20000人)来构建自己的参考面板。

pval为SNP的p值文件,包含两列 SNP 以及 P, 这里N为样本量,

gene-annot为上一步注释后得到的文件。

完成后有两个文件输出;1 .genes.out 2 ..genes.raw

1 .genes.out 基因关联分析的结果

GENE       CHR      START       STOP  NSNPS  NPARAM       N        ZSTAT            P
148398       1     859993     879961    125      27  157848      -1.7291       0.9581

2 ..genes.raw 在第三步通路分析时会使用到这个文件

# VERSION = 109
# COVAR = NSAMP MAC
148398 1 859993 879961 125 27 157848 133.304 -1.72907

基因集 通路分析 gene-set analysis 、 pathway

第三步,通路分析

这一步是对显著的基因是否富集于某个基因集或通路进行检验,

如果是对经典的通路进行检验,可以在MSigDB(GSEA)下载通路文件 msigdb.v7.4.entrez.gmt

MSigDB:https://www.gsea-msigdb.org/gsea/downloads.jsp#msigdb

示例代码如下:

magma \
	--gene-results [GENE_PREFIX].genes.raw \
	--set-annot [SET_FILE] \
	--out [GS_PREFIX]

gene-results 为上一步基因关联分析所得的.genes.raw文件

set-annot 为基因集或通路的定义文件,可以直接使用MSigDB下载的文件(注意基因ID要与之前相对应)

默认输出三个.gsa.out .gsa.genes.out, .gsa.sets.genes.out

.gsa.out 为最主要的输出文件,包含了各个通路的检验结果

# TOTAL_GENES = 17198
# TEST_DIRECTION = one-sided, positive (set), two-sided (covar)
# CONDITIONED_INTERNAL = gene size, gene density, inverse mac, log(gene size), log(gene density), log(inverse mac)
VARIABLE                                TYPE  NGENES         BETA     BETA_STD           SE            P FULL_NAME
chr1p12                                  SET      18    -0.096902     -0.00381      0.30843      0.71093 chr1p12


.gsa.genes.out 为在此分析中使用到的基因关联结果

GENE       CHR      START       STOP  NSNPS  NPARAM       N        ZSTAT  ZFITTED_BASE  ZRESID_BASE
148398       1     859993     879961    125      42  12345      -1.62             0      -1.62

.gsa.sets.genes.out 为多重检验调整后, 显著的通路里的基因的信息

参考

MAGMA: Generalized Gene-Set Analysis of GWAS Data. de Leeuw CA, Mooij JM, Heskes T, Posthuma D (2015) MAGMA: Generalized Gene-Set Analysis of GWAS Data. PLOS Computational Biology 11(4): e1004219. https://doi.org/10.1371/journal.pcbi.1004219

https://ctg.cncr.nl/software/magma

多基因风险分数 PRS( Polygenic risk score)系列之七:Pathway-based PRS 通路PRS

本文是多基因风险分数PRS系列的第七篇文章,主要介绍基于通路的PRS(Pathway-based PRS)的概念,以及简要的计算方法(仅供参考)。

回顾:

基于通路的PRS (Pathway-based PRS )简介

目前主流PRS计算模型的局限

当前主流的PRS计算方法都是基于疾病的经典多基因模型,也就是假设个体处在一个从低到高风险的线性分布上,其PRS作为易感性(liability)的估计值,能够总结这个个体的遗传概况。

易感性:易感性-阈值模型 Genetic liability, Threshold model

但这种方法也存在显著的缺陷,那就是这种概括性的估计值不能完全捕捉个体遗传特征,存在明显的信息丢失,一个最显著的例子就是无法判别不同生物学过程与通路之间遗传风险大小的变化,但这类信息通常在PRS的应用中(例如病人分层,或是治疗反应预测)起到重要的作用。

为了解决上述问题,近年来基于通路的PRS方法逐渐获得关注,本文将主要介绍Paul O’Reilly课题组开发的Pathway-based PRS方法PRSet。PRSet方法可以解释基因组中的亚结构(genomic sub-structure),该模型在经典多基因模型中进行扩展,使其能更好反映疾病的异质性。

基于通路的PRS : Pathway-based PRS

经典PRS模型计算整个基因组上risk allele与其效应估计乘积的加和,而pathway-based PRS只分别纳入k个相关通路上的SNP。也就是说,使用pathway-based PRS方法时,一个个体会有k个不同通路的通路PRS,每个通路PRS都对应基因组上一个具体的通路。(如图a)

在这里,通路可以由多种方式定义,可以是一些经典的通路数据库(如:KEGG,REACTOME等),也可以是通过基因共表达,蛋白质互作,实验扰动的功能产出等分析得到的模组。

理想状态下,通路能够反映不同生物学功能的编码。这些功能是可分割的,就像流行病学研究中,不同环境风险因素(抽烟,饮食,等等)也是分割的一样。基于这种观点,我们可以吧GWAS的结果也视为不同通路编码的生物学功能的信号的综合。(如图b)

PRSet的通路PRS方法简要原理

PRSet采用传统的C+T方法,分别对k条通路分别计算PRS,mk为每条通路上SNP数量,对于每个个体i,计算后会得到对应k个通路的k个PRS:

Clumping

与传统C+T对基因组上所有SNP进行clumping的方法不同,PRSet独立地对每条通路上的SNP进行clumping,确保能最大程度的保留信号。PRSet采用如下所示的bit-flag方法,对不同通路独立clumping。简单来说就是只有indexSNP包含在该gene set的时候才会去除掉需要被clump的SNP,否则会保留。

PRSet软件链接:https://www.prsice.info/prset_detail/

注:该方法的优势是简单快速,而且已经在软件中实现,作为探索可以尝试,但具体效果还有待检验。

(20211211:目前该文章还没有正式发表,文章里的检验方法不能令人信服,所以仅供参考)

参考:https://www.prsice.info/prset_detail/

https://europepmc.org/article/ppr/ppr362752

孟德尔随机化系列之二:两样本MR – TwoSampleMR

目录

  1. TwoSampleMR简介
  2. TwoSampleMR简要教程
    1. 方法概览
    2. 读取暴露GWAS数据,选取工具变量
    3. 读取结局GWAS数据,提取对应工具变量
    4. 对数据进行预处理,使其效应等位与效应量保持统一
    5. MR分析与可视化
      1. MR分析
      2. 敏感性分析
      3. 散点图
      4. 森林图
      5. 漏斗图
  3. 参考

TwoSampleMR简介

两样本孟德尔随机化(Two sample Mendelian randomisation,2SMR)是使用GWAS概括性数据估计暴露对结果的因果效应的一种方法。尽管孟德尔随机化在概念上相对直观简单,但实际操作却相对繁琐,有很多细节需要注意。TwoSampleMR就是一款致力于简化MR分析的R包,其整合了以下的分析步骤:

  1. 数据管理与统一
  2. 因果推断的常规统计学分析
  3. 接入了GWAS概括性数据的数据库,使分析更为便捷

孟德尔随机化的原理可以参考G. Davey Smith and Ebrahim 2003; George Davey Smith and Hemani 2014, 统计方法可以参考Pierce and Burgess 2013; Bowden, Davey Smith, and Burgess 2015等。

TwoSampleMR简要教程

本文仅对TwoSampleMR使用方法进行介绍。基础概念概念可以参考:GWASLab:孟德尔随机化系列之一:基础概念 Mendelian randomization I

下载(注:本文所用语言均为R)

TwoSampleMR官网: https://mrcieu.github.io/TwoSampleMR/

TwoSampleMR是一个R包,可以通过以下代码在R中直接安装

install.packages("remotes")
remotes::install_github("MRCIEU/TwoSampleMR")

0 方法概览

MR分析的主要步骤如下:

  1. 读取暴露因素GWAS数据
  2. 选取合适的工具变量(如有必要,需要进行clumping)
  3. 读取结局GWAS数据,提取上述的工具变量的SNP
  4. 对暴露因素与结局的GWAS数据进行预处理,使其格式统一
  5. 采用选中的MR方法进行分析
  6. 将结果可视化
    1. 散点图
    2. 森林图
    3. 漏斗图

1 读取暴露GWAS数据,选取工具变量

1.1 读取数据

对于暴露因素的GWAS数据,TwoSampleMR需要一个工具变量的data frame,每行对应一个SNP,至少需要4列,分别为:

  • SNP – rs ID
  • beta – The effect size. If the trait is binary then log(OR) should be used
  • se – The standard error of the effect size
  • effect_allele – The allele of the SNP which has the effect marked in beta

其他可能有助于MR预处理或分析的列包括

  • other_allele – The non-effect allele
  • eaf – The effect allele frequency
  • Phenotype – The name of the phenotype for which the SNP has an effect

你也可以提供额外的信息(可选,对于分析非必须)

  • chr – Physical position of variant (chromosome)
  • position – Physical position of variant (position)
  • samplesize – Sample size for estimating the effect size
  • ncase – Number of cases
  • ncontrol – Number of controls
  • pval – The P-value for the SNP’s association with the exposure
  • units – The units in which the effects are presented
  • gene – The gene or other annotation for the the SNP

本教程将从本地文本文件中读取暴露GWAS数据:

本文使用的暴露因素的GWAS数据的前5行如下所示:

rsid,effect,SE,a1,a2,a1_freq,p-value,Units,Gene,n
rs10767664,0.19,0.030612245,A,T,0.78,5.00E-26,kg/m2,BDNF,225238
rs13078807,0.1,0.020408163,G,A,0.2,4.00E-11,kg/m2,CADM2,221431
rs1514175,0.07,0.020408163,A,G,0.43,8.00E-14,kg/m2,TNNI3K,207641
rs1558902,0.39,0.020408163,A,T,0.42,5.00E-120,kg/m2,FTO,222476

该示例数据随TwoSampleMR包一同下载,可以通过以下代码定位其位置,并读取:

## 定位数据位置,将路径赋予bmi2_file
bmi2_file <- system.file("extdata/bmi.csv", package="TwoSampleMR")

##读取数据
bmi_exp_dat <- read_exposure_data(
    filename = bmi2_file,
    sep = ",",
    snp_col = "rsid",
    beta_col = "effect",
    se_col = "SE",
    effect_allele_col = "a1",
    other_allele_col = "a2",
    eaf_col = "a1_freq",
    pval_col = "p-value",
    units_col = "Units",
    gene_col = "Gene",
    samplesize_col = "n"
)

1.2 Clumping

对于一个标准的两样本MR分析来说,我们需要确保工具变量之间是互相独立的(即不存在显著的LD),在读取完数据后我们应当对其进行LD Clumping,这里可以使用clump_data()函数,指定LD参考面板为EUR,r2的阈值为0.01,对数据进行Clumping。 该函数与OpenGWAS API进行交互,其存储了千人基因组中5个群体(EUR, SAS, EAS, AFR, AMR)的LD数据。对东亚人进行分析时指定pop = "EAS"即可。

bmi_exp_dat <- clump_data(bmi_exp_dat,clump_r2=0.01 ,pop = "EUR")
#> Please look at vignettes for options on running this locally if you need to run many instances of this command.
#> Clumping UVOe6Z, 30 variants, using EUR population reference
#> Removing 3 of 30 variants due to LD with other variants or absence from LD reference panel

2 读取结局GWAS数据,提取对应工具变量

结局数据可以像上一节暴露因素GWAS数据的读取一样从本地文件中读取,也可以从在线数据库中提取。因为上一节已经演示过本地数据的读取,在这里就演示从在线数据库中提取的方法, 使用extract_outcome_data函数,指定结局GWAS的id,与要提取的SNP的rsID,即可完成数据提取。

例如我们想分析BMI与冠心病(coronary heart disease)之间的因果关系,首先我们要查找冠心病GWAS在数据库中的id

2.1 查找相应的GWAS

使用available_outcomes()可以查看当前可用的所有表型的GWAS数据,然后使用grep1抓取关键字

ao <- available_outcomes()
#> API: public: <http://gwas-api.mrcieu.ac.uk/>
head(ao)
#> # A tibble: 6 x 22
#>   id      trait     group_name  year consortium author sex   population    unit 
#>   <chr>   <chr>     <chr>      <int> <chr>      <chr>  <chr> <chr>         <chr>
#> 1 ieu-b-~ Number o~ public      2021 MRC-IEU    Clare~ Male~ European      SD   
#> 2 prot-a~ Leptin r~ public      2018 NA         Sun BB Male~ European      NA   
#> 3 prot-a~ Adapter ~ public      2018 NA         Sun BB Male~ European      NA   
#> 4 ukb-e-~ Impedanc~ public      2020 NA         Pan-U~ Male~ Greater Midd~ NA   
#> 5 prot-a~ Dual spe~ public      2018 NA         Sun BB Male~ European      NA   
#> 6 eqtl-a~ ENSG0000~ public      2018 NA         Vosa U Male~ European      NA   
#> # ... with 13 more variables: sample_size <int>, nsnp <int>, build <chr>,
#> #   category <chr>, subcategory <chr>, ontology <chr>, note <chr>, mr <int>,
#> #   pmid <int>, priority <int>, ncase <int>, ncontrol <int>, sd <dbl>

## 使用grep1抓取目标表型
ao[grepl("heart disease", ao$trait), ]
#> # A tibble: 28 x 22
#>    id      trait       group_name  year consortium author sex   population unit 
#>    <chr>   <chr>       <chr>      <int> <chr>      <chr>  <chr> <chr>      <chr>
#>  1 ieu-a-8 Coronary h~ public      2011 CARDIoGRAM Schun~ Male~ European   log ~
#>  2 finn-a~ Valvular h~ public      2020 NA         NA     Male~ European   NA   
#>  3 finn-a~ Other or i~ public      2020 NA         NA     Male~ European   NA   
#>  4 ukb-b-~ Diagnoses ~ public      2018 MRC-IEU    Ben E~ Male~ European   SD   
#>  5 ukb-a-~ Diagnoses ~ public      2017 Neale Lab  Neale  Male~ European   SD   
#>  6 ukb-e-~ I25 Chroni~ public      2020 NA         Pan-U~ Male~ South Asi~ NA   
#>  7 ukb-b-~ Diagnoses ~ public      2018 MRC-IEU    Ben E~ Male~ European   SD   
#>  8 finn-a~ Ischemic h~ public      2020 NA         NA     Male~ European   NA   
#>  9 finn-a~ Major coro~ public      2020 NA         NA     Male~ European   NA   
#> 10 finn-a~ Other hear~ public      2020 NA         NA     Male~ European   NA   
#> # ... with 18 more rows, and 13 more variables: sample_size <int>, nsnp <int>,
#> #   build <chr>, category <chr>, subcategory <chr>, ontology <chr>, note <chr>,
#> #   mr <int>, pmid <int>, priority <int>, ncase <int>, ncontrol <int>, sd <dbl>

查看完整结果后我们发现冠心病GWAS id为 ieu-a-7

当然可以直接进入数据库网站搜索 https://gwas.mrcieu.ac.uk/ ,简单直观

2.2 提取结局GWAS数据

指定GWAS id,指定要提取的SNP rsid (1中选取的工具变量),使用extract_outcome_data进行提取

chd_out_dat <- extract_outcome_data(
    snps = bmi_exp_dat$SNP,
    outcomes = 'ieu-a-7'
)

head(chd_out_dat )
A data.frame: 6 × 16
SNP	chr	pos	beta.outcome	se.outcome	samplesize.outcome	pval.outcome	eaf.outcome	effect_allele.outcome	other_allele.outcome	outcome	id.outcome	originalname.outcome	outcome.deprecated	mr_keep.outcome	data_source.outcome
<chr>	<chr>	<chr>	<dbl>	<dbl>	<dbl>	<dbl>	<dbl>	<chr>	<chr>	<chr>	<chr>	<chr>	<chr>	<lgl>	<chr>
1	rs887912	2	59302877	-0.021960	0.0111398	184305	0.04868780	0.731654	C	T	Coronary heart disease || id:ieu-a-7	ieu-a-7	Coronary heart disease	Coronary heart disease || ||	TRUE	igd
2	rs2112347	5	75015242	-0.005855	0.0096581	184305	0.54436400	0.401399	G	T	Coronary heart disease || id:ieu-a-7	ieu-a-7	Coronary heart disease	Coronary heart disease || ||	TRUE	igd
3	rs3817334	11	47650993	0.000355	0.0095386	184305	0.97031200	0.387831	T	C	Coronary heart disease || id:ieu-a-7	ieu-a-7	Coronary heart disease	Coronary heart disease || ||	TRUE	igd
4	rs1555543	1	96944797	0.002516	0.0093724	184305	0.78835500	0.558318	C	A	Coronary heart disease || id:ieu-a-7	ieu-a-7	Coronary heart disease	Coronary heart disease || ||	TRUE	igd
5	rs2815752	1	72812440	0.010402	0.0098384	184305	0.29038200	0.611282	A	G	Coronary heart disease || id:ieu-a-7	ieu-a-7	Coronary heart disease	Coronary heart disease || ||	TRUE	igd
6	rs10938397	4	45182527	0.030606	0.0093485	184305	0.00106079	0.416076	G	A	Coronary heart disease || id:ieu-a-7	ieu-a-7	Coronary heart disease	Coronary heart disease || ||	TRUE	igd

3 对数据进行预处理,使其效应等位与效应量保持统一

完成暴露因素与结局GWAS数据的提取后,我们要对其进行预处理,使其效应等位保持统一,可以使用harmonise_data函数,方便的完成处理:

dat <- harmonise_data(
    exposure_dat = bmi_exp_dat, 
    outcome_dat = chd_out_dat
)

到这一步数据的准备工作就完成了,下一步可以开始分析

4 MR分析与可视化

4.1 MR分析

使用mr函数对处理好的数据dat 进行分析,结果如下

res <- mr(dat)
#> Analysing 'ieu-a-2' on 'ieu-a-7'
res
#>   id.exposure id.outcome                              outcome
#> 1     ieu-a-2    ieu-a-7 Coronary heart disease || id:ieu-a-7
#> 2     ieu-a-2    ieu-a-7 Coronary heart disease || id:ieu-a-7
#> 3     ieu-a-2    ieu-a-7 Coronary heart disease || id:ieu-a-7
#> 4     ieu-a-2    ieu-a-7 Coronary heart disease || id:ieu-a-7
#> 5     ieu-a-2    ieu-a-7 Coronary heart disease || id:ieu-a-7
#>                        exposure                    method nsnp         b
#> 1 Body mass index || id:ieu-a-2                  MR Egger   79 0.5024935
#> 2 Body mass index || id:ieu-a-2           Weighted median   79 0.3870065
#> 3 Body mass index || id:ieu-a-2 Inverse variance weighted   79 0.4459091
#> 4 Body mass index || id:ieu-a-2               Simple mode   79 0.3401554
#> 5 Body mass index || id:ieu-a-2             Weighted mode   79 0.3888249
#>           se         pval
#> 1 0.14396056 8.012590e-04
#> 2 0.07226598 8.541141e-08
#> 3 0.05898302 4.032020e-14
#> 4 0.15698810 3.330579e-02
#> 5 0.09240475 6.833558e-05

mr默认使用五种方法( MR Egger,Weighted median,Inverse variance weighted,Simple mode ,Weighted mode )

但我们可以额外指定方法,使用mr_method_list()查看当前支持的统计方法

mr_method_list()

obj	name	PubmedID	Description	use_by_default	heterogeneity_test
<chr>	<chr>	<chr>	<chr>	<lgl>	<lgl>
mr_wald_ratio	Wald ratio			TRUE	FALSE
mr_two_sample_ml	Maximum likelihood			FALSE	TRUE
mr_egger_regression	MR Egger	26050253		TRUE	TRUE
mr_egger_regression_bootstrap	MR Egger (bootstrap)	26050253		FALSE	FALSE
mr_simple_median	Simple median			FALSE	FALSE
mr_weighted_median	Weighted median			TRUE	FALSE
mr_penalised_weighted_median	Penalised weighted median			FALSE	FALSE
mr_ivw	Inverse variance weighted			TRUE	TRUE
mr_ivw_radial	IVW radial			FALSE	TRUE
mr_ivw_mre	Inverse variance weighted (multiplicative random effects)			FALSE	FALSE
mr_ivw_fe	Inverse variance weighted (fixed effects)			FALSE	FALSE
mr_simple_mode	Simple mode			TRUE	FALSE
mr_weighted_mode	Weighted mode			TRUE	FALSE
mr_weighted_mode_nome	Weighted mode (NOME)			FALSE	FALSE
mr_simple_mode_nome	Simple mode (NOME)			FALSE	FALSE
mr_raps	Robust adjusted profile score (RAPS)			FALSE	FALSE
mr_sign	Sign concordance test		Tests for concordance of signs between exposure and outcome	FALSE	FALSE
mr_uwr	Unweighted regression		Doesn't use any weights	FALSE	TRUE

在mr函数中,添加想要使用的方法即可:

mr(dat, method_list=c("mr_egger_regression", "mr_ivw"))
#> Analysing 'ieu-a-2' on 'ieu-a-7'
#>   id.exposure id.outcome                              outcome
#> 1     ieu-a-2    ieu-a-7 Coronary heart disease || id:ieu-a-7
#> 2     ieu-a-2    ieu-a-7 Coronary heart disease || id:ieu-a-7
#>                        exposure                    method nsnp         b
#> 1 Body mass index || id:ieu-a-2                  MR Egger   79 0.5024935
#> 2 Body mass index || id:ieu-a-2 Inverse variance weighted   79 0.4459091
#>           se        pval
#> 1 0.14396056 8.01259e-04
#> 2 0.05898302 4.03202e-14

4.2 敏感性分析

4.2.1 异质性检验 mr_heterogeneity

mr_heterogeneity(dat)
#>   id.exposure id.outcome                              outcome
#> 1     ieu-a-2    ieu-a-7 Coronary heart disease || id:ieu-a-7
#> 2     ieu-a-2    ieu-a-7 Coronary heart disease || id:ieu-a-7
#>                        exposure                    method        Q Q_df
#> 1 Body mass index || id:ieu-a-2                  MR Egger 143.3046   77
#> 2 Body mass index || id:ieu-a-2 Inverse variance weighted 143.6508   78
#>         Q_pval
#> 1 6.841585e-06
#> 2 8.728420e-06

4.2.2 水平多效性检验 mr_pleiotropy_test

MR Egger 回归中的截距是反应水平多效性的一个有效指标,可以通过mr_pleiotropy_test计算

mr_pleiotropy_test(dat)
#>   id.exposure id.outcome                              outcome
#> 1     ieu-a-2    ieu-a-7 Coronary heart disease || id:ieu-a-7
#>                        exposure egger_intercept          se      pval
#> 1 Body mass index || id:ieu-a-2    -0.001719304 0.003985962 0.6674266

4.3 可视化

4.3.1 散点图

对上述的MR结果与输入数据,使用mr_scatter_plot函数绘制散点图

res <-mr(dat)
#> Analysing 'ieu-a-2' on 'ieu-a-7'
p1 <-mr_scatter_plot(res, dat)

4.3.2 森林图

首先使用mr_singlesnp获取单个SNP的结果,然后使用mr_forest_plot绘制森林图

res_single <- mr_singlesnp(dat)
p2 <- mr_forest_plot(res_single)
p2[[1]]
#> Warning: Removed 1 rows containing missing values (geom_errorbarh).
#> Warning: Removed 1 rows containing missing values (geom_point).

4.3.2 漏斗图

首先使用mr_singlesnp获取单个SNP的结果,然后使用mr_funnel_plot绘制漏斗图

res_single <- mr_singlesnp(dat)
p4 <- mr_funnel_plot(res_single)
p4[[1]]

参考:

Hemani G, Tilling K, Davey Smith G (2017) Orienting the causal relationship between imprecisely measured traits using GWAS summary data. PLOS Genetics 13(11): e1007081. https://doi.org/10.1371/journal.pgen.1007081

Hemani G, Zheng J, Elsworth B, Wade KH, Baird D, Haberland V, Laurin C, Burgess S, Bowden J, Langdon R, Tan VY, Yarmolinsky J, Shihab HA, Timpson NJ, Evans DM, Relton C, Martin RM, Davey Smith G, Gaunt TR, Haycock PC, The MR-Base Collaboration. The MR-Base platform supports systematic causal inference across the human phenome. eLife 2018;7:e34408. doi: 10.7554/eLife.34408

https://mrcieu.github.io/TwoSam

多基因风险分数 PRS( Polygenic risk score)系列之六:metaGRS介绍

目录

  1. PRS回顾
  2. 为什么要构建metaGRS
  3. metaGRS构建方法
  4. 总结
  5. 参考

回顾

  1. GWASLab:多基因风险分数 PRS( Polygenic risk score)系列之一:概念入门
  2. GWASLab:多基因风险分数 PRS( Polygenic risk score)系列之二:使用PLINK计算PRS(C+T方法)
  3. GWASLab:多基因风险分数 PRS( Polygenic risk score)系列之三:使用PRSice计算PRS(C+T方法)
  4. ldpred2 (预留链接)
  5. prs-cs(预留链接)

为什么要构建metaGRS

以往的PRS研究中,PRS模型通常以单一的GWAS概括性数据为基础进行计算,但此方法往往不能达到较高的预测能力,主要是因为

  1. 有限的样本量
  2. 目标表型较为显著的异质性
  3. 对基因组覆盖的不完全
  4. 基因定型与插补存在较大不确定性

等原因。

在存在上述问题的情况下使用单一PRS进行预测会降低准确度,为了解决以上描述的问题,Michael Inouye等人最早在冠状动脉疾病(CAD)的预测中,引入了metaGRS的概念,类似于meta分析,meGRS将多个GRS进行合并得到metaGRS,以提升其风险预测能力。

metaGRS构建方法

本文以 Abraham,G等人在2019年发表的论文为例,简要介绍metaGRS的构建方法:

第一步:常规的单一PRS的计算

第二步:使用弹性网络来构建metaGRS,具体步骤如下所示

例如,Abraham,G等人构建的对IS缺血性中风的metaGRS中,纳入了如下的GRS,包括了AS(所有中风),以及中风的各个亚型(IS, SVS, LAS, CES),以及各个中风的风险因子(例如血压,BMI,2型糖尿病,冠状动脉疾病等)的GRS

注:弹性网络 elastic net:

在损失函数中同时加入L1 (Lasso回顾)与L2(Ridge回归)的正则项:

该计算可以通过R包glmnet实现

https://cran.r-project.org/web/packages/glmnet/index.html

第三步:最后和单一PRS时一样,需要使用独立样本对metaGRS进行验证


总结

目前使用metaGRS的研究还比较少,且集中于特定的表型(CAD和IS),但可以预计随着PRS研究数量不断增加,在未来metaGRS的应用也会随之增加。

参考

Inouye, Michael, et al. “Genomic risk prediction of coronary artery disease in 480,000 adults: implications for primary prevention.” Journal of the American College of Cardiology 72.16 (2018): 1883-1893.

Abraham, G., Malik, R., Yonova-Doing, E. et al. Genomic risk score offers predictive performance comparable to clinical risk factors for ischaemic stroke. Nat Commun 10, 5819 (2019). https://doi.org/10.1038/s41467-019-13848-1

Friedman, Jerome, Trevor Hastie, and Rob Tibshirani. “glmnet: Lasso and elastic-net regularized generalized linear models.” R package version 1.4 (2009): 1-24.

GWAS多表型分析-MTAG

本文内容:

  1. MTAG简介
  2. 核心概念
  3. 核心假设
  4. 算法简介
  5. 特点与不足
  6. 使用教程
  7. 参考

MTAG简介

MTAG( multi-trait analysis of GWAS)是一个使用GWAS概括新数据进行多表型联合分析的方法,相比于单表型的GWAS,MTAG可以利用关联表型的信息提升目标表型的检验统计power。

核心概念

MTAG的核心概念是当某个表型的GWAS结果与其他表型的结果存在相关性时,就可以通过整合其他表性的效应量来提高该表型效应量的估计值。

核心假设

对于不同表型,所有的SNP都共享同一个效应量的方差协方差矩阵

MTAG算法简单介绍如下所示:

特点:

  1. 使用GWAS概括性数据,不需要个体基因型信息
  2. 所使用的GWAS概括性数据可以有样本重叠,不需要独立样本,因为MTAG会通过二变量LD分数回归来调整样本重叠可能带来的误差。(GWASLab:通过Bivariate LD Score regression估计遗传相关性 genetic correlation
  3. MTAG可以计算对于特定表型每一个SNP的效应量估计值。
  4. MTAG计算相对高效,因为其每一步都有封闭解。

不足:

MTAG最主要的问题来源于那些与一个表型无关,而与另一个表型存在真实相关的SNP,MTAG对于此类SNP会有估计偏差,对于无关的SNP产生远离0的偏倚,造成假阳性。


使用教程

安装

MTAG是一个基于python的软件,可以从作者的github上下载:

https://github.com/JonJala/mtag

环境要求:

python2.7

  • numpy (>=1.13.1)
  • scipy
  • pandas (>=0.18.1)
  • argparse
  • bitarray (for ldsc)
  • joblib

示例数据下载:

neuroticism 与 subjective well-being gwas的概括性数据:

http://ssgac.org/documents/1_OA2016_hm3samp_NEUR.txt.gz

http://ssgac.org/documents/1_OA2016_hm3samp_SWB.txt.gz

输入格式 (GWAS的概括性数据)

snpid    chr    bpos    a1    a2    freq    z    pval    n

snpid,chr,bpos分别为snp的rsID,染色体号,与碱基位置,

a1,a2分别为效应等位(effect allele),与非效应等位

freq为a1的频率

z,pval,n则分别为检验的Z分数,p值,与样本量

(也可以使用beta与se来代替z,-use_beta_se

MTAG示例代码

python /[path]/mtag.py  \
	--sumstats 1_OA2016_hm3samp_NEUR.txt,1_OA2016_hm3samp_SWB.txt \
	--out ./tutorial_results_1.1NS \
	--n_min 0.0 \
  --stream_stdout

sumstats: 输入的GWAS的概括性数据, 使用逗号间隔

out: 输出文件的前缀

n_min:样本量阈值 (n低于此阈值的SNP会被舍弃)

stream_stdout : 将log文件实时输出到终端

如果使用东亚的LD分数参考,还需要指定

-ld_ref_panel 这个选项所使用的数据与LDSC相同,可以通过LDSC下载 (GWASLab:连锁不平衡分数回归 LD score regression -LDSChttps://alkesgroup.broadinstitute.org/LDSCORE/

输出

总共四组文件,

  1. .log 文件
  2. _sigma_hat.txt 存储估计的残差协方差矩阵
  3. _omega_hat.txt 存储估计的遗传方差矩阵
  4. _trait_1.txt 与_trait_2.txt文件则为MTAG的效应量估计结果

.log 文件:

head -n 20 tutorial_results_1.1NS.log
2021/10/31/10:43:32 PM 
<><><<>><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
<>
<> MTAG: Multi-trait Analysis of GWAS 
<> Version: 1.0.8
<> (C) 2017 Omeed Maghzian, Raymond Walters, and Patrick Turley
<> Harvard University Department of Economics / Broad Institute of MIT and Harvard
<> GNU General Public License v3
<><><<>><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
<> Note:  It is recommended to run your own QC on the input before using this program. 
<> Software-related correspondence: maghzian@nber.org 
<> All other correspondence: paturley@broadinstitute.org 
<><><<>><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>

Calling ./mtag.py \
--stream-stdout  \
--n-min 0.0 \
--sumstats 1_OA2016_hm3samp_NEUR.txt,1_OA2016_hm3samp_SWB.txt \
--out ./tutorial_results_1.1NS

MTAG效应量估计值文件(trait_1):

head tutorial_results_1.1NS_trait_1.txt
SNP	CHR	BP	A1	A2	Z	N	FRQ	mtag_beta	mtag_se	mtag_z	mtag_pval
rs2736372	8	11106041	T	C	-7.7161416126199995	111111.11111099999	0.4179	-0.032488048690724455	0.004191057650619415	-7.751754186899077	9.063170638233748e-15
rs2060465	8	11162609	T	C	7.69444599845	62500.0	0.6194	0.038971244976047835	0.005364284755639267	7.264947099439278	3.731842884367329e-13
rs10096421	8	10831868	T	G	-7.561098219	111111.11111099999	0.4646	-0.0306226260844897350.004144573386350028	-7.388607518772383	1.483744201034853e-13
rs2409722	8	11039816	T	G	-7.382616018080001	111111.11111099999	0.4627	-0.032187004733709536	0.004145724613962613	-7.763903233057294	8.235474166666265e-15
rs11991118	8	10939273	T	G	7.32202915636	111111.11111099999	0.5056	0.030603923980300953 0.004134432028802615	7.402207550419989	1.339389362466671e-13
rs2736371	8	11105529	A	G	-7.32009158327	62500.0	0.3806	-0.03759068256663257	0.005364284755639268	-7.007585219467501	2.42466338629309e-12
rs2736313	8	11086942	T	C	-7.24228035161	111111.11111099999	0.4646	-0.03068115211425502 0.004144573386350028	-7.402728641577938	1.3341420385130596e-13
rs876954	8	8310923	A	G	-7.15791677597	62500.0	0.4813	-0.03422779585744538	0.005212736369758894 -6.566185862767606	5.162037825451834e-11
rs1533059	8	8684953	A	G	-7.074128564239999	62500.0	0.4478	-0.035027431607855014	0.00523771146606734	-6.687545091932079	2.269452965596589e-11

其中mtag_beta mtag_se mtag_z mtag_pval列为这一个表型mtag计算后的结果。

参考:

Turley, P., Walters, R.K., Maghzian, O.et al.Multi-trait analysis of genome-wide association summary statistics using MTAG.Nat Genet50,229–237 (2018). https://doi.org/10.1038/s41588-017-0009-4

Tutorial 1: The Basics · JonJala/mtag Wiki

使用PLINK检测纯合性片段 ROH(Runs of homozygosity)


本文内容

ROH定义
不同群体ROH的特征
检测ROH的方法
使用PLINK检测ROH

ROH的定义

对于个体,其基因组上的一段区域内所有位点均为纯合的区域,被称为一段纯合性片段 (Runs of homozygosity,ROH). ROH的出现通常是由于个体来自父母双方的单倍体型是相同的,而这个单倍体型又是从过去某个时间点的共同祖先继承而来。ROH的概念不依赖于已知的家系,也不需要一个基线群体。但实际操作中,ROH通常规定有一个基于可用基因型密度的最小的长度,以判别是因为IBD而产生的ROH,或仅仅是概率偶然。

不同群体ROH的特征

不同的群体史会产生不同的长短ROH的分布:

在一个非近交群体(outbred populations )中,ROH的总数量与总长度与该群体的有效样本量有关,较小的群体趋向于有更多的ROH而较大的群体则趋向于有较少的ROH。

在混合群体(Admixed populations)中,由于该群体的祖先群体共享的祖先成分较远,所以混合群体的ROH通常少于其相应的祖先群体。

在近亲群体(Consanguineous communities)中,与非近交群体相比,会有更长的ROH,这是由于时间上较近的近亲交配,

经历过人口瓶颈( population bottleneck)的群体则会携带大量的较短的ROH,显示其更深层的父母的亲缘关系。

而经历过人口瓶颈且叠加近亲交配的群体则会有最高程度的ROH。

检测ROH的方法

目前使用最多的检测方法为PLINK中采用的观测法

PLINK采用一个固定大小的滑窗,对每条染色体进行扫描,以寻找连续的纯合SNP。 PLINK首先计算包含某个SNP的完全纯合滑窗的比例,如果该比例超过事先设定好的阈值,那么这个SNP就被认为是在一段ROH中。在每个滑窗中可以指定一定数量的缺失或是杂合的SNP,以包含基因定型错误,失败或是稀有变异等情况。最后,如果在某个片段中连续纯合SNP的数量超过一个数量或距离阈值(SNP数量或是染色体的距离),那么就可以判定这个片段是ROH。

使用PLINK检测ROH

示例代码如下所示:

plink \
        --bfile ${input} \
        --homozyg \
        --homozyg-density 50 \ 一段ROH中每50kb必须有1个SNP
        --homozyg-gap 100 \ 如果连续两个SNP的间隔大于100kb,那么就不能归为同一个ROH
        --homozyg-kb 500 \ 只检测长度大于500kb的ROH
        --homozyg-snp 50 \ 只检测长度超过50个SNP的ROH
        --homozyg-window-het 1 \ ROH滑窗中可以允许有一个SNP位点为杂合
        --homozyg-window-snp 50 \ 滑窗大小为50个SNP
        --homozyg-window-threshold 0.05 \ 包含某个SNP的完全纯合滑窗的比例至少为5%
        --out ${output}

计算完成后会得到 .hom 与.hom.indiv 等文件

.hom 文件包含了每段ROH的具体信息

FID IID PHE CHR SNP1 SNP2 POS1 POS2 KB NSNP DENSITY PHOM PHET
1 1 -9 chr1 rsxxx rsxxx 12345 67891 5.5 123 9.17 0.99 0.07

hom.indiv文件则是包含了对每个个体ROH汇总信息,包括总长度与总个数

FID IID PHE NSEG KB KBAVG
1   1   -9  50   75000  1500

这里的NSEG就是NROH,KB则是SROH

根据上面两个文件就可以做出SROH-NROH图

或是 ROH长度分层的分布图

来判断目标群体的群体特征。

参考:

  1. Ceballos, F. C., Joshi, P. K., Clark, D. W., Ramsay, M. & Wilson, J. F. Runs of homozygosity: windows into population history and trait architecture. Nat. Rev. Genet. 2018 194 19, 220–234 (2018).https://www.nature.com/articles/nrg.2017.109
  2. Identity-by-descent – PLINK 1.9

RaPID高效检测IBD片段 (IBD segments detection)

本文内容:

RaPID简介
RaPID算法
RaPID教程
注意事项
参考

RaPID简介

RaPID是一款用于在基因组数据中检测IBD(identity-by-descent segments)片段的工具,其特点是应用了PBWT(Positional Burrows-Wheeler Transform)算法,能够快速高效地完成检测。BWT被广泛应用于文件压缩与序列比对等领域,序列比对的BWA软件也利用的是这个算法。

IBD回顾:GWASLab:状态同源 / 血缘同源 IBS/ IBD

RaPID算法示意图

RaPID算法简介

第一步,通过从每个窗口(wi)内随机取一个变异位点,对输入的定像后的基因型进行多重随机投影。

第二步,对每个投影后的面板使用PBWT(Positional Burrows-Wheeler Transform)算法,找出截断值L以上长度的精确匹配序列。

第三步,收集上一步的精确匹配序列,当某一区域精确匹配序列多于一定数量时,就判定为IBD片段。

图中例子各参数为:长度的截断值为10,窗口大小为5,重复次数为4,成功判定需要的次数为2,不足2次的精确匹配被舍弃


RaPID教程

下载地址:

https://github.com/ZhiGroup/RaPID

RaPID输入文件:

  1. 遗产图谱文件格式(tab间隔):

<site_number> <genetic_location>

每一行包含位点索引以及位点的遗传位置,位点的顺序要与输入VCF文件中位点顺序相同。

该文件的位点顺序应该是单调上升的,且不能有缺失。

RaPID也提供了两个python脚本可以用来对异常图谱进行过滤与插值填充:

对 genetic mapping file 进行过滤

python filter_mapping_file.py <genetic_map> <filtered_map>

对遗传位置进行插值填充, 使位点与输入VCF中位点一一匹配

python interpolate_loci.py <filtered_map> <vcf_input_gzip> <output_map_file>

2. 定相过的VCF文件

参考:GWASLab:Eagle2单倍型定相工具 Haplotype phasing

RaPID_v.1.7 版本 具体使用方法

./RaPID_v.1.7 \
	-i <input_file_vcf_compressed> \
	-g <genetic_mapping_file> \
	-d <min_length_in_cM> \
	-o <output_folder> \
	-w <window_size> \
	-r <#runs> \
	-s <#success>

使用作者提供的演示数据:

./RaPID_v.1.7 \
	-i 4k_1e7.vcf.gz \
	-g 4k_1e7_e0.001.g \
	-d 5 \
	-w 250 \
	-r 10 \
	-s 2 \
	-o output_folder

RaPID会将在样本两两之间检测到的所有IBD片段以以下格式输出:

<chr_name> <sample_id1> <sample_id2> <hap_id1> <hap_id2> <starting_pos_genomic> <ending_pos_genomic> <genetic_length> <starting_site> <ending_site>

执行后会得到名为 results.max.gz 的结果

Create sub-samples..
Done!

zcat results.max.gz | head
chr1	0	256	0	0	189	9999752	9.99956	0	94991
chr1	6	1510	1	1	3282417	9616920	6.3345	31000	91249
chr1	18	1801	0	1	189	5186009	5.18582	0	49249
chr1	33	435	0	0	3523968	8873991	5.35002	33250	84249
chr1	42	1854	0	0	1002623	6026274	5.02365	9500	57249
chr1	44	794	1	1	3282417	9797410	6.51499	31000	92999
chr1	51	1394	1	0	3337555	9999752	6.6622	31500	94991
chr1	73	88	1	1	149874	6820265	6.67039	1500	64749
chr1	80	199	0	1	1831845	6974084	5.14224	17500	66249
chr1	82	1849	0	0	3445503	8974078	5.52858	32500	85249

注意事项

如果输入文件的变异密度较低的话,需要相应的减小窗口大小 -w 的值。 例如,对于UKBB,位点密度比示例数据中低了80倍,那么窗口小就应相应的从-w 250减小到-w 3.

参考:

  1. Naseri, Ardalan, Xiaoming Liu, Kecong Tang, Shaojie Zhang, and Degui Zhi. “RaPID: ultra-fast, powerful, and accurate detection of segments identical by descent (IBD) in biobank-scale cohorts.” Genome biology 20, no. 1 (2019): 143;
  2. Ultra-fast Identity by Descent Detection in Biobank-Scale Cohorts using Positional Burrows-Wheeler Transform Ardalan Naseri, Xiaoming Liu, Shaojie Zhang, Degui Zhi bioRxiv 103325;

使用UMAP对基因组数据降维,对比PCA

本文内容:
UMAP简介
在群体遗传学中的应用(与PCA的不同)
UMAP使用方法
使用对示例千人基因组数据进行降维
参考

关键词:UMAP, PCA, t-SNE, PCA-UMAP, 基因组降维


UMAP 简介

UMAP(uniform manifold approximation and projection)是近年来新出现的一种相对灵活的非线性降维算法,目前在统计遗传学等领域也有了较为广泛的应用。

UMAP的理论基础基于流形理论(manifold theory)与拓扑分析

主要基于以下假设:

  1. 存在一个数据均一分布的流形。
  2. 这个目标流形是局部相连的。
  3. 该算法的主要目标是保存此流形的拓扑结构。

总体来看,UMAP利用了局部流形近似,并拼接模糊单纯集合表示(local fuzzy simplicial set representation),以构建高维数据的拓扑表示。在给定低维数据时,UMAP会采取相似的手法构建一个等价的拓扑表示。最后UMAP会对低维空间中数据表示的布局进行最优化,以最小化高维和低维两种拓扑表示之间的交叉熵(cross-entropy)。

算法概览如下:

UMAP与其他降维方法对比:

快,准确:需要降维数据维度增加时,t-SNE计算时间呈指数型增长,umap则线性增长。


在群体遗传学中的应用:

在处理大样本基因组数据时,通常我们会对数据进行降维,以达到数据可视化,并发现存在亲缘关系的样本。

最常用的方法是主成分分析PCA:GWASLab:群体分层与主成分分析教程 Population structure & PCA

UMAP与PCA的不同:

但由于PCA投影找的是最大化方差的方向,通常会忽略掉其他方向的方差,也就是说PCA倾向于发现较大的人群结构,而忽略精细的结构,但UMAP的思路则与PCA不同,如第一节所述,其主要目的是保留其与邻接样本的拓扑结构,也就是更为精细的局部人群结构,而非整体结构。

目前UMAP已经被广泛应用于群体遗传学的研究之中。


下面简单介绍UMAP使用方法:

UMAP (是一个python包),使用方法:

通过pip或conda安装:

pip install umap-learn
#或者
conda install -c conda-forge umap-learn

使用文档详见:https://umap-learn.readthedocs.io/en/latest/parameters.html

一个最简单的示例:

#导入umap包
import umap   

#创建UMAP实例
reducer = umap.UMAP()   

#使用你的数据对该实例进行训练,得到嵌入后的结果
embedding = reducer.fit_transform(your_data)

UMAP() 的主要参数,可参考上述算法概览

  • n_neighbors : 邻接样本的数量,默认15
  • min_dist :控制布局的参数,取值范围0-1,默认0.1
  • n_components :维数,默认2

使用基因型数据进行实际演示:

教程改编与数据改编自:

Sakaue, S., Hirata, J., Kanai, M. et al. Dimensionality reduction reveals fine-scale structure in the Japanese population with consequences for polygenic risk prediction. Nat Commun 11, 1569 (2020). https://doi.org/10.1038/s41467-020-15194-z

代码与数据下载:

https://github.com/saorisakaue/Genotype-dimensionality-reduction

数据在umap_data中:1KG.selected.bed/bim/fam

使用软件:

PLINK,python(umap,pandas,matplotlib)

注意:

  1. UMAP只接受完整的数据,对于有缺失的基因型数据要事先对缺失的SNP进行填补以得到完整的数据,填补方法可参考:GWASLab:Eagle2单倍型定相工具 Haplotype phasing
  2. 对于PLINK格式的数据,一般需要在LD-pruning 后,转换为 genotype matrix

输入文件预处理:

#如果数据有缺失请先进行填补

#首先进行LD-pruning
GENOTYPE="./data_umap/1KG.selected"

plink \
 --bfile ${GENOTYPE} \
 --indep-pairwise 50 5 0.2 \
 --maf 0.01 \
 --hwe 1E-6 \
 --out ${GENOTYPE}

#对二进制plink文件进行转换,转为0/1/2的文本文件
plink \
 --bfile ${GENOTYPE} \
 --extract ${GENOTYPE}.prune.in \
 --recode A \
 --out ${GENOTYPE}.pruned

# 2) 抽取出 genotype matrix
cat ${GENOTYPE}.pruned.raw | cut -d " " -f7- | awk 'NR>1{print}' > ${GENOTYPE}.pruned.geno.txt

log文件如下:

PLINK v1.90b6.21 64-bit (19 Oct 2020)          www.cog-genomics.org/plink/1.9/
(C) 2005-2020 Shaun Purcell, Christopher Chang   GNU General Public License v3
Logging to ./data_umap/1KG.selected.log.
Options in effect:
  --bfile ./data_umap/1KG.selected
  --hwe 1E-6
  --indep-pairwise 50 5 0.2
  --maf 0.01
  --out ./data_umap/1KG.selected

191875 MB RAM detected; reserving 95937 MB for main workspace.
Allocated 3037 MB successfully, after larger attempt(s) failed.
120489 variants loaded from .bim file.
50 people (25 males, 25 females) loaded from .fam.
Using 1 thread (no multithreaded calculations invoked).
Before main variant filters, 50 founders and 0 nonfounders present.
Calculating allele frequencies... done.
--hwe: 14 variants removed due to Hardy-Weinberg exact test.
861 variants removed due to minor allele threshold(s)
(--maf/--max-maf/--mac/--max-mac).
119614 variants and 50 people pass filters and QC.
Note: No phenotypes present.
Pruned 5127 variants from chromosome 1, leaving 4909.
Pruned 5171 variants from chromosome 2, leaving 4680.
Pruned 4052 variants from chromosome 3, leaving 3919.
Pruned 3398 variants from chromosome 4, leaving 3517.
Pruned 3594 variants from chromosome 5, leaving 3586.
Pruned 4346 variants from chromosome 6, leaving 3628.
Pruned 3298 variants from chromosome 7, leaving 3193.
Pruned 3421 variants from chromosome 8, leaving 3027.
Pruned 2854 variants from chromosome 9, leaving 2895.
Pruned 3445 variants from chromosome 10, leaving 3244.
Pruned 3235 variants from chromosome 11, leaving 3021.
Pruned 2936 variants from chromosome 12, leaving 3020.
Pruned 2281 variants from chromosome 13, leaving 2326.
Pruned 1916 variants from chromosome 14, leaving 2070.
Pruned 1875 variants from chromosome 15, leaving 1943.
Pruned 1848 variants from chromosome 16, leaving 2005.
Pruned 1589 variants from chromosome 17, leaving 1839.
Pruned 1744 variants from chromosome 18, leaving 1925.
Pruned 947 variants from chromosome 19, leaving 1208.
Pruned 1528 variants from chromosome 20, leaving 1620.
Pruned 874 variants from chromosome 21, leaving 887.
Pruned 759 variants from chromosome 22, leaving 914.
Pruning complete.  60238 of 119614 variants removed.
Marker lists written to ./data_umap/1KG.selected.prune.in and
./data_umap/1KG.selected.prune.out .
PLINK v1.90b6.21 64-bit (19 Oct 2020)          www.cog-genomics.org/plink/1.9/
(C) 2005-2020 Shaun Purcell, Christopher Chang   GNU General Public License v3
Logging to ./data_umap/1KG.selected.pruned.log.
Options in effect:
  --bfile ./data_umap/1KG.selected
  --extract ./data_umap/1KG.selected.prune.in
  --out ./data_umap/1KG.selected.pruned
  --recode A

191875 MB RAM detected; reserving 95937 MB for main workspace.
Allocated 3037 MB successfully, after larger attempt(s) failed.
120489 variants loaded from .bim file.
50 people (25 males, 25 females) loaded from .fam.
--extract: 59376 variants remaining.
Using 1 thread (no multithreaded calculations invoked).
Before main variant filters, 50 founders and 0 nonfounders present.
Calculating allele frequencies... done.
59376 variants and 50 people pass filters and QC.
Note: No phenotypes present.
--recode A to ./data_umap/1KG.selected.pruned.raw ... done.

接下来使用umap的默认参数进行降维处理:

import umap

prefix = sys.argv[1]
filename = prefix + ".pruned.geno.txt"
pre_data = pd.read_table(filename, delim_whitespace=True, header=None, low_memory=False)
data = pre_data.dropna(how='any', axis=1)

# UMAP
outfile = prefix + ".umap.txt"
d_embedding = umap.UMAP().fit_transform(data)
pd.DataFrame(d_embedding).to_csv(outfile, sep='\t', header=False, index=False)

查看d_embedding ,基因组数据已经降至2维,结果如下:

array([[ 29.74708  ,   3.0977843],
       [ 29.213293 ,   3.1712177],
       [  8.758959 ,  -1.9003359],
       [  8.377356 ,  -1.4676492],
       [ 29.458044 ,   3.3701472],
       [ 29.87717  ,   3.4556358],
       [ 29.3555   ,   3.8484392],
       [ 28.955818 ,   3.5634878],
       [ 29.105188 ,   2.8024642],
       [ 29.197195 ,   3.7704961],
       [ 29.347229 ,   4.2163496],
       [ 29.865662 ,   3.1569576],
       [  8.503107 ,  -1.3564333],
       [-24.176699 , -14.017474 ],
       [-23.141544 , -13.751009 ],
       [  8.204682 ,  -1.8065634],
       [ 29.94206  ,   2.8537552],
       [-23.501389 , -13.829134 ],
       [ 29.065151 ,   4.255709 ],
       [-23.86171  , -13.711441 ],
       [-23.297297 , -13.290715 ],
       [ 30.9667   , -10.477952 ],
       [-22.91213  , -13.484747 ],
       [-23.249172 , -14.22486  ],
       [-22.951435 , -13.851592 ],
       [ 30.514542 , -11.441013 ],
       [ 30.728407 , -11.229405 ],
       [ 31.13736  , -11.319468 ],
       [ 30.189419 , -10.865067 ],
       [ 30.20413  , -11.283942 ],
       [ 30.89431  , -11.590417 ],
       [ 29.568645 ,   2.9131896],
       [ 29.632095 ,   2.6519256],
       [-23.177608 , -14.538039 ],
       [-23.335829 , -13.95216  ],
       [  8.488959 ,  -2.0645304],
       [  8.731548 ,  -1.8205943],
       [  8.5880165,  -1.6314453],
       [-23.663996 , -13.476801 ],
       [-23.71588  , -14.627886 ],
       [-23.864864 , -14.236027 ],
       [-23.965855 , -14.178329 ],
       [-23.203787 , -14.796338 ],
       [-23.587828 , -14.443732 ],
       [-22.973204 , -14.444413 ],
       [ 30.451714 , -10.90268  ],
       [ 31.011879 , -11.050354 ],
       [ 30.863823 , -10.923892 ],
       [ 30.679998 , -11.574213 ],
       [ 30.77399  , -10.824773 ]], dtype=float32)

绘图后可以看到样本被清楚地分到了4个cluster:

可以自己试着改变UMAP()的参数,看看有什么变化,这里不过多演示,(下图为UMAP(min_dist=1)的结果)

当然,也可以使用PCA后各个样本主成分PCs进行UMAP (PCA-UMAP):

PCA方法:GWASLab:群体分层与主成分分析教程 Population structure & PCA

可以参考:Sakaue, S., Hirata, J., Kanai, M. et al. Dimensionality reduction reveals fine-scale structure in the Japanese population with consequences for polygenic risk prediction. Nat Commun 11, 1569

该文章对日本人群结构做了分析,并对比了各种降维方法的结果,强烈推荐。

参考

McInnes, L, Healy, J, UMAP: Uniform Manifold Approximation and Projection for Dimension Reduction, ArXiv e-prints 1802.03426, 2018

Sakaue, S., Hirata, J., Kanai, M. et al. Dimensionality reduction reveals fine-scale structure in the Japanese population with consequences for polygenic risk prediction. Nat Commun 11, 1569

Diaz-Papkovich, A., Anderson-Trocmé, L. & Gravel, S. A review of UMAP in population genetics. J. Hum. Genet. 66, 85–91 (2021).

https://umap-learn.readthedocs.io

多基因风险分数 PRS( Polygenic risk score)系列之三:使用PRSice计算PRS(C+T方法)

前情回顾:

本文内容:

1 PRSice-2简介与下载
2 PRSice-2教程
3 输入文件
4 C+T 参数
5 PRS计算
6 经验p值计算
7 示例演示
8 参考

PRSice-2简介与下载

PRSice-2是一款方便快捷的PRS计算软件,其主要功能是可以自动化执行一系列PLINK中用于PRS计算的功能,本文将简要讲解PRSice2并演示C+T方法的PRS计算。

PRSice下载链接:

https://www.prsice.info/

演示数据下载 (由教程原作者提供,与系列之二PLINK教程中使用的示例数据相同):

https://drive.google.com/file/d/1x_G0Gxk9jFMY-PMqwtg6-vdEyUPp5p5u/view


PRSice-2教程:

首先,需要的输入文件包括:

1 .base datatset GWAS概括性数据
2 .target dataset 目标数据集
3 .Phenotype files 表型文件
4. covariate files 协变量文件
5 .LD reference (optional: <500 samples) LD参考面板

1.base datatset

通常为GWAS的概括性数据,示例输入文件如下

如果base dataset的格式与示例不同,则可以通过以下选项自行指定

通过列名指定
--snp SNP --chr CHR --bp BP --A1 A1 --A2 A2 --stat OR --pvalue P
或者通过列数指定
--snp 0 --chr 1 --bp 2 --A1 3 --A2 4 --stat 5 --pvalue 7 --index

2.Target Dataset 目标数据集

目标数据集即为目标群体的基因型或填补后的基因型,目前支持PLINK的二进制格式,与BGEN格式

plink文件通过 -target 来指定,输入bed,bim,fam文件的前缀即可

bgen文件还需额外加上 -type bgen 选项

3 & 4 Phenotype & Covariates files

通过–pheno来指定表型文件,该文件是一个tab或space间隔的文本文件,前两列为FID与IID,第三列开始为表型或协变量,例如

FID	IID	Height
HG00096	HG00096	169.132168767547
HG00097	HG00097	171.256258630279
HG00099	HG00099	171.534379938588
HG00101	HG00101	169.850176470551
HG00102	HG00102	172.788360878389
HG00103	HG00103	169.862973824923
HG00105	HG00105	168.939248611414
HG00107	HG00107	168.972346393861
HG00108	HG00108	171.311736719186

如果表性文件中有多列,可以通过–pheno-col来指定表型的列名。

协变量文件格式与表型的一致。

5 LD reference

当样本量小于500时,建议额外指定LD参考面板, 输入格式与上述Target Dataset一致

--ld <LD refernce>

C+T 参数

Clumping

这里的clumping方法与plink的大体一致,可以参考:

SNP的LD剪枝与聚集 LD pruning & clumping

多基因风险分数 PRS( Polygenic risk score)系列之二:使用PLINK计算PRS(C+T方法)

Clumping 参数可以通过 –clump-kb, –clump-r2 与–clump-p 选项来改变。

PRS计算

prsice2提供了多种计算PRS的模型与公式,默认的为计算均值,如下图所述

其他参数

可以指定运行所占用的内存,线程数,以及随机种子

--memory
--thread
--seed

经验p值计算

PRS的计算涉及到参数优化,那么必然会有过拟合的问题。

为了解决这一问题,通常有以下三种方法:

  1. 在独立的检验样本中评估
  2. 交叉验证
  3. 计算经验p值

PRSice2采用了第三种方法,通过permutation 来计算经验p值


PRS计算示例演示

使用之前下载的示例文件,执行以下命令:

Rscript PRSice.R \
    --prsice PRSice_linux \
    --base Height.QC.gz \
    --target EUR.QC \
    --binary-target F \
    --pheno EUR.height \
    --cov EUR.covariate \
    --base-maf MAF:0.01 \
    --base-info INFO:0.8 \
    --stat OR \
    --or \
    --out EUR

其中

prsice	PRSice_xxx	指定PRSice二进制文件路径 
base	        Height.QC.gz	 输入的base的GWAS summary statistic target	
EUR.QC	指定target的plink文件名的前缀 
binary-target	F	指定表型是否为二进制表型,F为否 
pheno	EUR.height	提供表型文件 
cov	EUR.covariate	        提供协变量文件 
base-maf	MAF:0.01	使用base文件中MAF列来过滤掉maf<0.01的变异 
base-info	INFO:0.8	使用base文件中INFO列来过滤掉info<0.8的变异 stat	
OR	base文件中包含效应量的列名 
or	-	指定效应量的形式为OR 
out	EUR	指定输出前缀为EUR

执行后log文件如下所示:

PRSice 2.3.3 (2020-08-05) 
<https://github.com/choishingwan/PRSice>
(C) 2016-2020 Shing Wan (Sam) Choi and Paul F. O'Reilly
GNU General Public License v3
If you use PRSice in any published work, please cite:
Choi SW, O'Reilly PF.
PRSice-2: Polygenic Risk Score Software for Biobank-Scale Data.
GigaScience 8, no. 7 (July 1, 2019)
2021-09-06 12:47:56
PRSice_linux \
    --a1 A1 \
    --a2 A2 \
    --bar-levels 0.001,0.05,0.1,0.2,0.3,0.4,0.5,1 \
    --base Height.QC.gz \
    --base-info INFO:0.8 \
    --base-maf MAF:0.01 \
    --binary-target F \
    --bp BP \
    --chr CHR \
    --clump-kb 250kb \
    --clump-p 1.000000 \
    --clump-r2 0.100000 \
    --cov EUR.covariate \
    --interval 5e-05 \
    --lower 5e-08 \
    --num-auto 22 \
    --or  \
    --out EUR \
    --pheno EUR.height \
    --pvalue P \
    --seed 3490962723 \
    --snp SNP \
    --stat OR \
    --target EUR.QC \
    --thread 1 \
    --upper 0.5

Initializing Genotype file: EUR.QC (bed) 

Start processing Height.QC 
================================================== 

Base file: Height.QC.gz 
GZ file detected. Header of file is: 
CHR	BP	SNP	A1	A2	N	SE	P	OR	INFO	MAF 

Reading 100.00%
499617 variant(s) observed in base file, with: 
499617 total variant(s) included from base file 

Loading Genotype info from target 
================================================== 

483 people (232 male(s), 251 female(s)) observed 
483 founder(s) included 

489805 variant(s) included 

Phenotype file: EUR.height 
Column Name of Sample ID: FID+IID 
Note: If the phenotype file does not contain a header, the 
column name will be displayed as the Sample ID which is 
expected. 

There are a total of 1 phenotype to process 

Start performing clumping 

Clumping Progress: 100.00%
Number of variant(s) after clumping : 193758 

Processing the 1 th phenotype 

Height is a continuous phenotype 
11 sample(s) without phenotype 
472 sample(s) with valid phenotype 

Processing the covariate file: EUR.covariate 
============================== 

Include Covariates: 
Name	Missing	Number of levels 
Sex	0	- 
PC1	0	- 
PC2	0	- 
PC3	0	- 
PC4	0	- 
PC5	0	- 
PC6	0	- 

After reading the covariate file, 472 sample(s) included in 
the analysis 

Start Processing
Processing 100.00%
There are 1 region(s) with p-value less than 1e-5. Please 
note that these results are inflated due to the overfitting 
inherent in finding the best-fit PRS (but it's still best 
to find the best-fit PRS!). 
You can use the --perm option (see manual) to calculate an 
empirical P-value. 

Begin plotting
Current Rscript version = 2.3.3
Plotting Bar Plot
Plotting the high resolution plot

默认输出结果中有两张图,以及两个文本文件:

第一张为柱状图可以看到不同P值阈值下PRS模型R2的大小:

第二种则是高精度图,表示所有p值阈值的模型拟合:

第一个后缀为prsice的文本文件各个C+T参数的模型的结果:

head EUR.prsice
Pheno	Set	Threshold	R2	P	Coefficient	Standard.Error	Num_SNP
-	Base	5e-08	0.0192512	0.000644758	563.907	164.163	1999
-	Base	5.005e-05	0.0619554	5.24437e-10	3080.12	485.501	7615
-	Base	0.00010005	0.0713244	2.27942e-11	3816.99	557.044	9047
-	Base	0.00015005	0.0785205	2.00391e-12	4362.01	603.601	10014
-	Base	0.00020005	0.0799241	1.24411e-12	4666.13	639.344	10756
-	Base	0.00025005	0.0820088	6.11958e-13	4947.48	668.217	11365
-	Base	0.00030005	0.0818422	6.47686e-13	5146.63	695.905	11884
-	Base	0.00035005	0.0836689	3.47353e-13	5392.8	720.237	12373
-	Base	0.00040005	0.0849879	2.21299e-13	5589.41	739.972	12817

第二个后缀为best的文本文件则为使用最优模型计算得到的target样本的PRS值

head EUR.best
FID IID In_Regression PRS
HG00096 HG00096 Yes -1.90234673e-05
HG00097 HG00097 Yes 1.27505253e-05
HG00099 HG00099 Yes -3.46628033e-06
HG00101 HG00101 Yes 9.02490969e-06
HG00102 HG00102 Yes 1.69546146e-05
HG00103 HG00103 Yes 1.91180157e-05
HG00105 HG00105 Yes 4.62832238e-06
HG00107 HG00107 Yes 7.59715813e-07
HG00108 HG00108 Yes 1.25453063e-05

参考:

https://www.prsice.info/