plink格式文件的介绍及相互转换
本文最后更新于 1149 天前,如有失效请评论区留言。

技术标签: 其他  基因组学  软件工具  

plink格式文件的介绍及相互转换

Plink常用的文件格式有两套:map/ped 和 bim/fam/bed。两组文件均没有列名,且每一列表示的意思是一定的。几种格式之间可以相互转换。推荐使用BED/BIM/FAM这种格式,读取速度快。

1. map/ped 文件

.map文件
格式说明链接:http://www.cog-genomics.org/plink/1.9/formats#map
map格式的文件, 主要是图谱文件信息, 主要包括染色体名称, 所在的染色体和所在染色体的坐标。

map文件包括:

第一列:染色体编号(1-22, X, Y or 0 if unplaced), 未知为0;
第二列:SNP名称(字符或数字), 如果不重要, 可以从1编号, 注意要和bed文件SNP列一一对应;
第三列:染色体的摩尔位置(可选项, 可以用0);
第四列:SNP物理坐标;

示例:

1 snp1 0 1
1 snp2 0 2
1 snp3 0 3

示例说明:这里有3个SNP, 分别名为snp1, snp3, snp3 (第二列);这三个SNP在第一个染色体上 (第一列);第三列为0;第四列为SNP所在染色体的坐标。

.ped文件
格式说明链接:http://www.cog-genomics.org/plink/1.9/formats#ped
ped格式的文件, 主要包括SNP的信息, 包括个体ID, 系谱信息, 表型和SNP的分型信息。

.ped 文件主要有 6 列,后面都是基因型:

第一列: Family ID # 如果没有, 可以用个体ID代替;
第二列: Individual ID # 个体ID编号;
第三列: Paternal ID # 父本编号;
第四列: Maternal ID # 母本编号;
第五列: Sex (1=male; 2=female; other=unknown) # 性别, 如果未知, 用0表示;
第六列: Phenotype (0=unknown; 1=unaffected; 2=affected) # 表型数据, 如果未知, 用0表示;
第七列以后: 为SNP分型数据, 可以是AT CG或11 12, 或者A T C G或1 1 2 2;

示例:

1 1 0 0 1 0 G G 2 2 C C
1 2 0 0 2 0 A A 0 0 A C
1 3 1 2 1 2 0 0 1 2 A C
2 1 0 0 1 0 A A 2 2 0 0
2 2 0 0 2 2 A A 2 2 0 0
2 3 1 2 1 2 A A 2 2 A A

示例说明:数据包括两个家系 (第一列);每个家系有三个个体 (第二列);第三列父本编号;第四列母本编号;第五列性别;第六列表型值;第七、八列为第一个基因型;第九、十列为第二个基因型;第十一、十二列为第三个基因型。

2. bim/fam/bed文件

格式说明链接:http://www.cog-genomics.org/plink/1.9/formats 或 http://www.cog-genomics.org/plink/2.0/formats

.bim文件
bim文件存储每个遗传变异(通常是SNP)的相关信息,每一行代表一个遗传变异,共6列:
第一列:染色体编号(常用整数标记,如22表示第22条染色体,性染色体和线粒体染色体用’X’/‘Y’/‘XY’/‘MT’表示,而’0’ 代表染色体信息缺失);
第二列:变异标识符,这个就相当与每一个遗传变异的编号,常见的SNP可以采用以“rs”开头的编号;
第三列:每个遗传变异在基因组上的位置,用摩尔根或者厘摩尔根表示;
第四列:碱基对的坐标;
第五列:等位基因1(A1),通常是次要等位基因(minor allele);
第六列:等位基因2(A2),通常是主要等位基因(major allele)。

.fam文件
fam存储的是样本家系等信息,共6列:
第一列:家系编号(‘FID’);
第二列:个体编号(‘IID’; 不能是 ‘0’);
第三列:父系编号 (‘0’ 表示父系信息缺失);
第四列:母系编号(‘0’ 表示母系信息缺失);
第五列:性别编号(‘1’ = 男, ‘2’ = 女, ‘0’ = 性别未知);
第六列:表型值 (‘1’ = 对照, ‘2’ = 病例, ‘-9’/‘0’/表示表型缺失)。

