计算等位基因频率
用--freq
计算等位基因频率
vcftools --vcf test.vcf --freq --out output
对来自chr1的每一个位点统计其基因频率
vcftools --gzvcf combined200.vcf.gz --freq --chr chr1 --out chr1_analysis
计算Fst
使用--weir-fst-pop
进行Fst计算
vcftools --vcf test.vcf --weir-fst-pop population1.txt --weir-fst-pop population2.txt --out pop1VSpop2
转换为plink格式
使用--plink
进行文件转换
vcftools --vcf test.vcf --plink --chr 1 --out output_in_plink
转换plink格式的报错解决
当使用plink转换vcf为ped、map报错:
Writing PLINK PED and MAP files ... Error: Could not open temporary file.报错
这时可以先用-tped
转换,再转换为plink格式。
vcftools --vcf test.vcf --plink-tped --out test
转换为ped、map格式的命令:
plink --tfile test --recode --out test
转换为bim、bed、fam格式的命令:
plink --tfile test --make-bed --out test
比较两个vcf文件
比较2个VCF文件,看哪些个体或者位点是2个文件共享的。指定第二个文件要用--diff --gzdiff or --diff-bcf
vcftools --vcf test1.vcf --diff test2.vcf --out compare
根据id保留或去除vcf文件的样本
#保留
vcftools --vcf in.vcf --recode --recode-INFO-all --stdout --keep id.txt > out.vcf
#去除
vcftools --vcf in.vcf --recode --recode-INFO-all --stdout --remove id.txt > out.vcf
只保留1号和10号
vcftools --vcf in.vcf --recode --recode-INFO-all --stdout --indv 1 --indv 10 > out.vcf
基因型数据转换为012格式
用 vcftools 生成 012 矩阵:
vcftools --vcf test.genotypes_no_missing_IDs.vcf --012 --out snp_matrix
后缀为 .012
的 012 基因型矩阵文件,每行为样本,列为基因型。缺失基因型用 -1 表示。
第一列为索引,并不是真实的样本名,在接下来的步骤中需要替换。
0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0
2 0 0 1 1 1 1 1 1
3 0 0 0 0 0 0 0 0
4 0 0 0 0 0 0 0 0
5 1 1 1 0 0 1 1 1
6 1 1 1 0 0 0 0 0
7 0 0 0 0 0 0 0 0
8 1 1 1 0 0 0 0 0
9 0 0 0 0 0 0 0 0
后缀为 .012.indv
的样本信息文件。
后缀为 .012.pos
的 SNP 位点坐标文件。
参考链接
VCF格式的学习及对VCF文件的统计
收集vcftools所有用法
vcf文件与vcftools(二)
vcf格式解读
vcftools去除或保留vcf文件中的样品
如何将基因型数据转为 012 格式
vcftools报错的解决方式