GEMMA演示脚本

1.计算亲缘关系矩阵

# BIMBAM格式文件
gemma \
-g mouse_hs1940.geno.txt.gz \
-p mouse_hs1940.pheno.txt \
-a mouse_hs1940.anno.txt \
-gk 2 \
-o mouse_hs1940

# plink格式文件
gemma \
-bfile mouse_hs1940 \
-gk 2 \
-o mouse_hs1940test

# The estimated relatedness matrix should look like this:
0.3350590  -0.0227226  0.0103535 ...
-0.0227226  0.3035960 -0.0253762 ...
0.0103535  -0.0253762  0.3536100 ...
....................................

2.单性状LMM GWAS分析

# BIMBAM格式文件
gemma \
-g mouse_hs1940.geno.txt.gz \
-p mouse_hs1940.pheno.txt \
-n 1 \
-a mouse_hs1940.anno.txt \
-k ./output/mouse_hs1940.cXX.txt \
-lmm 1 \
-o mouse_hs1940_CD8_lmm
# plink格式文件
gemma \
-bfile mouse_hs1940 \
-n 1 \
-k ./output/mouse_hs1940.cXX.txt \
-lmm 1 \
-o mouse_hs1940_CD8_lmm

# The result for top 5 SNPs should look like this:
# chr rs ps n_miss allele1 allele0 af beta se l_remle p_wald
# 1 rs3683945 3197400 0 A G 0.443 -7.788665e-02 6.193502e-02 4.317993e+00 2.087616e-01
# 1 rs3707673 3407393 0 G A 0.443 -6.654282e-02 6.210234e-02 4.316144e+00 2.841271e-01
# 1 rs6269442 3492195 0 A G 0.365 -5.344241e-02 5.377464e-02 4.323611e+00 3.204804e-01
# 1 rs6336442 3580634 0 A G 0.443 -6.770154e-02 6.209267e-02 4.315713e+00 2.757541e-01
# 1 rs13475700 4098402 0 A C 0.127 -5.659089e-02 7.175374e-02 4.340145e+00 4.304306e-01

# The log file also contains pve estimates and its standard error
# pve estimate in the null model = 0.608801
# se(pve) in the null model = 0.032774

3.多性状LMM GWAS分析

## To perform association tests with a multivariate linear mixed model, for two phenotypes CD8 (column 1) and MCH (column 6):
## Notice that the number of individuals in this analysis is different from that above, so the allele frequencies are different between the two analyses
# BIMBAM格式文件
gemma \
-g mouse_hs1940.geno.txt.gz \
-p mouse_hs1940.pheno.txt \
-n 1 6 \
-a mouse_hs1940.anno.txt \
-k ./output/mouse_hs1940.cXX.txt \
-lmm 1\
-o mouse_hs1940_CD8MCH_lmm
# plink格式文件
gemma \
-bfile mouse_hs1940 \
-n 1 6 \
-k ./output/mouse_hs1940.cXX.txt \
-lmm 1\
-o mouse_hs1940_CD8MCH_lmm

# The result for top 5 SNPs should look like this:
# chr rs ps n_miss allele1 allele0 af beta_1 beta_2 Vbeta_1_1 Vbeta_1_2 Vbeta_2_2 p_wald
# 1 rs3683945 3197400 0 A G 0.451 -9.611213e-02 8.165302e-02 3.966873e-03 -2.526118e-04 5.540032e-03 1.862363e-01
# 1 rs3707673 3407393 0 G A 0.451 -8.464470e-02 7.130876e-02 3.986286e-03 -2.593467e-04 5.571616e-03 2.757067e-01
# 1 rs6269442 3492195 0 A G 0.377 -7.146771e-02 5.179252e-02 3.157023e-03 -7.187157e-05 4.276041e-03 3.317712e-01
# 1 rs6336442 3580634 0 A G 0.451 -8.502513e-02 6.813728e-02 3.985054e-03 -2.577585e-04 5.568602e-03 2.835426e-01
# 1 rs13475700 4098402 0 A C 0.128 -6.727883e-02 1.685363e-01 5.597160e-03 -1.366799e-04 7.574216e-03 1.060482e-01

# The log file also contains Vg and Ve estimates and their standard errors
## REMLE estimate for Vg (遗传方差)in the null model:
# 1.39398
# -0.226714 2.08168
## se(Vg):标准误
# 0.156661
# 0.136319 0.235858

## REMLE estimate for Ve (误差方差)in the null model:
# 0.348882
# 0.0490525 0.414433

## se(Ve):标准误
# 0.0206226
# 0.0166233 0.0266869

4.先填充缺失表型,再做LMM GWAS分析

# Since there are individuals with partially missing phenotypes, one can impute these missing values before association tests
# BIMBAM格式文件
gemma \
-g mouse_hs1940.geno.txt.gz \
-p mouse_hs1940.pheno.txt \
-n 1 6 \
-a mouse_hs1940.anno.txt \
-k ./output/mouse_hs1940.cXX.txt \
-predict \
-o mouse_hs1940_CD8MCH_prdt