.bed文件
bed存储基因型信息,是plink中的二元等位基因表。
解释详见 http://www.cog-genomics.org/plink/1.9/formats#bed
注意:此处的bed文件与 UCSC Genome Browser’s BED format 中的bed文件格式是完全不同的东西。

3. plink格式文件的相互转换

参考:https://zzz.bwh.harvard.edu/plink/dataman.shtml

#1. bed/bim/fam 转为 ped/map
#input files: test.bed; test.bim; test.fam  #output files: test1.ped; test1.map
plink --file test --recode --out test1 

#2. ped/map转为二进制格式 bed/bim/fam
#input files: test.ped; test.map  #output files: test2.bed; test2.bim; test2.fam
plink --file test --make-bed --out test2

#3.SNP编码成加性(字母 012) 
# http://zzz.bwh.harvard.edu/plink/dataman.shtml#recode
# 注:默认编码方式:两个等位均为major allele,则编码为0;杂合等位编码为1;两个minor等位编码为2。
#input files: test.ped; test.map  #output files: test.raw
plink --file test --recodeA --out test 
# ped文件中, SNP的分型是1 1 2 2 或 11 22  或 AA TT 或 AA 22,均采用该命令进行转换,且不影响结果。

#4.vcf转ped/map
#input files: test.vcf;  #output files: test.ped; test.map
plink --vcf test.vcf --recode --out test   # 当出现错误,无法读取chrom时,加 --allow-extra-chr,可以强制程序接受编号
vcftools --vcf test.vcf --plink --out test

#5.bed/bim/fam转vcf
#input files: test.bed; test.bim; test.fam  #output files: test.vcf
plink --bfile test --export vcf --out test
plink --bfile test --recode vcf-iid --out test  

plink --bfile filename --a1-allele file.bim 6 --make-bed --out newfilename # a1 a2在bim文件中替换位置。

4. 利用plink进行数据预处理(修剪SNP集)

(1) 删除基因型缺失率大于5%、次要等位基因频率小于0.01的SNPs

plink --file hapmap --geno 0.05 --maf 0.01 --out hapmap --make-bed

(2) 基于连锁不平衡的SNP修剪(窗宽500、删除LD大于0.1的SNP对中的一个、每次将窗口向前移动10个SNP)

plink --file hapmap --indep-pairwise 500 10 0.1 
plink --file hapmap --extract plink.prune.in --make-bed --out prunedhapmap

(3) 基于随机采样保留部分SNPs(例如只随机保留20%的SNP)

plink --file hapmap --thin  0.2 --out hapmap --make-bed

(4) 采用上述所有步骤并输出bed、bim、fam文件

plink --file hapmap --geno 0.05 --maf 0.01 --indep-pairwise 500 10 0.1 --thin 0.2
plink --file hapmap --extract plink.prune.in --make-bed --out prunedhapmap

plink --bfile cluster_remove --recode --out data --noweb #由bed文件转为ped、map文件
plink --file data --geno 0.05 --maf 0.01 --indep-pairwise 500 10 0.1 --thin 0.2
plink --file data --extract plink.prune.in --make-bed --out pruneddata

(5) 将23andme原始数据文件转化为.ped文件

plink --23file File.txt --make-bed --out NewFile

(6) 将多个数据合并
其中fileset3.txt中包含要合并的文件名。

plink --file genom0 --merge-list filesets3.txt --make-bed --out combdata

(7) 筛选vcf文件中的SNPs
在file.txt中, snp名字作为一列,无header,输出格式为vcf

vcftools --gzvcf test.vcf --snps snps.txt --recode --recode-INFO-all --out filter.snp

5. 总结

