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

博文

使用TASSEL学习GWAS笔记(3/6):基因型数据可视化:kingship,PCA,MDS

已有 4030 次阅读 2021-7-25 19:29 |个人分类:GWAS|系统分类:科研笔记

第三篇:基因型数据可视化:kingship,LD,MDS,PCA

笔记计划分为六篇:

第一篇:读取plink基因型数据和表型数据

第二篇:对基因型数据质控:缺失质控,maf质控,hwe质控,样本质控

第三篇:基因型数据可视化:kingship,LD,MDS,PCA 

第四篇:一般线性模型进行GWAS分析(GLM模型) 

第五篇:混合线性模型进行GWAS分析(MLM模型) 

第六篇:TASSEL结果可视化:QQ plot,曼哈顿图

已完成前两篇,本篇是第三篇。

1. 将质控的plink数据读入到TASSEL软件

上个教程中,质控后的数据:

读取到TASSEL中:

2. 构建kinship矩阵

kinship矩阵是亲缘关系矩阵,是根据样本的SNP,构建样本间的亲缘关系矩阵,在GS中也叫G矩阵。

首先,选中基因型数据,然后点击Kinship按钮:默认选项,点击OK

查看结果:

将Kinship矩阵导出到本地文件夹,通过R语言进行可视化。

设置名称:导出到本地:

文件查看: 前三行,为文件的信息,第一列为ID,没有行头。

「使用R代码进行可视化:」

library(data.table)

kinship = fread("kinship-result.txt",skip = 3)
setDF(kinship)
row.names(kinship) = kinship$V1
kinship$V1 = NULL
colnames(kinship) = row.names(kinship)
kinship = as.matrix(kinship)

heatmap(kinship)

3. 构建PCA分析及可视化

选中基因型,选择PCA按钮:默认选项:

PCA结果1:PCA得分

PCA结果2:特征值及百分比及累计百分比PCA结果3:特征向量

将PCA结果导出到本地:

「使用R语言绘制PCA图:」

# PCA
pca_re = fread("pca-result.txt",skip = 2)
head(pca_re)

## 2D-PCA
library(ggplot2)
ggplot(pca_re, aes(x=PC1, y=PC2))  + geom_point(size=2) +
  geom_hline(yintercept = 0)  + # 添加x坐标
  geom_vline(xintercept = 0) + # 添加y坐标
  theme_bw()

当然,也可以画3D-PCA:

library(scatterplot3d)
scatterplot3d(pca_re[,2:4],
              pch = 16,angle=30,
              box=T,type="p",
              lty.hide=2,lty.grid = 2)

当然,这里可以见PCA不同的解释百分比加到坐标轴上,这里不再做介绍,感兴趣的可以翻看我之前的博客内容。

4. 构建MDS分析及可视化

多维标度(Multidimensional scaling,缩写MDS,又译“多维尺度”)也称作“相似度结构分析”(Similarity structure analysis),属于多重变量分析的方法之一,是社会学、数量心理学、市场营销等统计实证分析的常用方法。--wiki

MDS The MDS method performs classical multidimensional scaling as adapted from the R code for cmdscale(). An alternate name for this analysis is principal coordinate analysis. It produces results that are very similar to PCA (principal components analysis) but starts with a distance matrix and results in coordinate axes that are scaled differently. To use MDS, create a distance matrix from a genotype using Analysis/Distance Matrix in TASSEL or import a distance matrix. Then, select the distance matrix, choose Analysis/MDS, and enter the number of coordinate axes and associated eigenvalues to be reported.

在GWAS分析时,MDS分析和PCA分析类似,都可以将成分作为协变量放到模型中,可视化也和PCA类似.

MDS and PCA will handle missing data differently. PCA imputes missing data to the mean allele frequency. The distance matrix calculation computes pairwise distances between taxa, using only sites with non-missing data for each taxon in a pair. There is no theoretical reason to prefer one method over the other. The axes produced by either MDS or PCA can be used as covariates in GLM or MLM models to correct for population structure.

「MDS分析分为两步:」

  • 首先构建Distance Matrix
  • 然后进行MDS分析

这里我们做一下演示:

选中基因型,点击Distance Matrix

生成距离矩阵:

然后进行MDS分析:

生成结果:

导出到本地:

查看文件:

「使用R语言进行可视化:」

# MDS
mds_re = fread("MDS-result.txt",skip = 2)
head(mds_re)

## 2D-MDS
library(ggplot2)
ggplot(mds_re, aes(x=PC1, y=PC2))  + geom_point(size=2) +
  geom_hline(yintercept = 0)  + # 添加x坐标
  geom_vline(xintercept = 0) + # 添加y坐标
  theme_bw()

可以看到MDS的图和PCA的图比较类似。

下一章节,我们进行:第四篇:一般线性模型进行GWAS分析(GLM模型)的部分,到时候和R语言进行比较,深入理解GLM模型的本质。

下期见!




https://wap.sciencenet.cn/blog-2577109-1296935.html

上一篇:使用TASSEL学习GWAS笔记(2/6):对基因型数据进行质控及导出基因型
下一篇:R语言操作文件与文件夹总结笔记
收藏 IP: 223.90.189.*| 热度|

0

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

数据加载中...

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

GMT+8, 2024-3-29 22:19

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部