gemma \
-g mouse_hs1940.geno.txt.gz \
-p ./output/mouse_hs1940_CD8MCH_prdt.prdt.txt \
-n 1 2 \
-a mouse_hs1940.anno.txt \
-k ./output/mouse_hs1940.cXX.txt \
-lmm 1\
-o mouse_hs1940_CD8MCH_prdt_lmm

###############################################
# plink格式文件
gemma \
-bfile mouse_hs1940 \
-n 1 6 \
-k ./output/mouse_hs1940.cXX.txt \
-predict \
-o mouse_hs1940_CD8MCH_prdt

gemma \
-bfile mouse_hs1940 \
-n 1 2 \
-k ./output/mouse_hs1940.cXX.txt \
-lmm 1\
-o mouse_hs1940_CD8MCH_prdt_lmm

5.贝叶斯稀疏线性混合模型

## To fit BSLMM in the training set:
## To fit a quantitative trait(数量性状)
# BIMBAM格式文件
gemma \
-g mouse_hs1940.geno.txt.gz \
-p mouse_hs1940.pheno.txt \
-n 2 \
-a mouse_hs1940.anno.txt \
-bslmm \
-o mouse_hs1940_CD8_bslmm \
-w 1000 \
-s 10000 \
-seed 1
# plink格式文件
gemma \
-bfile mouse_hs1940 \
-n 2 \
-bslmm \
-o mouse_hs1940_CD8_bslmm \
-w 1000 \
-s 10000 \
-seed 1

# the following three files may be of most importance:
# the *.hyp.txt contains a column for pve and pge
# the *.param.txt contains estimates for betas, gammas and alphas
# the *.bv.txt contains breeding value estimates
## To fit a binary trait(质量性状) using a linear model
# BIMBAM格式文件
gemma \
-g mouse_hs1940.geno.txt.gz \
-p mouse_hs1940.pheno.txt \
-n 4 \
-a mouse_hs1940.anno.txt \
-bslmm \
-o mouse_hs1940_CD8_bslmm_cc1 \
-w 1000 \
-s 10000
-seed 1

## To fit a binary trait using a probit model instead
gemma \
-g mouse_hs1940.geno.txt.gz \
-p mouse_hs1940.pheno.txt \
-n 4 \
-a mouse_hs1940.anno.txt \
-bslmm 3 \
-o mouse_hs1940_CD8_bslmm_cc3 \
-w 1000 \
-s 10000 \
-seed 1

# The pve estimates in the log file are based on the standard linear model (i.e. on the observed scale), and so you will need to properly transform it back to the liability scale
# To generate relatedness matrix based on the training data.

gemma \
-g mouse_hs1940.geno.txt.gz \
-p mouse_hs1940.pheno.txt \
-n 2 \
-a mouse_hs1940.anno.txt \
-gk 1 \
-o mouse_hs1940_CD8_train

# This matrix will only be required if you want to do prediction based on estimated breeding values
# Prediction can also be done without using the breeding values but instead using the alphas.
# This later approach does not appear to lose much accuracy in many examples we have encountered,
# although this may not be the case in your data.

## To obtain predicted values for the test set using estimates from BSLMM
## To do prediction in the test set for quantitative traits

gemma \
-g mouse_hs1940.geno.txt.gz \
-p mouse_hs1940.pheno.txt \
-n 2 \
-epm ./output/mouse_hs1940_CD8_bslmm.param.txt \
-emu ./output/mouse_hs1940_CD8_bslmm.log.txt \
-ebv ./output/mouse_hs1940_CD8_bslmm.bv.txt \
-k ./output/mouse_hs1940_CD8_train.cXX.txt \
-predict \
-o mouse_hs1940_CD8_prdt_k

## or use the alphas instead of breeding values
gemma \
-g mouse_hs1940.geno.txt.gz \
-p mouse_hs1940.pheno.txt \
-n 2 \
-epm ./output/mouse_hs1940_CD8_bslmm.param.txt \
-emu ./output/mouse_hs1940_CD8_bslmm.log.txt \
-predict \
-o mouse_hs1940_CD8_prdt

# The results will be inside ./output/*.prdt.txt
# If you load both results in R and check the mean squared error or correlation, you will find that both ways give very similar results. Both the correlation and the mean squared error should be around 0.65

## Now, do prediction in the test set for the binary traits
## If the traits were fitted using the linear model, then:

gemma \
-g mouse_hs1940.geno.txt.gz \
-p mouse_hs1940.pheno.txt \
-n 4 \
-epm ./output/mouse_hs1940_CD8_bslmm_cc1.param.txt \
-emu ./output/mouse_hs1940_CD8_bslmm_cc1.log.txt \
-predict \
-o mouse_hs1940_CD8_prdt_cc1

## If the traits were fitted using the probit model, then use predict option 2:
gemma \
-g mouse_hs1940.geno.txt.gz \
-p mouse_hs1940.pheno.txt \
-n 4 \
-epm ./output/mouse_hs1940_CD8_bslmm_cc3.param.txt \
-emu ./output/mouse_hs1940_CD8_bslmm_cc3.log.txt \
-predict 2 \
-o mouse_hs1940_CD8_prdt_cc3

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

推荐阅读更多精彩内容