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 | 摩尔位置 | 物理坐标 | 图谱文件信息 | ||||||||
.ped | FID | IID | PID | MID | Sex | 表型 | SNP1_A1 | SNP1_A2 | SNP2_A1 | SNP2_A2 | … | … | 个体ID, 系谱信息, 表型和SNP的分型信息 |
.raw | FID | IID | PID | MID | Sex | 表型 | SNP1_A | SNP2_G | … | … | … | … | 个体ID, 系谱信息, 表型和SNP的分型信息 |
bed | chr | chrStart | chrEnd | name | score | strand | ThickStart | ThickEnd | ItemRgb | BlockCount Block Sizes | Block Starts | UCSC Genome Browser’s BED format | |
.bed | SNP数据,二进制格式 | ||||||||||||
.bim | chr | rsID | 摩尔位置 | 物理坐标 | A1 | A2 | SNP位置信息 | ||||||
.fam | FID | IID | PAT | MAT | Sex | 表型 | 家系表型信息 | ||||||
.vcf | chr | pos | ID | REF | ALT | QUAL | FILTER | INFO | FORMAT | sample1 | sample2 | sample3 | variant call format |
参考阅读:
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