准备写一系列plink软件常用的命令,最近在数据分析时,需要将基因型的数据转化为0-1-2的形式,编程实现效果太差,100万的数据,plink十几秒完成,真的是厉害,非常值得学习,所以,开始搞起!
格式说明链接: http://zzz.bwh.harvard.edu/plink/data.shtml#map
❝map格式的文件, 主要是图谱文件信息, 主要包括染色体名称, 所在的染色体和所在染色体的坐标. ❞
1, map文件没有行头
2, map文件包括四列: 染色体, SNP名称, SNP位置, 碱基对坐标
3, 如果只有SNP名称, 可以手动构建map文件, 第二列为SNP名称, 其它三列为0即可.
「英文格式说明」
By default, each line of the MAP file describes a single marker and must contain exactly 4 columns:
chromosome (1-22, X, Y or 0 if unplaced)
rs# or snp identifier
Genetic distance (morgans)
Base-pair position (bp units)
Genetic distance can be specified in centimorgans with the --cm flag. Alternatively, you can use a MAP file with the genetic distance excluded by adding the flag --map3, i.e.
plink --file mydata --map3
In this case, the three columns are expected to be
chromosome (1-22, X, Y or 0 if unplaced)
rs# or snp identifier
Base-pair position (bp units)
Base-pair positions are expected to correspond to positive integers within the range of typical human chromosome sizes.
1 snp1 0 1
1 snp2 0 2
1 snp3 0 3
格式说明链接:http://zzz.bwh.harvard.edu/plink/data.shtml#ped
❝bed格式的文件, 主要包括SNP的信息, 包括个体ID, 系谱信息, 表型和SNP的分型信息. ❞
1, 数据没有行头, 空格或者tab隔开的文件 2, 必须要有六列, 包括系谱信息, 表型信息
3, 上面六列, 必须要有, 如果没有相关数据, 用0表示.
「英文格式说明」
As well as the --file command described above, PED and MAP files can be specified separately, if they have different names:
plink --ped mydata.ped --map autosomal.map
Note Loading a large file (100K+ SNPs) can take a while (which is why we suggest converting to binary format). PLINK will give an error message in most circumstances when something has gone wrong.
The PED file is a white-space (space or tab) delimited file: the first six columns are mandatory:
Family ID
Individual ID
Paternal ID
Maternal ID
Sex (1=male; 2=female; other=unknown)
Phenotype
The IDs are alphanumeric: the combination of family and individual ID should uniquely identify a person. A PED file must have 1 and only 1 phenotype in the sixth column. The phenotype can be either a quantitative trait or an affection status column: PLINK will automatically detect which type (i.e. based on whether a value other than 0, 1, 2 or the missing genotype code is observed).
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
ped格式是1 1 2 2 的格式转化为0 1 2 这里1 1之间有空格
「test1.ped」
1 1 0 0 1 0 1 1 2 2 1 1
1 2 0 0 2 0 2 2 0 0 2 1
1 3 1 2 1 2 0 0 1 2 2 1
2 1 0 0 1 0 1 1 2 2 0 0
2 2 0 0 2 2 2 2 2 2 0 0
2 3 1 2 1 2 1 1 2 2 1 1
「test1.map」
1 snp1 0 1
1 snp2 0 2
1 snp3 0 3
「plink命令行」
plink --file test2 --recodeA
「结果:」
FID IID PAT MAT SEX PHENOTYPE snp1_2 snp2_1 snp3_2
1 1 0 0 1 -9 0 0 0
1 2 0 0 2 -9 2 NA 1
1 3 1 2 1 2 NA 1 1
2 1 0 0 1 -9 0 0 NA
2 2 0 0 2 2 2 0 NA
2 3 1 2 1 2 0 0 0
可以看出, 表型值缺失的部分变为了"-9", 基因型值缺失的部分变为了NA, snp的major变为了0, snp的minor变为了2, 杂合变为了1.
ped格式是11 22 的格式转化为0 1 2 这里11中间没有空格「test2.ped」
1 1 0 0 1 0 11 22 11
1 2 0 0 2 0 22 00 21
1 3 1 2 1 2 00 12 21
2 1 0 0 1 0 11 22 00
2 2 0 0 2 2 22 22 00
2 3 1 2 1 2 11 22 11
「test2.map」
1 snp1 0 1
1 snp2 0 2
1 snp3 0 3
「命令:」结果:plink.raw
FID IID PAT MAT SEX PHENOTYPE snp1_2 snp2_1 snp3_2
1 1 0 0 1 -9 0 0 0
1 2 0 0 2 -9 2 NA 1
1 3 1 2 1 2 NA 1 1
2 1 0 0 1 -9 0 0 NA
2 2 0 0 2 2 2 0 NA
2 3 1 2 1 2 0 0 0
ped格式是A T C G 的格式转化为0 1 2 这里A A之间有空格
「test3.ped」
1 1 0 0 1 0 A A T T G G
1 2 0 0 2 0 G G 0 0 A G
1 3 1 2 1 2 0 0 A T A G
2 1 0 0 1 0 A A A T 0 0
2 2 0 0 2 2 G G T T 0 0
2 3 1 2 1 2 A A T T G G
「test3.map」
1 snp1 0 1
1 snp2 0 2
1 snp3 0 3
「plink命令行」
plink --file test3 --recodeA
「结果不变」
FID IID PAT MAT SEX PHENOTYPE snp1_2 snp2_1 snp3_2
1 1 0 0 1 -9 0 0 0
1 2 0 0 2 -9 2 NA 1
1 3 1 2 1 2 NA 1 1
2 1 0 0 1 -9 0 0 NA
2 2 0 0 2 2 2 0 NA
2 3 1 2 1 2 0 0 0
ped格式是AT CG 的格式转化为0 1 2 这里AT之间没有空格
「test3.ped」
1 1 0 0 1 0 AA TT GG
1 2 0 0 2 0 GG 00 AG
1 3 1 2 1 2 00 AT AG
2 1 0 0 1 0 AA AT 00
2 2 0 0 2 2 GG TT 00
2 3 1 2 1 2 AA TT GG
「test3.map」
1 snp1 0 1
1 snp2 0 2
1 snp3 0 3
「plink命令行」
plink --file test4 --recodeA
「结果不变」
FID IID PAT MAT SEX PHENOTYPE snp1_2 snp2_1 snp3_2
1 1 0 0 1 -9 0 0 0
1 2 0 0 2 -9 2 NA 1
1 3 1 2 1 2 NA 1 1
2 1 0 0 1 -9 0 0 NA
2 2 0 0 2 2 2 0 NA
2 3 1 2 1 2 0 0 0
ped格式是A T 1 2 的格式转化为0 1 2 这里AT和12都包含
「test3.ped」
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 G G 2 2 0 0
2 2 0 0 2 2 A A 2 2 0 0
2 3 1 2 1 2 G G 2 2 C C
「test3.map」
1 snp1 0 1
1 snp2 0 2
1 snp3 0 3
「plink命令行」
plink --file test4 --recodeA
「结果不变」
FID IID PAT MAT SEX PHENOTYPE snp1_2 snp2_1 snp3_2
1 1 0 0 1 -9 0 0 0
1 2 0 0 2 -9 2 NA 1
1 3 1 2 1 2 NA 1 1
2 1 0 0 1 -9 0 0 NA
2 2 0 0 2 2 2 0 NA
2 3 1 2 1 2 0 0 0