1. 常用的各種格式之間的轉(zhuǎn)換
在獲得vcf文件之后,經(jīng)過(guò)過(guò)濾和提取SNP的變異之后,獲得snp.vcf文件(從fq到vcf這些可以看GTAK4的教程)。
vcf 轉(zhuǎn)為二進(jìn)制bedfile
plink --vcf test.vcf --make-bed --out test --allow-extra-chr
把vcf轉(zhuǎn)為map和ped格式
plink --vcf test.vcf --recode --out test --allow-extra-chr
map和ped文件轉(zhuǎn)為vcf格式
plink --file test --recode vcf --out test
把二進(jìn)制bedfile 轉(zhuǎn)為map和ped格式
plink --bfile test --recode --out test
#二進(jìn)制bed轉(zhuǎn)為vcf文件
plink --bfile b --recode vcf --out e
把測(cè)試的vcf轉(zhuǎn)為0,1,2編碼格式
plink --vcf Test.vcf --recode A --out TAGSNP --allow-extra-chr
ped文件中,SNP轉(zhuǎn)化為012的標(biāo)準(zhǔn)是,主等位基因?yàn)?,雜合為1,次等位基因?yàn)?,這里還區(qū)分了基因的顯隱性。
plink --bfile test --recode AD --out output_coded --allow-extra-chr
輸出文件是output_coded.raw
2. 常用的各種參數(shù)過(guò)濾
--file參數(shù)后就是plink的map和ped格式的文件名的前綴
刪除樣本材料缺失超過(guò)10%的基因型
plink --file a --geno 0.1 --recode --out re
刪除基因型缺失超過(guò)10%的樣本材料
plink --file a --mind 0.1 --recode --out re
次要等位基因頻率MAF過(guò)濾,過(guò)濾MAF<0.05的基因型,(一般設(shè)置為0.01或0.05)
plink --file a --maf 0.05 --recode --out re
這里是刪除MAF低于0.05的SNP位點(diǎn)。即大部分位置相同的基因型,這些位點(diǎn)貢獻(xiàn)的信息很少,所以就刪除,以減小計(jì)算量。
注意:過(guò)濾的順序是先做SNP過(guò)濾--geno,再做材料過(guò)濾--mind,不要同時(shí)過(guò)濾或者顛倒過(guò)濾的順序
哈德溫伯格平衡過(guò)濾
plink --bfile test -hwe 1e-5 --recode -out test2 --allow-extra-chr 過(guò)濾哈德溫伯格p值,保留大于1e-5的變異
plink --bfile test --hardy 可以輸出plink.hwe文件,可以查看具體的哈德溫伯格p值。
3.文件提取
樣本提取,提取指定樣本的基因型
plink --file test --keep id_sample.txt --recode --out re
test.ped的格式如下:

id_sample.txt的格式和內(nèi)容如下:
第一列:FID,家系ID
第二列:IID,個(gè)體ID
B001 B001
B002 B002
B003 B003
B004 B004
B005 B005
B006 B006
B007 B007
B008 B008
B009 B009
提取指定的SNP
plink --file a --extract id_snp.txt --recode --out re --allow-extra-chr
--extract, 提取SNP ID
--exclude,刪除SNP ID
plink --file test --extract id_snp.txt --recode --out res --allow-extra-chr
id_snp.txt是一列SNP ID序列編號(hào)。
我編寫(xiě)的python3腳本
vcf的ID列字符串.替換為Chr_Pos這種格式,
vcfaddID.py input.vcf out.vcf
vcfaddID.py 下載
替換vcf文件的染色體編號(hào)
replaceVcfChr.py Input.vcf old2newidfile Output.vcf
replaceVcfChr.py 下載
old2newidfile是兩列chr的id,第1列是原始id,第2列是新的id,中間是tab分割。
腳本會(huì)把第1列的id替換為第2列的id。
注意事項(xiàng):
1. plink1.9 會(huì)自動(dòng)修改你的vcf的主次等位基因。
所以如果你后續(xù)操作需要區(qū)分REF和ALT列,一定要注意這一點(diǎn)??梢允褂?code>--keep-allele-order來(lái)保持原有的主等位基因,但是如果某一次忘記了,后續(xù)會(huì)很麻煩。需要重新調(diào)整主等位基因。
plink --vcf ${abbr}.filter.vcf --recode A --out ${abbr}.filter --allow-extra-chr --keep-allele-order
2. plink1.9會(huì)自動(dòng)修改你的vcf的頭部的染色體的長(zhǎng)度
比如你vcf原始的頭部中
##contig=<ID=Chr03,length=105315579>
使用plink對(duì)vcf進(jìn)行過(guò)濾操作之后,輸出的內(nèi)容的頭部可能會(huì)變成
##contig=<ID=Chr03,length=105310001>