3
$\begingroup$

I am evaluating the tool somalier (https://github.com/brentp/somalier) and I need to create a list of about 65,000 SNPs where the allele frequency (AF) is as close to 0.5 as possible across the most representative set of populations possible with today's data.

My alignments are in GRCh38, so I need a vcf input file for somalier also in GRCh38, not the one that is available in the somalier website, which is in GRCh37.

I am starting as input with the vcfs from the 1000genomes project in GRCh38 positions, and I would like to come up with a filtering strategy that: (1) Sorts all SNPs by the AF being close to 0.5 in as many populations as possible. (2) Takes the first 65,000 SNPs from that list and produces a vcf file from them.

My simplistic strategy so far has been to take the global AF value if it's between 0.3-0.7 and print it if it's a SNP with this perl one-liner:

gunzip -c my.vcf.gz | grep -v '#' | perl -lne 'if ($_ =~ /\;AF=0\.[34567]/) { if ($_ =~ /\w+\t\d+\t\S+\t\w\t\w\t/) {print $_} }'

Any recommendations?

$\endgroup$
4
  • $\begingroup$ If possible, I strongly urge you to use hg19 instead of GRCh38 because there are much better frequency data available. Basically, GnomAD uses hg19, so any gnomAD frequencies for hg38 will come from lifting over the positions and that doesn't work too well in my experience. $\endgroup$
    – terdon
    Feb 8, 2019 at 14:17
  • $\begingroup$ I haven't been able to reliably liftover the sites.vcf.gz file that can be downloaded from the github.com/brentp/somalier site. I will create another Q for the liftover issue. $\endgroup$
    – 719016
    Feb 8, 2019 at 14:24
  • $\begingroup$ What do you mean? Somalier's github page says it's for hg19, not hg38: "where sites is a VCF of variant sites (provided by somalier for hg19)." $\endgroup$
    – terdon
    Feb 8, 2019 at 14:33
  • $\begingroup$ My alignments are in GRCh38, so I need a vcf input file for somalier also in GRCh38, not the one that is in GRCh37 (gh19). $\endgroup$
    – 719016
    Feb 8, 2019 at 14:47

2 Answers 2

5
$\begingroup$

Just use bcftools view for filtering:

$ bcftools view -i 'AF>0.3 && AF<0.7' input.vcf.gz > output.vcf

To truncate this list to 65,000 SNPs count the header lines, sum them to the number of SNPs you like to have and use head -n.

$ bcftools view -h input.vcf.gz|wc -l
255

$ bcftools view -i 'AF>0.3 && AF<0.7' input.vcf.gz | head -n 65255 > output.vcf
$\endgroup$
3
$\begingroup$

Using bcftools is the right way, but you could also greatly simplify the command you're using. You can do the same thing with a single zgrep call:

zgrep -P '^[^#]+\t\d+\t\S+\t\w\t\w\t.*;AF=0\.[3-7]' my.vcf.gz

And to limit to the first 65000 results:

zgrep -m 65000 -P '^[^#]+\t\d+\t\S+\t\w\t\w\t.*;AF=0\.[3-7]' my.vcf.gz

Finally, to keep the header of the original vcf unchanged, you could do:

zgrep -m 65000 -P '^(#|[^#]+\t\d+\t\S+\t\w\t\w\t.*;AF=0\.[3-7])' my.vcf.gz

I also suggest you use hg19 instead of hg38 data since the best available source for frequencies, the gnomAD database, is based on hg19 and the tool you want to test also provides a site file for hg19. But that may not be possible for you.

If your VCF file has multiple AF entries for different sub-populations and you want to use those, you'll probably need to script something. We can't really help with that unless you show us some example input lines and start writing the basic script yourself though.

$\endgroup$
2
  • 1
    $\begingroup$ I have a different opinion about that. hg19 is outdated sind 2013. Whenever you start something new, you should move to the current reference genome, which is by now hg38. There are lifted over versions of 1000 Genomes, ExAC and gnomAD which provide at least the frequency data by ensembl. As long as the frequency data are given in the INFO column you can easily filter by them using bcftools. So there is no need to script something. $\endgroup$
    – finswimmer
    Feb 8, 2019 at 19:07
  • $\begingroup$ @finswimmer not sure what you are referring to, but if it's about hg38, I am not saying hg19 is better (it isn't) only that the gnomAD data is based on hg19 and liftover is imperfect. As for the rest, yes of course bcftools is the way to go! $\endgroup$
    – terdon
    Feb 8, 2019 at 19:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.