File第1列第2列第3列第4列第5列第6列第7列第8列第9列第10列第11列第12列说明
.map染色体rsID摩尔位置物理坐标图谱文件信息
.pedFIDIIDPIDMIDSex表型SNP1_A1SNP1_A2SNP2_A1SNP2_A2个体ID, 系谱信息, 表型和SNP的分型信息
.rawFIDIIDPIDMIDSex表型SNP1_ASNP2_G个体ID, 系谱信息, 表型和SNP的分型信息
bedchrchrStartchrEndnamescorestrandThickStartThickEndItemRgbBlockCount Block SizesBlock StartsUCSC Genome Browser’s BED format
.bedSNP数据,二进制格式
.bimchrrsID摩尔位置物理坐标A1A2SNP位置信息
.famFIDIIDPATMATSex表型家系表型信息
.vcfchrposIDREFALTQUALFILTERINFOFORMATsample1sample2sample3variant call format

一文掌握Plink文件格式转换

5 赞同

6 评论

30 收藏

欢迎关注微信公众号”生信小王子“!

Plink是我们常用的全基因关联分析工具,具有多种文件格式。许多分析工具都需要Plink的文件格式作为输入文件,今天小编就带大家掌握多种Plink文件格式的转换,解决分析过程中遇到的输入文件问题。

## 下载Plink
wget -c http://s3.amazonaws.com/plink1-assets/plink_linux_x86_64_20200219.zip
## 解压
unzip plink_linux_x86_64_20200219.zip

vcf 转为 ped/map

## 使用vcftools
vcftools --vcf snp.vcf --plink --out snp
## 使用plink
plink --vcf snp.vcf --recode --out snp

ped和map文件是Plink的基本格式。

ped文件包含以下几列:

第一列:Family ID。

第二列:Individual ID。自然群体这列和Family ID是一样的。

第三列:Paternal ID。未提供信息的话这列为0。

第四列:Maternal ID。未提供信息的话这列为0。

第五列:Sex。未提供信息的话这列为0。

第六列:Phenotype。一般来说,直接拿vcf转换的话这列为-9,也就是缺失。

第七列开始就是个体在每个标记位点的基因型。

map文件包含以下几列:

第一列:染色体编号。

第二列:SNP编号。

第三列:遗传距离。未提供信息的话这列为0。

第四列:物理位置。

ped/map 与 tped/tfam 格式互换

## ped/map转换为tped/tfam
plink --file snp --recode --transpose --out snp_test
## tped/tfam转换为ped/map
plink --tfile snp_test --recode --out snp

ped/map 与 bed/bim/fam互换

## ped/map转换为bed/bim/fam
plink --file snp --make-bed --out snp_test
## bed/bim/fam转换为ped/map
plink --bfile snp_test --recode --out snp

tped/tfam 与 bed/bim/fam互换

## tped/tfam转换为bed/bim/fam
plink --tfile snp --make-bed --out snp_test
## bed/bim/fam转换为tped/tfam
plink --bfile snp_test --recode --transpose --out snp

bed/bim/fam 转为 vcf

## bed/bim/fam 转为 vcf
plink --bfile snp --export vcf --out snp_test

常用的Plink格式转换就是这些,大家可以根据自己实际需要相互转换。

参考阅读:

plink格式的map文件和ped文件,https://blog.csdn.net/weixin_42948291/article/details/103333306
GWAS | 原理和流程 | 全基因组关联分析 | Linkage disequilibrium (LD)连锁不平衡 | 曼哈顿图 Manhattan_plot | QQ plot,https://www.cnblogs.com/leezx/p/9013615.html

版权声明:本文为转载请附上原文出处链接和本声明。本文链接:https://blog.csdn.net/qq_22253901/article/details/121608557

版权声明:除特殊说明,博客文章均为Vensin原创,依据CC BY-SA 4.0许可证进行授权,转载请附上出处链接及本声明。 如有需要,请至学习地图系统学习本博客的教程。 | 博客订阅:RSS | 广告招租:留言板 | 博客 |
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇
# # #