育种数据分析之放飞自我分享 http://blog.sciencenet.cn/u/yijiaobai 关注:生物统计,数量遗传,混合线性模型,生物信息,R,Perl,Python,GWAS,GS相关方法,文章及代码

博文

blupf90根据G矩阵和H矩阵构建PCA分析以及与Plink以及GCTA的结果对比

已有 4775 次阅读 2019-4-28 18:02 |个人分类:农学统计|系统分类:科研笔记| 群体遗传, PCA

模拟一套数据, 5个世代, 最后三代有基因型数据, 每个世代400个个体, SNP为50K

1. blupf90构建G矩阵的PCA

blupf90如果想要进行GBLUP分析, 不写系谱信息即可, 示例par文件:

DATAFILE
dat_f90.txt
TRAITS
10         # This is column 10 (phenotype) from QMSim data file
FIELDS_PASSED TO OUTPUT
1          # This will copy the ID number to the renf90.dat data file
WEIGHT(S)  # WARNING: ALWAYS PUT AN EMPTY LINE AFTER THIS!!!!!

RESIDUAL_VARIANCE
0.9                # add starting values for residual variance
EFFECT
4 cross alpha    # Fit generation as a fixed effect, 'cross alpha' is a class in SAS
EFFECT
1 cross alpha    # Fit animal effect
RANDOM
animal           # Fit animal effect (A matrix) for the effect directly above it (column 1, animal)
#FILE
#ped_f90.txt  #  pedigree file (animal, sire, dam), 0's are missing always!!!
#FILE_POS
#1 2 3 0 0        # indicates that column 1 = Animal, column 2 = Sire, column 3 = Dam
SNP_FILE
yM.txt
(CO)VARIANCES    
0.1               # add starting values for additive animal effect
OPTION alpha_size 25               # Equal to the max number of characters within a column
OPTION max_string_readline 800  # maximum number of characters in one line of data file
OPTION max_field_readline 100   # maximum number of columns in the dataset
#OPTION saveHinvOrig
#OPTION saveHinv
#OPTION sol se
#OPTION use_yams
#OPTION missing -999
OPTION plotpca

运行preGSf90后, 会生成pc1vspc2文件, 里面包括PC1和PC2两列, 增加世代为pop, 然后使用R画图:

pca = read.table(("pc1vspc2"))
head(pca)
names(pca) = c("PC1","PC2")
pca$pop = rep(c("A","B","C"),each=400)
library(ggplot2)
p <- ggplot(pca, aes(x=PC1, y=PC2, colour=pop)) 
p <- p + geom_point(size=2)
p <- p + stat_ellipse(level = 0.95, size = 1)
p <- p + geom_hline(yintercept = 0) 
p <- p + geom_vline(xintercept = 0) 
p <- p + theme_bw()
p

结果:

image

2. blupf90构建H矩阵的PCA

需要定义系谱和基因型, 示例par文件:

DATAFILE
dat_f90.txt
TRAITS
10         # This is column 10 (phenotype) from QMSim data file
FIELDS_PASSED TO OUTPUT
1          # This will copy the ID number to the renf90.dat data file
WEIGHT(S)  # WARNING: ALWAYS PUT AN EMPTY LINE AFTER THIS!!!!!

RESIDUAL_VARIANCE
0.9                # add starting values for residual variance
EFFECT
4 cross alpha    # Fit generation as a fixed effect, 'cross alpha' is a class in SAS
EFFECT
1 cross alpha    # Fit animal effect
RANDOM
animal           # Fit animal effect (A matrix) for the effect directly above it (column 1, animal)
FILE
ped_f90.txt  #  pedigree file (animal, sire, dam), 0's are missing always!!!
FILE_POS
1 2 3 0 0        # indicates that column 1 = Animal, column 2 = Sire, column 3 = Dam
SNP_FILE
yM.txt
(CO)VARIANCES    
0.1               # add starting values for additive animal effect
OPTION alpha_size 25               # Equal to the max number of characters within a column
OPTION max_string_readline 800  # maximum number of characters in one line of data file
OPTION max_field_readline 100   # maximum number of columns in the dataset
#OPTION saveHinvOrig
#OPTION saveHinv
#OPTION sol se
#OPTION use_yams
#OPTION missing -999
OPTION plotpca

运行preGSf90后, 会生成pc1vspc2文件, 里面包括PC1和PC2两列, 增加世代为pop, 然后使用R画图:

pca = read.table(("pc1vspc2"))
head(pca)
names(pca) = c("PC1","PC2")
pca$pop = rep(c("A","B","C"),each=400)
library(ggplot2)
p <- ggplot(pca, aes(x=PC1, y=PC2, colour=pop)) 
p <- p + geom_point(size=2)
p <- p + stat_ellipse(level = 0.95, size = 1)
p <- p + geom_hline(yintercept = 0) 
p <- p + geom_vline(xintercept = 0) 
p <- p + theme_bw()
p

image

3. plink根据G矩阵做PCA

代码:

plink --file b --pca 3

结果生成:

plink.eigenval  plink.eigenvec  plink.log  plink.nosex

R语言作图:

library(ggplot2)
head(dd)
p <- ggplot(dd, aes(x=PC1, y=PC2, colour=pop)) 
p <- p + geom_point(size=2)
p <- p + stat_ellipse(level = 0.95, size = 1)
# p <- p + scale_color_manual(values = cols)
p <- p + geom_hline(yintercept = 0) 
p <- p + geom_vline(xintercept = 0) 
p <- p + theme_bw()
p

image

4. gcta64根据G矩阵做PCA

将ped文件转化为bed文件

plink --file b --make-bed --out c

生成grm文件

gcta64 --bfile c --autosome --make-grm --out grm

生成pca文件

gcta64 --grm grm --pca 3

根据PCA信息作图

image



https://blog.sciencenet.cn/blog-2577109-1176001.html

上一篇:GCTA PCA分析以及软件安装教程
下一篇:R 语言如何提取日期中的年份-月份-季节-天
收藏 IP: 47.75.116.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-12-28 08:35

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部