繼續(xù)上一節(jié)課教程的下半節(jié),繼續(xù)介紹一些其他過濾SNP的工具,歡迎大家跟著學(xué)習(xí)。
從現(xiàn)在開始,過濾步驟假定vcf文件是由FreeBayes生成的。(但是其他的vcf也是類似的,可能在header等不同地方有小許的差異)。
查看VCF 文件的Header
FreeBayes在VCF文件中輸出大量關(guān)于基因座的信息,使用這些信息和RADseq的屬性,我們?yōu)閿?shù)據(jù)添加了一些復(fù)雜的過濾器。讓我們看看我們的VCF文件的header,并快速查看所有信息。
mawk '/#/' DP3g95maf05.recode.vcf
這將輸出幾行INFO標(biāo)簽,我在下面展示了抽取的一部分信息:
##fileformat=VCFv4.1
##fileDate=20150301
##source=freeBayes v0.9.20-16-g3e35e72
##reference=reference.fasta
##phasing=none
##INFO=<ID=NS,Number=1,Type=Integer,Description="Number of samples with data">
##INFO=<ID=DP,Number=1,Type=Integer,Description="Total read depth at the locus">
##INFO=<ID=DPB,Number=1,Type=Float,Description="Total read depth per bp at the locus; bases in reads overlapping / bases in haplotype">
##INFO=<ID=AC,Number=A,Type=Integer,Description="Total number of alternate alleles in called genotypes">
##INFO=<ID=AN,Number=1,Type=Integer,Description="Total number of alleles in called genotypes">
vcffilter的安裝和使用
vcffilter是基于等位基因平衡的一個工具。那什么是等位基因平衡?0到1之間的數(shù)字,表示參考等位基因的reads與所有reads的比率。在僅考慮來自被稱為雜合子的個體的reads情況下,我們期望我們的數(shù)據(jù)中的等位基因應(yīng)該接近0.5。這樣情況下,我們可以使用vcflib的vcffilter程序。
可以快速用conda 安裝
conda install vcflib
或者自行到GitHub下載安裝 (https://github.com/ekg/vcflib)
快速了解一下vcffilter的使用說明
vcffilter
usage: vcffilter [options] <vcf file>
options:
-f, --info-filter specifies a filter to apply to the info fields of records,
removes alleles which do not pass the filter
-g, --genotype-filter specifies a filter to apply to the genotype fields of records
-k, --keep-info used in conjunction with '-g', keeps variant info, but removes genotype
-s, --filter-sites filter entire records, not just alleles
-t, --tag-pass tag vcf records as positively filtered with this tag, print all records
-F, --tag-fail tag vcf records as negatively filtered with this tag, print all records
-A, --append-filter append the existing filter tag, don't just replace it
-a, --allele-tag apply -t on a per-allele basis. adds or sets the corresponding INFO field tag
-v, --invert inverts the filter, e.g. grep -v
-o, --or use logical OR instead of AND to combine filters
-r, --region specify a region on which to target the filtering, requires a BGZF
compressed file which has been indexed with tabix. any number of
regions may be specified.
第一次使用vcffilter過濾嘗試
vcffilter -s -f "AB > 0.25 & AB < 0.75 | AB < 0.01" DP3g95maf05.recode.vcf > DP3g95p5maf05.fil1.vcf
vcffilter使用簡單的條件語句,因此過濾掉小于等于0.25且高于0.75的等位基因平衡的基因座。但是,它確還是包括了等位基因平衡接近于0的基因座。最后一個條件是捕獲那些具有固定變異的基因座(所有個體對于兩個變體之一是純合的)。使用 -s
告訴過濾工具應(yīng)用于sites每個位點,而不僅僅是等位基因使用。
要查看VCF文件中現(xiàn)在有多少個基因座,您只需使用簡單的mawk語句。
mawk '!/#/' DP3g95p5maf05.recode.vcf | wc -l
12754
#過濾前基因座的數(shù)量
mawk '!/#/' DP3g95p5maf05.fil1.vcf | wc -l
9678
#過濾后基因座的數(shù)量
您會注意到我們已經(jīng)過濾了很多基因座。根據(jù)我的經(jīng)驗,我發(fā)現(xiàn)其中大多數(shù)往往是某種錯誤導(dǎo)致的。但是,這將取決于數(shù)據(jù)。我建議您探索自己的數(shù)據(jù)集。
下一個過濾練習(xí)
下一個過濾練習(xí),我們過濾掉兩個鏈都有reads都有的位點。對于GWAS甚至RNAseq,這可能是一件好事。
除非您使用超小基因組片段或長reads(MiSeq)。 SNP應(yīng)僅由正向reads或僅反向reads涵蓋。
vcffilter -f "SAF / SAR > 100 & SRF / SRR > 100 | SAR / SAF > 100 & SRR / SRF > 100" -s DP3g95p5maf05.fil1.vcf > DP3g95p5maf05.fil2.vcf
這次的過濾是基于比例,因此一些無關(guān)的reads不會刪除整個基因座。簡單來說,它保留的位點比反向交替reads的前向交替reads多100倍,前向參考reads比反向參考reads多100倍。
查看一下剩下基因座的數(shù)量
···
mawk '!/#/' DP3g95p5maf05.fil2.vcf | wc -l
9491
···
這只能去除一小部分基因座,但這些基因座可能是旁系同源物,微生物污染物或奇怪的PCR嵌合體。(對比DP3g95p5maf05.fil1.vcf, 這次只過濾了不到200個位點 )
samtools是直接從終端可視化比對的好方法
samtools tview BR_006-RG.bam reference.fasta -p E28188_L151
#-p 具體展示那個位置的比對情況
這里由于微信公眾號的顯示,不能很好地展示,就不放出來了,建議大家自己親自嘗試,以獲取更好的理解。
下一個過濾標(biāo)準(zhǔn)是根據(jù)參考和備用等位基因之間的比對質(zhì)量比率來過濾
vcffilter -f "MQM / MQMR > 0.9 & MQM / MQMR < 1.05" DP3g95p5maf05.fil2.vcf > DP3g95p5maf05.fil3.vcf
這里過濾的基本原理是,因為RADseq基因座和等位基因都應(yīng)該從相同的基因組位置開始,所以兩個等位基因的作圖質(zhì)量之間不應(yīng)該存在很大的差異。看看剩余的基因座數(shù)目:
mawk '!/#/' DP3g95p5maf05.fil3.vcf | wc -l
9229
這過濾掉了不到3%的變體,但可能還需要進(jìn)行過濾。
繼續(xù)過濾,根據(jù)它們是否支持參考或備選等位基因的reads的正確配對狀態(tài)的差異進(jìn)行過濾。
vcffilter -f "PAIRED > 0.05 & PAIREDR > 0.05 & PAIREDR / PAIRED < 1.75 & PAIREDR / PAIRED > 0.25 | PAIRED < 0.05 & PAIREDR < 0.05" -s DP3g95p5maf05.fil3.vcf > DP3g95p5maf05.fil4.vcf
由于從頭組裝并不完美,因此某些基因座只會將unpaired的reads比對到它們。這不是問題。當(dāng)支持參考等位基因的所有reads是paired但不支持備用等位基因時,會出現(xiàn)問題,所以要將其過濾。
mawk '!/#/' DP3g95p5maf05.fil4.vcf | wc -l
9166
可以看到,我們的位點數(shù)量逐漸減少,但我們的信噪比不斷增加。
額外的過濾步驟
因為reads不是隨機(jī)分布在contigs上的,所以可以進(jìn)一步過濾,首先:刪除任何質(zhì)量得分低于深度1/4的基因座。
vcffilter -f "QUAL / DP > 0.25" DP3g95p5maf05.fil4.vcf > DP3g95p5maf05.fil5.vcf
第二步更復(fù)雜。先創(chuàng)建每個基因座深度的列表:
cut -f8 DP3g95p5maf05.fil5.vcf | grep -oe "DP=[0-9]*" | sed -s 's/DP=//g' > DP3g95p5maf05.fil5.DEPTH
第二步是創(chuàng)建質(zhì)量得分列表。
mawk '!/#/' DP3g95p5maf05.fil5.vcf | cut -f1,2,6 > DP3g95p5maf05.fil5.vcf.loci.qual
下一步是計算平均深度:
mawk '{ sum += $1; n++ } END { if (n > 0) print sum / n; }' DP3g95p5maf05.fil5.DEPTH
1952.82
現(xiàn)在平均值加上平均值的3倍
python -c "print int(1952+3*(1952**0.5))"
2084
接下來,我們將深度和質(zhì)量文件粘貼在一起,找到截止點上方?jīng)]有質(zhì)量分?jǐn)?shù)2倍深度的位點
paste DP3g95p5maf05.fil5.vcf.loci.qual DP3g95p5maf05.fil5.DEPTH | mawk -v x=2084 '$4 > x' | mawk '$3 < 2 * $4' > DP3g95p5maf05.fil5.lowQDloci
現(xiàn)在我們可以刪除這些位點,并使用VCFtools重新計算基因座的深度。
cftools --vcf DP3g95p5maf05.fil5.vcf --site-depth --exclude-positions DP3g95p5maf05.fil5.lowQDloci --out DP3g95p5maf05.fil5
現(xiàn)在讓我們將VCFtools輸出并將其切割為僅深度分?jǐn)?shù)
cut -f3 DP3g95p5maf05.fil5.ldepth > DP3g95p5maf05.fil5.site.depth
現(xiàn)在讓我們通過將上述文件除以個體數(shù)量(31)來計算平均深度
mawk '!/D/' DP3g95p5maf05.fil5.site.depth | mawk -v x=31 '{print $1/x}' > meandepthpersite
具有高平均深度的基因座指示旁系同源物或多拷貝基因座。無論哪種方式,我們都想刪除它們。在這里,我將刪除平均深度為102.5以上的所有位點。現(xiàn)在我們可以組合兩個過濾器來生成另一個VCF文件。
vcftools --vcf DP3g95p5maf05.fil5.vcf --recode-INFO-all --out DP3g95p5maf05.FIL --max-meanDP 102.5 --exclude-positions DP3g95p5maf05.fil5.lowQDloci --recode
最后,VCFtools在可能的9164位點中保留了8417個。
這個教程主要是展示了如果從多角度進(jìn)行過濾的可能性,但實際上很多paper 或者project都不可能考慮到那么仔細(xì),一般只是按照一些比較標(biāo)準(zhǔn)的過濾標(biāo)準(zhǔn)進(jìn)行過濾(下節(jié)再討論)。